[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[FWP] Re: Neat or horrid?



abigail@arenanetworks.com writes:

> Here's a interesting way to sum the elements of a list:
> 
>     sub sum {@_ ? shift () + &sum : 0}
> 
> 
> Neat or horrid?

Neat, but not as neat as primality testing...

Does it do proper tail recursion?  If not, I'd try

     sub sum {@_ ? shift () + goto &sum : 0}

except that it doesn't work (5.005_03).  I don't think I understand
why not, though.

-- 
Ariel Scolnicov        |"GCAAGAATTGAACTGTAG"            | ariels@compugen.co.il
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

==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe