Nim is full of surprises
proc Zug(RIn:int) =
let Reihe = RIn -1
I couldn't believe it, after many trials I found that a space is needed in front of 1. What a strange syntax! (This is with nim-1.4.0)
Is there a list of such pitfalls in Nim?
Thanks, Helmut
So when you write RIn -1 it should be read "RIn neagtive 1" as Nim's function calling syntax is very flexible. For example echo RIn is equal to echo(RIn). In this case it interprets RIn -1 as RIn(-1) which doesn't exists.
This particular error was caused by method call syntax - because you can omit parenthesis around functionCall arguments, RIn -1 got parsed as RIn(-1) and not RIn - 1.
As for the list of "pitfalls" - the only thing that comes to mind is passing tuples to function calls funcall(1, 2) is a call for function with two parameters, while funcall (1, 2) is a call for function with single parameter that accepts tuple of two elements.
Also for array access arrayVar[12] is not the same as funcall [12]
Well you don't have Nim's flexible function call syntax in a dozen other programming languages. If using this particular code formatting is crucial to you, Nim is probably not your choice.
On a personal note, I find this code style absolutely ugly and actually like that the Nim compiler wouldn't allow it.
If you prefer a terse syntax, write simply: let Reihe = RIn-1 But I'd visualize a let Reihe = RIn -1 directly as an application of RIn to the negative number -1.
So, the Nim lexer supports both terse (condensed) syntax and wide syntax with space. If space is available, write binops with space. This is pretty much standard today.