[erlang-questions] Passing functions as arguments requires export?

Kostis Sagonas kostis@REDACTED
Wed Nov 3 19:25:52 CET 2010

Michal D. wrote:
> Hi All,
> I'm having some problems working with functions in Erlang.  Specifically,
> passing functions as arguments. Given the following module:
> -module(test).
> -export([res/0]).
> res() -> lists:map({test,incr}, [0,1,2]).
> incr(X) -> X + 1.
> I stumbled upon the syntax {test,incr} to pass a (not anonymous) function.
> When I go to run this code in the emulator, I get an error that doesn't get
> resolved unless I add "incr/1" to the export list.  However, there's no
> reason to export the function because I don't ever want to call it
> directly.  What am I missing?

You are using a really obsolete language feature that should have been 
completely eliminated by now.  There is absolutely no reason for it to 
still exist in the language.

Use the more modern (and more fun ;-) construct instead:

   res() -> lists:map(fun incr/1, [0,1,2]).


More information about the erlang-questions mailing list