mirror of
https://github.com/HigherOrderCO/Bend.git
synced 2024-09-11 03:45:29 +03:00
1.2 KiB
1.2 KiB
CLI arguments
It's possible to pass arguments to a program executed with bend run
:
bend run <Path to program> [Arguments in expression form]...
It accepts any expression that would also be valid inside a bend function.
Arguments are passed to programs by applying them to the entry point function:
# Imp syntax
def main(x1, x2, x3):
return MainBody(x1 x2 x3)
# Calling with `bend run <file> arg1 arg2 arg3 argN`, it becomes (in the "fun" syntax):
main = (λx1 λx2 λx3 (MainBody x1 x2 x3) arg1 arg2 arg3 argN)
There are no restrictions on the number of arguments passed to the program. You can even pass more arguments than the function expects, although that can lead to unexpected results.
# Expects 2 CLI arguments
def main(x, y):
return {x - y, y - x}
# Calling with just one argument
> bend run <path> +5
λa {(- a 5) (- a +5)}
# Calling with two argument
> bend run <path> +5 +3
{+2 -2}
# Calling with three argument
# In this case, the third argument doesn't change anything
# due to the underlying interaction rules.
# If this were a variant of simply-typed lambda-calculus
# it wouldn't be well-typed.
> bend run <path> +5 +3 +1
{+2 -2}