discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Variable scope - undocumented feature ?

GS
Guenther Sohler
Wed, Jun 19, 2019 2:28 PM

I have written this funciton in OpensCAD 2019.05:

module build(s,ndst)
{
thing(s,$nsrc,ndst,port)
union()
{
$nsrc=ndst;
children();
}
}

Watch the custom $nsrc variable.
Its set to a certain value at the beginning. But it can be redefined for
the inner scope
when children() is executed.

The fact that variables are set at  compile time and only the latest value
set holds is no longer true.
Without using the $ sign, this does not work anymore

cheers, Günther

I have written this funciton in OpensCAD 2019.05: module build(s,ndst) { thing(s,$nsrc,ndst,port) union() { $nsrc=ndst; children(); } } Watch the custom $nsrc variable. Its set to a certain value at the beginning. But it can be redefined for the inner scope when children() is executed. The fact that variables are set at compile time and only the latest value set holds is no longer true. Without using the $ sign, this does not work anymore cheers, Günther
NH
nop head
Wed, Jun 19, 2019 2:49 PM

Variables that start with a $ have dynamic scope and are visible in all the
called functions and modules and children. Normal variables have lexical
scope and are visible in the textually nested blocks only.

It is mentioned here:
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/The_OpenSCAD_Language#Special_Variables

On Wed, 19 Jun 2019 at 15:29, Guenther Sohler guenther.sohler@gmail.com
wrote:

I have written this funciton in OpensCAD 2019.05:

module build(s,ndst)
{
thing(s,$nsrc,ndst,port)
union()
{
$nsrc=ndst;
children();
}
}

Watch the custom $nsrc variable.
Its set to a certain value at the beginning. But it can be redefined for
the inner scope
when children() is executed.

The fact that variables are set at  compile time and only the latest value
set holds is no longer true.
Without using the $ sign, this does not work anymore

cheers, Günther


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

Variables that start with a $ have dynamic scope and are visible in all the called functions and modules and children. Normal variables have lexical scope and are visible in the textually nested blocks only. It is mentioned here: https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/The_OpenSCAD_Language#Special_Variables On Wed, 19 Jun 2019 at 15:29, Guenther Sohler <guenther.sohler@gmail.com> wrote: > > I have written this funciton in OpensCAD 2019.05: > > > module build(s,ndst) > { > thing(s,$nsrc,ndst,port) > union() > { > $nsrc=ndst; > children(); > } > } > > Watch the custom $nsrc variable. > Its set to a certain value at the beginning. But it can be redefined for > the inner scope > when children() is executed. > > The fact that variables are set at compile time and only the latest value > set holds is no longer true. > Without using the $ sign, this does not work anymore > > cheers, Günther > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >