by coolreader18 · 6y ago · 0 comments
echo $foo
# is parsed as
echo($foo)
[..] echo(1, 2) # pass 1 and 2 to echo
echo (1, 2) # pass the tuple (1, 2) to echo
[..] proc optarg(x: int, y: int = 0): int = x + y
proc singlearg(x: int): int = 20*x
echo optarg 1, " ", singlearg 2 # prints "1 40"
let fail = optarg 1, optarg 8 # Wrong. Too many arguments for a command call
let x = optarg(1, optarg 8) # traditional procedure call with 2 arguments
let y = 1.optarg optarg 8 # same thing as above, w/o the parenthesis
assert x == y
[0]: https://nim-lang.org/docs/manual.html#syntax-precedence[1]: https://nim-lang.org/docs/manual.html#procedures-command-inv...
This makes it quite hard to "sight-read" code with reasonably-sized function names and arg lists:
do_some_thing_descriptive (some_arg_2, some_longer_arg)
[ ... other code ] do_some_very_descriptive_thing(some_arg_2, some_longer_arg)
I imagine that each file would try to remain internally-consistent with preferring one syntax over the other.IMO, in scenarios where a module must remain internally-consistent on its one-of-many-ways to do it, for the sake of legibility, there should be only one way to do it. Although, I'm open to hearing any good-faith arguments to the contrary!