smerl: for awesome!

by Sean Cribbs

Here's a quick hack with smerl to turn a fun() into a module function:

1> Fun = fun() -> ok end.
#Fun<erl_eval.20.67289768>
2> {env, [_,_,_,Forms]} = erlang:fun_info(Fun, env).
{env,[[],
      {value,#Fun<shell.7.115410035>},
      {eval,#Fun<shell.24.81953817>},
      [{clause,1,[],[],[{atom,1,ok}]}]]}
3> smerl:new(foo).
{meta_mod,foo,undefined,[],[],false}
4> Mod = smerl:new(foo).
{meta_mod,foo,undefined,[],[],false}
5> {ok, Mod2} = smerl:add_func(Mod, {function,1,bar,0,Forms}, true).
{ok,{meta_mod,foo,undefined,
              [{bar,0}],
              [{function,1,bar,0,[{clause,1,[],[],[{atom,1,ok}]}]}],
              false}}
6> smerl:compile(Mod2, [{outdir, "ebin"}]).
ok
7> l(foo).
{module,foo}
8> foo:bar().
ok

Comments

© 2006-present Sean CribbsGithub PagesTufte CSS