Luke Palmer wrote:

[Piers wrote:]

> > Look, closing braces, ending statements, not on a line by
> > themselves. There's code like this all through the apocalypse and
> > its associated Exegesis, so it looks to me like C<< rx/\} \s* \n/ >>
> > is the regex for 'end of statement'. Either that or we're back with
> > a pile of special cases, which I thought the Apocalypse was supposed
> > to be eliminating.
> 
> That's because C<when>s are statements. Statements don't need to be
> terminated. In C (or even Perl 5) you don't need to write:
> 
>       if (a < b) { foo(); };
> 
> That's because the grammar says that conditionals (and loops) are
> statements all by themselves, because this doesn't make sense:
> 
>       1 + if (a < b) { foo(); } / 2;
> 
> But in Perl 6, things are moving around.  Perl 6 needs the ability for
> users to program such interfaces with subs, which I<are> expressions.
> So, according to Damian, if a sub's last argument is a closure, it can
> (but not necessarily will) act like a statement rather than an
> expression.

The way I remember hearing Damian explain it was the other way round --
that many things that have been statements will now be built-in
functions that take closures as arguments, and that they won't have any
special powers that user-defined functions can't.

I'm reasonably sure it was that way round, cos Damian saying it (in
London) provoked me into asking "Does that mean that C<if> now needs a
semicolon after the block?"  I'm reasonably sure the answer was that any
sub with a closure as a final argument can be invoked without a trailing
semicolon.

> From what I understand of his message, this has nothing to do with
> whitespace.

I think so too, which definitely disagrees with 'A4'.

> I don't know the exact semantics, if they are what I think they are, 
then 
> I disagree.
> 
>       sub cond_if ($condition, &code) {...} # returns something
> 
>       cond_if ($x < $y) { $y }
>       for @a; @b; @c; # ...
> 
> This requires infinite lookahead to parse.

Yup.

> Personally, I liked the A4 decision the best ('}' on a line by
> itself), 

I'm not overly keen on that because it suddenly gives line-breaks a
special meaning.  The rule in Perl at the moment that all whitespace is
interchangeable and you can arrange your code as you like is very
simple.  Adding a special case (aka 'inconsistency') for a single
punctuation character sounds to be against the spirit of 'A5''s intro,
about making things simpler and more consistent.

I think I'd be happy enough with requiring semicolons at the end of all
statements, including C<if> blocks, C<sub> definitions -- everything.
It'd at least be consistent (and the problem with C<eval> and anonymous
C<sub> blocks in Perl 5 is not the semicolon _per se_, just the
semicolon there compared to the lack of one elsewhere).

> and I think otherwise there's too many ambiguities like this one.
> However, if an elegant solution has been (or is going to be) found,
> I'm all ears.

Smylers

Reply via email to