[erlang-questions] *current* value?
Tim Bates
tim@REDACTED
Thu Oct 18 15:32:13 CEST 2007
Joel Reymont <joelr1@REDACTED> wrote:
> {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}}}.
Thomas Lindgren wrote:
> I'd probably prefer a parse transform, because it's
> cleaner and probably faster, ...
Does anyone have a parse transform for this kind of thing? I currently
use macros in a pattern like this:
-define(E(Expr), fun(State) -> Expr, State end).
-define(U(Expr), fun(State) -> Expr, NewState end).
-define(EXPRSEQ(Init, List), lists:foldl(fun(Fun, State) -> Fun(State)
end, Init, List)).
Final = ?EXPRSEQ(Initial, [
?U( {ok, NewState} = some_function(State) ),
?E( some_other_function(State) ),
?U( {ok, NewState} = a_third_function(State) )
])
I use it alot in tests where there's lots of sequential code, and it
allows me to insert and reorder the expressions without having to update
all the variable numbers (S1, S2, etc) but it's ugly and involves
constructing lots of funs. I'd love a parse transform to do something
like this.
If nobody's got one, I'm prepared to have a crack at writing one if
anyone has suggestions as to how it might work.
Thanks,
Tim.
--
Tim Bates
tim@REDACTED
More information about the erlang-questions
mailing list