Perl's lack of 'in' keyword

Andy Wardley abw at wardley.org
Fri Oct 10 14:48:22 BST 2008


Paul Makepeace wrote:
> Guido eventually Making a Decision.
> What's interesting is that python gets ?: without any additional keywords,
> or... punctuation: http://www.python.org/dev/peps/pep-0308/

    X if C else Y

I don't like having the condition in the middle of the expression.
It would have been better to add a 'then' keyword.

    C then X else Y

It's certainly easier on the eyes than this:

    C ?? X !! Y            # Perl6 - not yummy

Having the condition in the middle is consistent with Guido's ass-backwards
approach to side-effect expressions.  Like having guard expressions at the end
of list generators:

    [ x for xs if c ]

This looks wrong to me because the expression is non-associative. Whichever
way you group it (mentally, if nothing else) is wrong:

    [ (x for xs) if c ]    # NOPE
    [ x for (xs if c) ]    # NOPE

In fact, it really means:

    [ (x if c) for xs ]  or  [ for x { if c { yield x } } ]

I suspect it's down to Guido's insistence on using an LL(1) parser to keep
the language stup^H simple.

A




More information about the london.pm mailing list