[OpenSCAD] test if variable is defined

nop head nop.head at gmail.com
Mon Jun 18 22:54:55 CEST 2012


It is simply because when you call defined(COMMANDLINE_A) you are using the
undefined variable  COMMANDLINE_A.

On 18 June 2012 21:49, Johannes Reinhardt <jreinhardt at ist-dein-freund.de>wrote:

>
> Yes I do, but a has the correct values. I assume that OpenSCAD inspects
> both alternatives of the ternary operator, and therefore warns about
> COMMANDLINE_A, even if it is not used.
>
>
> On Mon, 18 Jun 2012 21:42:22 +0100
> nop head <nop.head at gmail.com> wrote:
> > But don't you get a warning every time the module is called
> > when COMMANDLINE_A is not defined.
> >
> > On 18 June 2012 21:24, Johannes Reinhardt <jreinhardt at ist-dein-freund.de
> >wrote:
> >
> > > Is this what you want to do:
> > >
> > > function defined(a) = str(a) != "undef";
> > >
> > > module default_test(a_){
> > >        a = defined(a_) ? a_ : defined(COMMANDLINE_A) ? COMMANDLINE_A :
> > > "fallback_default"; echo(a);
> > > }
> > >
> > > Then if I call openscad without commandline arguments I get
> > >
> > > default_test();              ECHO:"fallback_default"
> > > default_test("supplied");    ECHO:"supplied"
> > >
> > > And if I start openscad with openscad -D COMMANDLINE_A='"commandline"'
> > >
> > > default_test();              ECHO:"commandline"
> > > default_test("supplied");    ECHO:"supplied"
> > >
> > > with OpenSCAD 2012.06.02 under Ubuntu 11.10.
> > >
> > > Greetings
> > >
> > > Johannes
> > >
> > >
> > > On Mon, 18 Jun 2012 20:53:33 +0100
> > > nop head <nop.head at gmail.com> wrote:
> > >
> > > > It only seems to work properly with function arguments.
> > > >
> > > > With ordinary variables you get a warning which says "WARNING:
> Ignoring
> > > > unknown variable 'fred'." so you don't gain anything testing it.
> > > >
> > > > I would love a way of defining a default value for a variable and
> being
> > > > able to override it on the command line. The documentation implies
> it can
> > > > be done but it doesn't work.
> > > >
> > > > On 18 June 2012 08:28, Giles Bathgate <giles.bathgate at gmail.com>
> wrote:
> > > >
> > > > > On 17 June 2012 22:42, Johannes Reinhardt <
> > > jreinhardt at ist-dein-freund.de>
> > > > > wrote:
> > > > >
> > > > > > function defined(a) = str(a) != "undef";
> > > > >
> > > > > You should be able to simply write this as:
> > > > >
> > > > >    function defined(a) = a != undef;
> > > > >
> > > > > Unfortunately there is a bug in openscad so that this doesn't work
> > > > > correctly! The following test highlights the problem:
> > > > >
> > > > >    if(undef==undef) echo("Should work!");
> > > > >    if(undef!=undef) echo("Broken!");
> > > > >
> > > > > Regards
> > > > >
> > > > > Giles
> > > > > _______________________________________________
> > > > > OpenSCAD mailing list
> > > > > OpenSCAD at rocklinux.org
> > > > > http://rocklinux.net/mailman/listinfo/openscad
> > > > >
> > >
> > >
> > > --
> > > Johannes Reinhardt <jreinhardt at ist-dein-freund.de>
> > > _______________________________________________
> > > OpenSCAD mailing list
> > > OpenSCAD at rocklinux.org
> > > http://rocklinux.net/mailman/listinfo/openscad
> > >
>
>
> --
> Johannes Reinhardt <jreinhardt at ist-dein-freund.de>
> _______________________________________________
> OpenSCAD mailing list
> OpenSCAD at rocklinux.org
> http://rocklinux.net/mailman/listinfo/openscad
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rocklinux.net/pipermail/openscad/attachments/20120618/19d21e33/attachment.html


More information about the OpenSCAD mailing list