aboutsummaryrefslogblamecommitdiffstats
path: root/lib/syntax_tools/examples/test.erl
blob: 087c49ed4c0e9e94d656ad3055d613261158f67a (plain) (tree)
























                                               
%%
%% This is a test file
%%

-module(test).

-export([nrev/1]).

%% Just a naive reverse function in order
%% to get a code example with some comments.

nrev([X | Xs]) ->
    append(X, nrev(Xs));  % Quadratic behaviour
nrev([]) ->
    %% The trivial case:
    [].

  %% We need `append' as a subroutine:

append(Y, [X | Xs]) ->
    [X | append(Y, Xs)];    % Simple, innit?
append(Y, []) ->
    [Y].    % Done.

%% ---- end of file ----