discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

$slop special variable and threads

AK
Arne Koehn
Fri, Feb 24, 2023 6:09 AM

Hi,

I am trying to understand the impact of $slop and I am not sure whether
I misunderstand how $ variables work, how slop in BOSL2 works, or
possibly both.

Here is my minimal example where I expect to see a difference between
slop values:

,----
| difference() {
|  {
|    $slop=0.0;
|    threaded_rod(d=20, l=20, pitch=2, $fa=1, $fs=1, internal=true);
|  }
|  {
|    $slop=1.0;
|    threaded_rod(d=20, l=20, pitch=2, $fa=1, $fs=1, internal=true);
|  }
| }
`----

This renders as empty, the three alternatives (internal=false and
swapping slop values from first and second) do as well.

Where am I misunderstanding things?

Best
Arne

Hi, I am trying to understand the impact of $slop and I am not sure whether I misunderstand how $ variables work, how slop in BOSL2 works, or possibly both. Here is my minimal example where I expect to see a difference between slop values: ,---- | difference() { | { | $slop=0.0; | threaded_rod(d=20, l=20, pitch=2, $fa=1, $fs=1, internal=true); | } | { | $slop=1.0; | threaded_rod(d=20, l=20, pitch=2, $fa=1, $fs=1, internal=true); | } | } `---- This renders as empty, the three alternatives (internal=false and swapping slop values from first and second) do as well. Where am I misunderstanding things? Best Arne
NH
nop head
Fri, Feb 24, 2023 7:24 AM

I don't think surplus braces create a new scope.

Try:

difference() {
let($slop = 0)
threaded_rod(d=20, l=20, pitch=2, $fa=1, $fs=1, internal=true);

let($slop = 1)
     threaded_rod(d=20, l=20, pitch=2, $fa=1, $fs=1, internal=true);

}

On Fri, 24 Feb 2023 at 06:16, Arne Koehn arne@chark.eu wrote:

Hi,

I am trying to understand the impact of $slop and I am not sure whether
I misunderstand how $ variables work, how slop in BOSL2 works, or
possibly both.

Here is my minimal example where I expect to see a difference between
slop values:

,----
| difference() {
|  {
|    $slop=0.0;
|    threaded_rod(d=20, l=20, pitch=2, $fa=1, $fs=1, internal=true);
|  }
|  {
|    $slop=1.0;
|    threaded_rod(d=20, l=20, pitch=2, $fa=1, $fs=1, internal=true);
|  }
| }
`----

This renders as empty, the three alternatives (internal=false and
swapping slop values from first and second) do as well.

Where am I misunderstanding things?

Best
Arne


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

I don't think surplus braces create a new scope. Try: difference() { let($slop = 0) threaded_rod(d=20, l=20, pitch=2, $fa=1, $fs=1, internal=true); let($slop = 1) threaded_rod(d=20, l=20, pitch=2, $fa=1, $fs=1, internal=true); } On Fri, 24 Feb 2023 at 06:16, Arne Koehn <arne@chark.eu> wrote: > Hi, > > I am trying to understand the impact of $slop and I am not sure whether > I misunderstand how $ variables work, how slop in BOSL2 works, or > possibly both. > > Here is my minimal example where I expect to see a difference between > slop values: > > ,---- > | difference() { > | { > | $slop=0.0; > | threaded_rod(d=20, l=20, pitch=2, $fa=1, $fs=1, internal=true); > | } > | { > | $slop=1.0; > | threaded_rod(d=20, l=20, pitch=2, $fa=1, $fs=1, internal=true); > | } > | } > `---- > > This renders as empty, the three alternatives (internal=false and > swapping slop values from first and second) do as well. > > Where am I misunderstanding things? > > Best > Arne > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
AK
Arne Koehn
Fri, Feb 24, 2023 7:31 AM

nop head nop.head@gmail.com writes:

I don't think surplus braces create a new scope.

Try:

difference() {
let($slop = 0)
threaded_rod(d=20, l=20, pitch=2, $fa=1, $fs=1, internal=true);

 let($slop = 1)
      threaded_rod(d=20, l=20, pitch=2, $fa=1, $fs=1, internal=true);

}

Thx, that works! (the first one needs $slop=1 and the second $slop=0)
Seems like I am too much used to scoping rules from other languages.

Now on to reading up on how the special variables work and doing test
prints.

