Hello all,
I wanted to play with a little with nim (PS I'm not a programmer) and was puzzled by the first error which wasn't obvious at all.
proc main () =
echo "Test"
main ()
It was a space between the the function name and the parenthesis! Is there an explanation on the tutorial about the reason behind it? I would appreciate any reference in the documentation about what formatting not allowed in the code.
(as I side not: it's also somewhat irritating to discover that declarations is order-dependent, I'm not sure of other modern programming languages impose such restriction.)
Thanks
The whitespace before parentheses in your call: main (), causes it to be interpreted as command call syntax which is a way of calling procedures that allows you to omit the parentheses. It's used right there in your code, with the echo call:
echo "a", "b", "c"
# is equivalent to
echo("a", "b", "c")
What the parser interprets this as is a command call with empty parentheses, and empty parentheses are an error.
To fix this, you need to remove the whitespace as you probably already figured out:
main()
See the following sections in the manual:
it's also somewhat irritating to discover that declarations is order-dependent,
But programs following such an order are much more clean. It is much more easy to follow the code when data types and procs are used only after they are declared. Whenever the codeReordering pragma should be available, I would switch it of for my own manually written code. Unfortunately for generating bindings that ordering of symbols is some additional work, as long as one will not generate extremely ugly modules with all data types just put on top as early gtk2 modules did.
But programs following such an order are much more clean. It is much more easy to follow the code when data types and procs are used only after they are declared.
The case could be made that public procedures and types are preferable on top and internal should be at the bottom, so that when you read a file you start from the big details and go down the nitty gritty as you read on the file.