Luke --

I guess it might be nice to just do that with a block...

  my $n;
  while { $n++; @accum } < $total {
    ...;
  }

since we already have a nice do-this-then-do-this syntax.

Sure, it looks a little weird in a for loop:

  for ($i = 0; $i < $X; { $i++; some_func() }) {
    ...;
  }


but they are already weird anyway.


FWIW, In the (hypothetical) future Jako (see parrot's
languages/jako/docs/future.pod), I've toyed with a few different ways of
looking at these sorts of constructs, one of which is this (I've made it
look a *little* more Perlish than in future.pod):

You can still write for() like this:

    for ($i = 0; $i < l;$ i++) { print $x[$i], "\n" }

but it is really shorthand for this (there's a nit here wrt mapping
"for (my $i ...)" to something reasonable):

    for { $i = 0 } { $i < l } { $i++ } { print $x[$i], "\n" }

or, more verbosely:

    for {
      $i = 0;
    } while {
      $i < l
    } continue {
      $i++
    } do {
      print $x[$i], "\n"
    }

That is, the construct:

  ( ...; ...; ...; )

is another way of saying

  { ... } { ... } { ... }

which, in the case of for(), is interpreted as

  { ... } while { ... } continue { ... }

when each of the "..." is a single statement. For any case where you
want to use more than one statement for one of the "...", you just use
the more verbose syntax.

Now, that won't map directly to Perl 6, since it will handle continue
differently inside the "do" part (right?), but it fits my mental model
nicely (this idea came from looking at looping constructs from Eiffel
as well as elsewhere and looking for the unifying stuff).


Regards,

-- Gregor

On Mon, 2003-11-24 at 16:00, Luke Palmer wrote: 
> Honestly you guys, I'm not trolling.  I'm just getting a lot of ideas
> recently. :-)
> 
> The C comma has always bugged me, but its function is indeed useful
> (many times I use C<and> in its place, if I know the left side will
> always be true). I don't know whether it's staying or not (I've heard
> rumors of both), but I'd suggest that it leave and allow itself to be
> replaced by a word, alongside C<and>, C<or>, and C<err>.
> 
> This word:  C<then>.  
> 
> So, from a recent script of mine:
> 
>     my $n;
>     while $n++ then @accum < $total {
>         ...
>     }
> 
> (Where I got in trouble for using C<and> and never executing anything :-)
> 
> To me, it's very clear what's going on, and eliminates the mystery of
> the comma in scalar context for a syntax error.
> 
> Luke

-- 
Gregor Purdy                            [EMAIL PROTECTED]
Focus Research, Inc.               http://www.focusresearch.com/

Reply via email to