Re: reduce via ^ again

2002-09-09 Thread Damian Conway

John Williams wrote:

> Back in October I suggested that   $a ^+= @b   would act like reduce,
> but in discussion
> it was decided that it would act like length

> I now pose the question: Is ^+= a "hyper assignment operator" or an
> "assignment hyper operator"?


> with a scalar involved
> the method and the result is different.  $a = length(@b) is the
> "assignment hyper operator"
> interpretation.  The "hyper assignment operator" interpretation looks
> like this:
> 
> $a ^+= @b
> ($a, $a, $a, ...) ^+= @b
> $a += $b[0], $a += $b[1], $a += $b[2], ...

I can't remember what side I argued last October (I can't remember last
October! %-) I have to say that I'm with John here. That interpretation
certainly seems more DWIM to me.

Damian





reduce via ^ again

2002-09-07 Thread John Williams

Apologies for trying to resuscitate this old horse, but a new idea
occurred to me.

Back in October I suggested that   $a ^+= @b   would act like reduce,
but in discussion
it was decided that it would act like length, by the interpretation:

$a ^+= @b
$a = $a ^+ @b
$a = ($a, $a, $a, ...) ^+ @b
$a = ($a+$b[0], $a+$b[1], ...)
$a = (a list in scalar context )
$a = length(@b)

I now pose the question: Is ^+= a "hyper assignment operator" or an
"assignment hyper operator"?
An "assignment hyper operator" would be interpreted as above, or with
two arrays as:

@a ^+= @b
@a = @a ^+ @b
@a = ($a[0] + $b[0], $a[1] + $b[1], ... )

A "hyper assignment operator" would be interpreted like this (doing the
"hyper" part first):

@a ^+= @b
$a[0] += $b[0], $a[1] += $b[1], ...
$a[0] = $a[0] + $b[0], $a[1] = $a[1] + $b[1], ...

With two arrays the method is different, but the end result is the
same.  (One might be more
efficient than the other, but I won't speculate on that here.)  But with
a scalar involved
the method and the result is different.  $a = length(@b) is the
"assignment hyper operator"
interpretation.  The "hyper assignment operator" interpretation looks
like this:

$a ^+= @b
($a, $a, $a, ...) ^+= @b
$a += $b[0], $a += $b[1], $a += $b[2], ...

which is DWIM: $a = reduce(@b), assuming, of course that $a is
initially zero.

For @a = $b, the end result also appears to be the same.
"assignment hyper operator"
@a ^+= $b
@a = @a ^+ $b
@a = @a ^+ ($b, $b, $b, ...)
@a = ($a[0]+$b, $a[1]+$b, $a[2]+$b, ...)

"hyper assignment operator"
@a ^+= $b
@a  ^+= ($b, $b, $b, ...)
$a[0] += $b, $a[1] += $b, $a[2] += $b, ...

~ John Williams