A = A + 1;

44 messages
123
Open this post in threaded view
|

A = A + 1;

 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.... 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 Mike Wrobel If this were an equation, you'd be right. But it isn't an equation. It is an assignment. If you continue to support a paradigm that runs counter to people's expectation, you will have no piece.-------- Original message --------From: Bananapeel <[hidden email]> Date:03/02/2015 07:25 (GMT-05:00) To: [hidden email] Cc: Subject: Re: [OpenSCAD] A = A + 1; You don't. An OpenSCAD program is like a big math equation. x = x + 1 isillegal because x can't have two values at once.--View this message in context: http://forum.openscad.org/A-A-1-tp11385p11386.htmlSent 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;

 In reply to this post by Mike Wrobel Argh! You will have no peace! That's what i meant :).-------- Original message --------From: Adrian Grajdeanu <[hidden email]> Date:03/02/2015 10:20 (GMT-05:00) To: OpenSCAD general discussion <[hidden email]> Cc: Subject: Re: [OpenSCAD] A = A + 1; If this were an equation, you'd be right. But it isn't an equation. It is have noan assignment. If you continue to support a paradigm that runs counter to people's expectation, you will have no piece.-------- Original message --------From: Bananapeel <[hidden email]> Date:03/02/2015 07:25 (GMT-05:00) To: [hidden email] Cc: Subject: Re: [OpenSCAD] A = A + 1; You don't. An OpenSCAD program is like a big math equation. x = x + 1 isillegal because x can't have two values at once.--View this message in context: http://forum.openscad.org/A-A-1-tp11385p11386.htmlSent 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;

 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;

 In reply to this post by Mike Wrobel You may beat this into me, but you will not squash most people's expectation. Hence you will have no peace.Why is there this stubborness to cripple variables? Is there a technical reason, or is merely adherence to some purist dogma?I can understand the tree structure of an openscad 'program'. Not only can i understand it, but appreciate it enormously. This paradigm simplifies things and enables caching of geometrical elements. However programers feel the need for variables (in the classical way). If at some point you accept this statement, and endeavor to provide variables in a languge, then embrace it all the way and support variables in a manner free of gotchas or arbitrarily seeming limitation. -------- Original message --------From: Alan Cox <[hidden email]> Date:03/02/2015 11:19 (GMT-05:00) To: Adrian Grajdeanu <[hidden email]> Cc: OpenSCAD general discussion <[hidden email]> Subject: Re: [OpenSCAD] A = A + 1; On Tue, 03 Feb 2015 10:20:53 -0500Adrian 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 eitherequations 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 defineanything else in life to be two conflicting things at once.If you see it as an assignment you are going to continue suffering fromiterative programmer disease. Think of it as #defineAlan_______________________________________________ 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;

 On Tue, 03 Feb 2015 11:40:48 -0500 Adrian Grajdeanu <[hidden email]> wrote: > You may beat this into me, but you will not squash most people's > expectation. Hence you will have no peace. As a long-time programmer, I understand what you are saying. However, an OpenSCAD file is not a program. It does not execute. I think many of us agree that "constant" would be a better name than "variable" for this concept. Like many have said, the variable concept makes no sense in OpenSCAD, because the file is not a program executing in time. Think of it as a description of a physical object. I can't have a physical sphere with a variable diameter (barring inflatables, and such). I describe the sphere with a dimension and it does not change. What OpenSCAD calls variables are really named constants. Since variables do not exist in the language, there is no "crippling" of them. > Why is there this stubborness to cripple variables? Is there a > technical reason, or is merely adherence to some purist dogma? The technical reason is that the file does not execute in time. Several people have pointed this out. > I can understand the tree structure of an openscad 'program'. Not > only can i understand it, but appreciate it enormously. This paradigm > simplifies things and enables caching of geometrical elements. > However programers feel the need for variables (in the classical > way). If at some point you accept this statement, and endeavor to As I said, decades of programming experience here and I have not felt limited in my OpenSCAD designs by a lack of variables. G. Wade > provide variables in a languge, then embrace it all the way and > support variables in a manner free of gotchas or arbitrarily seeming > limitation.  > > -------- Original message -------- > From: Alan Cox <[hidden email]> > Date:03/02/2015  11:19  (GMT-05:00) > To: Adrian Grajdeanu <[hidden email]> > Cc: OpenSCAD general discussion <[hidden email]> > Subject: Re: [OpenSCAD] A = A + 1; > > 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 -- There will always be things we wish to say in our programs that in all known languages can only be said poorly.             -- Alan Perlis _______________________________________________ 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;

 In reply to this post by adriang Because this is a HDL, not a programming language. The closest cousin I know to openscad in the hdl world is a limited subset of vhdl or verilog. Identifiers in loops (which aren't really loops, they are a big expansion macro) are parameters. For there to be true variables we would need to have real synthesis - a separate mode that does run procedurally. Personally I think every mention of "variable" should be purged from the official docs and the wiki book. Identifiers in "loops" become parameters as does modules. Everything else is called a constant. If people bring their incorrect assumptions after that we can point at the docs. On Feb 3, 2015 10:40 AM, "Adrian Grajdeanu" <[hidden email]> wrote: > > You may beat this into me, but you will not squash most people's expectation. Hence you will have no peace. > > Why is there this stubborness to cripple variables? Is there a technical reason, or is merely adherence to some purist dogma? > > I can understand the tree structure of an openscad 'program'. Not only can i understand it, but appreciate it enormously. This paradigm simplifies things and enables caching of geometrical elements. However programers feel the need for variables (in the classical way). If at some point you accept this statement, and endeavor to provide variables in a languge, then embrace it all the way and support variables in a manner free of gotchas or arbitrarily seeming limitation.  > > > -------- Original message -------- > From: Alan Cox <[hidden email]> > Date:03/02/2015 11:19 (GMT-05:00) > To: Adrian Grajdeanu <[hidden email]> > Cc: OpenSCAD general discussion <[hidden email]> > Subject: Re: [OpenSCAD] A = A + 1; > > 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;

 In reply to this post by adriang On Tue, 03 Feb 2015 11:40:48 -0500 Adrian Grajdeanu <[hidden email]> wrote: > You may beat this into me, but you will not squash most people's expectation. Hence you will have no peace. > > Why is there this stubborness to cripple variables? Is there a technical reason, or is merely adherence to some purist dogma? Technically it allows parallelism and a lot of optimisations because the functions are all without side effects. Also because it's not a programming language as such but a mathematical description of an object. > I can understand the tree structure of an openscad 'program'. Not only can i understand it, but appreciate it enormously. This paradigm simplifies things and enables caching of geometrical elements. However programers feel the need for variables (in the classical way). That's why I called it 'iterative programmers disease'. It's a peculiar worldview problem of programmers, and one that gets them into a lot of trouble with parallelism, trying to do electronics or write VHDL. Programmers can use the python bindings and all the other ways of interacting with OpenSCAD. Everyone on the other hand (including those with a normal world view) can use OpenSCAD. Given the number of people who 'get' openscad and its modelling who are not programmers I'd really hate to see OpenSCAD lose that property. The biggest problem I think is that the syntax and documentation of OpenSCAD make it look like a variable to a programmer. It's very misleading. Some of the other systems of similar nature do at least make the difference explicit, or  use constructs that make it more clear what is going on  (eg with x = [ 1, 2, 3, 4, 5] { blah } ) I'm not immune to it either - several of my tools write OpenSCAD files - it's an output format for a program in C that computes models of model railway coaches from a mix of inputs and an inbuilt understanding of how they are assembled. 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;

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;

 Administrator Hi all, OK, it’s this time of year again. I’ll be short and try to reiterate from earlier discussions: First of all, the question “why” we have these “limitations” will become more clear once we start better exploiting the opportunities, as Alan hinted towards. I admit: o We need a “reduce” function to help collecting information depending on a list of input. Recursion is fine, but people tend to struggle with it and we could offer some help. o We should probable disallow any attempt of reassignment, to make it more clear what’s going on. The only real reason we partially allow it is to allow cmd-line variable overrides. To help think about things: o Imagine every expression in OpenCAD being executed in parallel. Any dependency of existing expressions must be made explicit by hierarchical grouping. This will kill the idea of iterating in order to accumulate information. o In terms of functions: Imagine a function expression being something you’d type into a spreadsheet cell. Not totally mappable, but it might help framing it. Now, we _could_ add all kinds of sugar to help people apply their existing programming problem solving skills. Question is more if it really helps us, secondary who will spearhead the design of such language extensions, as we currently don’t really have attachment for these ideas on the dev team. If you think about the OpenSCAD language as something similar to HTML, but for 3D modeling, you’d still have a need for various programs generating code in this language (similar to the plethora of HTML generators out there). There exist a number of tools for helping with OpenSCAD code generation from existing programming languages (python, ruby, C++, haskell, clojure off the top of my head) and there are tools offering Javascript interfaces for similar purposes (OpenJSCAD, CoffeeSCAD). Until we have a really good reason to do so in OpenSCAD proper, and a really good candidate for which language to support, I think it’s better to keep these things separate. Cheers,  -Marius _______________________________________________ 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 Mike Wrobel This was precisely my latest surprise too: no sum vector over array. Can be done with recursion, but yuck! Can't write like soSum(v,i=0) = {(i=len(v))? 0: v[i]+sum(v,i+1)}Because that only works for vector of scalars. If you have vector of vectors you need a new function like above, but replace 0 with [0,0,0], or whatever the equivalent appropiate neutral element for addition. Or you can write it the ugly way:Sum(v,i=0) = {(i=len(v)-1)? v[i]: v[i]+sum(v,i+1)}(Syntax may be slightly wrong!)-------- Original message --------From: Joymaker <[hidden email]> Date:03/02/2015 14:06 (GMT-05:00) To: [hidden email] Cc: Subject: Re: [OpenSCAD] A = A + 1; My question falls right into this theme.  A few days ago I set out to write alittle function to compute the average of a vector. Thought everything wouldbe straightforward.// average a vectorfunction 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 hasfunctions 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 theissue goes much deeper than I realized.So, please suggest to me how to write the avg function. PLEASE don't tell methat recursion is the best approach; this feels about as pretty as usingpliers to do a screwdriver's job.Suggestion on the side: I was surprised not to find sum() and avg() on thelist of built-in functions operating on vectors. I recommend adding them.Surely they are trivial to implement!Cheers,Ken_______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|