On Wed, May 04, 2005 at 09:55:31PM -0600, John Williams wrote:
:    $sum = reduce(+) @array;           # macro

That one suffers the operator/term confusion I mentioned earlier.

:    $sum = reduce &infix:<+> @array;   # regular sub

That one's complicated enough that you actually installed a syntax error.

:    $sum = [+] @array;                 # meta operator

That's rather pretty.  :-)

:    ($sum = 0) >>+=<< @array;          # hyper tricks

That's rather ugly.

:    use My::Cool::Reduce::Mixin;       # unless in core
:    $sum = @array.reduce(+);           # macro-ey method

Macro methods are probably not going to be in anyone's Best Practices book.

: There can never be too many ways to do it, but as one who hasn't been able
: to keep very current with perl6l lately, I think a particularly relevant
: question we should be asking a lot is, "How long will it take someone
: reading that code to figure out what it means?"

It would be nice to have an easy-to-access "What's this?" interface
that could be stitched into your favorite editor to identify what's
under the cursor, or at least a command like:

    p6explain '[+]'

: The nice thing about "reduce" is that it is easy to find in the index.
: "[+]" will not be in the index, although I'm sure it would be the first
: thing one would look for.  I'm not sure how many other things a newbie
: will try before looking up "metacircumfix:<[ ]>" or however that is
: spelled.

I think a p6explain would be a rather popular program.

: Also in the same light, I am not convinced that reduce is used often
: enough to deserve a shorter huffman encoding.  Sure it makes that fancy
: slice shorter, but how much headscratching is required for a human to
: parse that shortness?

That has to be balanced out against the probability that it will soon
be learned by the newbie, especially if it gets into popular idioms.
For instance, since [EMAIL PROTECTED] is going to install spaces between 
elements
just like "@foo", we might see frequently [EMAIL PROTECTED] to do join('',@foo).
Sum of squares is now [+](@foo »*« @foo) or [+](@foo »**« 2).
We'll probably see [//] and [||] now and then.  Lisp hackers will
probably like [=>] to turn a flat list into a car/cdr list.  [<]
could mean "monotonically increasing".

: Personally, I think this would be more readable, in part because the
: object paradigm is widely understood.
: 
:     @foo[0..9; @array.reduce(&infix<;>) ; 0..9];
:     @foo[0..9; @array.reduce(;) ; 0..9];

Well, we're also trying to give the mathematicians various kinds of
built-in syntactic relief where it doesn't greatly interfere with
one's sanity.  The verbose approach would really turn off the PDLers.

: I actually kinda like the idea, in spite of coming across as a naysayer
: here.  It just seems like an idea that should be in a module instead of in
: core, which seems like an awful strange thing to say to $Larry.

As I said in another message, I think this one is kind of a no-brainer
to teach to newbies, since like += it can be taught as a rewrite rule.
I would like it to be as much a part of core Perl as += is.

It also might be slightly easier to optimize something like [+] than
its less direct counterparts.

Larry

Reply via email to