discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

is_range?

A
adrianv
Sat, Mar 16, 2019 3:06 PM

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/

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/
TP
Torsten Paul
Sat, Mar 16, 2019 3:22 PM

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.

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.
DM
Doug Moen
Sun, Mar 17, 2019 12:22 AM

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
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

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 > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >
P
Parkinbot
Sun, Mar 17, 2019 1:32 AM

function is_range(A) = is_num(A[0]) && !is_list(A);

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

function is_range(A) = is_num(A[0]) && !is_list(A); -- Sent from: http://forum.openscad.org/
R
runsun
Sun, Mar 17, 2019 6:33 AM

A range checker needs to fulfill:

-- a list of all numbers
-- same distance for all i~i+1 pairs
function is_range(o, _d, _i=0){  _i==0?    ( is_num(o[0]) && is_num(o[1])?
is_range( o, _d= o[1]-o[0], _i=1)      : false      )      : _i<length-1?
( is_num(o[i+1]) && _d != o[i+1]-o[i] ? false    : is_range( o,
_d=_d, _i=_i+1)        )  : true}</pre>
This code has not been tested yet.


$  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: http://forum.openscad.org/

A range checker needs to fulfill: -- a list of all numbers -- same distance for all i~i+1 pairs function is_range(o, _d, _i=0){ _i==0? ( is_num(o[0]) && is_num(o[1])? is_range( o, _d= o[1]-o[0], _i=1) : false ) : _i<length-1? ( is_num(o[i+1]) &amp;&amp; _d != o[i+1]-o[i] ? false : is_range( o, _d=_d, _i=_i+1) ) : true}&lt;/pre> This code has not been tested yet. ----- $ Runsun Pan, PhD $ libs: scadx , doctest , faces ( git ), offline doc ( git ), runscad.py ( 2 , git ), editor of choice: CudaText ( OpenSCAD lexer );&nbsp;$ Tips ;&nbsp;$ Snippets -- Sent from: http://forum.openscad.org/
R
runsun
Sun, Mar 17, 2019 5:00 PM

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: http://forum.openscad.org/

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]) &amp;&amp; _d != o[_i+1]-o[_i] ? false : is_range( o, _d=_d, _i=_i+1) ) : true );&lt;/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 );&nbsp;$ Tips ;&nbsp;$ Snippets -- Sent from: http://forum.openscad.org/
P
Parkinbot
Sun, Mar 17, 2019 9:09 PM

runsun wrote

is_range([1,2,3])= true

I would expect a false in this case.

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

runsun wrote > is_range([1,2,3])= true I would expect a false in this case. -- Sent from: http://forum.openscad.org/