A reason for this behaviour is that if there is no `result` nor `return`, the 
last expression of the proc will be used. I can't find in the manual where it 
is documented but the following code compiles:
    
    
    proc foo: int =
      2
    
    echo foo()
    
    
    Run

My understanding is that Nim uses these 3 different proc result syntaxes for 
different reasons:

  * `return` allows breaking out of proc à la C and is like a goto end 
statement. Some would see it like an optimization and it can make code 
verification more difficult.
  * `result` comes from the Oberon or Eiffel heritage. An interesting fact of 
having the result in a variable is that the compiler could reason on the state 
of the variable (i.e. value has changed).
  * And the last expression value is the functional way.



But yes, useful warnings would help writing safer code.

Reply via email to