# A = A + 1;

44 messages
123
Open this post in threaded view
|

## A = A + 1;

 This post has NOT been accepted by the mailing list yet. How do I add a variable to itself?      a = 0;      a = a+ 1; Compile returns:      WARNING: Ignoring unknown variable 'a'.      Note: "a = 0;" is fine.  The warning comes from the a = a + 1;
Open this post in threaded view
|

## Re: A = A + 1;

 You don't. An OpenSCAD program is like a big math equation. x = x + 1 is illegal because x can't have two values at once.
Open this post in threaded view
|

## Re: A = A + 1;

 Administrator 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.... Admin - email* me if you need anything, or if I've done something stupid... * 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. The TPP is no simple “trade agreement.” Fight it! http://www.ourfairdeal.org/ time is running out!
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;

 Well exactly.  It sure looks like a programming language to me.  It has everything you find in a programming language, including comments, semicolon delimiters, functions, all the tschotschkes you find in a programming language.  Except variables.  Unless you're running a loop, in which case you do get variables. Ehhh??? And we all know that a = a + 1 is because keypunches didn't have a left-arrow key.  Some languages like APL and SAIL do use the left arrow to please the mathematicians in the audience.  All I know is that Openscad should offer real variables.  Apparently I wasn't the only one to get caught by this.
Open this post in threaded view
|

## Re: A = A + 1;

 In reply to this post by adriang On Tue, 03 Feb 2015 10:20:53 -0500 Adrian Grajdeanu <[hidden email]> wrote: > If this were an equation, you'd be right. But it isn't an equation. It is an assignment. Depending how you look at it the statements in question are either equations or just definitions. In openscad  X = Y + 1 is a definition of X with a scope. You cannot define X to be two things at once any more than you can define anything else in life to be two conflicting things at once. If you see it as an assignment you are going to continue suffering from iterative programmer disease. Think of it as #define Alan _______________________________________________ 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;

 Back in the old days, I was introduced to Pascal and Modular-2, where the assignment was ' := ' to make it clear that it was different. The thing to remember with OpenSCAD is that it is timeless. The cad script you write is to describe an object that simply 'is'. there is no 'now' object and no 'later' object. The use of loops is simply to describe a set of similar parts, not to go back and do something different with the same parts. Think of the  loop structures as a convenient way of shortening the ammount of typing - it simply unwinds as a list all at once to produce a logical hierarchy of lumps of STL triangles. As such, the 'variables' are also all the same everywhere, as there is no earlier or later as there is no program flow. Perhaps 'Operand' would be better than 'variable' or 'constant'. On 03/02/2015 16:19, Alan Cox wrote: > On Tue, 03 Feb 2015 10:20:53 -0500 > Adrian Grajdeanu <[hidden email]> wrote: > >> If this were an equation, you'd be right. But it isn't an equation. It is an assignment. > Depending how you look at it the statements in question are either > equations or just definitions. > > In openscad  X = Y + 1 is a definition of X with a scope. > > You cannot define X to be two things at once any more than you can define > anything else in life to be two conflicting things at once. > > If you see it as an assignment you are going to continue suffering from > iterative programmer disease. Think of it as #define > > Alan > > _______________________________________________ > 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;

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;

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 Mike Wrobel My question falls right into this theme.  A few days ago I set out to write a little function to compute the average of a vector. Thought everything would be straightforward. // average a vector function avg(vec) {         sum = 0;         for (n=vec) sum = sum + n;         return sum / len(vec); } Surprise! This language doesn't have functions with curly braces, it has functions with equal signs. Given that it has modules with curly braces, this took me greatly by surprise. Now, as I read this thread, I see that the issue goes much deeper than I realized. So, please suggest to me how to write the avg function. PLEASE don't tell me that recursion is the best approach; this feels about as pretty as using pliers to do a screwdriver's job. Suggestion on the side: I was surprised not to find sum() and avg() on the list of built-in functions operating on vectors. I recommend adding them. Surely they are trivial to implement! Cheers, Ken
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
|