[nem-en] incorrect side effect of ++ operator

Kamil Skalski nazgul at nemerle.org
Tue Sep 28 11:14:08 CEST 2004


Dnia wtorek, 28 września 2004 10:59, rzyj at o2.pl napisał:
> >traversal functions for parsetree. But it seems very hackish...
> >and sometimes would need to do complex transoformations
> >
> >foo (i, ++i)  ====>   ++i; foo (i, i);    ?
>
> Why not:
>
>   foo (i, {i = i + 1; i})
>
> ?

Right, this would be changing current implementation of ++i from
        <[ $cached; $safe = $safe + $one ]>        
to
        <[ $cached; $safe = $safe + $one; $safe ]>                

So, this is not an implementation problem - the ++i macro could even check 
some command line flag. The problem is "what we, as language definers, want 
to be the official version" ;-)


>
> Anyway, your example is incorrect since it changes the semantics -
> transformed code passes foo two identical values, whereas the original one
> two different.


This is why I left the question mark - as it is not trivial to do in the 
simples way. In the next line, there is the correct epxression:
this would force us to do
def prev = i; ++i; foo (prev, i);

But ok, changing it at the very ++ definition is much better idea (or 
parametrising it somehow).

The def prev = i; ++i; foo (prev, i); stuff would be better done by some IDE 
tool, so every time someone write
foo (x, ++i), after a second it becomes  ++i; foo (x, i); :D


-- 
Kamil Skalski
http://nemerle.org developer




More information about the devel-en mailing list