discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

each - Assertion failed on flat list

P
Parkinbot
Fri, Apr 27, 2018 9:55 PM

@Marius. The following is nonsense from a semantical point of view, but it
shouldn't fail.

a = [each for(i=[1]) i];

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

@Marius. The following is nonsense from a semantical point of view, but it shouldn't fail. a = [each for(i=[1]) i]; -- Sent from: http://forum.openscad.org/
R
runsun
Fri, Apr 27, 2018 10:17 PM

shouldn't 'each' be always followed by a list ?


$  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/

shouldn't 'each' be always followed by a list ? ----- $ 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/
DM
doug moen
Fri, Apr 27, 2018 10:28 PM

Yes, but OpenSCAD shouldn't crash on a syntax error.

On 27 April 2018 at 18:17, runsun runsun@gmail.com wrote:

shouldn't 'each' be always followed by a list ?


$  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/


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

Yes, but OpenSCAD shouldn't crash on a syntax error. On 27 April 2018 at 18:17, runsun <runsun@gmail.com> wrote: > shouldn't 'each' be always followed by a list ? > > > > ----- > > $ 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/ > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >
P
Parkinbot
Fri, Apr 27, 2018 11:28 PM

@runsun in general the parser doesn't know what a for loop will return. Thus
it is not a syntax error

E.g. this is correct:

a = [each for(i=[1,2]) [i]];

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

@runsun in general the parser doesn't know what a for loop will return. Thus it is not a syntax error E.g. this is correct: a = [each for(i=[1,2]) [i]]; -- Sent from: http://forum.openscad.org/
NH
nop head
Sat, Apr 28, 2018 7:34 AM

Or this

a = [each [for(i=[1]) i]];

Rather than assert should it return undef or just return the scalar?

On 28 April 2018 at 00:28, Parkinbot rudolf@parkinbot.com wrote:

@runsun in general the parser doesn't know what a for loop will return.
Thus
it is not a syntax error

E.g. this is correct:

a = [each for(i=[1,2]) [i]];

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


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

Or this a = [each [for(i=[1]) i]]; Rather than assert should it return undef or just return the scalar? On 28 April 2018 at 00:28, Parkinbot <rudolf@parkinbot.com> wrote: > @runsun in general the parser doesn't know what a for loop will return. > Thus > it is not a syntax error > > E.g. this is correct: > > a = [each for(i=[1,2]) [i]]; > > > > > > -- > Sent from: http://forum.openscad.org/ > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >
P
Parkinbot
Sat, Apr 28, 2018 8:58 AM

I would expect a run time error.

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

I would expect a run time error. -- Sent from: http://forum.openscad.org/
MK
Marius Kintel
Sat, Apr 28, 2018 4:00 PM

On Apr 27, 2018, at 5:55 PM, Parkinbot rudolf@parkinbot.com wrote:

@Marius. The following is nonsense from a semantical point of view, but it
shouldn't fail.

a = [each for(i=[1]) i];

> On Apr 27, 2018, at 5:55 PM, Parkinbot <rudolf@parkinbot.com> wrote: > > @Marius. The following is nonsense from a semantical point of view, but it > shouldn't fail. > > a = [each for(i=[1]) i]; > This is covered by https://github.com/openscad/openscad/issues/1851 -Marius
TP
Torsten Paul
Sat, Apr 28, 2018 7:11 PM

On 04/28/2018 10:58 AM, Parkinbot wrote:

I would expect a run time error.

Why? What's the benefit of making it an error?

The proposal for each reads:
https://github.com/doug-moen/openscad2/blob/master/rfc/Generators.md

The each operator is new: it takes a sequence value
as argument, and adds each element to the list being
constructed. each x is equivalent to for(i=x)i.

So according to that, both lines should be identical:

echo([for(i=3) i]);
echo([each 3]);

The first one currently gives
ECHO: [3]

ciao,
Torsten.

