[erlang-questions] core erlang evaluator?

Ulf Wiger <>
Thu Nov 15 10:03:48 CET 2007


Is there a core erlang evaluator somewhere, and I just couldn't find it?

I am looking for a way to plug in the Haskerl compiler into
my hacked shell. The Haskerl compiler is written in Haskell,
and it compiles to core erlang. Perhaps the compiler isn't
complete enough to compile itself?

For now, I've made a simple lersp plugin
(lersp interprets "an approximation of scheme"):

2> @ mod(lersp_exp).
(+ 1 3)
@
4

(I added options to inspect the resulting parse tree:

3> @ mod(lersp_exp), return(parsed).
(+ 1 3)
@
[[{call,1,
        {remote,1,{atom,1,lersp_exp},{atom,1,eval}},
        [{cons,0,{cons,0,{atom,0,'+'},{string,0,[1,3]}},{nil,0}}]}]]

(...as well as pretty-printing the parsed code - might be handy e.g. if
the block contains weird macro expansion)

4> @ mod(lersp_exp), return(pretty).
(+ 1 3)
@
"lersp_exp:eval([['+'|\"\\001\\003\"]]).\n"


The callback module that makes this happen:

-module(lersp_exp).

-export([shell_parse/3,
	 eval/1]).

shell_parse(Str, Bs, Env) ->
    Exprs = lersp_parse:parse_all(Str),
    {erl_eval,
     [[{call,1,{remote,1,{atom,1,?MODULE},{atom,1,shell_eval}},
	[erl_parse:abstract(Exprs)]}]]}.

shell_eval(Exprs) ->
    {Value, _} = lersp_eval:eval_exprs(Exprs),
    Value.



BR,
Ulf W



More information about the erlang-questions mailing list