On Thu, 14 Nov 2002, Luke Palmer wrote:
> > Mailing-List: contact [EMAIL PROTECTED]; run by ezmlm
> > Date: Fri, 15 Nov 2002 07:37:51 +1100 (EST)
> > From: "Timothy S. Nelson" <[EMAIL PROTECTED]>
> > Sender: [EMAIL PROTECTED]
> > X-SMTPD: qpsmtpd/0.12, http://develooper.com/code/qpsmtpd/
> >
> > Here's the next part to the Control Structures message I sent before.
> >
> > The next part is to apply the same idea to loop. Please note that
> > this syntax conflicts with stuff already in Perl, but it's a bit clearer what
> > I mean when I do it this way; the question is, do we scrap my idea, or the
> > other syntax? :)
> >
> > I'll begin with a few words of explanation of what follows. First,
> > you normally wouldn't spread it out this much. Second, each line is
> > optional, except "loop" and { blockL }.
> >
> > ----------------------------------------------------------------------
> > loop
> > parallel
> > first { BLOCKF }
> > each [ actual ] [ $key [ => $value ] ] (@array|%hash)
> > while ( EXPR )
> > count [ $autocount ] [ ($start, $end, $step) ]
> > nest { BLOCKT }
> > { BLOCKL }
> > next { BLOCKX }
> > all { BLOCKA }
> > any { BLOCKB }
> > some { BLOCKS }
> > none { BLOCKN }
> > ----------------------------------------------------------------------
>
> Do you grok the current C<for> syntax? Do you know about the FIRST,
> NEXT, and LAST blocks? If so, you'll easily see that your
> million-and-a-half keywords are complicating what we already have.
Thanks for the comments about the FIRST, NEXT, and LAST blocks. I
knew about NEXT, but the other two I've only seen in answers to my recent
posts (including yours :) ).
> for parallel(<>, 0..Inf) -> $line, $count {
> FIRST { $line //= "#!/usr/bin/perl" }
> # processing...
> NEXT { print STDERR "Next line...\n" }
> LAST { print STDERR "Done\n" }
> }
>
> That 'example' (ignoring the fact that examples usually have some
> purpose ;) has all the useful stuff from your list, and IMO is more
> comprehensible than a LISPish do-ish loop.
Hmm. It's still missing the all/any/some/none part. After looking at
your example here, and a few others I found elsewhere when I went searching, I
modified my original plan. Here's something more like what I'm aiming at
(example now, instead of spec, so I've left out some of the bits I like):
for each actual $key => $value (%hash) while ( ($key + $value) < 3 )
count $autocount (40, 50, 0.2) {
carpe_jugulum($key, $autocount + $value);
LAST {
all { do_something(); }
any { do_something_else(); }
some { do_something_different(); }
none { do_something_the_same(); }
}
}
So, it loops for each element in %hash, evaluates the "while" clause
(modifying $truecount and $falsecount), sets up the $autocount variable, and
loops around the carpe_jugulum; when it's all over, it executes the
all/any/some/none in the LAST section depending on the values of $truecount
and $falsecount.
I'm not particularly attached to that syntax I just used -- more to
the concept behind it.
As for "LISPish", I never got the hang of LISP :).
> Also, keep in mind that that C<parallel> function can be any (possibly
> user-defined) function. I really like that interface. Also keep in
> mind that that may not be The Interface :( i.e. still under debate ).
>
> The only thing it doesn't cover is C<nest>, which, in practical
> situations, isn't all that useful anyway. It's cleaner just to nest
> manually.
As the Finkel book points out, that only works if you know ahead of
time how many layers deep you're going to be nesting. Personally, I don't
expect to need nest more than once or twice in my life, but it'd be useful for
the times it's needed.
Anyway, hope this explains what I'm going on about a bit more.
:)
---------------------------------------------------------------------
| Name: Tim Nelson | Because the Creator is, |
| E-mail: [EMAIL PROTECTED] | I am |
---------------------------------------------------------------------
----BEGIN GEEK CODE BLOCK----
Version 3.1
GCS d? s: a-- C++>++++$ US+ P++ L++ E- W+++ N+ w+> M-- V- Y+>++
PGP->++ R(+) !tv B++ DI++++ D+ G e>++ h!/* y-
-----END GEEK CODE BLOCK-----