<div dir="ltr"><div dir="ltr"><div>



        
        
        
        <style type="text/css">P { margin-bottom: 0.21cm; }</style>


<p style="margin-bottom:0cm" lang="en">       Hello , friends. I want to
tell you about a bug in Erlang:</p>
<p style="margin-bottom:0cm" lang="en">
</p>
<p style="margin-bottom:0cm" lang="en">       I have differences between
result of using methods map() and input data. I attached simple
sample, where you can see this differences.</p>
<p style="margin-bottom:0cm" lang="en">
</p>
<p style="margin-bottom:0cm" lang="en">1) For getitng syntax tree
input:</p>
<p style="margin-bottom:0cm" lang="en">_______________________________________________________________________</p>
<p style="margin-bottom:0cm" lang="en">{ok, Forms} =
epp:parse_file("example.erl", [], []).</p>
<p style="margin-bottom:0cm" lang="en">_______________________________________________________________________</p>
<p style="margin-bottom:0cm" lang="en">
</p>
<p style="margin-bottom:0cm" lang="en">You get this:</p>
<p style="margin-bottom:0cm" lang="en">_______________________________________________________________________</p>{ok,[{attribute,1,file,{"example.erl",1}},<br>     {attribute,1,module,example},<br>     {attribute,3,export,[{handle_event,2}]},<br>
     {function,5,handle_event,2,<br>               [{clause,5,<br>                        [{var,5,'_'},{var,5,'_'}],<br>                        [],<br>                        [{cons,6,<br>                               {tuple,6,[]},<br>
                               {cons,7,{nil,7},{cons,8,{...},...}}}]}]},<br>     {eof,9}]}<br>_______________________________________________________________________
<p style="margin-bottom:0cm" lang="en">2) Then input:</p>
<p style="margin-bottom:0cm" lang="en">_______________________________________________________________________</p>
<p style="margin-bottom:0cm" lang="en">io:format("~p~n",[Forms]).
</p>
<p style="margin-bottom:0cm" lang="en">_______________________________________________________________________</p>
<p style="margin-bottom:0cm" lang="en">
</p>
<p style="margin-bottom:0cm" lang="en">You get this:</p>
<p style="margin-bottom:0cm" lang="en">_______________________________________________________________________</p>[{attribute,1,file,{"example.erl",1}},<br> {attribute,1,module,example},<br> {attribute,3,export,[{handle_event,2}]},<br>
 {function,5,handle_event,2,<br>     [{clause,5,<br>          [{var,5,'_'},{var,5,'_'}],<br>          [],<br>          [{cons,6,<br>               {tuple,6,[]},<br>               {cons,7,<br>                   {nil,7},<br>
                   {cons,8,<br>                       {cons,8,{atom,8,asd},{cons,8,{atom,8,asd},{nil,8}}},<br>                       {nil,8}}}}]}]},<br> {eof,9}]<br>ok<br><p style="margin-bottom:0cm" lang="en">_______________________________________________________________________</p>

<p style="margin-bottom:0cm" lang="en">
</p>
<p style="margin-bottom:0cm" lang="en">3) Then input:</p>
<p style="margin-bottom:0cm" lang="en">_______________________________________________________________________</p>
<p style="margin-bottom:0cm" lang="en">Form = {function,5,handle_event,2,<br>     [{clause,5,<br>          [{var,5,'_'},{var,5,'_'}],<br>          [],<br>          [{cons,6,<br>               {tuple,6,[]},<br>
               {cons,7,<br>                   {nil,7},<br>                   {cons,8,<br>                       {cons,8,{atom,8,asd},{cons,8,{atom,8,asd},{nil,8}}},<br>                       {nil,8}}}}]}]}.</p><p style="margin-bottom:0cm" lang="en">
_______________________________________________________________________</p>
<p style="margin-bottom:0cm" lang="en">
</p>
<p style="margin-bottom:0cm" lang="en">You get:</p>
<p style="margin-bottom:0cm" lang="en">_______________________________________________________________________{function,5,handle_event,2,<br>          [{clause,5,<br>                   [{var,5,'_'},{var,5,'_'}],<br>
                   [],<br>                   [{cons,6,<br>                          {tuple,6,[]},<br>                          {cons,7,<br>                                {nil,7},<br>                                {cons,8,<br>
                                      {cons,8,{atom,8,asd},{cons,8,...}},<br>                                      {nil,8}}}}]}]}<br></p><p style="margin-bottom:0cm" lang="en">_______________________________________________________________________</p>

