On Wed, 2002-04-17 at 11:23, Jonathan Scott Duff wrote: > On Wed, Apr 17, 2002 at 01:38:59PM +0100, Piers Cawley wrote: > > I've got the horrible feeling that doing it this way will lead to > > nasty ambiguities in parsing, but if that's not the case then I must > > confess that I prefer this syntax. Especially if you want to do > > something like: > > > > for @a, @b ; @c, @d -> $x ; $y {...} # Apocalypse > > for @a, @b -> $x ; @c, @d -> $y {...} > > > > I think the second version of that looks cleaner, but neither of them > > is exactly gorgeous. > > And while we're at it, could someone write out the equivalent of this in > perl6 without the use of the -> or the funny for syntax? I find it hard > to think of -> as synonymous to "sub" with either syntax above.
As usual, I'm coming into this late, and so I'm going to sound a little wild-eyed (how do I *sound* any such thing, you may ask...) I think this syntax is sensible in concept, but in practice, it breaks down into incomprehensible very quickly. If I step, back, the goal was this, right? for LIST[;LIST...] -> ARG[,ARG...][;ARG[,ARG...]...] BLOCK It seems simple enough, but we're getting hung up because of the multiple list thing... I agree that while for LIST -> ARG[,ARG...] [; LIST -> ARG[,ARG...]...] BLOCK may LOOK, better, it's very broken WRT the idea that ->x is sub(x) in disguise (with topicalization, of course), and it's still hard to read, just not AS hard. What you're trying to have is a loop union construct, and semicolon is fairly hard to interpret in that way. However, since this is not likely to be the common case (not rare, but uncommon) Larry's Huffman-style coding of syntax would seem to suggest that a longer operator is called for anyway. for LIST -> ARG during LIST -> ARG BLOCK would seem to fit nicely (notice I'm simplifying ARG to save typing here, but the complex case still holds), and if you accept that this is a special case short-hand for: for LIST -> ARG during for LIST -> ARG BLOCK then you have two loops sharing a block in a well defined way to create a single closure, and yet it stays fairly readable. Want more? for @a -> $a during <> -> $_ during 0 .. Inf { last unless exists $a && exists $_ ... } If you read this as you do in English, the length of the last during clause should control the length of the loop, so this is a nice way to say keep looping until both are exhausted. After all, if you eat popcorn during the big game, you don't stop watching the big game when the popcorn runs out, but you stop eating popcorn when the game is over (at least, I would). This gets ugly when you mix in traditional C for (are we keeping that in Perl6?): for @a -> $a during for ($i=1000;$i<$a;$i-=$a) {...} but not by a whole lot.