Use of anonymous blocks in the wild??

classic Classic list List threaded Threaded
16 messages Options
Reply | Threaded
Open this post in threaded view
|

Use of anonymous blocks in the wild??

MichaelAtOz
Administrator
Anonymous blocks, a pair of '{...}' currently have no syntactic effect.
They do not create a new scope.

tl;dr - does anyone use them, or have seen them in the wild?

a=1;
{
  b=2;
  cube(b);
  c=b+a;
  module m(v) echo(v);
}
echo(a=a,b=b,c=c);
m("hello world");
//ECHO: a = 1, b = 2, c = 3
//ECHO: "hello world"

The only thing they do, AFAIK, is to allow the source to be collapsed in the
editor.

I have used that sometimes to group sets of variables and/or chunks of code.

Changes to OpenSCAD are now making the existence of such blocks
inconvenient.
But changing their behaviour COULD break backward compatibility.

I believe it is very unlikely that they they are used much.

So does anyone use them, or seen them in the wild? (In real code)

...and don't start collapsing code just because I mentioned it....




-----
Admin - email* me if you need anything, or if I've done something stupid...

* click on my MichaelAtOz label, there is a link to email me.

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!
--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Admin - email* me if you need anything,
or if I've done something stupid...
* click on my MichaelAtOz label, there is a link to email me.

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!
Reply | Threaded
Open this post in threaded view
|

Re: Use of anonymous blocks in the wild??

nophead
It has been discussed in that past. Apparently people use them to fold sections of variables in an editor. I don't really think that is a good enough reason for making the language different to all others though.

On Wed, 6 Mar 2019 at 02:04, MichaelAtOz <[hidden email]> wrote:
Anonymous blocks, a pair of '{...}' currently have no syntactic effect.
They do not create a new scope.

tl;dr - does anyone use them, or have seen them in the wild?

a=1;
{
  b=2;
  cube(b);
  c=b+a;
  module m(v) echo(v);
}
echo(a=a,b=b,c=c);
m("hello world");
//ECHO: a = 1, b = 2, c = 3
//ECHO: "hello world"

The only thing they do, AFAIK, is to allow the source to be collapsed in the
editor.

I have used that sometimes to group sets of variables and/or chunks of code.

Changes to OpenSCAD are now making the existence of such blocks
inconvenient.
But changing their behaviour COULD break backward compatibility.

I believe it is very unlikely that they they are used much.

So does anyone use them, or seen them in the wild? (In real code)

...and don't start collapsing code just because I mentioned it....




-----
Admin - email* me if you need anything, or if I've done something stupid...

* click on my MichaelAtOz label, there is a link to email me.

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!
--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Use of anonymous blocks in the wild??

Troberg
In reply to this post by MichaelAtOz
Never seen them, never used them.

If you just want folding in the editor, it's better to have specific
commands for that. Example:

    region("Nuts and bolts"){
         //All modules for nuts and bolts go here
        ...
    }



--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Use of anonymous blocks in the wild??

Parkinbot
In reply to this post by MichaelAtOz
I use them regularily during debug and code analysis and for code
development.

//hull()
{
  translate([10, 10, 10]) cube(10, 10,.1);
  translate([10, -10, -10]) cube(10, 10,.1);
}



--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Use of anonymous blocks in the wild??

shadowwynd
This post was updated on .
I also use them for debugging and nudging things together.  

For example:

translate ([10, 0, 0])
{
    thing1();
    translate ([15, 0, 0]) part2();
}

in this case, I have already gotten thing1 and part2 where I need them to be
in relationship to each other, now I need (or think I need) them moved
again, together.  It is easy enough to comment out if I don't need it, or
want to try it both ways.  This is also a great way to make microadjustments
to a part location/rotation.  

I didn't know about the code-folding aspect of {} until this post. :-)






--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Use of anonymous blocks in the wild??

nophead
I think what we are discussing is the special case use at the top level that doesn't create a new scope. I.e. all other uses create a new scope but the top level doesn't because people have used it to group global variables. If it did create a new scope they would no longer be global and would not be accessible outside the block.

On Wed, 6 Mar 2019 at 11:43, shadowwynd <[hidden email]> wrote:
I also use them for debugging and nudging things together. 

For example:

translate ([10, 0, 0])
{
    thing1();
    translate ([15, 0, 0]) part2();
}

in this case, I have already gotten thing1 and part2 where I need them to be
in relationship to each other, now I need (or think I need) them moved
again, together.  It is easy enough to comment out if I don't need it, or
want to try it both ways.  This is also a great way to make microadjustments
to a part location/rotation. 







--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
tp3
Reply | Threaded
Open this post in threaded view
|

Re: Use of anonymous blocks in the wild??

tp3
In reply to this post by Parkinbot
On 06.03.19 11:37, Parkinbot wrote:
> //hull()
> {
>    translate([10, 10, 10]) cube(10, 10,.1);
>    translate([10, -10, -10]) cube(10, 10,.1);
> }

