discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Special Variables

W
whburling
Sat, Nov 14, 2015 5:45 PM

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.

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.
R
runsun
Sat, Nov 14, 2015 6:21 PM

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.

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.
NH
nop head
Sat, Nov 14, 2015 6:23 PM

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

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 >
DM
doug moen
Sat, Nov 14, 2015 8:41 PM

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

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 > > >
NH
nop head
Sat, Nov 14, 2015 10:21 PM

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

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 >> >> >> > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > >
W
whburling
Sat, Nov 14, 2015 11:06 PM

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.

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.
R
runsun
Sat, Nov 14, 2015 11:22 PM

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.

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.
DM
doug moen
Sat, Nov 14, 2015 11:29 PM

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

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 >>> >>> >>> >> >> _______________________________________________ >> OpenSCAD mailing list >> Discuss@lists.openscad.org >> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >> >> > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > >
NH
nop head
Sat, Nov 14, 2015 11:31 PM

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

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 >
W
whburling
Sun, Nov 15, 2015 1:51 AM

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.

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.