# A = A + 1;

44 messages
123
Open this post in threaded view
|

## Re: A = A + 1;

Open this post in threaded view
|

## Re: A = A + 1;

 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 wrote:A well reasoned, and encouraging response. I offer my help with language improvements. Seems the need is there, i have the experience and the interest._______________________________________________ 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
Open this post in threaded view
|

## Re: A = A + 1;

 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 wrote:>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 wrote:A well reasoned, and encouraging response. I offer my help with language improvements. Seems the need is there, i have the experience and the interest._______________________________________________ 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
Open this post in threaded view
|

## Re: A = A + 1;

 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.
Open this post in threaded view
|

## Re: A = A + 1;

 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 non-deterministicly 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.
Open this post in threaded view
|

## Re: A = A + 1;

 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 > non-deterministicly 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 "Non-Hierarchical".  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
Open this post in threaded view
|

## Re: A = A + 1;

 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]));
Open this post in threaded view
|

## Re: A = A + 1;

 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 (c-style 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 sub-union() creates its own variable b that shadows the global b. In C you would be able to re-assign 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 :)
Open this post in threaded view
|

## Re: A = A + 1;

 Administrator In reply to this post by MichaelAtOz MichaelAtOz wrote I really think we should use 'constant' or some equally descriptive term. (define value? like #define)? Bite the bullet, this keeps coming up so often... But we need to clarify the iterative list comprehension/recursion in expressions, v's the for() loops/if() in geometry... I think we are having/approaching a clash of terminology of module geometry instantiation v's expression evaluation. Let the battle begin.... 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 're-definable' 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.
Open this post in threaded view
|

## Re: A = A + 1;

 MichaelAtOz wrote Unless I see objections, I will start a project to change the wiki to use 'identifier', 'definition', 'constant' and 're-definable' 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/VariableVariable (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
Open this post in threaded view
|

## Re: A = A + 1;

 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 left-hand 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.
Open this post in threaded view
|

## Re: A = A + 1;

Open this post in threaded view
|

## Re: 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.
Open this post in threaded view
|

## Re: A = A + 1;

 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 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/A-A-1-tp11385p11429.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
Open this post in threaded view
|

## Re: A = A + 1;

Open this post in threaded view
|

## Re: A = A + 1;

Open this post in threaded view
|

## Re: A = A + 1;

 adriang wrote Does the following echo(vsum([[1,2],[3,4]])); work for your definition? 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]?
Open this post in threaded view
|

## Re: A = A + 1;

 In reply to this post by jon_bondy Every other language without destructive update operator (c-style 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 (C-style). * Push all these changes to release version. Have a nice day, Bananapeel :)
Open this post in threaded view
|