discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Weird problem

MF
Michael Frey
Thu, Mar 31, 2022 6:37 PM

Hi Bob,

I found a work around/solution: Just move the include.

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)
    );

include <BOSL2/std.scad>

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

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

The trick is two fold:

All variables and functions needed to calculate "$slop" need to be
defined before the include.

Then comes the include.

Then the assignment that overwrites $slop.

As discussed: The assignment of $slop is actually effective where first
deceleration is in BOSL2/constants.scad.

Therefor, everything required to calculate $slope, needs to be defined,
before the first assignment of $slope.

As this is overwriting of included variables is a feature.

Not warning about that is also a feature.


I still have an idea how to simplify debugging:

WARNING: Ignoring unknown variable 'printer' in file main3.scad, line 15

TRACE: called by 'get_slop' in file main3.scad, line 15

TRACE: assignment to '$slop' in file BOSL2/constants.scad, line 95

Execution aborted

I do not know how to improve the actual warning, but adding trace to
assignments seams like a good idea as that leads to the right questions.

With Kind regards,

Michael Frey

Hi Bob, I found a work around/solution: Just move the include. 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)     ); *include <BOSL2/std.scad>* echo("---Version---",version()); echo(printer=printer); $slop = get_slop(printer); echo($slop=$slop); The trick is two fold: All variables and functions needed to calculate "$slop" need to be defined before the include. Then comes the include. Then the assignment that overwrites $slop. As discussed: The assignment of $slop is actually effective where first deceleration is in BOSL2/constants.scad. Therefor, everything required to calculate $slope, needs to be defined, before the first assignment of $slope. As this is overwriting of included variables is a feature. Not warning about that is also a feature. ------------ I still have an idea how to simplify debugging: WARNING: Ignoring unknown variable 'printer' in file main3.scad, line 15 TRACE: called by 'get_slop' in file main3.scad, line 15 TRACE: assignment to '$slop' in file BOSL2/constants.scad, line 95 Execution aborted I do not know how to improve the actual warning, but adding trace to assignments seams like a good idea as that leads to the right questions. With Kind regards, Michael Frey
AM
Adrian Mariano
Wed, Apr 13, 2022 12:49 AM

To avoid this weirdness, BOSL2 has been changed so that $slop is
undefined by default, and its default value is assigned when it is
used.  This means you should be able to set it however you want
without triggering bizarre behavior.

On Thu, Mar 31, 2022 at 2:37 PM Michael Frey michael.frey@gmx.ch wrote:

Hi Bob,

I found a work around/solution: Just move the include.

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)
);

include <BOSL2/std.scad>

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

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

The trick is two fold:

All variables and functions needed to calculate "$slop" need to be defined before the include.

Then comes the include.

Then the assignment that overwrites $slop.

As discussed: The assignment of $slop is actually effective where first deceleration is in BOSL2/constants.scad.

Therefor, everything required to calculate $slope, needs to be defined, before the first assignment of $slope.

As this is overwriting of included variables is a feature.

Not warning about that is also a feature.


I still have an idea how to simplify debugging:

WARNING: Ignoring unknown variable 'printer' in file main3.scad, line 15

TRACE: called by 'get_slop' in file main3.scad, line 15

TRACE: assignment to '$slop' in file BOSL2/constants.scad, line 95

Execution aborted

I do not know how to improve the actual warning, but adding trace to assignments seams like a good idea as that leads to the right questions.

With Kind regards,

Michael Frey


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

To avoid this weirdness, BOSL2 has been changed so that $slop is undefined by default, and its default value is assigned when it is used. This means you should be able to set it however you want without triggering bizarre behavior. On Thu, Mar 31, 2022 at 2:37 PM Michael Frey <michael.frey@gmx.ch> wrote: > > Hi Bob, > > > I found a work around/solution: Just move the include. > > 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) > ); > > include <BOSL2/std.scad> > > echo("---Version---",version()); > echo(printer=printer); > > $slop = get_slop(printer); > echo($slop=$slop); > > The trick is two fold: > > All variables and functions needed to calculate "$slop" need to be defined before the include. > > Then comes the include. > > Then the assignment that overwrites $slop. > > As discussed: The assignment of $slop is actually effective where first deceleration is in BOSL2/constants.scad. > > Therefor, everything required to calculate $slope, needs to be defined, before the first assignment of $slope. > > > As this is overwriting of included variables is a feature. > > Not warning about that is also a feature. > > > ------------ > > > I still have an idea how to simplify debugging: > > WARNING: Ignoring unknown variable 'printer' in file main3.scad, line 15 > > TRACE: called by 'get_slop' in file main3.scad, line 15 > > TRACE: assignment to '$slop' in file BOSL2/constants.scad, line 95 > > Execution aborted > > I do not know how to improve the actual warning, but adding trace to assignments seams like a good idea as that leads to the right questions. > > > With Kind regards, > > Michael Frey > > > > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org
AC
A. Craig West
Wed, Apr 13, 2022 1:12 AM

