Star in front of if

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

Star in front of if

nophead
If you put a star in front "if" you get a syntax error. 

//works
if(...)
   *circle();

// does not work
*if(...)
   circle();

Shouldn't star work on any bit of the tree?

Reply | Threaded
Open this post in threaded view
|

Re: Star in front of if

Giles Bathgate-2
I think it only works on modules, and "if" in openscad is not
implemented as a module.

Have a look at the openscad bnf if you are interested:
http://git.rapcad.org/cgit.cgi/rapcad/tree/openscad.bnf

Regards

Giles

Reply | Threaded
Open this post in threaded view
|

Re: Star in front of if

Giles Bathgate-2
Of course you can always work around this by wrapping your "if" in a module

module workaround() {
 if(...)
   circle();
}

*workaround();

But that might be a bit cumbersome.

Regards

Giles.

Reply | Threaded
Open this post in threaded view
|

Re: Star in front of if

Whosawhatsis
You can also just precede the if with "union()" and put your asterisk before that. You don't even need to add any braces ( {} ) and this should not affect your design as the contents of the conditional statement are likely being silently unioned anyway.

On Thursday, September 20, 2012 at 4:56 AM, Giles Bathgate wrote:

Of course you can always work around this by wrapping your "if" in a module

module workaround() {
if(...)
circle();
}

*workaround();

But that might be a bit cumbersome.

Regards

Giles.
_______________________________________________
OpenSCAD mailing list

Reply | Threaded
Open this post in threaded view
|

Re: Star in front of if

nophead
Seems like a bug rather than a feature though.

On 20 September 2012 17:44, whosawhatsis <[hidden email]> wrote:
You can also just precede the if with "union()" and put your asterisk before that. You don't even need to add any braces ( {} ) and this should not affect your design as the contents of the conditional statement are likely being silently unioned anyway.

On Thursday, September 20, 2012 at 4:56 AM, Giles Bathgate wrote:

Of course you can always work around this by wrapping your "if" in a module

module workaround() {
if(...)
circle();
}

*workaround();

But that might be a bit cumbersome.

Regards

Giles.
_______________________________________________
OpenSCAD mailing list


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566

Reply | Threaded
Open this post in threaded view
|

Re: Star in front of if

Giles Bathgate-2
In reply to this post by Whosawhatsis
This gives me an idea, I've always found the module modifiers (! # %
*) difficult to remember, and found myself continually referring to
the documentation to see which one I need. How about in addition to
the modifier characters a "debug" module that you just place in front
of the section that you need e.g:

debug() cube();

and the full compliment of other modules  background() root() disable()

I know its much more terse and harder to quickly go in mark out areas
whilst debugging, but its easier to remember self documenting etc...

it would also work with "if"

disable()
 if(...)
   circle(...);

etc...

on further thought you might be able to achieve this in a library already...

module disable() {
   *child();
}

??

Regards

Giles

Reply | Threaded
Open this post in threaded view
|

Re: Star in front of if

nophead
I like them being single characters as they are quick to insert and delete (I don't touch type so typing very slow end error prone for me).

Making low level modules with child() in them doesn't work in practice because of the bug that doesn't allow them to be nested. E.g. if you disabled a bit of tree that already had a disable in it then it would fail.

On 20 September 2012 17:59, Giles Bathgate <[hidden email]> wrote:
This gives me an idea, I've always found the module modifiers (! # %
*) difficult to remember, and found myself continually referring to
the documentation to see which one I need. How about in addition to
the modifier characters a "debug" module that you just place in front
of the section that you need e.g:

debug() cube();

and the full compliment of other modules  background() root() disable()

I know its much more terse and harder to quickly go in mark out areas
whilst debugging, but its easier to remember self documenting etc...

it would also work with "if"

disable()
 if(...)
   circle(...);

etc...

on further thought you might be able to achieve this in a library already...

module disable() {
   *child();
}

??

Regards

Giles
_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566

Reply | Threaded
Open this post in threaded view
|

Re: Star in front of if

Giles Bathgate-2
In reply to this post by nophead
On 20 September 2012 17:51, nop head <[hidden email]> wrote:
> Seems like a bug rather than a feature though.
>

I think it could be considered a bug yes. Interestingly "if" is not
implemented as a module but "for" is. Yet due to two separate issues
which I consider both to be bugs, you can neither do:

if(...) {
    r=d/2; //This is illegal
    sphere(r);
}

nor:

for(...) {
    r=d/2; //This is illegal
    sphere(r);
}


The above is possible in RapCAD of course, but as for your issue with
the module modifiers, well that isn't even implemented yet. But when I
do implement them I could possibly make them statement modifiers, then
they would be viable for anything, not just modules. Of course I will
have to give it some more thought.

Regards

Giles

Reply | Threaded
Open this post in threaded view
|

Re: Star in front of if

kintel
Administrator
In reply to this post by Giles Bathgate-2
Hi guys,

I'm super-busy with life these days, but here are my few cents:

o if statements are modules, but are parsed in a particular way causing them to miss the modifier check. This should be easy to fix, I just need to make sure the tests are hardened in terms of modifiers:
https://github.com/openscad/openscad/issues/197

o I like the idea of more explicit modifier statements, although I'm not sure I like to introduce a new layer of modules, due to modules having a 1-to-1 relationship with the resulting tree structure and thus has potential for introducing more issues down the road. Removing this 1-to-1 relationship is, of course, a slightly more long-term possibility which I haven't thought too much about yet. We could, however, easily solve that by adding the verbose modifier statements as alternative keywords in the parser.

 -Marius


Reply | Threaded
Open this post in threaded view
|

Re: Star in front of if

Giles Bathgate-2
On 20 September 2012 18:44, Marius Kintel <[hidden email]> wrote:
> o if statements are modules,

Oh yeah so they are, Ignore most of the things I said.

Regards

Giles

Reply | Threaded
Open this post in threaded view
|

Re: Star in front of if

kintel
Administrator
In reply to this post by nophead
Fixed: https://github.com/openscad/openscad/issues/197

 -Marius

On 2012-09-20, at 05:34 , nop head wrote:

> If you put a star in front "if" you get a syntax error.
>
> //works
> if(...)
>    *circle();
>
> // does not work
> *if(...)
>    circle();
>
> Shouldn't star work on any bit of the tree?
>
> _______________________________________________
> OpenSCAD mailing list
> [hidden email]
> http://rocklinux.net/mailman/listinfo/openscad
> http://openscad.org - https://flattr.com/thing/121566