visibility of a function in a module

HP Wei hp@REDACTED
Fri Apr 11 13:59:07 CEST 2003


In this module, f(N) is a function visible in the entire module of test.
% --------------------
-module(test).
-export([do/0]).

do() ->
    go().

f(N) -> 
    Base = 10,
    Base + N.

go() ->
    io:format("~w~n", [f(3)]).
% ---------------------------

But, I want to construct f() when do() is invoked.
Now, I have the following module, in which F_() is not visible in
the module.  And I need to pass it to go() through the parameter passing.
Is this the only alternative ?
% -----------------------------
-module(test).
-export([do/1]).

do(Base) ->
    F_ = fun(N) -> Base+N end,
    go(F_).

go(F) ->
    io:format("~w~n", [F(3)]).
% --------------------------------------

--HP




More information about the erlang-questions mailing list