is_range?

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

is_range?

adrianv
I see that we now have is_list(), is_num(), is_bool(), and is_string(), but
there is no is_range.  It seems like maybe right now you can write

function is_range(x) = !is_list(x) && !is_num(x) && !is_bool(x) &&
!is_string(x), but I'm not sure if I've missed anything, and this seems kind
of clumsy.  Also it's problematic down the road if a new type is ever added.  

Have I missed something here?  




--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
tp3
Reply | Threaded
Open this post in threaded view
|

Re: is_range?

tp3
On 16.03.19 16:06, adrianv wrote:
> I see that we now have is_list(), is_num(), is_bool(), and is_string(), but
> there is no is_range.  It seems like maybe right now you can write

It's not likely that is_range() will ever be added.

See https://github.com/openscad/openscad/issues/1584 for details.

ciao,
   Torsten.



_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
-- Torsten
Reply | Threaded
Open this post in threaded view
|

Re: is_range?

doug.moen
In issue 1584, I was proposing that range values should behave exactly like lists of numbers, so that is_list([1:3]) would be true. I proposed this for OpenSCAD2 and implemented it in Curv. If there are no plans to ever unify lists and ranges in OpenSCAD, then it would make sense to introduce an is_range function.

On Sat, Mar 16, 2019, at 11:23 AM, Torsten Paul wrote:

> On 16.03.19 16:06, adrianv wrote:
> > I see that we now have is_list(), is_num(), is_bool(), and is_string(), but
> > there is no is_range.  It seems like maybe right now you can write
>
> It's not likely that is_range() will ever be added.
>
> See https://github.com/openscad/openscad/issues/1584 for details.
>
> ciao,
>    Torsten.
>
>
>
> _______________________________________________
> OpenSCAD mailing list
> [hidden email]
> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
>

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: is_range?

Parkinbot
In reply to this post by adrianv
function is_range(A) = is_num(A[0]) && !is_list(A);




--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: is_range?

runsun
This post was updated on .
In reply to this post by adrianv
NOTE: I delete this post 'cos the syntax is wrong. See a corrected/tested version in my post below this one.


$ Runsun Pan, PhD
$ libs: scadx, doctest, faces(git), offline doc(git), runscad.py(2,git), editor of choice: CudaText ( OpenSCAD lexer); $ Tips; $ Snippets
Reply | Threaded
Open this post in threaded view
|

Re: is_range?

runsun
My apology to the group for the wrong syntax in my previous post. I have been working on javascript intensively and mess it up in my head with the syntax of OpenSCAD. Here is the correct and tested one:
function is_range(o, _d, _i=0) =
(
   _i==0?
     ( isnum(o[0]) && isnum(o[1])?
       is_range( o, _d= o[1]-o[0], _i=1)
       : false 
     )   
   : _i<len(o)-1?
     ( isnum(o[_i+1]) && _d != o[_i+1]-o[_i] ? false
     : is_range( o, _d=_d, _i=_i+1)   
     )
   : true
 );
</pre>

Test:
| 0> is_range([2:6])= true
| 1> is_range([2:2:10])= true
| 2> is_range([1,2,3])= true
| 3> is_range([1,2,3,5])= false
| 4> is_range("abc")= false
$ Runsun Pan, PhD
$ libs: scadx, doctest, faces(git), offline doc(git), runscad.py(2,git), editor of choice: CudaText ( OpenSCAD lexer); $ Tips; $ Snippets


Sent from the OpenSCAD mailing list archive at Nabble.com.

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
$ Runsun Pan, PhD
$ libs: scadx, doctest, faces(git), offline doc(git), runscad.py(2,git), editor of choice: CudaText ( OpenSCAD lexer); $ Tips; $ Snippets
Reply | Threaded
Open this post in threaded view
|

Re: is_range?

Parkinbot
runsun wrote
> is_range([1,2,3])= true

I would expect a false in this case.



--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org