POV-Ray : Newsgroups : povray.off-topic : Ratatouille : Re: Ratatouille Server Time
10 Oct 2024 23:17:52 EDT (-0400)
  Re: Ratatouille  
From: Darren New
Date: 28 Mar 2008 14:09:17
Message: <47ed425d$1@news.povray.org>
Orchid XP v7 wrote:
> Darren New wrote:
> 
>> I thought it was pretty cool that the latest Erlang compilers will see 
>> code like
>>
>> map(F, [H|T]) -> [F(H)|map(F,T)];
>> map(F, []) -> [].
>>
>> and turn it into the same code you'd get with an auxiliary accumulator 
>> and a call to "reverse" at the end.
> 
> Doesn't reverse require N operations? Wouldn't that mean that map now 
> takes 2N operations instead of just N?

Probably. But note that map as I wrote it isn't tail recursive, unless 
the compiler can do what I said.  Hence, on a list of 10,000 elements, 
the code there will take 10,000 stack frames.  The compiler is now smart 
enough to see what you're doing and generate tail-recursive code from it.

-- 
   Darren New / San Diego, CA, USA (PST)
     "That's pretty. Where's that?"
          "It's the Age of Channelwood."
     "We should go there on vacation some time."


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.