[OpenSCAD] if statement ignores non boolean values
Marius Kintel
marius at kintel.net
Tue Sep 27 19:59:41 CEST 2011
On Sep 17, 2011, at 17:06 PM, nop head wrote:
> 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.
This was implemented in commit 6659ad47b0b07b66b62ca79f3929d361733cc67a in the visitor branch.
From the release notes:
"if() and else() can now take any value type as parameter. false, 0, empty string and empty vector or illegal value type will evaluate as false, everything else as true."
My implementation corresponds to that of Brad, except mine considers any string with length > 0 as true.
I'm uncertain about whether the string "0" should be considered false or not. If we make it false, what about the string "false", or the array [0] (thinking about strings as arrays of characters)?
-Marius
More information about the OpenSCAD
mailing list