My library solves the same problem with functions, I have one defined
getDrawEpsilon() which is what I use whenever I need the value
($draw_epsilon) in my case. I actually have an argument which is a
multiplier, to make it easier to use for nested objects

On Tue, 12 Apr 2022, 20:49 Adrian Mariano, avm4@cornell.edu wrote:

To avoid this weirdness, BOSL2 has been changed so that $slop is
undefined by default, and its default value is assigned when it is
used.  This means you should be able to set it however you want
without triggering bizarre behavior.

On Thu, Mar 31, 2022 at 2:37 PM Michael Frey michael.frey@gmx.ch wrote:

Hi Bob,

I found a work around/solution: Just move the include.

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)
);

include <BOSL2/std.scad>

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

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

The trick is two fold:

All variables and functions needed to calculate "$slop" need to be

defined before the include.

Then comes the include.

Then the assignment that overwrites $slop.

As discussed: The assignment of $slop is actually effective where first

deceleration is in BOSL2/constants.scad.

Therefor, everything required to calculate $slope, needs to be defined,

before the first assignment of $slope.

As this is overwriting of included variables is a feature.

Not warning about that is also a feature.


I still have an idea how to simplify debugging:

WARNING: Ignoring unknown variable 'printer' in file main3.scad, line 15

TRACE: called by 'get_slop' in file main3.scad, line 15

TRACE: assignment to '$slop' in file BOSL2/constants.scad, line 95

Execution aborted

I do not know how to improve the actual warning, but adding trace to

assignments seams like a good idea as that leads to the right questions.

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

My library solves the same problem with functions, I have one defined getDrawEpsilon() which is what I use whenever I need the value ($draw_epsilon) in my case. I actually have an argument which is a multiplier, to make it easier to use for nested objects On Tue, 12 Apr 2022, 20:49 Adrian Mariano, <avm4@cornell.edu> wrote: > To avoid this weirdness, BOSL2 has been changed so that $slop is > undefined by default, and its default value is assigned when it is > used. This means you should be able to set it however you want > without triggering bizarre behavior. > > On Thu, Mar 31, 2022 at 2:37 PM Michael Frey <michael.frey@gmx.ch> wrote: > > > > Hi Bob, > > > > > > I found a work around/solution: Just move the include. > > > > 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) > > ); > > > > include <BOSL2/std.scad> > > > > echo("---Version---",version()); > > echo(printer=printer); > > > > $slop = get_slop(printer); > > echo($slop=$slop); > > > > The trick is two fold: > > > > All variables and functions needed to calculate "$slop" need to be > defined before the include. > > > > Then comes the include. > > > > Then the assignment that overwrites $slop. > > > > As discussed: The assignment of $slop is actually effective where first > deceleration is in BOSL2/constants.scad. > > > > Therefor, everything required to calculate $slope, needs to be defined, > before the first assignment of $slope. > > > > > > As this is overwriting of included variables is a feature. > > > > Not warning about that is also a feature. > > > > > > ------------ > > > > > > I still have an idea how to simplify debugging: > > > > WARNING: Ignoring unknown variable 'printer' in file main3.scad, line 15 > > > > TRACE: called by 'get_slop' in file main3.scad, line 15 > > > > TRACE: assignment to '$slop' in file BOSL2/constants.scad, line 95 > > > > Execution aborted > > > > I do not know how to improve the actual warning, but adding trace to > assignments seams like a good idea as that leads to the right questions. > > > > > > 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 >
AM
Adrian Mariano
Wed, Apr 13, 2022 2:02 AM

Are you saying that your library solves the problem of $draw_epsilon
possibly being undefined by using a getDrawEpsilon() function?  I
mean, that is of course the obvious approach and it is how the
handling of the $slop variable has been managed in BOSL2 to deal with
the change: there is now a get_slop() function.  But it wasn't
apparent that this was necessary until this thread.

On Tue, Apr 12, 2022 at 9:13 PM A. Craig West acraigwest@gmail.com wrote:

My library solves the same problem with functions, I have one defined getDrawEpsilon() which is what I use whenever I need the value ($draw_epsilon) in my case. I actually have an argument which is a multiplier, to make it easier to use for nested objects

On Tue, 12 Apr 2022, 20:49 Adrian Mariano, avm4@cornell.edu wrote:

