Unless I have made a mistake, it appears as if a special variable is not a
global variable (meaning that the variable can be seen by any module and
changed by any module so that its value is always the value last defined).
In my example, I defined a special variable($C=2) then called a module (no
parameters passed). I read the special variable within the called
module($C=5). Changed that special variable (originally had the value of 2,
but now defined it as 5), then returned from the called module. Upon return
I looked at the value of the special character. its value, newly defined
within the called module(5), did not persist but retained the value it
originally had(2) before the call to the module.
Interpretation of the results imply that special variables are defined at
compile time and not dynamically.
I thought, that special variables were dynamically assigned and hence have
the attributes of a global variable defined by me in the first paragraph.
I must have a misunderstanding. please help me understand.
bil
--
View this message in context: http://forum.openscad.org/Special-Variables-tp14477.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
can you show some code ?
$ Runsun Pan, PhD
$ libs: doctest , faces ( git ), offline doc ( git ),runscad.py( 1 , 2 , git );
$ tips: hash( 1 , 2 ), sweep , var , lerp , animGif
--
View this message in context: http://forum.openscad.org/Special-Variables-tp14477p14479.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
Special variables have dynamic scope instead of the default lexical scope.
It doesn't make them mutable.
On Nov 14, 2015 5:45 PM, "whburling" whburling@outlook.com wrote:
Unless I have made a mistake, it appears as if a special variable is not a
global variable (meaning that the variable can be seen by any module and
changed by any module so that its value is always the value last defined).
In my example, I defined a special variable($C=2) then called a module (no
parameters passed). I read the special variable within the called
module($C=5). Changed that special variable (originally had the value of 2,
but now defined it as 5), then returned from the called module. Upon return
I looked at the value of the special character. its value, newly defined
within the called module(5), did not persist but retained the value it
originally had(2) before the call to the module.
Interpretation of the results imply that special variables are defined at
compile time and not dynamically.
I thought, that special variables were dynamically assigned and hence have
the attributes of a global variable defined by me in the first paragraph.
I must have a misunderstanding. please help me understand.
bil
--
View this message in context:
http://forum.openscad.org/Special-Variables-tp14477.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
The only thing that is "special" about special variables like $fn is that
you can set their value in a module call, like this:
M($fn=10);
and this will override the "global" value of $fn that the module M would
otherwise use.
On 14 November 2015 at 12:45, whburling whburling@outlook.com wrote:
Unless I have made a mistake, it appears as if a special variable is not a
global variable (meaning that the variable can be seen by any module and
changed by any module so that its value is always the value last defined).
In my example, I defined a special variable($C=2) then called a module (no
parameters passed). I read the special variable within the called
module($C=5). Changed that special variable (originally had the value of 2,
but now defined it as 5), then returned from the called module. Upon return
I looked at the value of the special character. its value, newly defined
within the called module(5), did not persist but retained the value it
originally had(2) before the call to the module.
Interpretation of the results imply that special variables are defined at
compile time and not dynamically.
I thought, that special variables were dynamically assigned and hence have
the attributes of a global variable defined by me in the first paragraph.
I must have a misunderstanding. please help me understand.
bil
--
View this message in context:
http://forum.openscad.org/Special-Variables-tp14477.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
No it is more than that. You don't need to pass it as a parameter. It has
dynamic scope so is visible in anything you call from the block you set it
in. Functions, modules and children.
On Nov 14, 2015 8:42 PM, "doug moen" doug@moens.org wrote:
The only thing that is "special" about special variables like $fn is that
you can set their value in a module call, like this:
M($fn=10);
and this will override the "global" value of $fn that the module M would
otherwise use.
On 14 November 2015 at 12:45, whburling whburling@outlook.com wrote:
Unless I have made a mistake, it appears as if a special variable is not
a
global variable (meaning that the variable can be seen by any module and
changed by any module so that its value is always the value last defined).
In my example, I defined a special variable($C=2) then called a module (no
parameters passed). I read the special variable within the called
module($C=5). Changed that special variable (originally had the value of
2,
but now defined it as 5), then returned from the called module. Upon
return
I looked at the value of the special character. its value, newly defined
within the called module(5), did not persist but retained the value it
originally had(2) before the call to the module.
Interpretation of the results imply that special variables are defined at
compile time and not dynamically.
I thought, that special variables were dynamically assigned and hence
have
the attributes of a global variable defined by me in the first paragraph.
I must have a misunderstanding. please help me understand.
bil
--
View this message in context:
http://forum.openscad.org/Special-Variables-tp14477.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
I would love to show some code....but I am not sure how to attach the code
here. Do people prefer to "embed" (I am assuming if i point to a file in
Embed, the file contents will appear in this box), or link the file to this
box. not sure what linking will actually do. tell me what you want and how
and i will gladly respond
--
View this message in context: http://forum.openscad.org/Special-Variables-tp14477p14488.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
copy and paste ?
$ Runsun Pan, PhD
$ libs: doctest , faces ( git ), offline doc ( git ),runscad.py( 1 , 2 , git );
$ tips: hash( 1 , 2 ), sweep , var , lerp , animGif
--
View this message in context: http://forum.openscad.org/Special-Variables-tp14477p14489.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
Okay, thanks for clarifying that.
On 14 November 2015 at 17:21, nop head nop.head@gmail.com wrote:
No it is more than that. You don't need to pass it as a parameter. It has
dynamic scope so is visible in anything you call from the block you set it
in. Functions, modules and children.
On Nov 14, 2015 8:42 PM, "doug moen" doug@moens.org wrote:
The only thing that is "special" about special variables like $fn is that
you can set their value in a module call, like this:
M($fn=10);
and this will override the "global" value of $fn that the module M would
otherwise use.
On 14 November 2015 at 12:45, whburling whburling@outlook.com wrote:
Unless I have made a mistake, it appears as if a special variable is
not a
global variable (meaning that the variable can be seen by any module and
changed by any module so that its value is always the value last
defined).
In my example, I defined a special variable($C=2) then called a module
(no
parameters passed). I read the special variable within the called
module($C=5). Changed that special variable (originally had the value of
2,
but now defined it as 5), then returned from the called module. Upon
return
I looked at the value of the special character. its value, newly defined
within the called module(5), did not persist but retained the value it
originally had(2) before the call to the module.
Interpretation of the results imply that special variables are defined at
compile time and not dynamically.
I thought, that special variables were dynamically assigned and hence
have
the attributes of a global variable defined by me in the first paragraph.
I must have a misunderstanding. please help me understand.
bil
--
View this message in context:
http://forum.openscad.org/Special-Variables-tp14477.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
To explain the original post. If you set a special variable at the file
scope it will be visible in every thing you call but if you try to assign
to it in a deeper scope you simply get a new one with the same name that
hides the original until it goes out of scope. Just the same as the normal
lexical scope variables in that respect.
On Nov 14, 2015 11:23 PM, "runsun" runsun@gmail.com wrote:
copy and paste ?
$ Runsun Pan, PhD
$ libs: doctest , faces ( git ), offline doc ( git ),runscad.py( 1 , 2 ,
git );
$ tips: hash( 1 , 2 ), sweep , var , lerp , animGif
--
View this message in context:
http://forum.openscad.org/Special-Variables-tp14477p14489.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
module a(b)
{ echo ("enterred module a");
// initial conditions for module
echo ("b, passed parameter value arriving within module a(), is
defined as = ", b);
echo ("special variable value before module a() code executed $C =
", $C);
// changing passed parameter
echo ("just before I change passed parameter");
$D = b; // simple change to test concept
echo (" passed parameter b which shall be changed $D =" , $D);
$D = b + 50;
echo ("changed passed parameter $D = ", $D);
// changing global value
$C = 5;
echo ("special variable value created outside of module a() but
changed within module a() $C = ", $C);
};
// TESTING MODULE a()
// Defining special variables prior to module a() call
$C = 2; //define a special variables prior to call to module
(a)
echo ( "before call to module a(), special variable, $C was
defined as", $C);
// Defining parameter to be passed to module a
b = 2;
echo ("before call to module a(b), b parameter to be passed was
defined as",b);
// Call to module a()
a(b);
// Return from module a()
echo ("returned from module a()");
echo ("upon return from module a() value of passed parameter b =
",b); //expect b to have original passed value
echo ("upon return from module a() value of special variable $C
=", $C); // expect special variable defined external to module a() to have
been changed by module a()
echo ("upon return from module a() value of special variable $D=
", $D); // expect special variable created within module a() to be seen
external to module a()
/* INTERPRETATIONS OF EXPERIMENT
(1) special variable $C, does not act as a global variable.
$C, created and defined before call to module a() is redefined in
module a(). The change does not make it out of module a().
(2) special variable $D does not act as a global variable.
$D, created and defined within module a() is not considered
defined outside of module a()
(3) Thus my interpretation of special value is that special values
allow an external (to a module) constant be seen internal to a module but it
can not be changed within the module and the outside world knows about the
change.
*/
--
View this message in context: http://forum.openscad.org/Special-Variables-tp14477p14494.html
Sent from the OpenSCAD mailing list archive at Nabble.com.