Isn't that actually an argument for *not* having a special
case for the anonymous scope? For example if it's having
some variables as

a = 6;
hull()
{
   a = 3;
   sphere(a);
   translate([a, a, a]) sphere(a);
}
translate([2 * a, 0, 0]) cube(a);

commenting out the hull() will not just make the 2 separate
spheres visible but also completely change position and size
of the cube.

ciao,
   Torsten.

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
-- Torsten
Reply | Threaded
Open this post in threaded view
|

Re: Use of anonymous blocks in the wild??

JordanBrown
In reply to this post by MichaelAtOz

I don't think I've ever used them.

From a language purist standpoint I'd say they *should* cause a new scope, just so that there's a general rule that braces always cause a new scope.



_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Use of anonymous blocks in the wild??

Parkinbot
In reply to this post by tp3
tp3 wrote
> Isn't that actually an argument for *not* having a special
> case for the anonymous scope?

It definitely is. And I guess, it is the reason why I never reuse "variable"
names in a module, even it would be safe within the body of a for loop or
so. I think this is an intuitive result of the development practice using //
as a surrogate for a more specific blank out operator.

If the scope rules are altered, they should be unifed to be the same in
functions and modules.



--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Use of anonymous blocks in the wild??

MichaelAtOz
Administrator
You can do:

module n() children();  // noop - do nothing to the children, just pass them
back

//hull()
n()
{
  cube(10);
  cylinder(d=5, h=20);
}



-----
Admin - email* me if you need anything, or if I've done something stupid...

* click on my MichaelAtOz label, there is a link to email me.

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!
--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Admin - email* me if you need anything,
or if I've done something stupid...
* click on my MichaelAtOz label, there is a link to email me.

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!
tp3
Reply | Threaded
Open this post in threaded view
|

Re: Use of anonymous blocks in the wild??

tp3
...or add a semicolon ;-)

hull();
{
   cube(10);
   cylinder(d=5, h=20);
}

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
-- Torsten
Reply | Threaded
Open this post in threaded view
|

Re: Use of anonymous blocks in the wild??

thehans
In reply to this post by MichaelAtOz
Should also be the same effect as using the group module.  
(I'm not sure  group is really documented, but if you ever look at csg output, you can see that children of control structures end up in a group after evaluation, for example)

//hull()
group()
{
  cube(10);
  cylinder(d=5, h=20);
}




On Wed, Mar 6, 2019 at 5:54 PM MichaelAtOz <[hidden email]> wrote:
You can do:

module n() children();  // noop - do nothing to the children, just pass them
back

//hull()
n()
{
  cube(10);
  cylinder(d=5, h=20);
}



-----
Admin - email* me if you need anything, or if I've done something stupid...

* click on my MichaelAtOz label, there is a link to email me.

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!
--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Use of anonymous blocks in the wild??

shadowwynd
In reply to this post by tp3
The thought of deliberately adding a semicolon to disable code - something
that has accidentally tripped me up countless times - is truly horrifying.



--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Use of anonymous blocks in the wild??

boxcarmib
Anonymous blocks are useful for grouping children. e.g.

module union_diff() {
        difference() {
                union()
                        children(0);
                children(1);
        }
}

union_diff() {
        { // first the union
                _circle(3);
                back(2)
                        _circle(4);}
        { // then the diff
                _rect(2);
        }
}





> On Mar 6, 2019, at 5:55 PM, shadowwynd <[hidden email]> wrote:
>
> The thought of deliberately adding a semicolon to disable code - something
> that has accidentally tripped me up countless times - is truly horrifying.
>
>
>
> --
> Sent from: http://forum.openscad.org/
>
> _______________________________________________
> OpenSCAD mailing list
> [hidden email]
> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Use of anonymous blocks in the wild??

boxcarmib
<sigh> I must be on drugs.
Forget that… it doesn’t work. I thought it worked… but obviously my brain is not working.

> On Mar 21, 2019, at 9:29 PM, Hugo Jackson <[hidden email]> wrote:
>
> Anonymous blocks are useful for grouping children. e.g.
>
> module union_diff() {
> difference() {
> union()
> children(0);
> children(1);
> }
> }
>
> union_diff() {
> { // first the union
> _circle(3);
> back(2)
> _circle(4);}
> { // then the diff
> _rect(2);
> }
> }
>
>
>
>
>
>> On Mar 6, 2019, at 5:55 PM, shadowwynd <[hidden email]> wrote:
>>
>> The thought of deliberately adding a semicolon to disable code - something
>> that has accidentally tripped me up countless times - is truly horrifying.
>>
>>
>>
>> --
>> Sent from: http://forum.openscad.org/
>>
>> _______________________________________________
>> OpenSCAD mailing list
>> [hidden email]
>> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
>


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Use of anonymous blocks in the wild??

grit
Same here , I use it for translating object every now and then for debugging,
but I don't expect the braces to express a new scope in that case.

/Henrik



--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org