[bug] syntax_tool-1.6.5, injury data in erl_syntax_lib:map()
Alexander Demidenko
alex.demidenko@REDACTED
Tue Jun 29 14:27:40 CEST 2010
Hi,
Try to show on a synthetic example:
I have some source data:
1> X = {function,34,handle_event,2, [{clause,34,
[{var,34,'_'},{var,34,'_'}],[], [{cons,35,{tuple,35,[]},{nil,36}}]}]}.
{function,34,handle_event,2,
[{clause,34,
[{var,34,'_'},{var,34,'_'}],
[],
[{cons,35,{tuple,35,[]},{nil,36}}]}]}
Now, I will try to traverse the data via erl_syntax_lib:map()
2> erl_syntax_lib:map(fun (El) -> io:format("~p~n",
[erl_syntax:revert(El)]), El end, X).
{atom,34,handle_event}
{var,34,'_'}
{var,34,'_'}
{tuple,35,[]}
{cons,35,{tuple,35,[]},{nil,35}}
{clause,34,[{var,34,'_'},{var,34,'_'}],[],[{cons,35,{tuple,35,[]},{nil,35}}]}
{function,34,handle_event,2,
[{clause,34,
[{var,34,'_'},{var,34,'_'}],
[],
[{cons,35,{tuple,35,[]},{nil,35}}]}]}
{tree,function,
{attr,34,[],none},
{function,{tree,atom,{attr,34,[],none},handle_event},
[{tree,clause,
{attr,34,[],none},
{clause,[{var,34,'_'},{var,34,'_'}],
none,
[{tree,list,
{attr,35,[],none},
{list,[{tuple,35,[]}],none}}]}}]}}
Ops, erl_syntax_lib vodoo magic, make unexpected change original
{nil,36} to {nil,35}
To test, make control measurements via erl_syntax_lib:fold()
3> erl_syntax_lib:fold(fun (El, Acc) -> io:format("~p~n", [El]) end, [], X).
{tree,atom,{attr,34,[],none},handle_event}
{var,34,'_'}
{var,34,'_'}
{tuple,35,[]}
{cons,35,{tuple,35,[]},{nil,36}}
{clause,34,[{var,34,'_'},{var,34,'_'}],[],[{cons,35,{tuple,35,[]},{nil,36}}]}
{function,34,handle_event,2,
[{clause,34,
[{var,34,'_'},{var,34,'_'}],
[],
[{cons,35,{tuple,35,[]},{nil,36}}]}]}
ok
Unlike map(), fold() working correctly.
PS Test on Erlang R13B04 (erts-5.7.5) and Erlang R13B01 (erts-5.7.2)
with same results
--
---------------------------------------------
With best regards,
Alexander.
More information about the erlang-bugs
mailing list