On Fri, Dec 22, 2006 at 09:16:08AM -0600, Peter da Silva wrote:
> On Dec 22, 2006, at 8:10 AM, Abigail wrote:
> >In Perl6:
> >
> >    print sqrt(9) + 7;  # Prints 10.
> >    print sqrt (9) + 7; # Prints  4.
> 
> Holy Mary's Abscessed Teeth.
> 
> Is this because whitespace is significant in the parse tree, or because 
> sqrt( is a token? Or don't I want to know?


Worse.

The space influences precedence.

Fully parenthesized, 
    the former is read as:  ((sqrt(9)) + (7))
    the latter is read as:  (sqrt((9) + (7)))


Now, the other example I gave (%hash {code} vs %hash{code}) is a parsing
issue. Any parenthesized block preceeded by a space is a coderef that is
executed directly. More or less a short hand for 'sub {code} -> ()'.
But without the space, well, then it can be an index in a hash.

Now, you might wonder what was gained by having this monster. It enables
you to leave of the parenthesis in an if statement. Perl goes from a
formfree language to a language with syntactically whitespace for the
benefit of making parenthesis around a conditional optional.

Woopy.


Abigail
(So, what's 'grep {/foo/} @bar;' meaning in perl6?)

Attachment: pgpOMfBXNwnA6.pgp
Description: PGP signature

Reply via email to