EvilTeach
EvilTeach

Reputation: 28837

How does one specify a forward reference in Erlang?

I have been plaing around with Erlang, and decided to try to make a directory lister. After hacking some code together I hit as road block, as the second commented line shows an error message. Literally it can't see the iterate function. I've done a bit of research here and on google. I have tried exporting the functions as well. There is something here that I am not thinking about correctly. Can someone point me in the correct direction?

-module(iterate_dir).

% exporting iterate/1 does not make it visible.
-export([start/0, iterate/1, show_files/2]).

show_files([], _) ->
    ok;

show_files([Head|Tail], Path) ->
    FullPath = [Path] ++ [Head],
    case filelib:is_dir(FullPath) of
                                                    % function iteratate/1 undefined
        true -> io:format("Dir  ~s\n", [FullPath]), iteratate(FullPath);
        false-> io:format("File ~s\n", [FullPath])
    end,
    show_files(Tail, Path).


iterate(Directory) ->
    case file:list_dir(Directory) of
        {ok,    Files}   -> show_files(Files, Directory);
        {error, Reason}  -> io:format("Error ~s~n", [Reason])
    end.

start() ->
    io:format("Running~n"),
    iterate("c:\\"),
    io:format("Complete~n").

Upvotes: 0

Views: 139

Answers (1)

David Budworth
David Budworth

Reputation: 11626

The function is called "iterate", you are calling it as "iteratate" notice the extra "at" in the middle at the call site (and comment)

Upvotes: 2

Related Questions