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?
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.
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" Torsten.Paul@gmx.de 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
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
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.
n is instantiated on the first line, when p is not defined.
n is then redefined as p it looks for p in the instantiated state, p does
not exist.
Compare to:
p = undef;
n = 0;
p = 0;
n = p;
echo(n=n,p=p);
Admin - PM me if you need anything, or if I've done something stupid...
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.
View this message in context: http://forum.openscad.org/variables-assignments-and-arithmetic-tp21997p22018.html
Sent from the OpenSCAD mailing list archive at Nabble.com.