[OpenSCAD] if statement ignores non boolean values

William Adams william_a_adams at msn.com
Sat Sep 17 19:21:15 CEST 2011


Yah, I guess a warning at least would be in line.  I assume the logic here is:   bool ? (value == true ? true : false) : false And the 'problem' is in the type coercion. bool ? boolvalue : false and you actually want bool ? boolvalue : (intype == numeric ? (value == 0 ? false : true): false)
or something like that. Perhaps it's just a simple bug, rather than an intentional feature.  I've actually been bitten by this a few times, but largely just use boolean values, probably from my usage of C#, which does coercions, but gives you warnings if you want. -- William
===============================

- Shaping clay is easier than digging it out of the ground.



http://internationalwilliam.spaces.msn.com/

 > Date: Sat, 17 Sep 2011 17:06:57 +0100
> From: nop.head at gmail.com
> To: openscad at rocklinux.org
> Subject: Re: [OpenSCAD] if statement ignores non boolean values
> 
> If it only handles boolean values it should complain if it gets
> something that is not one or it should convert it to a boolean like
> any other language.
> 
> On 17 September 2011 16:49, William Adams <william_a_adams at msn.com> wrote:
> > Why would it complain?  I thought OpenScad has 'true' and 'false', actual
> > boolean values.  In this context, 1 != true.
> >
> > so
> > if (1)
> >   echo(true);
> > else
> >   echo(false);
> >
> > will echo: false
> >
> > That seems like 'correct' behavior, if a bit annoying to classical 'C'
> > programmers.
> >
> > -- William
> >
> > ===============================
> > - Shaping clay is easier than digging it out of the ground.
> >
> >
> > http://internationalwilliam.spaces.msn.com/
> >
> >
> >> Date: Sat, 17 Sep 2011 16:06:35 +0100
> >> From: nop.head at gmail.com
> >> To: openscad at rocklinux.org
> >> Subject: [OpenSCAD] if statement ignores non boolean values
> >>
> >> if(1) { ... } is not treated as true but does not complain either. A
> >> bit confusing as I can't think of another language that would not do
> >> one of the other.
> >> _______________________________________________
> >> OpenSCAD mailing list
> >> OpenSCAD at rocklinux.org
> >> http://rocklinux.net/mailman/listinfo/openscad
> >
> > _______________________________________________
> > OpenSCAD mailing list
> > OpenSCAD at rocklinux.org
> > http://rocklinux.net/mailman/listinfo/openscad
> >
> >
> _______________________________________________
> 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/20110917/3a57d7f2/attachment.html


More information about the OpenSCAD mailing list