I'm producing some examples of the echo function.
I came across a funny scope thing.
z=0;
//i=3;
j=4;
k=5;
i=3; // comment out & uncomment line 2
i = echo(j=j,k=k) z; // set new value of i to z (ie 0)
echo(i=i,j=j);
o= 10 + echo(i=i) 5;
echo(o=o); // 15
That works as expected.
If you invert the commented out lines it produces
WARNING: Ignoring unknown variable 'j'.
WARNING: Ignoring unknown variable 'k'.
ECHO: j = undef, k = undef
ECHO: i = 0
ECHO: i = 0, j = 4
ECHO: o = 15
I can understand the strange scoping behaviour if j or k was dependent on i,
buy i is the target of the assignment, I can't see why this happens.
Bug?
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.
Sent from: http://forum.openscad.org/
Also, I'm going to do the wiki doco for echo, unless someone has that
squirreled away somewhere??
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.
Sent from: http://forum.openscad.org/
Hi Michael,
I offered this explanation recently, perhaps that helps you understand this off quirk as well:
Something like this probably belongs in the FAQ; just don’t know how to best phase it in a way FAQ readers would benefit from.
-Marius
So in this case (with line 2 un-commented) , the echo() fn is evaluated at
scope of line two, when j & k are undef. OK. I tried to document this in the
wiki some time ago, I'll see if I can integrate your phraseology.
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.
Sent from: http://forum.openscad.org/
On Feb 24, 2018, at 11:26 PM, MichaelAtOz oz.at.michael@gmail.com wrote:
So in this case (with line 2 un-commented) , the echo() fn is evaluated at
scope of line two, when j & k are undef.
Exactly.
-Marius
This explanation is of little help when the issue arises in a long code
with many used libraries because the warning gives no clues where the
problem is. The poor fellow who gets the warning should scan all the code,
even of used libraries, before the offending assignment looking for another
assignment of the same variable. It is an error very hard to debug even for
experienced users.
2018-02-25 1:16 GMT-03:00 Marius Kintel marius@kintel.net:
I offered this explanation recently, perhaps that helps you understand
this off quirk as well:
Something like this probably belongs in the FAQ; just don’t know how to
best phase it in a way FAQ readers would benefit from.
-Marius