Passing functions as arguments requires export?

Michal D. michal.dobrogost@REDACTED
Wed Nov 3 18:24:23 CET 2010


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?

> c(test).
> test:res().
** exception error: undefined function test:incr/1
     in function  lists:map/2
>

Cheers,

Michal


More information about the erlang-questions mailing list