On 04/28/2018 10:58 AM, Parkinbot wrote: > I would expect a run time error. > Why? What's the benefit of making it an error? The proposal for each reads: https://github.com/doug-moen/openscad2/blob/master/rfc/Generators.md > The each operator is new: it takes a sequence value > as argument, and adds each element to the list being > constructed. each x is equivalent to for(i=x)i. > So according to that, both lines should be identical: echo([for(i=3) i]); echo([each 3]); The first one currently gives ECHO: [3] ciao, Torsten.
P
Parkinbot
Sat, Apr 28, 2018 10:40 PM

Torsten,

I wanted to say, I'd rather expect a runtime error instead of a failure! But
you are right, "each" can be implemented to not fail in this situation. Thus

a = [each for(i=[1:10]) i];

should be equivalent to

a = [for(i=[1:10]) i];

Why is this important? Because I want to write e.g.

a = [each for(i=[1:10]) myfunc(i)];

and there is no guarantee that e.g. myfunc() will return only list elements.

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

Torsten, I wanted to say, I'd rather expect a runtime error instead of a failure! But you are right, "each" can be implemented to not fail in this situation. Thus a = [each for(i=[1:10]) i]; should be equivalent to a = [for(i=[1:10]) i]; Why is this important? Because I want to write e.g. a = [each for(i=[1:10]) myfunc(i)]; and there is no guarantee that e.g. myfunc() will return only list elements. -- Sent from: http://forum.openscad.org/
TP
Torsten Paul
Sun, Apr 29, 2018 12:10 PM

Yes, that's what I was thinking too.

Test cases:
https://github.com/openscad/openscad/blob/a9a4ab2dba80bedddbbe4b6ae84238bce5913d89/testdata/scad/bugs/issue1851-each-fail-on-scalar.scad

echo([each for(i=1) i]);
echo([each for(i=[1,2]) i]);
echo([each for(i=[1,2,[3,4]]) i]);
echo([each for(i=[1,2,[3,4,[5,6]]]) i]);
echo([each each for(i=[1,2,[3,4,[5,6]]]) i]);
echo([each each for(i=[1,2,[3,4,[5,6,[7,8]]]]) i]);
echo([each each each for(i=[1,2,[3,4,[5,6,[7,8]]]]) i]);

Output:
https://github.com/openscad/openscad/blob/a9a4ab2dba80bedddbbe4b6ae84238bce5913d89/tests/regression/echotest/issue1851-each-fail-on-scalar-expected.echo

ECHO: [1]
ECHO: [1, 2]
ECHO: [1, 2, 3, 4]
ECHO: [1, 2, 3, 4, [5, 6]]
ECHO: [1, 2, 3, 4, 5, 6]
ECHO: [1, 2, 3, 4, 5, 6, [7, 8]]
ECHO: [1, 2, 3, 4, 5, 6, 7, 8]

Any other cases I may have missed?

ciao,
Torsten.

Yes, that's what I was thinking too. Test cases: https://github.com/openscad/openscad/blob/a9a4ab2dba80bedddbbe4b6ae84238bce5913d89/testdata/scad/bugs/issue1851-each-fail-on-scalar.scad echo([each for(i=1) i]); echo([each for(i=[1,2]) i]); echo([each for(i=[1,2,[3,4]]) i]); echo([each for(i=[1,2,[3,4,[5,6]]]) i]); echo([each each for(i=[1,2,[3,4,[5,6]]]) i]); echo([each each for(i=[1,2,[3,4,[5,6,[7,8]]]]) i]); echo([each each each for(i=[1,2,[3,4,[5,6,[7,8]]]]) i]); Output: https://github.com/openscad/openscad/blob/a9a4ab2dba80bedddbbe4b6ae84238bce5913d89/tests/regression/echotest/issue1851-each-fail-on-scalar-expected.echo ECHO: [1] ECHO: [1, 2] ECHO: [1, 2, 3, 4] ECHO: [1, 2, 3, 4, [5, 6]] ECHO: [1, 2, 3, 4, 5, 6] ECHO: [1, 2, 3, 4, 5, 6, [7, 8]] ECHO: [1, 2, 3, 4, 5, 6, 7, 8] Any other cases I may have missed? ciao, Torsten.