<p style="margin-bottom:0cm" lang="en">
</p>
<p style="margin-bottom:0cm"><span lang="en">4) </span>Now, I will
try to traverse the data via erl_syntax_lib:map()<span lang="en">:</span></p>
<p style="margin-bottom:0cm" lang="en">_______________________________________________________________________</p>
<p style="margin-bottom:0cm" lang="en">erl_syntax_lib:map(fun (El)
-> io:format("~p~n", [erl_syntax:revert(El)]), El end,
Form).</p>
<p style="margin-bottom:0cm" lang="en">_______________________________________________________________________</p>
<p style="margin-bottom:0cm" lang="en">
</p>
<p style="margin-bottom:0cm" lang="en">You get: 
</p>
<p style="margin-bottom:0cm" lang="en">____________________________________________</p>{atom,5,handle_event}<br>{var,5,'_'}<br>{var,5,'_'}<br>{tuple,6,[]}<br>{nil,7}<br>{atom,8,asd}<br>{atom,8,asd}<br>{cons,8,{atom,8,asd},{cons,8,{atom,8,asd},{nil,8}}}<br>
{cons,6,<br>      {tuple,6,[]},<br>      {cons,6,<br>            {nil,7},<br>            {cons,6,<br>                  {cons,8,{atom,8,asd},{cons,8,{atom,8,asd},{nil,8}}},<br>                  {nil,8}}}}<br>{clause,5,<br>
        [{var,5,'_'},{var,5,'_'}],<br>        [],<br>        [{cons,6,<br>               {tuple,6,[]},<br>               {cons,6,<br>                     {nil,7},<br>                     {cons,6,<br>                           {cons,8,{atom,8,asd},{cons,8,{atom,8,asd},{nil,8}}},<br>
                           {nil,8}}}}]}<br>{function,5,handle_event,2,<br>    [{clause,5,<br>         [{var,5,'_'},{var,5,'_'}],<br>         [],<br>         [{cons,6,<br>              {tuple,6,[]},<br>              {cons,6,<br>
                  {nil,7},<br>                  {cons,6,<br>                      {cons,8,{atom,8,asd},{cons,8,{atom,8,asd},{nil,8}}},<br>                      {nil,8}}}}]}]}<br>{tree,function,<br>    {attr,5,[],none},<br>
    {func,<br>        {tree,atom,{attr,5,[],none},handle_event},<br>        [{tree,clause,<br>             {attr,5,[],none},<br>             {clause,<br>                 [{var,5,'_'},{var,5,'_'}],<br>                 none,<br>
                 [{tree,list,<br>                      {attr,6,[],none},<br>                      {list,<br>                          [{tuple,6,[]},{nil,7},{tree,list,{...},...}],<br>                          {nil,8}}}]}}]}}<br>
<p style="margin-bottom:0cm" lang="en">_______________________________________________________________________</p>
<p style="margin-bottom:0cm" lang="en">
</p>
<p style="margin-bottom:0cm" lang="en">Part of initial datas is:</p>
<p style="margin-bottom:0cm" lang="en">_______________________________________________________________________</p> [{cons,6,<br>               {tuple,6,[]},<br>               {cons,7,<br>                   {nil,7},<br>                   {cons,8,<br>
                       {cons,8,{atom,8,asd},{cons,8,{atom,8,asd},{nil,8}}},<br>                       {nil,8}}}}]<p style="margin-bottom:0cm" lang="en">_______________________________________________________________________</p>

<p style="margin-bottom:0cm" lang="en">
</p>
<p style="margin-bottom:0cm" lang="en">But i get:</p>
<p style="margin-bottom:0cm" lang="en">_______________________________________________________________________</p> [{cons,6,<br>              {tuple,6,[]},<br>              {cons,6,<br>                  {nil,7},<br>                  {cons,6,<br>
                      {cons,8,{atom,8,asd},{cons,8,{atom,8,asd},{nil,8}}},<br>                      {nil,8}}}}]<p style="margin-bottom:0cm" lang="en">_______________________________________________________________________</p>

<p style="margin-bottom:0cm" lang="en">
</p>
<p style="margin-bottom:0cm" lang="en">Unexpected change
original:<br>“<span style="background:none repeat scroll 0% 0% rgb(255,255,0)">{cons,7,</span>”
to “<span style="background:none repeat scroll 0% 0% rgb(255,255,0)">{cons,6,</span>” and
“<span style="background:none repeat scroll 0% 0% rgb(255,255,0)">{cons,</span><span style="background:none repeat scroll 0% 0% rgb(255,255,0)">8</span><span style="background:none repeat scroll 0% 0% rgb(255,255,0)">,</span>”
to “<span style="background:none repeat scroll 0% 0% rgb(255,255,0)">{cons,6,</span>”.</p>
<p style="margin-bottom:0cm" lang="en">
</p>
<p style="margin-bottom:0cm" lang="en">Tested by Erlang 16B02
syntax_tools-1.6.11, and R15B02, syntax_tools-1.6.9</p>
<p style="margin-bottom:0cm" lang="en">
</p>
<p style="margin-bottom:0cm" lang="en">__________________________example.erl____________________________________-module(example).<br><br>-export([handle_event/2]).<br><br>handle_event( _, _) -><br>    [    {},<br>        [],<br>
        [asd,asd] ].</p><p style="margin-bottom:0cm"><span lang="en">_______________________________________________________________________</span><span lang="en"><br><br></span><span lang="en">With
best regards</span><span lang="en">,</span></p><p style="margin-bottom:0cm"><span lang="en">Malikov Constantin,
</span><span lang="en">so</span><span lang="en">ftware developer,
Eltex.</span></p><p style="margin-bottom:0cm"><br><span lang="en"></span></p><p style="margin-bottom:0cm"><span lang="en"><br></span></p>

</div></div>
</div>