[erlang-questions] RFC: brackets for staging code

Anthony Ramine nox@REDACTED
Fri Oct 21 13:33:31 CEST 2011


Hi,

On a regular basis on this mailing-list, someone wishes to be able to
write code while he's writing code. That is writing abstract syntax trees
like they are writing code, in lexical form. Recently it was a little
discussion earlier this month about improving epp to support
quasi-quotations [1], last year it was Ulf Wiger's parse_trans_codegen
parse transform [2].

Here is my contribution to support this feature directly in the language:
code brackets and escaped expressions (please note that I'm sure there
are better names for these concepts but I don't know them).

Basically I tried to reproduce what is MetaOCaml [3] for OCaml in Erlang by
introducing two new expressions: <| Expr |> and `Expr. Furthermore I also
wrote a basic support for code patterns but it only allows `Holes where
a single expression is expected in the abstract syntax tree.

That means that for this feature to be truly useful, we should extend the
grammar for code patterns and create new types of brackets for things that
aren't expressions, to be able to write code like:

	<| case `Expr of `Clauses end |> = CaseAST,
	lists:map(
		fun (<|clause| `Pattern -> `Body |>) ->
			do_stuff(Pattern, Body)
		end,
		Clauses).

More details can be found in the commit message in my otp fork's brackets
branch [4].

Regards,

[1] http://erlang.org/pipermail/erlang-questions/2011-October/061713.html
[2] http://erlang.org/pipermail/erlang-questions/2010-July/052186.html
[3] http://www.metaocaml.org/
[4] https://github.com/nox/otp/tree/brackets

-- 
Anthony Ramine / @nokusu
Dev:Extend — http://dev-extend.eu/
So as I pray, “Unlimited Erlang Works”




More information about the erlang-questions mailing list