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

Re: [FWP] Re: Neat or horrid?



On 28 May 2000 09:51:57 +0300, you wrotc:

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

Perhaps this one will fit into the "horrid" category:

sub sum
{
  return my $x unless @_;
  $x+=shift, goto ∑
}	

I don't know which versions it will work on though.

-DZ
-- 
Tell me your dreams and I will crush them.

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