In doing a solution to Adrian's last post
So in the case where if a is set then r=f(a), h=g(r,a) and if b is set
then
h=F(b), r=G(h,b), how would you write this?
I did this:
function f(i) = 2i;
function F(j) = 3j;
function g(k,l) = kl;
function G(m,n) = mn;
//a=5;
b=25;
aBased = !is_undef(a);
r = aBased
? f(a)
: G(F(b),b);
h = aBased
? g(r,a)
: F(b);
// without calling F(b) twice
aBased = !is_undef(a);
Fb = aBased ? 0 : F(b);
r = aBased
? f(a)
: G(Fb,b);
h = aBased
? g(r,a)
: Fb;
echo(r=r,h=h);
I added the second bit later, I was expecting the reassignment warnings, but
I get another problem.
WARNING: aBased was assigned on line 9 of "Logo" but was overwritten on
line 17
WARNING: r was assigned on line 10 of "Logo" but was overwritten on line
20
WARNING: h was assigned on line 13 of "Logo" but was overwritten on line
23
Compiling design (CSG Tree generation)...
WARNING: Ignoring unknown variable 'Fb', in file
../../Users/MeB/Documents/3D-REPRAP/Things/My Things/Logo, line 22.
WARNING: Ignoring unknown variable 'Fb', in file
../../Users/MeB/Documents/3D-REPRAP/Things/My Things/Logo, line 25.
ECHO: r = undef, h = undef
Why is Fb unknown?
It works if the top bit is commented out.
Side-effect of the new Warnings??
Using RC4.
Admin - email* 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/
It is the usual gotya that the last definition of a variable is used but
its evaluation is moved to the where the first definition is. So it uses Fb
before it has been defined.
On Sun, 28 Apr 2019 at 03:25, MichaelAtOz oz.at.michael@gmail.com wrote:
In doing a solution to Adrian's last post
So in the case where if a is set then r=f(a), h=g(r,a) and if b is set
then
h=F(b), r=G(h,b), how would you write this?
I did this:
function f(i) = 2i;
function F(j) = 3j;
function g(k,l) = kl;
function G(m,n) = mn;
//a=5;
b=25;
aBased = !is_undef(a);
r = aBased
? f(a)
: G(F(b),b);
h = aBased
? g(r,a)
: F(b);
// without calling F(b) twice
aBased = !is_undef(a);
Fb = aBased ? 0 : F(b);
r = aBased
? f(a)
: G(Fb,b);
h = aBased
? g(r,a)
: Fb;
echo(r=r,h=h);
I added the second bit later, I was expecting the reassignment warnings,
but
I get another problem.
WARNING: aBased was assigned on line 9 of "Logo" but was overwritten on
line 17
WARNING: r was assigned on line 10 of "Logo" but was overwritten on line
20
WARNING: h was assigned on line 13 of "Logo" but was overwritten on line
23
Compiling design (CSG Tree generation)...
WARNING: Ignoring unknown variable 'Fb', in file
../../Users/MeB/Documents/3D-REPRAP/Things/My Things/Logo, line 22.
WARNING: Ignoring unknown variable 'Fb', in file
../../Users/MeB/Documents/3D-REPRAP/Things/My Things/Logo, line 25.
ECHO: r = undef, h = undef
Why is Fb unknown?
It works if the top bit is commented out.
Side-effect of the new Warnings??
Using RC4.
Admin - email* 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/
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Yea, thanks.
If others want to know what's going on see here
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Include_Statement#Variables
.
Admin - email* 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/