On Tue, Jun 22, 2004 at 11:50:03AM -0600, Luke Palmer wrote:
: That one doesn't work.  Named arguments have to come at the end of the
: parameter list (just before the "data list", if there is one).  This is
: a decision I'm gradually beginning to disagree with, because of:
: 
:     sub repeat (&code, +$times = Inf) {
:         code() for 1..$times;
:     }
: 
: This is a plausable routine.  Now look how it's called:
: 
:     repeat {
:         print "I'm ";
:         print "doing ";
:         print "stuff\n";
:     } :times(4);
: 
: This is a horrid violation of the end weight principle.

Fer shure.

: Much nicer is the illegal:
: 
:     repeat :times(4) {
:         print "I'm ";
:         print "doing ";
:         print "stuff\n";
:     }

For some time I have been contemplating allowing (at least) a single
closure parameter to come at the end after the list parameter.  Otherwise
it becomes rather difficult to write a C<for> loop without chicanery.
It's not clear to me, though, how cascaded if/elsif/else blocks should
come in.  I'm leaning towards thinking that it still comes in as a
single closure, but with properties that contain the cascaded closures.

We'll have to be careful to make sure the list can be unambiguously left
out entirely, particularly when we want to pipe to such a function.  Also,
a form like

    for 1... { foo() }

reminds us that we can't just evaluate the list and pop off the closure at
at run time.  :-)

Larry

Reply via email to