Chaim Frenkel <[EMAIL PROTECTED]> writes:

> Okay, then for
> 
>       reduce &avg $identity, @list
> 
> What should $identity be?

This was my first point regarding C<reduce> -- not all functions have
an identity element.  One should note that in general

    (reduce &avg $x,@list) != (reduce &sum 0,@list)/@list

for I<any> value of $x; your reduction is I<not> the right way to
compute an average (I don't know if it was meant to be or not, but it
got me).

If you can tell me why you wish to perform this reduction, you should
also be able to figure out an identity element.  You're computing

    (($list[0]+$list[1])/2 + $list[2])/2 + ...

for some reason.  Knowing the reason will let you find the desired
result for an empty list.

Note that just I<having> C<reduce> require a non-empty list points out 
this subtlety.  

[...]

-- 
Ariel Scolnicov        |"GCAAGAATTGAACTGTAG"            | [EMAIL PROTECTED]
Compugen Ltd.          |Tel: +972-2-6795059 (Jerusalem) \ We recycle all our Hz
72 Pinhas Rosen St.    |Tel: +972-3-7658514 (Main office)`---------------------
Tel-Aviv 69512, ISRAEL |Fax: +972-3-7658555    http://3w.compugen.co.il/~ariels

Reply via email to