Command invocation syntax

Routines can be invoked without the () if the call is syntactically a statement. This command invocation syntax also works for expressions, but then only a single argument may follow. This restriction means echo f 1, f 2 is parsed as echo(f(1), f(2)) and not as echo(f(1, f(2))). The method call syntax may be used to provide one more argument in this case:

  1. proc optarg(x: int, y: int = 0): int = x + y
  2. proc singlearg(x: int): int = 20*x
  3. echo optarg 1, " ", singlearg 2 # prints "1 40"
  4. let fail = optarg 1, optarg 8 # Wrong. Too many arguments for a command call
  5. let x = optarg(1, optarg 8) # traditional procedure call with 2 arguments
  6. let y = 1.optarg optarg 8 # same thing as above, w/o the parenthesis
  7. assert x == y

The command invocation syntax also can’t have complex expressions as arguments. For example: (anonymous procs), if, case or try. Function calls with no arguments still needs () to distinguish between a call and the function itself as a first class value.