aboutsummaryrefslogtreecommitdiffstats
path: root/lib/syntax_tools/examples/test.erl
blob: 087c49ed4c0e9e94d656ad3055d613261158f67a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
%%
%% 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 ----