On Thu, Dec 22, 2005 at 03:19:03PM -0800, Jonathan Lang wrote: : As a third possibility, could we huffman-code "do nothing" clauses by : leaving out the appropriate argument? That is: : : while $x-- && some_condition($x); : : or : : loop ( ; some_condition($x) ; $x--);
We could, except that "do nothing" is actually something that often should be huffman coded to something longer rather than shorter, just for clarity. We did that already with <null> in rules, and in my mind the idea harks back at least to Ada, which had an explicit "null;" statement. Anyway, reducing {} to ; would be a mistake, I think, for a couple of reasons. The semicolon disappears visually, and it introduces a subtle ambiguity in the error recognition abilities of the parser, particularly for keywords that have both statement and modifier meanings, as "while" does. For instance, if the previous line accidentally omitted the semicolon (a common error in practice), then we can't tell whether the "while" was intended to be a new statement, and the parser might even pass it as as legal when it should fail. In fact, it's pretty much required to. I've never felt tempted to emulate C's block/statement confusion because it enables Perl to be richer in other parts of the language. But I don't think we need an explicit "null" statement, and in the mind of the programmer there is little ambiguity about whether {} means a null block or an empty hash. So I think we can solve the problem by merely declaring that a null hash can act as a null subroutine upon sufficient provocation. In their primary use, hashes and arrays are just strange-looking subroutines anyway, and ordinary subscripting might well desugar to something resembling a sub call. Larry