# variables, assignments, and arithmetic

5 messages
Open this post in threaded view
|

## variables, assignments, and arithmetic

 I understand that OpenSCAD's variables are ... unusual. But I'm puzzled by this: ```n = 0; p = 0; n = p; echo(n=n, p=p); ``` which yields: `WARNING: Ignoring unknown variable 'p'. ` ECHO: n = undef, p = 0 I'm not coming up with a mental model that explains this behavior. Can somebody briefly describe what's really going on? _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

## Re: variables, assignments, and arithmetic

 On 08/02/2017 08:31 PM, Jordan Brown wrote: > Can somebody briefly describe what's really going on? > The reassignment is placed at the point of the original variable, so the evaluation sees: n = p; p = 0; echo(n=n, p=p); ciao,   Torsten. _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org -- Torsten
Open this post in threaded view
|

## Re: variables, assignments, and arithmetic

 Variables in OpenSCAD aren't really variables. They are constants to which you can assign a value. You can have multiple assignments to a variable, but only the last one sets the value. On 3/08/2017 06:37, "Torsten Paul" <[hidden email]> wrote:On 08/02/2017 08:31 PM, Jordan Brown wrote: > Can somebody briefly describe what's really going on? > The reassignment is placed at the point of the original variable, so the evaluation sees: n = p; p = 0; echo(n=n, p=p); ciao,   Torsten. _______________________________________________ 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 tp3 On 8/2/2017 11:36 AM, Torsten Paul wrote: ```On 08/02/2017 08:31 PM, Jordan Brown wrote: ``` ```Can somebody briefly describe what's really going on? ``` ```The reassignment is placed at the point of the original variable, so the evaluation sees: n = p; p = 0; echo(n=n, p=p); ``` Thanks.  Makes sense... well, sort of :-) On 8/2/2017 4:37 PM, Frank van der Hulst wrote: Variables in OpenSCAD aren't really variables. They are constants to which you can assign a value. You can have multiple assignments to a variable, but only the last one sets the value. Right.  The question was why, in the example I originally quoted ```n = 0; p = 0; n = p; ``` I got an unknown variable error.  I was confused since, looking at the lines above in the sequence above, at the point where "p" is used it's been defined. _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org