To avoid this weirdness, BOSL2 has been changed so that $slop is
undefined by default, and its default value is assigned when it is
used.  This means you should be able to set it however you want
without triggering bizarre behavior.

On Thu, Mar 31, 2022 at 2:37 PM Michael Frey michael.frey@gmx.ch wrote:

Hi Bob,

I found a work around/solution: Just move the include.

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)
);

include <BOSL2/std.scad>

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

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

The trick is two fold:

All variables and functions needed to calculate "$slop" need to be defined before the include.

Then comes the include.

Then the assignment that overwrites $slop.

As discussed: The assignment of $slop is actually effective where first deceleration is in BOSL2/constants.scad.

Therefor, everything required to calculate $slope, needs to be defined, before the first assignment of $slope.

As this is overwriting of included variables is a feature.

Not warning about that is also a feature.


I still have an idea how to simplify debugging:

WARNING: Ignoring unknown variable 'printer' in file main3.scad, line 15

TRACE: called by 'get_slop' in file main3.scad, line 15

TRACE: assignment to '$slop' in file BOSL2/constants.scad, line 95

Execution aborted

I do not know how to improve the actual warning, but adding trace to assignments seams like a good idea as that leads to the right questions.

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


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

Are you saying that your library solves the problem of $draw_epsilon possibly being undefined by using a getDrawEpsilon() function? I mean, that is of course the obvious approach and it is how the handling of the $slop variable has been managed in BOSL2 to deal with the change: there is now a get_slop() function. But it wasn't apparent that this was necessary until this thread. On Tue, Apr 12, 2022 at 9:13 PM A. Craig West <acraigwest@gmail.com> wrote: > > My library solves the same problem with functions, I have one defined getDrawEpsilon() which is what I use whenever I need the value ($draw_epsilon) in my case. I actually have an argument which is a multiplier, to make it easier to use for nested objects > > On Tue, 12 Apr 2022, 20:49 Adrian Mariano, <avm4@cornell.edu> wrote: >> >> To avoid this weirdness, BOSL2 has been changed so that $slop is >> undefined by default, and its default value is assigned when it is >> used. This means you should be able to set it however you want >> without triggering bizarre behavior. >> >> On Thu, Mar 31, 2022 at 2:37 PM Michael Frey <michael.frey@gmx.ch> wrote: >> > >> > Hi Bob, >> > >> > >> > I found a work around/solution: Just move the include. >> > >> > 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) >> > ); >> > >> > include <BOSL2/std.scad> >> > >> > echo("---Version---",version()); >> > echo(printer=printer); >> > >> > $slop = get_slop(printer); >> > echo($slop=$slop); >> > >> > The trick is two fold: >> > >> > All variables and functions needed to calculate "$slop" need to be defined before the include. >> > >> > Then comes the include. >> > >> > Then the assignment that overwrites $slop. >> > >> > As discussed: The assignment of $slop is actually effective where first deceleration is in BOSL2/constants.scad. >> > >> > Therefor, everything required to calculate $slope, needs to be defined, before the first assignment of $slope. >> > >> > >> > As this is overwriting of included variables is a feature. >> > >> > Not warning about that is also a feature. >> > >> > >> > ------------ >> > >> > >> > I still have an idea how to simplify debugging: >> > >> > WARNING: Ignoring unknown variable 'printer' in file main3.scad, line 15 >> > >> > TRACE: called by 'get_slop' in file main3.scad, line 15 >> > >> > TRACE: assignment to '$slop' in file BOSL2/constants.scad, line 95 >> > >> > Execution aborted >> > >> > I do not know how to improve the actual warning, but adding trace to assignments seams like a good idea as that leads to the right questions. >> > >> > >> > 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 > > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org
AC
A. Craig West
Wed, Apr 13, 2022 2:11 AM

Yes. I think my $draw_epsilon is pretty much equivalent to $slop, as well,
but I'm not positive

On Tue, 12 Apr 2022, 22:02 Adrian Mariano, avm4@cornell.edu wrote:

Are you saying that your library solves the problem of $draw_epsilon
possibly being undefined by using a getDrawEpsilon() function?  I
mean, that is of course the obvious approach and it is how the
handling of the $slop variable has been managed in BOSL2 to deal with
the change: there is now a get_slop() function.  But it wasn't
apparent that this was necessary until this thread.

On Tue, Apr 12, 2022 at 9:13 PM A. Craig West acraigwest@gmail.com
wrote:

My library solves the same problem with functions, I have one defined

getDrawEpsilon() which is what I use whenever I need the value
($draw_epsilon) in my case. I actually have an argument which is a
multiplier, to make it easier to use for nested objects