nop head <nop.head@gmail.com> writes: > I don't think surplus braces create a new scope. > > Try: > > difference() { > let($slop = 0) > threaded_rod(d=20, l=20, pitch=2, $fa=1, $fs=1, internal=true); > > let($slop = 1) > threaded_rod(d=20, l=20, pitch=2, $fa=1, $fs=1, internal=true); > } Thx, that works! (the first one needs $slop=1 and the second $slop=0) Seems like I am too much used to scoping rules from other languages. Now on to reading up on how the special variables work and doing test prints.
NH
nop head
Fri, Feb 24, 2023 1:43 PM

Micheal just reminded me you can also pass $variables as parameters, even
if the module doesn't list it in the parameter list,

E.g.

threaded_rod(d=20, l=20, pitch=2, $fa=1, $fs=1, internal=true, $slop = 0);

On Fri, 24 Feb 2023 at 07:36, Arne Koehn arne@chark.eu wrote:

nop head nop.head@gmail.com writes:

I don't think surplus braces create a new scope.

Try:

difference() {
let($slop = 0)
threaded_rod(d=20, l=20, pitch=2, $fa=1, $fs=1, internal=true);

 let($slop = 1)
      threaded_rod(d=20, l=20, pitch=2, $fa=1, $fs=1, internal=true);

}

Thx, that works! (the first one needs $slop=1 and the second $slop=0)
Seems like I am too much used to scoping rules from other languages.

Now on to reading up on how the special variables work and doing test
prints.


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

Micheal just reminded me you can also pass $variables as parameters, even if the module doesn't list it in the parameter list, E.g. threaded_rod(d=20, l=20, pitch=2, $fa=1, $fs=1, internal=true, $slop = 0); On Fri, 24 Feb 2023 at 07:36, Arne Koehn <arne@chark.eu> wrote: > > nop head <nop.head@gmail.com> writes: > > > I don't think surplus braces create a new scope. > > > > Try: > > > > difference() { > > let($slop = 0) > > threaded_rod(d=20, l=20, pitch=2, $fa=1, $fs=1, internal=true); > > > > let($slop = 1) > > threaded_rod(d=20, l=20, pitch=2, $fa=1, $fs=1, internal=true); > > } > > Thx, that works! (the first one needs $slop=1 and the second $slop=0) > Seems like I am too much used to scoping rules from other languages. > > Now on to reading up on how the special variables work and doing test > prints. > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
JB
Jordan Brown
Fri, Feb 24, 2023 7:28 PM

On 2/23/2023 11:24 PM, nop head wrote:

I don't think surplus braces create a new scope.

They do not.  (That was what I remembered, and I just confirmed it.)

Does anybody know why that is?  Is there any reason that they should
not create a new scope?

If they don't create a new scope, I don't come up with anything that
they do do.

Here we are talking about braces not associated with a module
invocation.  That is:

...
{
    xxx = 1;
}
....

not

translate([1,1,1]) {
    xxx = 1;
}

I can't say that there are a lot of use cases for creating a new scope
in the middle of things, but there are a few, and if there's no use
cases for braces that don't create a scope, maybe we could and should
change OpenSCAD so that they do.

On 2/23/2023 11:24 PM, nop head wrote: > I don't think surplus braces create a new scope. They do not.  (That was what I remembered, and I just confirmed it.) Does anybody know why that is?  Is there any reason that they should *not* create a new scope? If they don't create a new scope, I don't come up with anything that they *do* do. Here we are talking about braces not associated with a module invocation.  That is: ... { xxx = 1; } .... not translate([1,1,1]) { xxx = 1; } I can't say that there are a lot of use cases for creating a new scope in the middle of things, but there are a few, and if there's no use cases for braces that *don't* create a scope, maybe we could and should change OpenSCAD so that they do.
BC
Bob Carlson
Fri, Feb 24, 2023 7:35 PM

Related: I assumed at first that braces would imply union(). Why isn’t his the case?

-Bob
Tucson AZ

On Feb 24, 2023, at 12:28, Jordan Brown openscad@jordan.maileater.net wrote:

On 2/23/2023 11:24 PM, nop head wrote:

I don't think surplus braces create a new scope.

They do not.  (That was what I remembered, and I just confirmed it.)

Does anybody know why that is?  Is there any reason that they should not create a new scope?

If they don't create a new scope, I don't come up with anything that they do do.

Here we are talking about braces not associated with a module invocation.  That is:
...
{
xxx = 1;
}
....
not
translate([1,1,1]) {
xxx = 1;
}
I can't say that there are a lot of use cases for creating a new scope in the middle of things, but there are a few, and if there's no use cases for braces that don't create a scope, maybe we could and should change OpenSCAD so that they do.


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

