On Fri, 13 Aug 2004 11:36:05 -0700, Larry Wall <[EMAIL PROTECTED]> wrote:
> Yes, that's precisely why I'm trying to generalize Ruby's single
> "magic" block into one or more ordinary parameters.

Excellent. :)

> Two anonymous adverbs?  Hmm.  While I can think of ways to force it to
> work, I'm inclined to disallow it simply because it'd make another
> arbitrary rule we'd have to explain.

And there's quite a bit to explain already.

> You know, at some point you just break down and write them positionally:
> 
>     @array.each( { $^odd.bar() }, { $^even.baz() });

Speaking of which, let's talk a little bit about how I'd write these
methods. After looking at Apocalypse, Exegesis, and Synopsis 6 again,
I have a few more questions. There are two different ways used to
declare a subroutine or method:

 sub foo (&block) {
     &block('foo');
 }

and

 sub foo (Code $block) {
     $block('foo');
 }

Which is right? both? The second seems more extensible. And that leads
me to another question: can a slurpy array pick up a block?

 sub foo ([EMAIL PROTECTED]) {
     say ref @args[0]; # @args[0].type?
 }
 
 foo { $^a =~ /bar/ }; # does this print "Block\n"?

It'd be nice to be able to declare my each method like so:

class Array {
    method each($self: [EMAIL PROTECTED]) {
        my $i = 0;
        my @results;
        for @$self -> $elem {
            my $block = @blocks[ $i++ % [EMAIL PROTECTED] ];
            @results.push( $block($elem) );
        }
        return @results;
    }
}

But that still doesn't let me call that like I'd want;

my @r = @array.each :{ $^first * 2 }
                    :{ $^second * 9 }
                    :{ $^third * 42 };

The other thing I'm wondering is how to apply adverbs to the results
of a function, if that's even possible. I believe this is valid:

 my $odd = 1... :by(2) # an infinite list of odd numbers 

But this?

 sub odd_numbers([EMAIL PROTECTED] of Pair) {
     return 1...;
 }
 my $odd = odd_numbers :by(2);

Does that pass C<by => 2> as a Pair to the function? Or does it apply
the adverb to the result? Maybe I need to do this?

 my $odd = (odd_numbers) :by(2);

My head is swimming at this point, so I'd better give it a rest.

matt

> On the other hand, the parser will have to deal with multi-block
> structures all the time, so perhaps something could be modelled on
> how we eventually handle if/elsif/else, presuming we actually
> declare those as macros, and not strictly as grammar rules.
> 
> Larry

Reply via email to