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

Kamil Skalski nazgul at nemerle.org
Mon Sep 27 14:32:53 CEST 2004


Dnia poniedziałek, 27 września 2004 14:18, Wiktor Zychla napisał:
> the side effect of the ++ operator is, in my opinion, incorrecly used in
> following scenario.
>
> class Hello
> {
>  static Main() : void
>  {
>   mutable i=0;
>   Console.WriteLine( "{0}", ++i );
>  }
> }
>
> output: empty
>
> is such behaviour consistent with Nemerle semantics or is it a bug?

It is the feature not a bug ;-)

It is consistent with
http://www.nemerle.org/csharp-diff.html#expr-changes
 The type of assignment operator is void

++i  ~  ( i = i + 1  ) : void

Probably you are right, that this is conterintuitive for C programmer. I also 
liked the semantics of tab [i++] = 5;

But in functional language it is better to keep assignments having type void.

> if it is not a bug, then I think that the semantics should be revisited
> because it's nonintuitive.

Just do
++i;
Console.WriteLine( "{0}", i );

BTW. it is strange that WriteLine works with void overload. I'm pretty sure it 
shouldn't and it's problably a bug, that we allow it.

void shouldn't be subtype of object

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




More information about the devel-en mailing list