Gus Wirth wrote:
And this one:
Now an example of this when working with lists - reversing the order of
a list:
-module(tut8).
-export([reverse/1]).
reverse(List) ->
reverse(List, []).
reverse([Head | Rest], Reversed_List) ->
reverse(Rest, [Head | Reversed_List]);
reverse([], Reversed_List) ->
Reversed_List.
Ah.
There was no reason at all to use function overloading here. The purpose
of a tutorial is make concepts stand out. There are two different
list_max functions and reverse functions here which do different things.
I could see showing a function say to_string that will convert anything
to a string, but the above examples are unnecessarily confusing.
Unfortunately, the way these are described seems to be a programming
convention of whoever wrote this
Yes, it is a convention.
I see your point, but I also see their point.
The functions have a logical connection. [reverse/2] is the
tail-recursive formulation of the exposed [reverse/1].
But, yeah, calling it "reverse_impl([Head | Rest], Reversed_list)" might
be better.
-a
--
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-lpsg