written just
quit
c-function returns void. nim wrapper declared in sources like this
proc quit*(errorcode: int = QuitSuccess) {.
magic: "Exit", importc: "exit", header: "<stdlib.h>", noreturn.}
but
murder.nim(9, 3) Error: expression 'quit' is of type 'None' and has to be discarded; start of expression here: murder.nim(8, 2)
wtf?
quit()
You can call them without (), when it's clear otherwise, that it's a call. Say, in command syntax with arguments: a b (means a(b)). In dot syntax: b.a.
In just a on its own a represents just the proc itself, so that you can send it as an argument to other procs or save to a variable, like: mySeq.map toUpperAscii, toUpperAscii is not called here, but passed to map. Or:
proc x(s: string) = echo "[", s, "]"
var y = x
y "z"
And as just quit returns the proc itself, it is an expression ('None' is its type), not a statement.
Ok, so if I have this
proc a(b: string) = echo b
I can use only this
a b
a(b)
b.a
b.a()
But if I have any proc without args, I cannot just call it without ()? May be it's clever, it could be confusing having vars and procedures without ()
b.a
b.a()
Called UFCS
But if I have any proc without args, I cannot just call it without ()?
Because you can write it like this
proc aha(): string = "aha"
let a = aha # `a` act as procvar for `aha`
echo a() # so you need '()' to call it
echo repr(a) # see what is actually `a`
May be it's clever, it could be confusing having vars and procedures without ()
Indeed it's confusing, but all you care is what it returns or does.
If the function expression invoked as right side, you'll know it has to return something, in case "aha" returned function pointer while "aha()" returned string.
If the function used solely in statement, meant it somehow has to return void type.
How do we know it's just variable or function? Just look for its definition.
Exactly, but again, it's possible to possible to call a.b without (). I've tried to call quit because of this.
When it's so, think about some type A, that have field has field B and there is a proc B(ololo: A).
I cannot imagine, what kind of error will I get for "A.B", and even don't want to know.
For module/lib writer to write proc with same name with exported field is redundant. Writing the proc with same name with field is for private field. And it's only getter , for setter you have to name the proc with fieldName= .
The confusion you raised before is accesing proc without () which has zero argument on its definition.