Front page | perl.perl6.language | Postings from January 2004

## Re: Semantics of vector operations (Damian)

Thread Previous | Thread Next
From:
Luke Palmer
Date:
January 22, 2004 13:42
Subject:
Re: Semantics of vector operations (Damian)
Message ID:
20040122214209.GC25098@babylonia.flatirons.org
```Austin Hastings writes:
> > Sortof.  I think Larry was implying that rand returned an infinite list
> > of random numbers in list context.  If not, then what he said was wrong,
> > because it would be sick to say that:
> >
> >     (1,2,3,4,5) »+« foo()
> >
> > Calls foo() 5 times.
>
> Why would it be sick, and in what context?
>
> With Larry's new "vectorized sides" suggestion, putting a guillemot on the right side of the operator vectorizes the right side operand, which *should* call foo() five times.
>
>      (1,2,3,4,5) »+  foo()   # do { my \$x=foo(); (1+\$x, 2+\$x, 3+\$x, 4+\$x, 5+\$x); }
>      (1,2,3,4,5) »+« foo()   # (1+foo(), 2+foo(), 3+foo(), 4+foo(), 5+foo())

I think that one is:

do { my @x=foo(); (1+@x[1], 2+@x[2], 3+@x[3], 4+@x[4], 5+@x[5]) }

We've forgotten that foo() could return a list in list context. :-)

>      (1,2,3,4,5)  +« foo()   # Maybe the same as above? What does infix:+(@list,\$scalar) do?

Well, what does a list return in scalar context?  In the presence of the
C comma, it returns 5 for the last thing evaluated.  In its absence, it
returns 5 for the length.

>      (1,2,3,4,5)  +  foo()   # foo() in list context? What does infix:+(@list, @list2) do?

Same deal, 5 + \$(foo())

Luke
à

```
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