[erlang-questions] String to Function

Bob Cowdery Bob.Cowdery@REDACTED
Mon Dec 18 12:01:50 CET 2006


Thanks very much for the prompt response, works a treat. I need the latter but it's an initialisation thing so efficiency is not an issue.

regards
Bob

Hi,

On 12/18/06, Bob Cowdery <Bob.Cowdery@REDACTED> wrote:
> Is there some way to call a function from a string or atom representation, i.e. to call it indirectly when the code does not know at compile time what function will be called.

If for example
    M = lists,
    F = seq,
you can write
    M:F(1,5),
or
    apply(M, F, [1, 5])

The latter is quite expensive and should only be used when the number
of arguments isn't known at compile time.

best regards,
Vlad




More information about the erlang-questions mailing list