Open skruger opened 13 years ago
After reading the source to file:consult() this is how to read terms directly from a string.
ErlTerms = "{a,b,c,d}.".
{ok,Tokens,_} = erl_scan:string(ErlTerms).
{ok,Term} = erl_parse:parse_term(Tokens).
Term -> {a,b,c,d}.
To parse a fun()
StrTerm = "fun() -> result_atom end.".
{ok,Tokens,_} = erl_scan:string(StrTerm).
{ok,[Expr]} = erl_parse:parse_exprs(Tokens).
erl_eval:expr(Expr,[]).
resulted in: {value,#Fun,[]}
After reading the source to file:consult() this is how to read terms directly from a string.
ErlTerms = "{a,b,c,d}.".
{ok,Tokens,_} = erl_scan:string(ErlTerms).
{ok,Term} = erl_parse:parse_term(Tokens).
Term -> {a,b,c,d}.