Erlang/OTP Forums

Author Message

<  Erlang bugs mailing list  ~  [bug] syntax_tool-1.6.5, injury data in erl_syntax_lib:map()

Guest
Posted: Tue Jun 29, 2010 12:28 pm Reply with quote
Guest
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.

Post received from mailinglist

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum