• Website
  • Search
  • Member List
  • Help
  • Old Forum
  • Social Media
    •   @Wings3dOfficial
    •   @Wings3dOfficial
    •   Wings3dOfficial
    •   Wings3dOfficial
  • Register
  • Login
  • Website
  • Search
  • Member List
  • Help
  • Old Forum
  • Register
  • Login
Wings 3D Development Forum Wings 3D Programming v
« Previous 1 2 3 4
Tidy recursion

 
  • 0 Vote(s) - 0 Average
Tidy recursion

dgud
Offline

Grumpy Dev
Posts: 692
Threads: 37
Joined: Nov 2012
#4
05-20-2013, 01:50 PM (This post was last modified: 05-20-2013, 01:57 PM by dgud.)
Micheus is right, the binary comprehension is the best for this code.

So example is kind of bad, for the question.
And the answer is that it depends, you will have to measure which one is fastest,
in current release, previously example 3 was always best and will be always be
if you don't need the lists:reverse at the end.
Now (since Björn have made some optimizations in erlang) if you really want
the fastest implementation you will have to measure, but for most of the
cases it doesn't matter if you use 1) or 3)
Number 2 is ugly and creates an unnecessary extra list.

If you want to return more than one thing only 3) is possible.

What I think Joe is saying is to avoid doing something like this.

init() ->
Result = loop(),
{ok, Result}.

loop() ->
receive
quit -> 42;
Msg -> io:format("Msg ~p~n",[Msg]),
loop()
end.

Which must save init function on the stack until loop returns.
See: http://en.wikipedia.org/wiki/Tail_call for a better explanation :-)
« Next Oldest | Next Newest »

Users browsing this thread: 2 Guest(s)



Messages In This Thread
Tidy recursion - by nemyax - 05-17-2013, 12:22 PM
RE: Tidy recursion - by micheus - 05-18-2013, 06:22 AM
RE: Tidy recursion - by nemyax - 05-19-2013, 09:14 PM
RE: Tidy recursion - by dgud - 05-20-2013, 01:50 PM
RE: Tidy recursion - by micheus - 05-20-2013, 01:58 PM

  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

© Designed by D&D - Powered by MyBB

Linear Mode
Threaded Mode