discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Usage of use and include

R
Ronaldo
Fri, Jul 1, 2016 2:55 PM

I really have not understood the behaviour of nested use and include as
expressed in the wiki Manual. And does not understand the outcomes of the
following three codes:

// file test1
VAR = 1;
function f(a) = VAR;

// file test2.scad
include
<test1.scad>
function g(a) = f(a);

// file test3.scad
include
<test1.scad>
use
<test2.scad>
function f(a) = a*VAR;
echo(g(5));

I would expect an output ECHO: 5 from running test3.scad. However, the
redefinition of f() in test3.scad does not override the test1.scad
definition. If, instead of use, I include test2.scad in test3.scad I get the
wanted overriding but at the expenses of an unwanted additional echo.

--
View this message in context: http://forum.openscad.org/Usage-of-use-and-include-tp17850.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

I really have not understood the behaviour of nested use and include as expressed in the wiki Manual. And does not understand the outcomes of the following three codes: > // file test1 > VAR = 1; > function f(a) = VAR; > // file test2.scad > include > <test1.scad> > function g(a) = f(a); > // file test3.scad > include > <test1.scad> > use > <test2.scad> > function f(a) = a*VAR; > echo(g(5)); I would expect an output ECHO: 5 from running test3.scad. However, the redefinition of f() in test3.scad does not override the test1.scad definition. If, instead of use, I include test2.scad in test3.scad I get the wanted overriding but at the expenses of an unwanted additional echo. -- View this message in context: http://forum.openscad.org/Usage-of-use-and-include-tp17850.html Sent from the OpenSCAD mailing list archive at Nabble.com.
M
MichaelAtOz
Fri, Jul 1, 2016 10:32 PM

AFAIK

include <> basically brings the text inline to the main file. Hence global
scope/context applies.
The internals of a use<>'ed file operates in its own context.

Thus, with use<> the f(a) defining g() in test2.scad will always be the f(a)
in test2.scad
With include<> the f(a) defining g() in test2.scad will be the f(a) in
scope, i.e. the redefined one in test3.scad.

use<> has similar issues if you want to override local variables, you can't.

IMO it is better practice to utilise include<> without executable code, than
use<>.


Admin - PM 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.

The TPP is no simple “trade agreement.”  Fight it! http://www.ourfairdeal.org/  time is running out!

View this message in context: http://forum.openscad.org/Usage-of-use-and-include-tp17850p17852.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

AFAIK include <> basically brings the text inline to the main file. Hence global scope/context applies. The internals of a use<>'ed file operates in its own context. Thus, with use<> the f(a) defining g() in test2.scad will always be the f(a) in test2.scad With include<> the f(a) defining g() in test2.scad will be the f(a) in scope, i.e. the redefined one in test3.scad. use<> has similar issues if you want to override local variables, you can't. IMO it is better practice to utilise include<> without executable code, than use<>. ----- Admin - PM 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. The TPP is no simple “trade agreement.” Fight it! http://www.ourfairdeal.org/ time is running out! -- View this message in context: http://forum.openscad.org/Usage-of-use-and-include-tp17850p17852.html Sent from the OpenSCAD mailing list archive at Nabble.com.
M
MichaelAtOz
Fri, Jul 1, 2016 10:33 PM

p.s. What 'unwanted additional echo'?


Admin - PM 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.

The TPP is no simple “trade agreement.”  Fight it! http://www.ourfairdeal.org/  time is running out!

View this message in context: http://forum.openscad.org/Usage-of-use-and-include-tp17850p17853.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

p.s. What 'unwanted additional echo'? ----- Admin - PM 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. The TPP is no simple “trade agreement.” Fight it! http://www.ourfairdeal.org/ time is running out! -- View this message in context: http://forum.openscad.org/Usage-of-use-and-include-tp17850p17853.html Sent from the OpenSCAD mailing list archive at Nabble.com.