On Tue, 12 Apr 2022, 20:49 Adrian Mariano, avm4@cornell.edu wrote:

To avoid this weirdness, BOSL2 has been changed so that $slop is
undefined by default, and its default value is assigned when it is
used.  This means you should be able to set it however you want
without triggering bizarre behavior.

On Thu, Mar 31, 2022 at 2:37 PM Michael Frey michael.frey@gmx.ch

wrote:

Hi Bob,

I found a work around/solution: Just move the include.

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)
);

include <BOSL2/std.scad>

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

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

The trick is two fold:

All variables and functions needed to calculate "$slop" need to be

defined before the include.

Then comes the include.

Then the assignment that overwrites $slop.

As discussed: The assignment of $slop is actually effective where

first deceleration is in BOSL2/constants.scad.

Therefor, everything required to calculate $slope, needs to be

defined, before the first assignment of $slope.

As this is overwriting of included variables is a feature.

Not warning about that is also a feature.


I still have an idea how to simplify debugging:

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

15

TRACE: called by 'get_slop' in file main3.scad, line 15

TRACE: assignment to '$slop' in file BOSL2/constants.scad, line 95

Execution aborted

I do not know how to improve the actual warning, but adding trace to

assignments seams like a good idea as that leads to the right questions.

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


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. I think my $draw_epsilon is pretty much equivalent to $slop, as well, but I'm not positive On Tue, 12 Apr 2022, 22:02 Adrian Mariano, <avm4@cornell.edu> wrote: > Are you saying that your library solves the problem of $draw_epsilon > possibly being undefined by using a getDrawEpsilon() function? I > mean, that is of course the obvious approach and it is how the > handling of the $slop variable has been managed in BOSL2 to deal with > the change: there is now a get_slop() function. But it wasn't > apparent that this was necessary until this thread. > > On Tue, Apr 12, 2022 at 9:13 PM A. Craig West <acraigwest@gmail.com> > wrote: > > > > My library solves the same problem with functions, I have one defined > getDrawEpsilon() which is what I use whenever I need the value > ($draw_epsilon) in my case. I actually have an argument which is a > multiplier, to make it easier to use for nested objects > > > > On Tue, 12 Apr 2022, 20:49 Adrian Mariano, <avm4@cornell.edu> wrote: > >> > >> To avoid this weirdness, BOSL2 has been changed so that $slop is > >> undefined by default, and its default value is assigned when it is > >> used. This means you should be able to set it however you want > >> without triggering bizarre behavior. > >> > >> On Thu, Mar 31, 2022 at 2:37 PM Michael Frey <michael.frey@gmx.ch> > wrote: > >> > > >> > Hi Bob, > >> > > >> > > >> > I found a work around/solution: Just move the include. > >> > > >> > 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) > >> > ); > >> > > >> > include <BOSL2/std.scad> > >> > > >> > echo("---Version---",version()); > >> > echo(printer=printer); > >> > > >> > $slop = get_slop(printer); > >> > echo($slop=$slop); > >> > > >> > The trick is two fold: > >> > > >> > All variables and functions needed to calculate "$slop" need to be > defined before the include. > >> > > >> > Then comes the include. > >> > > >> > Then the assignment that overwrites $slop. > >> > > >> > As discussed: The assignment of $slop is actually effective where > first deceleration is in BOSL2/constants.scad. > >> > > >> > Therefor, everything required to calculate $slope, needs to be > defined, before the first assignment of $slope. > >> > > >> > > >> > As this is overwriting of included variables is a feature. > >> > > >> > Not warning about that is also a feature. > >> > > >> > > >> > ------------ > >> > > >> > > >> > I still have an idea how to simplify debugging: > >> > > >> > WARNING: Ignoring unknown variable 'printer' in file main3.scad, line > 15 > >> > > >> > TRACE: called by 'get_slop' in file main3.scad, line 15 > >> > > >> > TRACE: assignment to '$slop' in file BOSL2/constants.scad, line 95 > >> > > >> > Execution aborted > >> > > >> > I do not know how to improve the actual warning, but adding trace to > assignments seams like a good idea as that leads to the right questions. > >> > > >> > > >> > 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 > > > > _______________________________________________ > > 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 >
FH
Father Horton
Wed, Apr 13, 2022 2:32 AM

Can you share the syntax for this? It’s not apparent to me how it can be
done.

Can you share the syntax for this? It’s not apparent to me how it can be done.
AM
Adrian Mariano
Wed, Apr 13, 2022 2:43 AM

