When reading Nim source code, I often come across proc definitions that mix , and ; in the parameter list. But I failed to find any useful references about the difference between the two, so I have to create my first thread in this forum to find out.
And it seems that more often than not the authors would break such parameter lists into multiple lines, even when the list is not that long, is that required by the syntax?
The comma can give multiple arguments the same type, while the semicolon makes sure they each have their own type.
using a: string
proc foo(a, b: int) = echo "foo"
proc bar(a; b: int) = echo "bar"
foo(1, 2)
bar("a", 2)
template foo(a, b: int) = echo "foo"
template bar(a; b: int) = echo "bar" # arguments with no type in templates are `untyped`
foo(1, 2)
bar(sdmfsp, 2)
proc foo[T, U: SomeInteger](a: T, b: U) = echo "foo"
proc bar[T; U: SomeInteger](a: T, b: U) = echo "bar"
foo(1, 2)
bar("a", 2)
Breaking into multiple lines should not be required by the syntax, it just looks weird if only 1 part of the parameter list is in a different line or something like that.