visibility of a function in a module

Fredrik Linder fredrik.linder@REDACTED
Fri Apr 11 14:17:06 CEST 2003


You can to it like this also:

% --------------------
-module(test).
-export([do/0]).

do() ->
    go(fun f/1).

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

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

-----Original Message-----
From: owner-erlang-questions@REDACTED
[mailto:owner-erlang-questions@REDACTED]On Behalf Of HP Wei
Sent: den 11 april 2003 13:59
To: erlang-questions@REDACTED
Subject: visibility of a function in a module


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