If you want to add iterativeness, please put it behind syntax so the person describing the part is explicit when they say "Yes, I want to do iterative work now", and at least blocklevel, so the parser isn't stuck assuming that everything depends on previous stuff. That should make things less crazy for the rest of the compiler and still allow some measure of parallelism. This is how two of the other big HDLs (Verilog and VHDL) do it with their behavioral modes. It's still a pain, as you can easily have a stack of dependencies. Alternatively, you can instead use a real programming language to generate OpenSCAD syntax (SolidPython, scripts, etc), so you get the comforting and familiar iterativeness. Joseph Lenox On Tue, Feb 3, 2015 at 2:38 PM, Adrian Grajdeanu <[hidden email]> wrote:
_______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org 
In reply to this post by adriang
>Finally then, absent variables in the language .., can everything
be done? Yes everything can be done with recursion. I don't know why people say yuck. It's much more like pure maths and far easier to see that it is correct.On 3 February 2015 at 20:38, Adrian Grajdeanu <[hidden email]> wrote:
_______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org 
function sum(v,i = 0) = i < len(v) ? v[i] + sum(v, i+1) : 0;
function ave(v) = sum(v) / len(v); How can you get clearer or more concise than that? On 3 February 2015 at 20:52, nop head <[hidden email]> wrote:
_______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org 
Administrator

