On Thu, Jun 24, 2004 at 08:04:10PM +0200, Juerd wrote: : Scott Bronson skribis 2004-06-24 10:44 (-0700): : > However, it seems that because Perl is finally getting a typing system, : > this hack can be fixed in Perl itself! No programmer intervention : > needed. Undef and '' can be false for strings, undef and 0 can be false : > for integers, undef, 0, and 0.0 can be false for floats, etc. : : I think this makes sense: : : string: undef, "" : number: undef, 0 (implies 0.0) : other: convert to number and then decide. Anything that can't : naturally be converted to a number (i.e. would be invalid syntax if : unquoted) is true.
Nope, various user-defined types will want to define their own version of truth. That's precisely what you're doing when you say "0 but true", for instance. : /me wanted to write this in Perl 6, but couldn't think of a good way to : represent true and false when returning from &is_true :) 0 and 1 works pretty well, according to Professor Boole... :-) : Perhaps having real true and false values (where true cannot be false : and false cannot be true) would make a lot of things much easier. I, for : one, would like "return true;" (where "true" is undef-ish: a keyword : that always returns the same value). This is Perl 6. Everything is an object, or at least pretends to be one. Everything has a .boolean method that returns 0 or 1. All conditionals call the .boolean method, at least in the abstract. (The optimizer is free to optimize the method call away for known types within known conditionals, of course. It had better, or evaluating the truth of .boolean will end up calling .boolean again... :-) It's likely that untyped scalars will still treat the string "0" as false, but that any kind of explicitly typed string will treat only the null string as false. (The special "0" rule will not pose as much trouble for Perl 6 as for Perl 5, because most iteration will be done with C<for> rather than C<while>, and a C<for> terminates when its iterator runs out, not when the data becomes false. Plus we'll have the // operator.) Larry