in reply to How to get sort-like semantics?

If your concern is $a and $b, then see other replies.

If your concern is the first line of your usage documentation:

reduce \&f @x

then you are out of luck. Part of the point of that syntax is that the function name is optional. And that is one of the "prototypes" that is available to built-ins but isn't available to user functions. Note that prototype("CORE::sort") returns undef to indicate that its calling conventions can't be expressed in a sub prototype.

Check opcode.pl in the Perl source and you'll see that sort's argument processing is defined by "dm@ C? L". User defined functions don't have access to all of those flags. The "?" means that you can just leave off the code part, which would make no sense for a "reduce" implementation.

If you use the typical "sub reduce(&@)" prototype, then you can always pass a code ref to your function via &reduce( \&f, ... ). You can also usually drop the & or even the parens, but I suspect that might vary between versions of Perl. See Algorithm::Loops for some comments on quirks in what types of arguments sort can deal with on different versions of Perl, since the quirks appear to be similar. But it looks like you can get away with that syntax except for leaving off the comma on all recent Perls. The lack of the comma has to do with sort making the subroutine name optional so you shouldn't emulate that part anyway.

- tye