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...
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.
Sent from: http://forum.openscad.org/
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 oz.at.michael@gmail.com 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...
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.
Sent from: http://forum.openscad.org/
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
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/
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/
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/
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 shadowwynd@gmail.com 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
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
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.
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.
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/
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...
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.
Sent from: http://forum.openscad.org/