I hope that examples like this, and nophead's, will make it into some
documentation, so that people do not have to reinvent the wheel.
Jon
On 9/7/2016 9:07 AM, Ronaldo wrote:
Counting ocurrences of some event was one of the first astonishing task stuck
me in my first steps in OpenSCAD when I found that variables are immutable.
I finally arrived to this non recursive solution:
len( [ for(element=list) if(event_predicate(element)) 1] )
For the problem of finding the first ocurrence of an event, you always can
do:
[ for(element=list) if(event_predicate(element)) element ][0]
Another surprising task was to add up the elements of a list. Now I have a
bunch of solutions to that.
Besides given better name to what is called now variables, it is important
to ilustrate the techniques for common tasks like those in the manual.
+1 for parameters.
please also consider that - besides in loops - its useful to have
changeable variables for those of us who want to use random sequences
with seeds for procedural variations in the design.
This is hard to control right now.
Neon22 wrote
please also consider that - besides in loops - its useful to have
changeable variables for those of us who want to use random sequences
with seeds for procedural variations in the design.
I don't believe that will help you.
The language is defined such that every procedure call is determinate.
Therefore the result of calling your Random() function can be assumed to be
constant and so it only needs to be called once. Even if it does get called
every time you want it to be, you can never predict the order in which each
instance is called.
It's messy, but it can be done. Here's one way.
So for example if B() used two numbers and C() used three, then A(), which
called B and C would use five. It would call B with a base index the same as
the base index it was given, and then it would call C with the base index
plus two.
--
View this message in context: http://forum.openscad.org/What-to-call-variables-tp18260p18344.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
How about for starters, we deprecate the ability to reassign. In the GUI, so command line -D is OK.
That will make it clear that such usage is not normal.