develooper Front page | perl.perl6.language | Postings from April 2005

Re: Hyper operator corner case?

Thread Previous | Thread Next
From:
John Williams
Date:
April 14, 2005 10:08
Subject:
Re: Hyper operator corner case?
Message ID:
Pine.LNX.4.33.0504141050290.25532-100000@sharkey.morinda.com
I found where Damain explains the rule as basically "replicate dimensions,
extend lengths", using an "identity value" when extending the length.
<http://www.mail-archive.com/perl6-language@perl.org/msg08304.html>

On Wed, 13 Apr 2005, Thomas Sandlaß wrote:

> Brent 'Dax' Royal-Gordon wrote:
> > IIRC, it's f) (1,2,3,4,5) >>+<< (1,2,$identity,$identity,$identity),
> > where $identity's value is determined by a table something like this:
>
> In the case of  &infix_circumfix_meta_operator:{'»','«'}:(List,List:&op)
> there's no "upgrade"---to use the S03 term.  A simple "apply &op where
> the lists overlap and keep the rest of the longer one" suffices.
> That is (1,2,3,4,5) >>+<< (1,2) becomes (1+1, 2+2, 3, 4, 5). For
> &infix_circumfix_meta_operator:{'»','«'}:(List,Scalar:&op) the upgrade
> works by applying the operator with the scalar to all entries:
> (1,2,3,4,5) >>+<< 1 becomes (1+1, 2+1, 3+1, 4+1, 5+1).

Good point.  Another one is: how does the meta_operator determine the
"identity value" for user-defined operators?

    (1,2,3,4,5) >>my_infix_op<< (3,2,4)

Maybe we should say that the excess length is simply copied unchanged.
But some might argue that not calling the op for each element would be
cheating somehow.  That's not my position, but I cannot think how to
refute it right now, if you want the side-effects.

> What I ask myself is wether (1,2,3) »+ 1 should be a syntax error or just
> a different form to express the :(List,Scalar:&) case. BTW, I know that
> &infix_prefix_meta_operator:{'»'} isn't mentioned in A12.
>
> > I could be wrong, though; I can't find any support for it in the design docs.

"Replicate dimensions" is specified in the first version of A3.

The length issue was resolved on the mailing lists.
Could someone add the ruling to S3 to answer this FAQ?

I believe the fine points fall out like this:

   @a >>+<< 1    # replicate
   @a >>+<< (1)  # replicate: (1) is still scalar
   @a >>+<< [1]  # extend: [1] is an array (and will auto-deref)

~ John Williams


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About