Created
December 28, 2008 17:36
-
-
Save jdallien/40998 to your computer and use it in GitHub Desktop.
side by side Prolog and Erlang list reversal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%%% Prolog | |
% [reverse]. | |
% [reverse loaded] | |
% yes | |
% | |
% | ?- reverse([1,2,3],L). | |
% L = [3,2,1] | |
% | |
reverse(List, ReversedList) :- | |
reverse(List, [], ReversedList). | |
reverse([], ReversedList, ReversedList). | |
reverse([Head | Rest], TempList, ReversedList) :- | |
reverse(Rest, [Head | TempList], ReversedList). | |
%%% Erlang | |
% | |
% 1> c(reverse). | |
% {ok,reverse} | |
% 2> reverse:reverse([1,2,3]). | |
% [3,2,1] | |
reverse(List) -> | |
reverse(List, []). | |
reverse([Head | Rest], Reversed_List) -> | |
reverse(Rest, [Head | Reversed_List]); | |
reverse([], Reversed_List) -> | |
Reversed_List. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment