erlang eval?

Vladimir Sekissov <>
Tue Nov 4 11:51:50 CET 2003


Good day,

bry> Is there an eval function in erlang, for evaluation of strings as erlang
bry> code? If so what module is it in?

Look at the following modules:

erl_scan
erl_parse
erl_eval

Small example:

1> FunStr = "fun (A) -> A+B end.". 
...
2> {ok, Tokens, _} = erl_scan:string(FunStr).
...
3> {ok, [Form]} = erl_parse:parse_exprs(Tokens).
...
4> Bindings = erl_eval:add_binding('B', 2, erl_eval:new_bindings()).
...
5> {value, Fun, _} = erl_eval:expr(Form, Bindings).
..
6> Fun(1).
3

Best Regards,
Vladimir Sekissov



More information about the erlang-questions mailing list