[erlang-questions] about fun vs. functions schisofrenia

Richard Carlsson richardc@REDACTED
Fri Jan 11 12:58:57 CET 2008


Matej Kosik wrote:
> In Erlang, these things cannot be used
> interchangably and this leads to fun vs. function schisofrenia. You have
> to define separate functions that requre "funs" and a separate set of
> functions that require funs.

Don't worry, you have simply misunderstood some things.

> How should I call
> 
> PrintedEntities = rpc:pmap( {?MODULE, print_entity}, [AttributeNames,
> ExportFunctions, State], SortedEntities ),
> 
> without being forced to export the `print_entity/4' function? I would
> really like to keep it "private".

It seems that the functions in the rpc module are written in a very
old style. Especially the pmap function has a strange interface.

Until this is fixed, you could easily implement you own pmap, with
a simpler interface: pmap(Fun, List1) -> List2.

Then you could simply call it like this:
   List2 = pmap(fun (X) -> print_entity(X, AttrN, ExpF, St) end, List1)

(without exporting print_entity/4).

Also, note that most functions in the rpc module are really meant only
for _remote_ procedure calls, and in that case, you can only call exported
functions anyway (functions in modules on a different node). I think that
the existing pmap function in rpc should be deprecated since it is almost
useless, and doesn't really belong in that module.

     /Richard





More information about the erlang-questions mailing list