discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

variables, assignments, and arithmetic

JB
Jordan Brown
Wed, Aug 2, 2017 6:31 PM

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?

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?
TP
Torsten Paul
Wed, Aug 2, 2017 6:36 PM

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.

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.
FV
Frank van der Hulst
Wed, Aug 2, 2017 11:37 PM

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

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 >
JB
Jordan Brown
Thu, Aug 3, 2017 5:19 PM

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.

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.
M
MichaelAtOz
Fri, Aug 4, 2017 1:16 AM

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.

The TPP is no simple “trade agreement.”  Fight it! http://www.ourfairdeal.org/  time is running out!

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.

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. The TPP is no simple “trade agreement.” Fight it! http://www.ourfairdeal.org/ time is running out! -- 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.