> There is no var keyword that you have to use when first create a variable. My 
> "implicit var" proposal was for Nim to behave the same way for b = 2 as for 
> var b = 2. You'd still get b type-inferred as int with static checking like 
> in Crystal (or like with b := 2 in Go).

But there are cases where var b = 2 and b = 2 have different meanings in Nim, 
for instance:
    
    
    proc p(b: var int) =
      var b = 2
    
    
    Run

and
    
    
    proc p(b: var int) =
      b = 2
    
    
    Run

And here:
    
    
    var a = 0
    # some code.
    while true:
      a = 2      #
    
    
    Run

compared to:
    
    
    var a = 0
    # some code.
    while true:
      var a = 2      #
    
    
    Run

So we need var to maintain the difference between a declaration with 
initialization and an assignment. Giving the user the possibility to remove var 
and let the compiler guess what he is meaning, would only make Nim confusing. 
In some cases b = 2 would be a declaration, in other cases an assignment, and 
in others something ambiguous. Personally, I think that this would be a mess.

And, still, I maintain that the languages have very different semantic and 
changing the syntax to make them look more closer is a trap. b = 2 in Python 
is, in Nim, neither equivalent to var b = 2 nor to b = 2 despite the apparences.

At least, when Python users use var in Nim, they know:

  * that they have reserved some memory to store a value whose size is 
determined by its type;
  * that no declaration with the same name is allowed in the same block;
  * that when exiting the block containing the declaration, the memory assigned 
to the variable will be freed.



None of these statements is true in Python.

Reply via email to