Chaim Frenkel wrote: > Okay, then for > > reduce &avg $identity, @list > > What should $identity be? > What's wrong with: $average = reduce (^last+^this, @^list) / scalar @^list; print $average->([1,3,5]); # Prints '3' You don't need to explicitly add a '0' to the front of the summed list. Although I guess for a geometric average you have to be more careful: $geo_average = reduce (defined(^last)?^last:1 * ^this, @^list) ** (1/scalar @^list); print $geo_average->([1,2,4]); # Prints '2'
- Re: RFC 76 (v1) Builtin: reduce Chaim Frenkel
- Re: RFC 76 (v1) Builtin: reduce Randal L. Schwartz
- Re: RFC 76 (v1) Builtin: reduce Damian Conway
- Re: RFC 76 (v1) Builtin: reduce Chaim Frenkel
- Re: RFC 76 (v1) Builtin: reduce Damian Conway
- Re: RFC 76 (v1) Builtin: reduce Dan Sugalski
- Re: RFC 76 (v1) Builtin: reduce Ariel Scolnicov
- Re: RFC 76 (v1) Builtin: reduce Chaim Frenkel
- Re: RFC 76 (v1) Builtin: reduce Ariel Scolnicov
- Re: RFC 76 (v1) Builtin: reduce Chaim Frenkel
- Re: RFC 76 (v1) Builtin: reduce Jeremy Howard
- Re: RFC 76 (v1) Builtin: reduce Ariel Scolnicov
- Re: RFC 76 (v1) Builtin: reduce Bart Lateur
- Re: RFC 76 (v1) Builtin: redu... Graham Barr
- Re: RFC 76 (v1) Builtin: redu... John Porter
- Re: RFC 76 (v1) Builtin: reduce Graham Barr
- Re: RFC 76 (v1) Builtin: reduce Chaim Frenkel
- Re: RFC 76 (v1) Builtin: reduce Damian Conway
- Re: RFC 76 (v1) Builtin: reduce Damian Conway
- Re: RFC 76 (v1) Builtin: reduce Damian Conway
- Re: RFC 76 (v1) Builtin: reduce Jeremy Howard