[erlang-questions] How to use erl_parse, erl_scan, erl_eval?
Erik Søe Sørensen
eriksoe@REDACTED
Wed Apr 2 08:06:47 CEST 2014
If it is a representation of a pattern you need, then perhaps it's match
specifications you're looking for:
http://www.erlang.org/doc/apps/erts/match_spec.html
[Here, imagine the code example I'd have written if I weren't writing this
on a phone :)]
/Erik
Den 01/04/2014 16.50 skrev "Max Lapshin" <max.lapshin@REDACTED>:
> Hi.
>
> I want to write a test for a function that returns list of some tuples:
>
> my_logic:handle_event(Event, State1) -> {ok, Requests, State2}
>
>
>
> My idea is to write such test helper:
>
> step(Event, RequiredRequests) ->
> State1 = get(remembered_state),
> {ok, Requests, State2} = my_logic:handle_event(Event, State1),
> put(remembered_state, State2),
> true = lists:all(fun(Match) ->
> case lists:any(fun(Request) ->
> case Request of
> Match -> true;
> _ -> false
> end
> end, Requests), RequiredRequests),
> ok.
>
> and use this function like:
>
> step(playlist_ready, [{set_timer, download_playlist, _}]) %% This test
> should check if new timer is set with some not very important time
>
> Problem here is that I cannot pass a match into function "step".
>
>
> I have two ideas:
>
> 1) wrap each match into macros:
>
> -define(P(Match), fun(Request) -> case Request of Match -> true; _ ->
> false end end).
>
> and use it like:
>
> step(playlist_ready, [?P({set_timer, download_playlist, _})])
>
>
> 2) make a macro:
>
> -define(step(Event, RequiredRequests), step(Event, ??RequiredRequests)).
>
> Now it will be:
>
> ?step(playlist_ready, [{set_timer, download_playlist, _}])
>
> but I cannot find any guide how to use those erl_parse, erl_scan,
> erl_eval to split string "[{set_timer, download_playlist, _}]" into some
> tokens and create a list of matches from it.
>
>
>
>
> Should I don't try to make new problems and just use first option?
> Or there is some possibility to scan/parse/eval string with matches in
> runtime?
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20140402/a066ac5a/attachment.htm>
More information about the erlang-questions
mailing list