I'm new to Nim. I'm wondering whether this behavior is intended or not.
In the following code, I tried something like closure. The 1st time and the 3rt time cl_test is called, the count value increased. But the 2nd time cl_test is called without parenthesis, the count value does not increase.
var count: int = 10
proc cl_test(): int=
count = count + 1
echo (count, "\n")
# returns 10
# 1st time cl_test() is called
discard cl_test()
echo(count, "\n")
# returns 11
# 2nd time cl_test is called
discard cl_test
echo(count, "\n")
# returns 11
# 3rd time cl_test() is called
discard cl_test()
echo(count, "\n")
# returns 12
Nim Compiler Version 0.11.2 (2015-05-04) [Windows: amd64]
Hi niceume!
Actually this is not a bug. You must write () to those function calls which function has no parameters. Let me show in an example:
var f = cl_test
var g = cl_test()
Here f is the actual function, while g is the returned value.
Peter
Thanks, Peter !
I got it! Without parenthesis, it's a function. This is a cool feature, and I like it.