Evaluating code snippets

Ulf Wiger (AL/EAB) ulf.wiger@REDACTED
Mon May 16 14:58:17 CEST 2005

I don't know what your performance requirements are, 
but you could consider using file:script/2

The file:script/2 function is like file:eval/2, but 
it returns the result of the last expression evaluated,
rather than 'ok', which is what you get back from 

The syntax is file:script(FileName, Bindings).

You could either specify a library function through
which the scripts can create new variable bindings,
or use a convention such that the scripts return e.g.
{Result, NewBindings}.


-----Original Message-----
From: owner-erlang-questions@REDACTED [mailto:owner-erlang-questions@REDACTED]On Behalf Of Vlad Dumitrescu
Sent: den 16 maj 2005 13:34
To: erlang-questions@REDACTED
Subject: Evaluating code snippets


I have a need to evaluate code snippets, kind of a scripting language, and I'm not sure what is the best way to do it.

The snippets are defining and using common variables, but I need to keep them separate (as opposed to compiling the whole file into a module, like for example .yaws files).

I see two alternatives:
    - save the source and evaluate it using erl_eval, and keeping the variable bindings global
    - "bake" them inside a template function that will take care of the bindings.

I would prefer the second approach, because the snippets will be called many times, but I have a problem: is there a way to retrieve the set of current bindings? I couldn't find anything, and I 'm not even sure it is possible to add such a BIF without confusing the compiler, but I thought I'd ask anyway because maybe some other idea might come up.

Thanks in advance! Regards,

More information about the erlang-questions mailing list