efene programming language

meta programming in efene

I was reading about template haskell and decided to give it a try in efene, the result after an hour of hacking (and reading) is this:

>>> [|1|]
{integer,1,1}

>>> [| 1 + 2 * 3 |]
{op,1,'+',{integer,1,1},{op,1,'*',{integer,1,2},{integer,1,3}}}

>>> erl_eval.expr([|1 + 2 * 3|], erl_eval.new_bindings())
{value,7,[]}

>>> [|fn (A, B) { A + B }|]
{'fun',1,
       {clauses,[{clause,1,
                         [{var,1,'A'},{var,1,'B'}],
                         [],
                         [{op,1,'+',{var,1,'A'},{var,1,'B'}}]}]}}

>>> [|fn (A, B) { A + ${1 + 2}}|]
{'fun',1,
       {clauses,[{clause,1,
                         [{var,1,'A'},{var,1,'B'}],
                         [],
                         [{op,1,'+',{var,1,'A'},3}]}]}}

>>> [|fn (A, B) { A + [|${1 + 2}|]}|]
{'fun',1,
       {clauses,[{clause,1,
                         [{var,1,'A'},{var,1,'B'}],
                         [],
                         [{op,1,'+',{var,1,'A'},{integer,1,3}}]}]}}

I don’t know if it will be useful to everybody, but I think I can use it to move some language features to libraries and allow to experiment without changing the core language

If you don’t understand then no problem, the main idea is that the expressions between ${ … } are evaluated (aka run) at compile time, that means that $(long_calculation(5)} will be run at compile time and the result will be placed in that part of the code. The expressions between

[| … |] are compiled into ast and inserted in the AST three, this allows simple code generation in libraries that paired with ${ … } will allow to build some complex stuff.

one example ${build_object(person, [firstname, lastname, mail])} will run build_object at compile time and generate AST that creates an object called person with the fields firstname, lastname and mail and insert the ast before the bytecode is generated.

This will also allow a simpler core language and some meta libraries to implement stuff like objects, behaviours… I don’t know, I’m dreaming a little right now but we will see


To Tumblr, Love Metalab