On Friday, November 1, 2002, at 08:02  AM, Mark J. Reed wrote:
When someone asks "what's the boolean type in Perl?" I'd rather answer "bit" than "Perl doesn't have one", if for no other reason than the latter answer will completely freak them out. :-)
Why?  Plenty of languages get along just fine without a Boolean type.
BASIC, C, LISP, Perl5, Python, TCL . . .
In langs that do not recognize boolean as a type, the convention is either to use an untyped thing or the "littlest possible" thing as a boolean type. (The latter has more possibilities for efficiency, obviously.) Let's look at a presumably common Perl6 construct:

If boolean is not a type, smart people are going to use the smallest possible thing, e.g. "bit", to declare boolean "true/false" vars and attributes.

has bit $.is_plugged_in;

They're going to do it whether we want them to or not (at least, I know I would), because they want to store a true/false value, and they want it to be enforced, and they want it to be small. So the above is the closest to DWIM that we have in Perl6 if you want to store a boolean value in a very compact form, correct? If not, how better would we say it?

Since a "bit" can't even have properties (tho a "Bit" can), it really is, for all practical purposes, a boolean value, and can be treated as such. Fine and dandy, that's OK.

But is that WYM? No. We've declared that a "bit" is _not_ a boolean, so the above is just a hack. It's not WYM it all, it just happens to do the right thing for all possible cases. And for proof that it's wrong, we have "Bit". "Bit" can be "1 but false", or "0 but true", etc. "Bit" is therefore much more clearly not a boolean: it's a 1 or 0, not a true or false. The usage of "bit" as a boolean breaks down if you think of it as the primitive of "Bit". It's not WYM anymore.

So what is the "official" way to efficiently store the result of a boolean expression, for example? If not as a "bit", then what?

If anything, I would suggest a primitive type, "bool", that has no promoted type "Bool". It can just be a placeholder -- a "bit" alias -- but I still don't understand the compelling reason for saying:

has bit $.is_plugged_in;

when WYM is, unambiguously:

has boolean $.is_plugged_in;

It's an excruciatingly common case, and yet we're making it into something that takes more than one sentence to explain. We're ignoring the feathers and the quacking: is this a case of being Too Smart For Our Own Good, here?

MikeL



Reply via email to