This post was updated on .
In reply to this post by adriang
oops
OpenSCAD Admin  email* me if you need anything, or if I've done something stupid...
* on the Forum, click on my MichaelAtOz label, there is a link to email me. Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. Obviously inclusion of works of previous authors is not included in the above. 
In reply to this post by adriang
"The thing to remember with OpenSCAD is that it is timeless."
This cannot be true. Otherwise, "rotate translate object" would be nondeterministicly identical to "translate rotate object", and they're not. Where object ends up depends on which transformation gets executed first. And if something gets executed "first", then time is involved. 
On Tue, Feb 3, 2015 at 4:28 PM, Michele <[hidden email]> wrote:
> /"The thing to remember with OpenSCAD is that it is timeless."/ > > This cannot be true. Otherwise, "rotate translate object" would be > nondeterministicly identical to "translate rotate object", and they're not. > Where object ends up depends on which transformation gets executed first. > And if something gets executed "first", then time is involved. "Timeless" does not mean "NonHierarchical". R T O is not the same as T R O because it's R>T not T>R. There is an order, but it's not iterative nor is there a frozen "moment in time" one could peek at the state of things and alter the outcome. ethan _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org 
In reply to this post by nophead
I don't have a problem with OpenSCAD, because I treat it as a functional language (with some recursion limitations), and everything is fine. There are ways to implement variable modification in functional languages by including a data store as an additional function parameter  I'd have to dig out my CS notes to find the way I was taught  but it's frequently the case that such a design is not necessary.
The 'concat' operator was, in my opinion, the final advance to make the language essentially turing complete (and therefore fully expressive). However, for proper use of functional languages, recursion is required in many cases. Thinking about the vector sum question, here's a recursive version that basically uses assignment. The "cumSum" argument stores the current sum, and the "pos" argument stores the current location in the vector: function vsum(vec, pos = 0, cumSum = 0) = pos >= len(vec) ? cumSum : vsum(vec, pos+1, cumSum + vec[pos]); echo(vsum([1,2,3,8])); 
In reply to this post by adriang
I see three complaints.
* OpenSCADs handling of variables is suboptimal. True, although there were some large improvements recently. * OpenSCAD is lacking as a functional language. True. * OpenSCAD lacks a destructive update operator (cstyle assignment). This is inherent to the way Openscad models the target domain (constructive solid geometry) and it can not possibly change, because it would violate that union is a commutative operator. A destructive update operator would have to be valid only in certain very limited places, causing even more confusion. Example: b = 5; union() { // Union operator // Operand A union() { b = b + 5; sphere(d=b, $fn=50); } // Operand B union() { b = b + 5; translate([40, 0, 0]) cube(b, center=true); } } Both shapes have size 10, because each subunion() creates its own variable b that shadows the global b. In C you would be able to reassign the global b. In this case the sphere would have d=5+5=10, and the cube would get size 5+5+5 = 15. By swapping the order of operand a and b, the sphere would be 15 and the cube 10. Union() is a commutative operator, meaning that the result does not depend on the order of the operands. Allowing reassignment breaks this fundamental property of union(). Have a nice day, Bananapeel :) 
Administrator

In reply to this post by MichaelAtOz
Yes we have been over this before more than once. Once you grok OpenSCAD it all makes sense. Unless I see objections, I will start a project to change the wiki to use 'identifier', 'definition', 'constant' and 'redefinable' as needed, and point out the D rationale. [eventually...]
OpenSCAD Admin  email* me if you need anything, or if I've done something stupid...
* on the Forum, click on my MichaelAtOz label, there is a link to email me. Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. Obviously inclusion of works of previous authors is not included in the above. 
You have my objection. They are variables in the mathematical sense. A symbol that represents a quantity in a mathematical expression. http://en.wikipedia.org/wiki/Variable Variable (mathematics), a symbol that represents a quantity in a mathematical expression, as used in many sciences Variable (computer science), a symbolic name associated with a value and whose associated value may be changed 
I'm comfortable with calling them variables, but I suppose they could be called parameters instead. The wikipedia definition suggests that "parameter" might be appropriate in a mathematical sense:
http://en.wikipedia.org/wiki/Parameter#Mathematical_functions "Mathematical functions have one or more arguments that are designated in the definition by variables. A function definition can also contain parameters, but unlike variables, parameters are not listed among the arguments that the function takes. When parameters are present, the definition actually defines a whole family of functions, one for every valid set of values of the parameters." The Variable wikipedia page defines parameters as a subclass of variables: http://en.wikipedia.org/wiki/Variable_%28mathematics%29#Specific_kinds_of_variables "To distinguish them, the variable x is called a unknown, and the other variables are called parameters or coefficients, or sometimes constants, although this last terminology is incorrect for an equation and should be reserved for the function defined by the lefthand side of this equation." It also works well with calling OpenSCAD files "parametric designs". However, "parameters" and "unknowns" are indistinguishable in code (and in a formula, for that matter), which would make explaining the difference a little bit more difficult to a naive person: unknowns appear in the argument list of the function. 
In reply to this post by Bananapeel
The "constants" that are used in OpenSCAD cannot be changed, so they are
not "variable" or "variables". These discussions about "variables" come up once a month. They consume time. And they frustrate many people away from OpenSCAD (I assume that for every newbie who persists in asking questions here, a dozen simply give up and wander off). In my opinion, the OpenSCAD community needs to explain the language in a way that is accessible to the average programmer (think "C" rather than "declarative") without many newbies having to reinvent the variable wheel. The discussion around OpenSCAD " variables" in the manual/documentation needs to include the meat of the discussions that we have on a regular basis with newbies. Jon On 2/3/2015 6:36 PM, Bananapeel wrote: > MichaelAtOz wrote >> Unless I see objections, I will start a project to change the wiki to use >> 'identifier', 'definition', 'constant' and 'redefinable' as needed, and >> point out the D rationale. [eventually...] > You have my objection. They are variables in the mathematical sense. A > symbol that represents a quantity in a mathematical expression. > > http://en.wikipedia.org/wiki/Variable > Variable (mathematics), a symbol that represents a quantity in a > mathematical expression, as used in many sciences > Variable (computer science), a symbolic name associated with a value and > whose associated value may be changed > > > > > >  > View this message in context: http://forum.openscad.org/AA1tp11385p11425.html > Sent from the OpenSCAD mailing list archive at Nabble.com. > > _______________________________________________ > OpenSCAD mailing list > [hidden email] > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > > > >  > No virus found in this message. > Checked by AVG  www.avg.com > Version: 2015.0.5646 / Virus Database: 4281/9052  Release Date: 02/03/15 > > _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org 
"You have my objection. They are variables in the mathematical sense. A
symbol that represents a quantity in a mathematical expression." I agree with Mr. Peel and cast my vote similarly. 
Yes, but using the mathematical definition contributed to this problem. To the layperson variable usually implies, in this context, a programming variable. While that person is also wrong, I think it is pragmatic to avoid confusion in the users if it is inexpensive to do so. On Feb 3, 2015 6:59 PM, "Michele" <[hidden email]> wrote:
/"You have my objection. They are variables in the mathematical sense. A _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org 
In reply to this post by Mike Wrobel
I disagree with your objections. If they are variables in mathemarical sense, they are also constants in mathematical sense. Since they are constants in programing sense too, i see broader apeal in simply calling them constants and avoid controvercy.
 Original message  From: Michele <[hidden email]> Date:03/02/2015 19:59 (GMT05:00) To: [hidden email] Cc: Subject: Re: [OpenSCAD] A = A + 1; /"You have my objection. They are variables in the mathematical sense. A symbol that represents a quantity in a mathematical expression."/ I agree with Mr. Peel and cast my vote similarly.  View this message in context: http://forum.openscad.org/AA1tp11385p11429.html Sent from the OpenSCAD mailing list archive at Nabble.com. _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org 
In reply to this post by Mike Wrobel
Does the following echo(vsum([[1,2],[3,4]])); work for your definition?  Original message  From: "David Eccles (gringer)" <[hidden email]> Date:03/02/2015 17:24 (GMT05:00) To: [hidden email] Cc: Subject: Re: [OpenSCAD] A = A + 1; I don't have a problem with OpenSCAD, because I treat it as a functional language (with some recursion limitations), and everything is fine. There are ways to implement variable modification in functional languages by including a data store as an additional function parameter  I'd have to dig out my CS notes to find the way I was taught  but it's frequently the case that such a design is not necessary. The 'concat' operator was, in my opinion, the final advance to make the language essentially turing complete (and therefore fully expressive). However, for proper use of functional languages, recursion is required in many cases. Thinking about the vector sum question, here's a recursive version that basically uses assignment. The "cumSum" argument stores the current sum, and the "pos" argument stores the current location in the vector: function vsum(vec, pos = 0, cumSum = 0) = pos >= len(vec) ? cumSum : vsum(vec, pos+1, cumSum + vec[pos]); echo(vsum([1,2,3,8]));  View this message in context: http://forum.openscad.org/AA1tp11385p11422.html Sent from the OpenSCAD mailing list archive at Nabble.com. _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org 
I don't know any normal language that would automatically allow vsum([1,2,3,8]) and vsum([[1,2],[3,4]]) into the same function and give a sensible result. They have different types. One is a vector of integers, the other is a vector of vector or integers. That's like applying an integer function to a string and expecting it to magically figure out what you want. Would you expect the result to be 10 or [4, 6]? 
In reply to this post by jon_bondy
Every other language without destructive update operator (cstyle assign) calls them variables, I don't see why OpenSCAD should be different.
They aren't "constant", because a constant is a value that never changes. function square(s) = s*s; b = 6; a = square(b); The variable a's value isn't constant  it changes according to the value of b. What's really needed is: * Giving an error message when trying to redefine a variable. * Clean up other doubtful cases. * An explanation for people from procedural programming languages (Cstyle). * Push all these changes to release version. Have a nice day, Bananapeel :) 
Hmm, I am no expert, but in your example below, 'a' is not varying, it
is constant  it gets calculated once and set up for use. It would only be a variable if it varies during the program run, eg if 'b' changes at certain points in time....but openscad never 'runs' it just puts the STL together, and 'b' is always the same. On 04/02/2015 13:03, Bananapeel wrote: > Every other language without destructive update operator (cstyle assign) > calls them variables, I don't see why OpenSCAD should be different. > > They aren't "constant", because a constant is a value that never changes. > function square(s) = s*s; > b = 6; > a = square(b); > The variable a's value isn't constant  it changes according to the value of > b. > > What's really needed is: > * Giving an error message when trying to redefine a variable. > * Clean up other doubtful cases. > * An explanation for people from procedural programming languages (Cstyle). > * Push all these changes to release version. > > Have a nice day, > Bananapeel :) > > > > >  > View this message in context: http://forum.openscad.org/AA1tp11385p11436.html > Sent from the OpenSCAD mailing list archive at Nabble.com. > > _______________________________________________ > OpenSCAD mailing list > [hidden email] > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org 
In reply to this post by Bananapeel
The main page of the manual: http://en.wikibooks.org/wiki/OpenSCAD_User_Manual
refers to an openscad source file as a script. The word script makes it sound iterative to me. Is there a better way to explain it? "Anonymous scopes are not considered scopes": { angle = 45; } IMO this should be a separate scope, or give an error. 
Free forum by Nabble  Edit this page 