@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/
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/
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
@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/
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
I would expect a run time error.
--
Sent from: http://forum.openscad.org/
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
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.
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/
Yes, that's what I was thinking too.
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]);
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.