This is for everyone: <<EOA4 In Perl, this problem comes up most often when people say "Why do I have to put a semicolon after do {} or eval {} when it looks like a complete statement?" Well, in Perl 6, you don't, if the final curly is on a line by itself. That is, if you use an expression block as if it were a statement block, it behaves as one. The win is that these rules are consistent across all expression blocks, whether user-defined or built-in. Any expression block construct can be treated as either a statement or a component of an expression. Here's a block that is being treated as a term in an expression: $x = do { ... } + 1;
However, if you write $x = do { ... } + 1; then the + will be taken erroneously as the start of a new statement. (So don't do that.) Note that this special rule only applies to constructs that take a block (that is, a closure) as their last (or only) argument. Operators like sort and map are unaffected. However, certain constructs that used to be in the statement class may become expression constructs in Perl 6. For instance, if we change BEGIN to an expression construct we can now use a BEGIN block inside an expression to force compile-time evaluation of a non-static expression: $value = BEGIN { call_me_once() } + call_me_again(); On the other hand, a one-line BEGIN would then have to have a semicolon. EOA4 To me, this looks like it has answers to all these questions. Luke On 11 Sep 2002, Smylers wrote: > Piers Cawley wrote: > > > So, the new rule for blocks and when the need semicolons seems to be > > "You don't need a semicolon if the block is the last argument of a > > subroutine which expects a block as its last argument", which is all > > very well and all, but ... Ah... hang on, that's *expression* not > > statement, so that should parse ... fine. > > > > Am I worrying unduly about nothing? > > > > What was my question? Argh! I'm more confused now then when I started > > this message... > > I'm wondering how implied semicolons will interact with statement > modifiers.[*0] This is Damian's example of calling a user-defined sub > without a trailing semicolon: > > perhaps $x<$y, 0.25 { print "Happened to be less than\n"} > > Presumably it's valid to put a statement modifier on such a line (with a > semicolon after it, obviously): > > perhaps $x < $_, 0.4 { print "Smaller\n"} for @max; > > Presumably it's also possible to have such a line (without a statement > modifier) with a for loop as the following statement, and for that loop > to use the new syntax for iterating through multiple lists in parallel: > > perhaps $x < $_, 0.4 { print "Smaller\n"} > for @max; @min -> $top; $bottom > { > # etc > } > > How are these two cases distinguished from each other? > > Since whitespace is interchangeable, the second fragment could be > formatted like this to make it look even more like the first: > > perhaps $x < $_, 0.4 { print "Smaller\n"} for @max; > @min -> $top; $bottom > { > # etc > } > > I'm scared. > > [*0] I actually tried to wonder this on this list last week. As I'm > not subscribed I thought that posting through the newsgroup interface > would be the best way of keep threading. I tried posting through Google > Groups. My article showed up there (see link below), but doesn't seem > to have filtered through to other places. Is it supposed to? > > I'm posting this with a newsreader rather than a web-browser so > hopefully it'll get through. Apologies to anybody who got it twice. > > >http://groups.google.co.uk/groups?hl=en&ie=UTF-8&oe=UTF-8&threadm=d7c367d5.0209051022.9ba6bea%40posting.google.com&rnum=1 > > Smylers >