On Thu, May 28, 2009 at 03:33:34PM -0400, Mark J. Reed wrote:
: On Thu, May 28, 2009 at 3:13 PM, Larry Wall <la...@wall.org> wrote:
: > :  I mean, prefix ops can be used in reduce, too, right?
: >
: > I will let you ponder the meaning of "reduce" a bit more, and the
: > relationship of that to the respective arity of infixes vs prefixes.
: 
: Well, infixes are necessarily binary, but while prefixes tend to be
: slurpy, I was thinking one could also declare a prefix op with a
: finite arity.

Well, sure, but we de-emphasize that arity when parsing anyway for
consistency.  All listop-y operators parse infinite args, even if
none of the candidates can handle them.

And if the prefix is declared slurpy, you'd just call it directly
on the arg list, I'd think, since it already has its own idea
of reduction built in.

: And does [...] only reduce if what's inside is an
: operator?

Yes, only operator, but including user-defined operators (unlike APL).

: How do you do a reduce using a plain old binary subroutine?

For the general form,

    [+] @x
    
is equivalent to

    reduce &[+], @x

(Which is another good reason to keep the [+] form.)  Note that the
first arg to reduce is simply a noun, so forgetting the & as in:

    reduce foo, @x

would be an error.  Unless foo returns something Callable, of course.
But the user probably meant:

    reduce &foo, @x.

So just as & turns the "foo" verb into a noun, it turns the [+] verb
into a noun.

Larry

Reply via email to