So the point is that BOSL2 has a $slop parameter, which used to be
defined as $slop=0 within the BOSL2 code to its default, but that
generated the above problem.  So now we just don't define it at all.
And then we have

function get_slop() = is_undef($slop) ? 0 : $slop;

That will return the default value of 0 if $slop is not set, or if it
is set, it returns the value it is set to.  BOSL2 actually has a
default() function where you can write

x = default(a,0)

and get x set to a if a is defined, or zero otherwise.  However, this
only works for variables that exist and are set to undef, not for
variables that don't exist at all.  (So a key example is a parameter
to a function or module: if you don't pass it then it exists and is
set to undef.)  In the case of variables that don't exist at all, you
get an error when you pass to the default() function.  Hence it was
necessary to have a special get_slop function to handle that case.

On Tue, Apr 12, 2022 at 10:32 PM Father Horton fatherhorton@gmail.com wrote:

Can you share the syntax for this? It’s not apparent to me how it can be done.  _______________________________________________
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

So the point is that BOSL2 has a $slop parameter, which used to be defined as $slop=0 within the BOSL2 code to its default, but that generated the above problem. So now we just don't define it at all. And then we have function get_slop() = is_undef($slop) ? 0 : $slop; That will return the default value of 0 if $slop is not set, or if it is set, it returns the value it is set to. BOSL2 actually has a default() function where you can write x = default(a,0) and get x set to a if a is defined, or zero otherwise. However, this only works for variables that exist and are set to undef, not for variables that don't exist at all. (So a key example is a parameter to a function or module: if you don't pass it then it exists and is set to undef.) In the case of variables that don't exist at all, you get an error when you pass to the default() function. Hence it was necessary to have a special get_slop function to handle that case. On Tue, Apr 12, 2022 at 10:32 PM Father Horton <fatherhorton@gmail.com> wrote: > > Can you share the syntax for this? It’s not apparent to me how it can be done. _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org
FH
Father Horton
Wed, Apr 13, 2022 2:46 AM

Ah. I was hoping for something a bit more magic that would automatically
invoke a function if a variable was accessed without being defined, but I
didn't see how to do that in OpenSCAD. I'm glad I wasn't overlooking
something obvious (or even moderately subtle).

On Tue, Apr 12, 2022 at 9:43 PM Adrian Mariano avm4@cornell.edu wrote:

So the point is that BOSL2 has a $slop parameter, which used to be
defined as $slop=0 within the BOSL2 code to its default, but that
generated the above problem.  So now we just don't define it at all.
And then we have

function get_slop() = is_undef($slop) ? 0 : $slop;

That will return the default value of 0 if $slop is not set, or if it
is set, it returns the value it is set to.  BOSL2 actually has a
default() function where you can write

x = default(a,0)

and get x set to a if a is defined, or zero otherwise.  However, this
only works for variables that exist and are set to undef, not for
variables that don't exist at all.  (So a key example is a parameter
to a function or module: if you don't pass it then it exists and is
set to undef.)  In the case of variables that don't exist at all, you
get an error when you pass to the default() function.  Hence it was
necessary to have a special get_slop function to handle that case.

On Tue, Apr 12, 2022 at 10:32 PM Father Horton fatherhorton@gmail.com
wrote:

Can you share the syntax for this? It’s not apparent to me how it can be

done.  _______________________________________________

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

Ah. I was hoping for something a bit more magic that would automatically invoke a function if a variable was accessed without being defined, but I didn't see how to do that in OpenSCAD. I'm glad I wasn't overlooking something obvious (or even moderately subtle). On Tue, Apr 12, 2022 at 9:43 PM Adrian Mariano <avm4@cornell.edu> wrote: > So the point is that BOSL2 has a $slop parameter, which used to be > defined as $slop=0 within the BOSL2 code to its default, but that > generated the above problem. So now we just don't define it at all. > And then we have > > function get_slop() = is_undef($slop) ? 0 : $slop; > > That will return the default value of 0 if $slop is not set, or if it > is set, it returns the value it is set to. BOSL2 actually has a > default() function where you can write > > x = default(a,0) > > and get x set to a if a is defined, or zero otherwise. However, this > only works for variables that exist and are set to undef, not for > variables that don't exist at all. (So a key example is a parameter > to a function or module: if you don't pass it then it exists and is > set to undef.) In the case of variables that don't exist at all, you > get an error when you pass to the default() function. Hence it was > necessary to have a special get_slop function to handle that case. > > On Tue, Apr 12, 2022 at 10:32 PM Father Horton <fatherhorton@gmail.com> > wrote: > > > > Can you share the syntax for this? It’s not apparent to me how it can be > done. _______________________________________________ > > 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 >