Related: I assumed at first that braces would imply union(). Why isn’t his the case? -Bob Tucson AZ On Feb 24, 2023, at 12:28, Jordan Brown <openscad@jordan.maileater.net> wrote: On 2/23/2023 11:24 PM, nop head wrote: > I don't think surplus braces create a new scope. They do not. (That was what I remembered, and I just confirmed it.) Does anybody know why that is? Is there any reason that they should *not* create a new scope? If they don't create a new scope, I don't come up with anything that they *do* do. Here we are talking about braces not associated with a module invocation. That is: ... { xxx = 1; } .... not translate([1,1,1]) { xxx = 1; } I can't say that there are a lot of use cases for creating a new scope in the middle of things, but there are a few, and if there's no use cases for braces that *don't* create a scope, maybe we could and should change OpenSCAD so that they do. _______________________________________________ OpenSCAD mailing list To unsubscribe send an email to discuss-leave@lists.openscad.org
JB
Jordan Brown
Fri, Feb 24, 2023 8:19 PM

On 2/24/2023 11:35 AM, Bob Carlson wrote:

Related: I assumed at first that braces would imply union(). Why isn’t
his the case?

Indeed.

The results here seem surprising:

difference() {
    {
        cube(1.3,center=true);
        sphere();
    }
    cube();
}
On 2/24/2023 11:35 AM, Bob Carlson wrote: > Related: I assumed at first that braces would imply union(). Why isn’t > his the case? Indeed. The results here seem surprising: difference() { { cube(1.3,center=true); sphere(); } cube(); }
TP
Torsten Paul
Fri, Feb 24, 2023 9:28 PM

Quoting a 2016 forum post:

The anonymous scopes was a design mistake in early OpenSCAD, where
scopes didn’t have a function. I don’t know how often people use that
feature to group variables, so I haven’t dared changing that yet, but
I do agree that ideally this should be a true scope.

ciao,
Torsten.

Quoting a 2016 forum post: > The anonymous scopes was a design mistake in early OpenSCAD, where > scopes didn’t have a function. I don’t know how often people use that > feature to group variables, so I haven’t dared changing that yet, but > I do agree that ideally this should be a true scope. ciao, Torsten.
FH
Father Horton
Fri, Feb 24, 2023 9:52 PM

I assume this would be a breaking change, though I doubt much code uses
apparently pointless braces.

On Fri, Feb 24, 2023 at 3:29 PM Torsten Paul Torsten.Paul@gmx.de wrote:

Quoting a 2016 forum post:

The anonymous scopes was a design mistake in early OpenSCAD, where
scopes didn’t have a function. I don’t know how often people use that
feature to group variables, so I haven’t dared changing that yet, but
I do agree that ideally this should be a true scope.

ciao,
Torsten.


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

I assume this would be a breaking change, though I doubt much code uses apparently pointless braces. On Fri, Feb 24, 2023 at 3:29 PM Torsten Paul <Torsten.Paul@gmx.de> wrote: > Quoting a 2016 forum post: > > > The anonymous scopes was a design mistake in early OpenSCAD, where > > scopes didn’t have a function. I don’t know how often people use that > > feature to group variables, so I haven’t dared changing that yet, but > > I do agree that ideally this should be a true scope. > > ciao, > Torsten. > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
NH
nop head
Fri, Feb 24, 2023 10:00 PM

IIRC people used braces to allow code folding in the editor without any
other meaning, so making them introduce a new scope would be a breaking
change.

On Fri, 24 Feb 2023 at 21:53, Father Horton fatherhorton@gmail.com wrote:

I assume this would be a breaking change, though I doubt much code uses
apparently pointless braces.

On Fri, Feb 24, 2023 at 3:29 PM Torsten Paul Torsten.Paul@gmx.de wrote:

Quoting a 2016 forum post:

The anonymous scopes was a design mistake in early OpenSCAD, where
scopes didn’t have a function. I don’t know how often people use that
feature to group variables, so I haven’t dared changing that yet, but
I do agree that ideally this should be a true scope.

ciao,
Torsten.


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

IIRC people used braces to allow code folding in the editor without any other meaning, so making them introduce a new scope would be a breaking change. On Fri, 24 Feb 2023 at 21:53, Father Horton <fatherhorton@gmail.com> wrote: > I assume this would be a breaking change, though I doubt much code uses > apparently pointless braces. > > On Fri, Feb 24, 2023 at 3:29 PM Torsten Paul <Torsten.Paul@gmx.de> wrote: > >> Quoting a 2016 forum post: >> >> > The anonymous scopes was a design mistake in early OpenSCAD, where >> > scopes didn’t have a function. I don’t know how often people use that >> > feature to group variables, so I haven’t dared changing that yet, but >> > I do agree that ideally this should be a true scope. >> >> ciao, >> Torsten. >> _______________________________________________ >> 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 >