On 01/06/2016 02:21 AM, Neon22 wrote:
Rather than go for a C style of loop I'd rather see a more lisp
and python kind of control.
For marketing purposes, we really have to call it python style,
sorry ;-) ...just joking... I think.
So, I guess we can't just change the whole list comprehension
syntax and break all the recently made scripts using it.
But there's a number of features that we could adopt by adding
new actions to the list comprehensions. One problem is that it
currently uses keywords for the list comprehension names, but
hopefully that can be changed in the parser (e.g. "each = 3;"
is now invalid with the latest changes due to that).
I'll have a look at the loop macro in lisp. At first glance
it seems most of the simple list generation features could be
somehow mapped to the OpenSCAD list comprehensions already.
The list and numeric accumulation might be a nice extension,
but I'm not sure how good those fit into the existing expression
code. But then the code is there to be changed, right :-).
ciao,
Torsten.
Thanks Torsten,
Note there is also a specific iterator called "across" which deals with
vectors.
Having a purpose helper iterator for triplets or doublets in OpenSCAD could
be useful.
Also I forgot about "return" to send back a single value instead of a list.
s = "alpha45";
[ for i=[0:len(s)]
for ch = chr(s[i])
when (ch==51)
return ch ]
we might not need all of them
Cheers...
--
View this message in context: http://forum.openscad.org/List-comprehensions-tp15321p15511.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
In the functional programming community, there's this idea that explicit
recursion is the "goto" of functional programming
I don't buy that as goto can make unstructured spaghetti which is hard to
read and analyze. Recursion is a succinct description of the result in
mathematical terms. Here is runsun's sequence:
function f(i) = i == 1 ? 1 : (f(i-1) + i) * i;
echo([for(i = [1 : 4]) f(i)]);
ECHO: [1, 6, 27, 124]
For me that is the most readable version so far and doesn't require any new
complication of the language. Having mutable variables in loops and not
outside is going to be very difficult to explain. You could argue for
instance that any variable that only has the scope of the loop could be
mutable in the loop body as each iteration is actually a new scope.
OpenScad is very simple language that can be learnt in hours. Please leave
all the complicated stuff for OpenScad2. Try not to end up with C++ that
actually nobody understands all of completely.
On 6 January 2016 at 06:33, Neon22 mschafer@wireframe.biz wrote:
Thanks Torsten,
Note there is also a specific iterator called "across" which deals with
vectors.
Having a purpose helper iterator for triplets or doublets in OpenSCAD could
be useful.
Also I forgot about "return" to send back a single value instead of a list.
s = "alpha45";
[ for i=[0:len(s)]
for ch = chr(s[i])
when (ch==51)
return ch ]
we might not need all of them
Cheers...
--
View this message in context:
http://forum.openscad.org/List-comprehensions-tp15321p15511.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
I agree with Torsten; we can't just throw out list comprehensions and
replace them with an incompatible syntax. The current syntax is popular and
works well.
Neon22, if you are serious about this, then you should propose something
that is an upward compatible extension of the current list comprehension
syntax. That might lead to a better discussion.
My impression of the Lisp LOOP macro is that it is extremely complicated.
It would really suck to hard code all of that syntax into the OpenSCAD
internals. The only reason that this exists in Lisp is that it isn't hard
coded, it is a user written library. I've got a copy of the Common Lisp
standard, and it lists 3 different loop libraries that you can choose from:
the LOOP macro, the Series package, and the Generator/Gatherer package.
List comprehensions are a popular feature that have been implemented in
many or most mainstream languages. But I've never heard of any other
language that has implemented the LOOP syntax. Why would that be?
What most languages provide, instead of a huge pile of syntax and keywords
like LOOP, is a library of list manipulation functions that can be composed
together, as an alternative to writing tail recursive loops over lists. All
of the examples you provided can be written in terms of list functions,
maybe in combination with list comprehensions. And these functions have
been mostly standardized across languages, with minor variations in naming.
I'm talking about map, filter, foldl/reduce, and so on.
I'm confused about your reference to a "lisp and python style of control".
Python doesn't have anything like the LOOP macro. What Lisp and Python have
in common is a standard set of high level list functions, as do most other
languages in this space.
Many of the standard list functions take functions as arguments, but that
problem is solved by OpenSCAD2, which allows functions to be passed as
arguments. The good thing about a list function library is that it doesn't
have to be hard coded into OpenSCAD. If you don't like somebodies list
library, you can write your own.
On 5 January 2016 at 22:03, Torsten Paul Torsten.Paul@gmx.de wrote:
On 01/06/2016 02:21 AM, Neon22 wrote:
Rather than go for a C style of loop I'd rather see a more lisp
and python kind of control.
For marketing purposes, we really have to call it python style,
sorry ;-) ...just joking... I think.
So, I guess we can't just change the whole list comprehension
syntax and break all the recently made scripts using it.
But there's a number of features that we could adopt by adding
new actions to the list comprehensions. One problem is that it
currently uses keywords for the list comprehension names, but
hopefully that can be changed in the parser (e.g. "each = 3;"
is now invalid with the latest changes due to that).
I'll have a look at the loop macro in lisp. At first glance
it seems most of the simple list generation features could be
somehow mapped to the OpenSCAD list comprehensions already.
The list and numeric accumulation might be a nice extension,
but I'm not sure how good those fit into the existing expression
code. But then the code is there to be changed, right :-).
ciao,
Torsten.
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
It was not my intention to start a flame war, merely to point out the way
another language did it.
I was referring to SCL:loop macro.
Python started with reduce and map - since removed due to pressure from C++
style people. Just because its good doesn't mean everyone adopts it. I can't
believe I have to explain this.
Just because there is another way to do it is not an attack on OpenSCAD 1 or
2 (which I rather like).
The entire Genera OS was written in lisp on a lisp machine. Yes an entire OS
in Lisp. It remains the best development system I worked on and the oldest
registered domain on the web - even though SMBX the company has gone. But
that's my problem not yours.
for OpenSCAD:
add structured assignment:
[for ([a b]=[[1 2] [3 4] [5 6]]) [b a] ]
giving [[2 1] [4 3] [6 5]]
add from
[ for (i=[1:10], j from 2) i*j ]
where j starts at 2 and counts up. the i variable sets the termination of
the loop
from could not appear on its own without a termination clause.
loop terminatoin with while, or until, or just one and use not operator
for the other - for readability
[ for (x=1,2,3,4,5,6], while prime(x)) [ x, x*x] ]
returning list of [x,x^2] until first non-prime encountered.
define more internal loop variables. inner scope only
[for (x=1,2,3,4,5,6], start=12) x*start ]
I can't imagine how to do if-then constructs and collect inside the
existing syntax.
Cheers everyone...
--
View this message in context: http://forum.openscad.org/List-comprehensions-tp15321p15534.html
Sent from the OpenSCAD mailing list archive at Nabble.com.