[erlang-questions] *current* value?

Joel Reymont joelr1@REDACTED
Thu Oct 18 13:28:36 CEST 2007


The process dictionary could be used to simplify parsing, I think.

You could write this Haskell parser combinator

whileStatement = do
   reserved "While"
   e <- expr
   reserved "Begin"
   xs <- statements
   reserved "End"
   return $ While e (Compound xs)

like this

reserved("while"),
E = expr(),
reserved("begin"),
Xs = statements(),
reserved("end"),
{while, e, {compound, xs}}.

instead of the more verbose

{S1, ok} = reserved(S, "while"),
{S2, E} = expr(S1),
{S3, ok} = reserved(S2, "begin"),
{S4, Xs} = statements(S3),
{S5, ok} = reserved(S4, "end"),
{S5, {while, e, {compound, xs}}}.

This assumes that parsers throw exceptions upon failure.

What do you think?

--
http://wagerlabs.com








More information about the erlang-questions mailing list