Doubt about funs

Jim Larson jim@REDACTED
Wed Feb 21 03:13:56 CET 2001

In message <Pine.GSO.4.21.0102201817150.8698-100000@REDACTED> you write:
>> "We can also refer a function defined in a different module with
>> the following syntax:
>> F = {Module,FunctionName}  "
>Yes, it is true that you can (still) use tuples {Module, FunctionName} in
>this manner, but it is a relic of early Erlang implementations and I
>strongly recommend that they are not used in new code. If you need to pass
>around a functional value to call a particular function in a particular
>module, the following is much better:
>	F = fun (X1, ..., Xn) -> m:f(X1, ..., Xn) end
>1), it is apparent that `m' is the target of a call (so e.g. tools like
>`xref' can know about it, and you can easily grep for `m:' in your source
>code. In general, avoid passing around module names as data. (For the same
>reason, it is better to use spawn/1 and spawn/2 than the old spawn/3 and
>spawn/4, if possible. Avoid `apply/3'.)

Do you also advise against the use of callback interfaces? If so,
how to you implement the desired dynamic dispatch? Pass funs to an
initialization function?


More information about the erlang-questions mailing list