echo(1,2) != echo (1,2) ; where is this documented?
inim
INim 0.2.0
Nim Compiler Version 0.18.1 [MacOSX: amd64] at /Users/timothee/.nimble/bin/nim
>>> echo (1,2)
(Field0: 1, Field1: 2)
>>> echo(1,2)
12
>>> echo (1,)
1
>>> echo (1)
1
T* he only place I could find is this: https://nim-lang.org/docs/manual.html#syntax-precedence > Whether an operator is used a prefix operator is also affected by preceding whitespace (this parsing change was introduced with version 0.13.0):
echo $foo
# is parsed as
echo($foo)
however this doesn't describe the story above
#nimble install tuples
import tuples
proc foo[T](a:T)=echo a.len
foo(("abcdef", "ghi", "def")) # 3
foo(("abcdef", "ghi")) #2
foo(("abcdef", )) # 6 (oups!) instead of 1
foo(()) # 0
EDIT
import tuples
proc getCalculatorTestCases[Calculator]():auto =
let a = (("1+1", 2), ("2*3", 6))
when Calculator.supportsDivision:
return a & (("8 / 2", 4),) # without 1 element tuple, this would be: (("1+1", 2), ("2*3", 6), "8 / 2", 4) which is not what we want here
else:
return a
I agree when incomplete tuple creation should be an error instead.
It's just, tuple for me just a convenient way to return multiple values. Usually I used it in helper procs that those just defined to help the main proc.
So return tuple with only a field is kinda weird considering tuple is there to get multiple values.
@mashingan
It is not. It's a common usecase, not the definition. You can use integers to denote count but that's not the definition of an integer.