@mashingan
No, it's not about number of arguments. See that:
proc fun(x,y: int) = echo x+y
proc gun(x,y: int): int = x+y
fun 1, 2 # works fine
let x = gun 1, 2 # doesn't compile
let x = gun 1: 2 # compiles (!), although it looks weird
Just like GULPF sa
@mashingan thank you for your detailed explanation and, @GULPF thank you for
your aditional information.
> calling function without parenthesis is only for single argument type. echo
> works because it expects varargs
Multiple arguments are allowed when the call is a statement, but not when it's
an expression. E.g `add 1, 2` would work if it was a statement (only possible
if doesn't return anythin
@Allosteric, calling function without parenthesis is only for single argument
type. `echo` works because it expects `varargs`
Limiting it only single argument is good to avoid confusion, it's convenience
that we don't have to write parenthesis when it's only a simple value variable
to supply.
@Araq Do you mean to say here we are dealing with CIS (command invocation
syntax) ? To me this felt under UFCS since it's about function call and about
giving more choices: it's "Universal". Now if UFCS means only a.f()/f(a) then
that's not very universal. But the thing that makes me hate UFCS (
Sorry for not replying so soon and thanks for the responces. However, this
doesn't seem to be a problem with discard since I can replace the discard to
echo to generate the same error.
proc add(x,y:int):int= x+y
echo add 1, 2 #=> Error: type mismatch: got
echo (add 1,
"anti UFCS fire"? There is no UFCS involved here. "vexing parse" also has
nothing to do with it. Hate what you want but an informed opinion can't hurt
either.
Why not just treat `discard` like a function call which takes another function
call? Then `discard fun x, y` would parse as `discard(fun(x), y)`, just like
with, say, `echo`. Then it just makes sense.
it took me a good minute to understand what you said @mashingan. That is a
vexing parse in my opinion, and only some more gasoline on my anti UFCS fire.
It's sad that I end up with negative judgments of a feature that sounds so
marvelous on paper. (and I like the command call syntax, spaces with
Because discard expects a single statement but in the line there were several
tokens space-separated.
Apart from that, it's preferable to use it only for single argument function or
other obvious function call.
I understand that in Nim, you can call a proc without using brackets. Indeed,
the following works fine:
write stdout, "a" #== write(stdout, "a")
#=>a
However, the followings fail.
import strutils
discard split "A,B,C" ',' #=> Error: invalid inden
11 matches
Mail list logo