Skip to content

Commit

Permalink
Update cli arguments doc
Browse files Browse the repository at this point in the history
  • Loading branch information
imaqtkatt committed Mar 8, 2024
1 parent cdf8bba commit 0949229
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions docs/cli-arguments.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
# CLI arguments

It's possible to pass arguments to a program executed with `hvml run`:

```sh
hvml run <Path to program> [Arguments in expression form]...
```

It accepts any expression that would also be valid inside an hvm-lang function.

Arguments are passed to programs by applying them to the entrypoint function:

```js
main x1 x2 x3 = (MainBody x1 x2 x3)

// Calling with `hvml run <file> arg1 arg2 arg3`, it becomes:
// Calling with `hvml run <file> arg1 arg2 arg3 argN`, it becomes:

main = (λx1 λx2 λx3 (MainBody x1 x2 x3) arg1 arg2 arg3)
main = (λx1 λx2 λx3 (MainBody x1 x2 x3) arg1 arg2 arg3 argN)
```

The entrypoint function must receive exactly the number of arguments specified in the left-hand side of its definition.
```
// Must pass exactly 3 arguments when running
main x y z = (MainBody x y z)
There are no restrictions on the number of arguments passed to the program.

```rust
// Can receive 2 CLI arguments
main x y = (+ x y)

// Can't receive CLI arguments
main = λx λy λz (MainBody x y z)
```
main = λx λy (+ x y)

// Calling with just one argument
hvml run <path> 5
λa (+ a 5)
```

0 comments on commit 0949229

Please sign in to comment.