Graham Barr <[EMAIL PROTECTED]> writes:

> On Mon, Jan 20, 2003 at 07:27:56PM -0700, Luke Palmer wrote:
>> > What benefit does C<< <~ >> bring to the language?
>> 
>> Again, it provides not just a "null operator" between to calls, but
>> rather a rewrite of method call syntax.  So:
>> 
>>   map {...} <~ grep {...} <~ @boing;
>> 
>> is not:
>> 
>>   map {...} grep {...} @boing;
>> 
>> But rather:
>> 
>>   @boing.map({...}).grep({...});
>
> This is not a for or against, but there is something that has been
> bugging me about this.
>
> Currently in Perl5 it is possible to create a sub that has map/grep-like
> syntax, take a look at List::Util
>
> If the function form of map/grep were to be removed, which has been
> suggested, and the <~ form maps to methods. How would you go about
> defining a utility module similar to List::Util that uses the same
> syntax as map/grep but without making the subs methods on the global
> ARRAY package ?

Well, I very much hope that the function form won't be going away;
functional style is bloody useful dammit and I don't want to be forced
to add line noise just to make those who have a woody for
orthogonality happy. Anyhoo, if it *does* go away, then it should be
possible to set up an appropriate set of multiply dispatched generic
functions.

  sub reduce ( &block, $init, *@array ) is multi {
    @array.reduce(&block, $init);
  }

  sub reduce ( &block, $init, Collection $collection ) is multi {
    $collection.reduce(&block, $init);
  }

  sub reduce ( $expr is qr/<Perl::term>/,
               $init, *@array ) is immediate, is multi {
    @array.reduce( $expr, $init);
  }

  sub reduce ( $expr is qr/Perl::term/,
               $init, Collection $collection ) is immediate, is multi
  {
    $collection.reduce($expr, $init);
  }

Though I'm sure Damian will be long eventually to correct my
syntax. I'm getting this weird feeling of deja vu though...

-- 
Piers

Reply via email to