Generic-user-small Yuichi Ito 1 post

Hello.
I want to execute the code of Chap14 “start_nano_server()”.

But there is no function “lib_misc:string2value(String)”.
So, I checked this book’s index(reference?), and searched in Google.
But couldn’t find both.

this function acts like this
> lib_misc:string2value(“list_to_tuple([2+3*4,10+20])”).
{14,30}

How do I create this function?
Or, is there a function which execute string like Python’s “exec Statement”?

Thsnks
(I’m using Japanese editon, so there may be little difference in English edition)

 
Generic-user-small Alain O'Dea 18 posts

lib_misc:string2value/1 is implemented as follows:

string2value(Str) ->
    {ok, Tokens, _} = erl_scan:string(Str ++ "."),
    {ok, Exprs} = erl_parse:parse_exprs(Tokens),
    Bindings = erl_eval:new_bindings(),
    {value, Value, _} = erl_eval:exprs(Exprs, Bindings),
    Value.

I could not find a direct equivalent to Python’s exec statement in the modules shipped with Erlang OTP R12B.

The entire set of example code for Programming Erlang is available for download here:
http://www.pragprog.com/titles/jaerlang/source_code

2 posts, 2 voices