discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Weird problem

BE
Bob Ewart
Wed, Mar 30, 2022 6:57 PM

I wrote a little function to set $slop for BOSL2 depending on which
printer I'm using.  I ran their slopTest.scad to find out what values to
use for each printer.  Normally the function would be included from my
library. I'm running with BOSL2 dated 3/30/22

Test code ==

include <BOSL2/std.scad> printer = "ender5"; // [ender5, tenlog, 10v3,
10S5] $slopspec =
[["ender5",.15],["tenlog",.15],["10S5",.04],["10v3",.14]]; function
get_slop(machine, i=0) =     assert(i < len($slopspec), str(machine, "
not recognized"))     ( machine == $slopspec[i][0]? $slopspec[i][1]:
        get_slop(machine,i+1)     ); echo("---Version---",version());
echo(printer=printer); $slop = get_slop(printer); echo($slop=$slop);

=== End code

If I run it as is, I get

WARNING: Ignoring unknown variable 'printer' in file testSlop.scad, line 14

TRACE: called by 'get_slop' in file testSlop.scad, line 14

If I comment out the include <BOSL2/std.scad>, it works!

If I change "printer" to "prtr", it works even with the include.

I grep'ed the BOSL2 library and the only places that "printer" appeared
are in comments

The same thing happens with OpenScad 2021.01 and the Nightly Build 2022
3 27.

--
Bob Ewart

I wrote a little function to set $slop for BOSL2 depending on which printer I'm using.  I ran their slopTest.scad to find out what values to use for each printer.  Normally the function would be included from my library. I'm running with BOSL2 dated 3/30/22 Test code == include <BOSL2/std.scad> printer = "ender5"; // [ender5, tenlog, 10v3, 10S5] $slopspec = [["ender5",.15],["tenlog",.15],["10S5",.04],["10v3",.14]]; function get_slop(machine, i=0) =     assert(i < len($slopspec), str(machine, " not recognized"))     ( machine == $slopspec[i][0]? $slopspec[i][1]:         get_slop(machine,i+1)     ); echo("---Version---",version()); echo(printer=printer); $slop = get_slop(printer); echo($slop=$slop); === End code If I run it as is, I get WARNING: Ignoring unknown variable 'printer' in file testSlop.scad, line 14 TRACE: called by 'get_slop' in file testSlop.scad, line 14 If I comment out the include <BOSL2/std.scad>, it works! If I change "printer" to "prtr", it works even with the include. I grep'ed the BOSL2 library and the only places that "printer" appeared are in comments The same thing happens with OpenScad 2021.01 and the Nightly Build 2022 3 27. -- Bob Ewart
BE
Bob Ewart
Wed, Mar 30, 2022 7:05 PM

I wrote a little function to set $slop for BOSL2 depending on which
printer I'm using.  I ran their slopTest.scad to find out what values
to use for each printer.  Normally the function would be included from
my library. I'm running with BOSL2 dated 3/30/22

Unix/DOS line ends messed up the code.  see attached

If I run it as is, I get

WARNING: Ignoring unknown variable 'printer' in file testSlop.scad,
line 14

TRACE: called by 'get_slop' in file testSlop.scad, line 14

If I comment out the include <BOSL2/std.scad>, it works!

If I change "printer" to "prtr", it works even with the include.

I grep'ed the BOSL2 library and the only places that "printer"
appeared are in comments

The same thing happens with OpenScad 2021.01 and the Nightly Build
2022 3 27.

--
Bob Ewart


OpenSCAD mailing list
To unsubscribe send an email todiscuss-leave@lists.openscad.org

> I wrote a little function to set $slop for BOSL2 depending on which > printer I'm using.  I ran their slopTest.scad to find out what values > to use for each printer.  Normally the function would be included from > my library. I'm running with BOSL2 dated 3/30/22 > > Unix/DOS line ends messed up the code.  see attached > > If I run it as is, I get > > WARNING: Ignoring unknown variable 'printer' in file testSlop.scad, > line 14 > > TRACE: called by 'get_slop' in file testSlop.scad, line 14 > > If I comment out the include <BOSL2/std.scad>, it works! > > If I change "printer" to "prtr", it works even with the include. > > I grep'ed the BOSL2 library and the only places that "printer" > appeared are in comments > > The same thing happens with OpenScad 2021.01 and the Nightly Build > 2022 3 27. > > -- > Bob Ewart > > > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email todiscuss-leave@lists.openscad.org
BE
Bob Ewart
Wed, Mar 30, 2022 7:49 PM

More testing showed that changing "printer" to "prtr" does not work.

If I put the function above the include for BOSL2 it does work

I can't find 'get_slop' or 'slopspec' anywhere in BOSL2. 'machine' does
appear in two comments.

I guess I have a solution to my current  problem.  I just don't
understand why putting the BOSL2 includes first causes a variable to be
unrecognized.

--
Bob

More testing showed that changing "printer" to "prtr" does not work. If I put the function above the include for BOSL2 it does work I can't find 'get_slop' or 'slopspec' anywhere in BOSL2. 'machine' does appear in two comments. I guess I have a solution to my current  problem.  I just don't understand why putting the BOSL2 includes first causes a variable to be unrecognized. -- Bob
MF
Michael Frey
Wed, Mar 30, 2022 8:01 PM

Hi,

The error message is non-sense.

I was able to drill it down from

include <BOSL2/std.scad>

to

include <BOSL2/constants.scad>

Now I can narrow down the issue:

The variable $slop is already defined in constant.scad.

rename $slop to for e.g. $slop1 and it seams to work.

But that is a workaround, not a solution.

Minimum failing example for tonight:

main.scad:

include <include.scad>
printer = "ender5"; // [ender5, tenlog, 10v3, 10S5]

$slopspec = [["ender5",.15],["tenlog",.15],["10S5",.04],["10v3",.14]];
function get_slop(machine, i=0) =
    assert(i < len($slopspec), str(machine, " not recognized"))
    ( machine == $slopspec[i][0]? $slopspec[i][1]:
        get_slop(machine,i+1)
    );

echo("---Version---",version());
echo(printer=printer);

$slop = get_slop(printer);
echo($slop=$slop);

include.scad:

$slop = 1;

There is something really wrong...

I will try to simplify the failing example above.

Then I will open a github issue.

This will become a regression test.

with kind regards,

Michael Frey

Hi, The error message is non-sense. I was able to drill it down from include <BOSL2/std.scad> to include <BOSL2/constants.scad> Now I can narrow down the issue: The variable $slop is already defined in constant.scad. rename $slop to for e.g. $slop1 and it seams to work. But that is a workaround, not a solution. Minimum failing example for tonight: main.scad: include <include.scad> printer = "ender5"; // [ender5, tenlog, 10v3, 10S5] $slopspec = [["ender5",.15],["tenlog",.15],["10S5",.04],["10v3",.14]]; function get_slop(machine, i=0) =     assert(i < len($slopspec), str(machine, " not recognized"))     ( machine == $slopspec[i][0]? $slopspec[i][1]:         get_slop(machine,i+1)     ); echo("---Version---",version()); echo(printer=printer); $slop = get_slop(printer); echo($slop=$slop); include.scad: $slop = 1; There is something really wrong... I will try to simplify the failing example above. Then I will open a github issue. This will become a regression test. with kind regards, Michael Frey
NH
nop head
Wed, Mar 30, 2022 8:05 PM

It is a well known feature of OpenSCAD.

If you define a variable twice it moves the assignments RHS to the site of
the first definition and printer is then not in scope.

On Wed, 30 Mar 2022 at 21:01, Michael Frey michael.frey@gmx.ch wrote:

Hi,

The error message is non-sense.

I was able to drill it down from

include <BOSL2/std.scad>

to

include <BOSL2/constants.scad>

Now I can narrow down the issue:

The variable $slop is already defined in constant.scad.

rename $slop to for e.g. $slop1 and it seams to work.

But that is a workaround, not a solution.

Minimum failing example for tonight:

main.scad:

include <include.scad>
printer = "ender5"; // [ender5, tenlog, 10v3, 10S5]

$slopspec = [["ender5",.15],["tenlog",.15],["10S5",.04],["10v3",.14]];
function get_slop(machine, i=0) =
assert(i < len($slopspec), str(machine, " not recognized"))
( machine == $slopspec[i][0]? $slopspec[i][1]:
get_slop(machine,i+1)
);

echo("---Version---",version());
echo(printer=printer);

$slop = get_slop(printer);
echo($slop=$slop);

include.scad:

$slop = 1;

There is something really wrong...

I will try to simplify the failing example above.

Then I will open a github issue.

This will become a regression test.

with kind regards,

Michael Frey


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

It is a well known feature of OpenSCAD. If you define a variable twice it moves the assignments RHS to the site of the first definition and printer is then not in scope. On Wed, 30 Mar 2022 at 21:01, Michael Frey <michael.frey@gmx.ch> wrote: > Hi, > > > The error message is non-sense. > > > I was able to drill it down from > > include <BOSL2/std.scad> > > to > > include <BOSL2/constants.scad> > > > Now I can narrow down the issue: > > The variable $slop is already defined in constant.scad. > > rename $slop to for e.g. $slop1 and it seams to work. > > But that is a workaround, not a solution. > > > Minimum failing example for tonight: > > main.scad: > > include <include.scad> > printer = "ender5"; // [ender5, tenlog, 10v3, 10S5] > > $slopspec = [["ender5",.15],["tenlog",.15],["10S5",.04],["10v3",.14]]; > function get_slop(machine, i=0) = > assert(i < len($slopspec), str(machine, " not recognized")) > ( machine == $slopspec[i][0]? $slopspec[i][1]: > get_slop(machine,i+1) > ); > > echo("---Version---",version()); > echo(printer=printer); > > $slop = get_slop(printer); > echo($slop=$slop); > > > include.scad: > > $slop = 1; > > > There is something really wrong... > > I will try to simplify the failing example above. > > Then I will open a github issue. > > This will become a regression test. > > > with kind regards, > > Michael Frey > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
MF
Michael Frey
Wed, Mar 30, 2022 8:32 PM

On 30.03.22 22:05, nop head wrote:

It is a well known feature of OpenSCAD.

If you define a variable twice it moves the assignments RHS to the
site of the first definition and printer is then not in scope.

with all due respect, but this looks like a bug:

inc-test.scad:

bla   = "bla";

main.scad:

include <inc-test.scad> fruit = "apple"; //[apple,jerry,lime,other]
$fruits = ["apple","jerry","lime"]; function known(toFind, i=0) =     (
i == len($fruits ) ? false : (toFind == $fruits[i]? $fruits[i]:         
known(toFind,i+1))     ); bla = known(fruit); echo(bla);

bla from the include should get overwritten with apple.

The warnings are a mess and the output incorrect:

WARNING: Ignoring unknown variable 'fruit' in file
function-overwrites-variable.scad, line 10

WARNING: Ignoring unknown variable '$fruits' in file
function-overwrites-variable.scad, line 6

WARNING: len() parameter could not be converted: argument 0: expected
string, found undefined in file function-overwrites-variable.scad, line 6

WARNING: Ignoring unknown variable '$fruits' in file
function-overwrites-variable.scad, line 6

WARNING: Ignoring unknown variable '$fruits' in file
function-overwrites-variable.scad, line 6

ECHO: undef

This looks like a bug to me.

From what I tested, it is the interaction of include and function that
is causing this.

With kind regards,

Michael Frey

On 30.03.22 22:05, nop head wrote: > It is a well known feature of OpenSCAD. > > If you define a variable twice it moves the assignments RHS to the > site of the first definition and printer is then not in scope. > with all due respect, but this looks like a bug: inc-test.scad: bla   = "bla"; main.scad: include <inc-test.scad> fruit = "apple"; //[apple,jerry,lime,other] $fruits = ["apple","jerry","lime"]; function known(toFind, i=0) =     ( i == len($fruits ) ? false : (toFind == $fruits[i]? $fruits[i]:          known(toFind,i+1))     ); bla = known(fruit); echo(bla); bla from the include should get overwritten with apple. The warnings are a mess and the output incorrect: WARNING: Ignoring unknown variable 'fruit' in file function-overwrites-variable.scad, line 10 WARNING: Ignoring unknown variable '$fruits' in file function-overwrites-variable.scad, line 6 WARNING: len() parameter could not be converted: argument 0: expected string, found undefined in file function-overwrites-variable.scad, line 6 WARNING: Ignoring unknown variable '$fruits' in file function-overwrites-variable.scad, line 6 WARNING: Ignoring unknown variable '$fruits' in file function-overwrites-variable.scad, line 6 ECHO: undef This looks like a bug to me. From what I tested, it is the interaction of include and function that is causing this. With kind regards, Michael Frey
LM
Leonard Martin Struttmann
Wed, Mar 30, 2022 10:45 PM

Hmmm, this fails even without using include.  Merely predining bla shows
the issue:

bla = "bla";

fruit = "apple"; //[apple,jerry,lime,other]
$fruits = ["apple","jerry","lime"];

function findIT(toFind, i=0) = echo(i)
( i == len($fruits ) ? false : (toFind == $fruits[i]? $fruits[i]:
known(toFind,i+1)) );

bla = findIT(fruit);

echo(bla);

Remove the bla = "bla"; and it works.

On Wed, Mar 30, 2022 at 3:32 PM Michael Frey michael.frey@gmx.ch wrote:

On 30.03.22 22:05, nop head wrote:

It is a well known feature of OpenSCAD.

If you define a variable twice it moves the assignments RHS to the site of
the first definition and printer is then not in scope.

with all due respect, but this looks like a bug:

inc-test.scad:

bla  = "bla";

main.scad:

include <inc-test.scad> fruit = "apple"; //[apple,jerry,lime,other]
$fruits = ["apple","jerry","lime"]; function known(toFind, i=0) =    ( i
== len($fruits ) ? false : (toFind == $fruits[i]? $fruits[i]:
known(toFind,i+1))    );      bla = known(fruit); echo(bla);

bla from the include should get overwritten with apple.

The warnings are a mess and the output incorrect:

WARNING: Ignoring unknown variable 'fruit' in file
function-overwrites-variable.scad, line 10

WARNING: Ignoring unknown variable '$fruits' in file
function-overwrites-variable.scad, line 6

WARNING: len() parameter could not be converted: argument 0: expected
string, found undefined in file function-overwrites-variable.scad, line 6

WARNING: Ignoring unknown variable '$fruits' in file
function-overwrites-variable.scad, line 6

WARNING: Ignoring unknown variable '$fruits' in file
function-overwrites-variable.scad, line 6

ECHO: undef

This looks like a bug to me.

From what I tested, it is the interaction of include and function that is
causing this.

With kind regards,

Michael Frey


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

Hmmm, this fails even without using include. Merely predining bla shows the issue: bla = "bla"; fruit = "apple"; //[apple,jerry,lime,other] $fruits = ["apple","jerry","lime"]; function findIT(toFind, i=0) = echo(i) ( i == len($fruits ) ? false : (toFind == $fruits[i]? $fruits[i]: known(toFind,i+1)) ); bla = findIT(fruit); echo(bla); Remove the bla = "bla"; and it works. On Wed, Mar 30, 2022 at 3:32 PM Michael Frey <michael.frey@gmx.ch> wrote: > On 30.03.22 22:05, nop head wrote: > > It is a well known feature of OpenSCAD. > > If you define a variable twice it moves the assignments RHS to the site of > the first definition and printer is then not in scope. > > with all due respect, but this looks like a bug: > > inc-test.scad: > > bla = "bla"; > > main.scad: > > include <inc-test.scad> fruit = "apple"; //[apple,jerry,lime,other] > $fruits = ["apple","jerry","lime"]; function known(toFind, i=0) = ( i > == len($fruits ) ? false : (toFind == $fruits[i]? $fruits[i]: > known(toFind,i+1)) ); bla = known(fruit); echo(bla); > > bla from the include should get overwritten with apple. > > The warnings are a mess and the output incorrect: > > WARNING: Ignoring unknown variable 'fruit' in file > function-overwrites-variable.scad, line 10 > > WARNING: Ignoring unknown variable '$fruits' in file > function-overwrites-variable.scad, line 6 > > WARNING: len() parameter could not be converted: argument 0: expected > string, found undefined in file function-overwrites-variable.scad, line 6 > > WARNING: Ignoring unknown variable '$fruits' in file > function-overwrites-variable.scad, line 6 > > WARNING: Ignoring unknown variable '$fruits' in file > function-overwrites-variable.scad, line 6 > > ECHO: undef > > This looks like a bug to me. > > From what I tested, it is the interaction of include and function that is > causing this. > > With kind regards, > > Michael Frey > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
NH
nop head
Wed, Mar 30, 2022 11:30 PM

Yes it is well known. bla has to have the same value throughout all the
code and that value is the last assigned, which is findIT(fruit) but fruit
is not defined where bla is first assigned.

On Wed, 30 Mar 2022 at 23:46, Leonard Martin Struttmann <
lenstruttmann@gmail.com> wrote:

Hmmm, this fails even without using include.  Merely predining bla shows
the issue:

bla = "bla";

fruit = "apple"; //[apple,jerry,lime,other]
$fruits = ["apple","jerry","lime"];

function findIT(toFind, i=0) = echo(i)
( i == len($fruits ) ? false : (toFind == $fruits[i]? $fruits[i]:
known(toFind,i+1)) );

bla = findIT(fruit);

echo(bla);

Remove the bla = "bla"; and it works.

On Wed, Mar 30, 2022 at 3:32 PM Michael Frey michael.frey@gmx.ch wrote:

On 30.03.22 22:05, nop head wrote:

It is a well known feature of OpenSCAD.

If you define a variable twice it moves the assignments RHS to the site
of the first definition and printer is then not in scope.

with all due respect, but this looks like a bug:

inc-test.scad:

bla  = "bla";

main.scad:

include <inc-test.scad> fruit = "apple"; //[apple,jerry,lime,other]
$fruits = ["apple","jerry","lime"]; function known(toFind, i=0) =    ( i
== len($fruits ) ? false : (toFind == $fruits[i]? $fruits[i]:
known(toFind,i+1))    );      bla = known(fruit); echo(bla);

bla from the include should get overwritten with apple.

The warnings are a mess and the output incorrect:

WARNING: Ignoring unknown variable 'fruit' in file
function-overwrites-variable.scad, line 10

WARNING: Ignoring unknown variable '$fruits' in file
function-overwrites-variable.scad, line 6

WARNING: len() parameter could not be converted: argument 0: expected
string, found undefined in file function-overwrites-variable.scad, line 6

WARNING: Ignoring unknown variable '$fruits' in file
function-overwrites-variable.scad, line 6

WARNING: Ignoring unknown variable '$fruits' in file
function-overwrites-variable.scad, line 6

ECHO: undef

This looks like a bug to me.

From what I tested, it is the interaction of include and function that is
causing this.

With kind regards,

Michael Frey


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

Yes it is well known. bla has to have the same value throughout all the code and that value is the last assigned, which is findIT(fruit) but fruit is not defined where bla is first assigned. On Wed, 30 Mar 2022 at 23:46, Leonard Martin Struttmann < lenstruttmann@gmail.com> wrote: > Hmmm, this fails even without using include. Merely predining bla shows > the issue: > > bla = "bla"; > > fruit = "apple"; //[apple,jerry,lime,other] > $fruits = ["apple","jerry","lime"]; > > function findIT(toFind, i=0) = echo(i) > ( i == len($fruits ) ? false : (toFind == $fruits[i]? $fruits[i]: > known(toFind,i+1)) ); > > bla = findIT(fruit); > > echo(bla); > > > Remove the bla = "bla"; and it works. > > > > > On Wed, Mar 30, 2022 at 3:32 PM Michael Frey <michael.frey@gmx.ch> wrote: > >> On 30.03.22 22:05, nop head wrote: >> >> It is a well known feature of OpenSCAD. >> >> If you define a variable twice it moves the assignments RHS to the site >> of the first definition and printer is then not in scope. >> >> with all due respect, but this looks like a bug: >> >> inc-test.scad: >> >> bla = "bla"; >> >> main.scad: >> >> include <inc-test.scad> fruit = "apple"; //[apple,jerry,lime,other] >> $fruits = ["apple","jerry","lime"]; function known(toFind, i=0) = ( i >> == len($fruits ) ? false : (toFind == $fruits[i]? $fruits[i]: >> known(toFind,i+1)) ); bla = known(fruit); echo(bla); >> >> bla from the include should get overwritten with apple. >> >> The warnings are a mess and the output incorrect: >> >> WARNING: Ignoring unknown variable 'fruit' in file >> function-overwrites-variable.scad, line 10 >> >> WARNING: Ignoring unknown variable '$fruits' in file >> function-overwrites-variable.scad, line 6 >> >> WARNING: len() parameter could not be converted: argument 0: expected >> string, found undefined in file function-overwrites-variable.scad, line 6 >> >> WARNING: Ignoring unknown variable '$fruits' in file >> function-overwrites-variable.scad, line 6 >> >> WARNING: Ignoring unknown variable '$fruits' in file >> function-overwrites-variable.scad, line 6 >> >> ECHO: undef >> >> This looks like a bug to me. >> >> From what I tested, it is the interaction of include and function that is >> causing this. >> >> With kind regards, >> >> Michael Frey >> _______________________________________________ >> OpenSCAD mailing list >> To unsubscribe send an email to discuss-leave@lists.openscad.org >> > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
M
MichaelAtOz
Thu, Mar 31, 2022 3:11 AM

It all comes back to the command line '-D var=val', which appends that assignment at the EOF.


From: nop head [mailto:nop.head@gmail.com]
Sent: Thu, 31 Mar 2022 10:31
To: OpenSCAD general discussion
Subject: [OpenSCAD] Re: Weird problem

Yes it is well known. bla has to have the same value throughout all the code and that value is the last assigned, which is findIT(fruit) but fruit is not defined where bla is first assigned.

On Wed, 30 Mar 2022 at 23:46, Leonard Martin Struttmann lenstruttmann@gmail.com wrote:

Hmmm, this fails even without using include.  Merely predining bla shows the issue:

bla = "bla";

fruit = "apple"; //[apple,jerry,lime,other]
$fruits = ["apple","jerry","lime"];

function findIT(toFind, i=0) = echo(i)
( i == len($fruits ) ? false : (toFind == $fruits[i]? $fruits[i]: known(toFind,i+1)) );

bla = findIT(fruit);

echo(bla);

Remove the bla = "bla"; and it works.

On Wed, Mar 30, 2022 at 3:32 PM Michael Frey michael.frey@gmx.ch wrote:

On 30.03.22 22:05, nop head wrote:

It is a well known feature of OpenSCAD.

If you define a variable twice it moves the assignments RHS to the site of the first definition and printer is then not in scope.

with all due respect, but this looks like a bug:

inc-test.scad:

bla  = "bla";

main.scad:

include <inc-test.scad> fruit = "apple"; //[apple,jerry,lime,other] $fruits = ["apple","jerry","lime"]; function known(toFind, i=0) =    ( i == len($fruits ) ? false : (toFind == $fruits[i]? $fruits[i]:          known(toFind,i+1))    );      bla = known(fruit); echo(bla);

bla from the include should get overwritten with apple.

The warnings are a mess and the output incorrect:

WARNING: Ignoring unknown variable 'fruit' in file function-overwrites-variable.scad, line 10

WARNING: Ignoring unknown variable '$fruits' in file function-overwrites-variable.scad, line 6

WARNING: len() parameter could not be converted: argument 0: expected string, found undefined in file function-overwrites-variable.scad, line 6

WARNING: Ignoring unknown variable '$fruits' in file function-overwrites-variable.scad, line 6

WARNING: Ignoring unknown variable '$fruits' in file function-overwrites-variable.scad, line 6

ECHO: undef

This looks like a bug to me.

From what I tested, it is the interaction of include and function that is causing this.

With kind regards,

Michael Frey


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

--
This email has been checked for viruses by AVG.
https://www.avg.com

It all comes back to the command line '-D var=val', which appends that assignment at the EOF. _____ From: nop head [mailto:nop.head@gmail.com] Sent: Thu, 31 Mar 2022 10:31 To: OpenSCAD general discussion Subject: [OpenSCAD] Re: Weird problem Yes it is well known. bla has to have the same value throughout all the code and that value is the last assigned, which is findIT(fruit) but fruit is not defined where bla is first assigned. On Wed, 30 Mar 2022 at 23:46, Leonard Martin Struttmann <lenstruttmann@gmail.com> wrote: Hmmm, this fails even without using include. Merely predining bla shows the issue: bla = "bla"; fruit = "apple"; //[apple,jerry,lime,other] $fruits = ["apple","jerry","lime"]; function findIT(toFind, i=0) = echo(i) ( i == len($fruits ) ? false : (toFind == $fruits[i]? $fruits[i]: known(toFind,i+1)) ); bla = findIT(fruit); echo(bla); Remove the bla = "bla"; and it works. On Wed, Mar 30, 2022 at 3:32 PM Michael Frey <michael.frey@gmx.ch> wrote: On 30.03.22 22:05, nop head wrote: It is a well known feature of OpenSCAD. If you define a variable twice it moves the assignments RHS to the site of the first definition and printer is then not in scope. with all due respect, but this looks like a bug: inc-test.scad: bla = "bla"; main.scad: include <inc-test.scad> fruit = "apple"; //[apple,jerry,lime,other] $fruits = ["apple","jerry","lime"]; function known(toFind, i=0) = ( i == len($fruits ) ? false : (toFind == $fruits[i]? $fruits[i]: known(toFind,i+1)) ); bla = known(fruit); echo(bla); bla from the include should get overwritten with apple. The warnings are a mess and the output incorrect: WARNING: Ignoring unknown variable 'fruit' in file function-overwrites-variable.scad, line 10 WARNING: Ignoring unknown variable '$fruits' in file function-overwrites-variable.scad, line 6 WARNING: len() parameter could not be converted: argument 0: expected string, found undefined in file function-overwrites-variable.scad, line 6 WARNING: Ignoring unknown variable '$fruits' in file function-overwrites-variable.scad, line 6 WARNING: Ignoring unknown variable '$fruits' in file function-overwrites-variable.scad, line 6 ECHO: undef This looks like a bug to me. From what I tested, it is the interaction of include and function that is causing this. With kind regards, Michael Frey _______________________________________________ OpenSCAD mailing list To unsubscribe send an email to discuss-leave@lists.openscad.org _______________________________________________ OpenSCAD mailing list To unsubscribe send an email to discuss-leave@lists.openscad.org -- This email has been checked for viruses by AVG. https://www.avg.com
MF
Michael Frey
Thu, Mar 31, 2022 4:39 AM

On 31.03.22 05:11, MichaelAtOz wrote:

It all comes back to the command line '-D var=val', which appends that
assignment at the EOF.

Now I remember/understand.

I think I will look into improving the error message.

Knowing that the assignment failed in BOSL2/constants.scad on line
(...)  would help a lot.

I think expanding trace should do the trick.

That will also require enabling "stop at first warning", but that often
helps troubleshooting.

With kind regards,

Michael

On 31.03.22 05:11, MichaelAtOz wrote: > > It all comes back to the command line '-D var=val', which appends that > assignment at the EOF. > Now I remember/understand. I think I will look into improving the error message. Knowing that the assignment failed in BOSL2/constants.scad on line (...)  would help a lot. I think expanding trace should do the trick. That will also require enabling "stop at first warning", but that often helps troubleshooting. With kind regards, Michael