Damian Conway wrote:

>    > Clever, and really obscure;
>
> "Invisible", rather than "obscure", I would say.
> DWIMity of the first order. :-)
>
>    > wouldn't this then require that _everyone_ that
>    > writes a curried expression for the sort sub use ^a & ^b, and that everyone
>    > writing a non-curried sort sub name their parameters a and b?
>
> No, that's the lovely part. If you use positional placeholders or the
> anonymous placeholder, the resulting curried function has *unnamed*
> parameters, so the *order* of the arguments passed by C<sort> is all
> that matters.

So that's what I missed, that you expect named actual parameters to be legally
passable to subs with unnamed formal parameters.  I would consider that
inappropriate, needing at least a warning.  If people want to use named parameters
with a sub with unnamed formal parameters, they should curry a wrapper.

> So all of these work as expected (as a consequence of the standard
> semantics of named parameters):
>
>         @sorted = sort ^b <=> ^a, @list;                # reverse sort
>         @sorted = sort ^1 <=> ^0, @list;                # reverse sort

I note your use of ^0 and ^1 where I and another poster both used ^1 & ^2.  I wonder
how many people will have to learn about ^0 if you implement it as a positional
placeholder.  Note that regexp produces $1, $2 ..., not $0.  And people really do
count from 1, until they've been indoctinated that computer arrays start at 0.  But
placeholders are not an array.

>         @sorted = sort ^_ <=> ^_, @list;                # normal sort
>         @sorted = sort {$_[1] <=> $_[0]}, @list;        # reverse sort
>         @sorted = sort sub{$_[1] <=> $_[0]}, @list;     # reverse sort
>
> The only case that traps the unwary is:
>
>         @sorted = sort ^y <=> ^x, @list;                # normal sort!
>
> But I don't think Larry was worried about that -- just about the inevitable
> resonances with the late unlamented $a and $b.
>
> Damian

--
Glenn
=====
There  are two kinds of people, those
who finish  what they start,  and  so
on...                 -- Robert Byrne



_____NetZero Free Internet Access and Email______
   http://www.netzero.net/download/index.html

Reply via email to