Thank you for replying. Very much appreciated.
So if I understand you . Special variables do not have global scope.
If they did then when I created a special variable within a module, it would
not go out of scope when the module was left.
What I thought I heard you say was that if I created a special variable it
could be seen by all modules regardless of scope but that it could not be
changed. I thought I heard an implication that just being see by all made it
global.
To allow a special variable to be changed locally and not be visible outside
of the module where it is changed seems to be illogical (maybe I am not
logical), because it is supposed to be seen by all.
So, unfortunately, I am still grappling with what a special variable is
bil
From: nophead [via OpenSCAD]
[mailto:ml-node+s1091067n14491h37@n5.nabble.com]
Sent: Saturday, November 14, 2015 6:32 PM
To: whburling whburling@outlook.com
Subject: Re: Special Variables
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" <[hidden email]> 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
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
If you reply to this email, your message will be added to the discussion
below:
http://forum.openscad.org/Special-Variables-tp14477p14491.html
To unsubscribe from Special Variables, click here
<http://forum.openscad.org/template/NamlServlet.jtp?macro=unsubscribe_by_cod
e&node=14477&code=d2hidXJsaW5nQG91dGxvb2suY29tfDE0NDc3fDU4Njc0MDk4NA==> .
<http://forum.openscad.org/template/NamlServlet.jtp?macro=macro_viewer&id=in
stant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-
nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamesp
ace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21na
bble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> NAML
--
View this message in context: http://forum.openscad.org/Special-Variables-tp14477p14544.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
just discsovered your reply. Let me digest it. play with simple examples.
You were careful wtih your wording...and so i suspect i will be able to
recreate your views and thus appreciate what you are saying.
please be patient with me.
--
View this message in context: http://forum.openscad.org/Special-Variables-tp14477p14547.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
The only thing special about them is they have dynamic scope. If you place
them at the file level they do have a global effect. For example setting
$fn at the top of file affects all cylinders, except those that specify it
themselves or those in modules that set it locally. If you have it set to
1000 to get really smooth cylinders but you want some hexagonal prisms you
wouldn't expect setting it locally to six to make all your cylinders
hexagonal.
So special variables have the intended behavior appropriate to settings
like fn. Also if you created you own variable and called a library module
that by coincidence used a variable with the same name you wouldn't want
the surprise of it affecting your variable.
Getting back to the original question, the poster was expecting special
variables to be an exception to the scope rules of regular variables. See
Variable scope
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/General#Scope_of_variables
.
Variables defined in an outer scope are visible within inner scopes. They
can be given new values within the inner scope, but that new value does not
leak out to an outer scope. This is true for both regular and special
variables.
Regular variables are visible inside modules defined in, or included into,
the local file. They are not visible inside modules loaded with run.
Special variables are also visible inside modules loaded with run.
--
View this message in context: http://forum.openscad.org/Special-Variables-tp14477p14574.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
ok.....after reading your comments and trying out code offered in this thread
and in writing my own code I came to conclude the following. If i have
incorrect understanding, please correct.
(1) there are no variables in openSCAD
(2) there are only constants.
(3) constants have two scopes
(a) if standard constant, the constant value is local to a given
module or function
(b) if special constants, the value is observable by all called
modules and functions, regardless of whether they were defined in the same
file as called or in some external file that was "included" or referenced
through "use"
(4) the constants are defined at compile time. there is no "dynamic"
aspect in that they can be redefined at run time.
(5) there is no way to extract data local to modules as they have no return
value and openSCAD does not have global values
(6) I am uncertain if functions can be written exactly as modules with the
ability to return a value unrelated to any passed parameter or any special
variable. I am finding out that I do not understand how to "return" an
arbitrary value.
--
View this message in context: http://forum.openscad.org/Special-Variables-tp14477p14601.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
All pretty much true except the is no run time in OpenSCAD. The source code
is compiled into geometry, not executable code that runs.
Functions are simply reusable expressions that yield a value. It can be as
arbitrary as you want or it can depend on passed parameters or any named
constants that are in scope.
function fred() = 42;
The are not like modules with return values at all.
On Nov 17, 2015 8:30 PM, "whburling" whburling@outlook.com wrote:
ok.....after reading your comments and trying out code offered in this
thread
and in writing my own code I came to conclude the following. If i have
incorrect understanding, please correct.
(1) there are no variables in openSCAD
(2) there are only constants.
(3) constants have two scopes
(a) if standard constant, the constant value is local to a given
module or function
(b) if special constants, the value is observable by all called
modules and functions, regardless of whether they were defined in the same
file as called or in some external file that was "included" or referenced
through "use"
(4) the constants are defined at compile time. there is no "dynamic"
aspect in that they can be redefined at run time.
(5) there is no way to extract data local to modules as they have no return
value and openSCAD does not have global values
(6) I am uncertain if functions can be written exactly as modules with the
ability to return a value unrelated to any passed parameter or any special
variable. I am finding out that I do not understand how to "return" an
arbitrary value.
--
View this message in context:
http://forum.openscad.org/Special-Variables-tp14477p14601.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
Everything you say is correct (although different people use different
terminology for the same things). As for point #6, the answer is no,
functions don't do that. The value returned by a function is a mathematical
function of its arguments (hence the name*), but functions can also depend
on special variables, as you say.
(*) It might be fair to say that OpenSCAD is executable mathematics for
describing geometry, rather than a conventional programming language.
Mathematics has things called 'variables' which resemble the things we call
variables in OpenSCAD. You prefer to use the term 'constant', and I
understand why.
On 17 November 2015 at 15:29, whburling whburling@outlook.com wrote:
ok.....after reading your comments and trying out code offered in this
thread
and in writing my own code I came to conclude the following. If i have
incorrect understanding, please correct.
(1) there are no variables in openSCAD
(2) there are only constants.
(3) constants have two scopes
(a) if standard constant, the constant value is local to a given
module or function
(b) if special constants, the value is observable by all called
modules and functions, regardless of whether they were defined in the same
file as called or in some external file that was "included" or referenced
through "use"
(4) the constants are defined at compile time. there is no "dynamic"
aspect in that they can be redefined at run time.
(5) there is no way to extract data local to modules as they have no return
value and openSCAD does not have global values
(6) I am uncertain if functions can be written exactly as modules with the
ability to return a value unrelated to any passed parameter or any special
variable. I am finding out that I do not understand how to "return" an
arbitrary value.
--
View this message in context:
http://forum.openscad.org/Special-Variables-tp14477p14601.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 following is based on testing using OpenSCAD version 2015.03-1.
Inside functions and modules, special variables behave differently than
normal variables.
User-Defined Functions and Modules are defined at the outer most scope of
the script.
They see and use the values of regular variables in effect at this outer
scope. New values assigned within inner scopes, from which they are called,
are not seen by the functions and modules.
When external files are loaded with include they are treated as if they were
internal, using the same values of regular variables as if locally defined.
When run is used to load only the functions and modules from an external
file, they use the values of regular variables from their external file,
rather than the local values.
Variables inside a single instance of a function or module can be overridden
by passing as parameters in the call.
For example
var = 5;
module showvar() echo(var);
showvar(); // ECHO: 5
showvar(var = 10); // ECHO: 10
showvar(var = 10); is equivalent to:
module showvar(){ var = 10; echo(var); }
showvar();
With special variables, the functions and modules DO see new values
assigned within the inner scope from which they were called. This includes
functions and modules loaded with run as well as those included and locally
defined.
--
View this message in context: http://forum.openscad.org/Special-Variables-tp14477p14622.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
Note that functions and modules don't have to defined at file scope. You
can define them in modules as well.
On Nov 18, 2015 4:41 PM, "L Boyd" lboyd@frontiernet.net wrote:
The following is based on testing using OpenSCAD version 2015.03-1.
Inside functions and modules, special variables behave differently than
normal variables.
User-Defined Functions and Modules are defined at the outer most scope of
the script.
They see and use the values of regular variables in effect at this outer
scope. New values assigned within inner scopes, from which they are called,
are not seen by the functions and modules.
When external files are loaded with include they are treated as if they
were
internal, using the same values of regular variables as if locally defined.
When run is used to load only the functions and modules from an external
file, they use the values of regular variables from their external file,
rather than the local values.
Variables inside a single instance of a function or module can be
overridden
by passing as parameters in the call.
For example
var = 5;
module showvar() echo(var);
showvar(); // ECHO: 5
showvar(var = 10); // ECHO: 10
showvar(var = 10); is equivalent to:
module showvar(){ var = 10; echo(var); }
showvar();
With special variables, the functions and modules DO see new values
assigned within the inner scope from which they were called. This includes
functions and modules loaded with run as well as those included and locally
defined.
--
View this message in context:
http://forum.openscad.org/Special-Variables-tp14477p14622.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
nophead wrote
Note that functions and modules don't have to defined at file scope. You
can define them in modules as well.
Learn something new every day!
Have not tried yet, but I assume this means the universe for these functions
and modules are the scope within which they were defined. This would mean:
Not sure how to use this knowledge, but it means some rewording where I
said "outer most scope".
Do you have some ideas where they might be useful?
L Boyd wrote
The following is based on testing using OpenSCAD version 2015.03-1.
Inside functions and modules, special variables behave differently than
normal variables.
User-Defined Functions and Modules are defined at the outer most scope of
the script.
They see and use the values of regular variables in effect at this outer
scope. New values assigned within inner scopes, from which they are
called,
are not seen by the functions and modules.
When external files are loaded with include they are treated as if they
were
internal, using the same values of regular variables as if locally
defined.
When run is used to load only the functions and modules from an external
file, they use the values of regular variables from their external file,
rather than the local values.
Variables inside a single instance of a function or module can be
overridden
by passing as parameters in the call.
For example
var = 5;
module showvar() echo(var);
showvar(); // ECHO: 5
showvar(var = 10); // ECHO: 10
showvar(var = 10); is equivalent to:
module showvar(){ var = 10; echo(var); }
showvar();
With special variables, the functions and modules DO see new values
assigned within the inner scope from which they were called. This
includes
functions and modules loaded with run as well as those included and
locally
defined.
View this message in context: http://forum.openscad.org/Special-Variables-tp14477p14628.html
Sent from the OpenSCAD mailing list archive at Nabble.com.