diff options
| author | seh <henesy.dev@gmail.com> | 2019-03-18 16:23:46 -0500 |
|---|---|---|
| committer | seh <henesy.dev@gmail.com> | 2019-03-18 16:23:46 -0500 |
| commit | 5cd0b7d8139f0cd5f4af1f9f3b82fe2cd3f37288 (patch) | |
| tree | 89d53f7496f368dd98f4fee660462647d5e4b2c9 | |
| parent | 169cceaef46664b809cc13f52f9cfaa88275d610 (diff) | |
add args.m example
| -rw-r--r-- | Args/README.md | 16 | ||||
| -rw-r--r-- | README.md | 4 |
2 files changed, 18 insertions, 2 deletions
diff --git a/Args/README.md b/Args/README.md index 3085784..2320046 100644 --- a/Args/README.md +++ b/Args/README.md @@ -1,22 +1,28 @@ # Command-Line Arguments -Inferno has a dedicated module for processing commandline flags and arguments, arg(2). +Inferno has a dedicated module for processing commandline flags and arguments, [arg(2)](http://man.cat-v.org/inferno/2/arg). ## Source ### args.b:17,22 +The module `Arg` is loaded and initialized. As per the manual, the `arg->init()` function must be called before any other functions can be called from `Arg`. +The usage message is also set pre-emptively for use later, if necessary. ### args.b:24,37 +There are two flag arguments, `r` and `c` which set reversal of arguments and the list item indicator mark, respectively. +The flag `r` is a binary option toggle, the flag's presence as an argument is sufficient to change the value of `rev`. + +The flag `c` takes an argument. The `arg->earg()` function is used to pop the flag's argument out of the list. Specifically with regards to `earg()` rather than `arg()` as per the manual, `earg()` will call `arg->usage()` if the relevant argument does not exist. Note: After the processing of all flags, `argv` is re-set from the value contained within `arg` to remove the elements (if any) utilized by flags and their arguments. ### args.b:41,51 - +This section utilizes the `rev` variable to (naively) reverse the list `argv`. After the `rev` check, the list `argv` is printed in order from beginning to end with each element being printed on a new line with the `mark` variable being prefixed to the list element currently at the head of the `argv` list each iteration during printout. ## Demo @@ -48,3 +54,9 @@ Note: After the processing of all flags, `argv` is re-set from the value contain -> c -> d ; + +## Exercises + +- Can you trick `earg()` into accepting a nil value? +- How would you pull an `int` out of `earg()`? +- How would you trip the `usage()` message call-able from `earg()`? @@ -47,6 +47,10 @@ Core language functionality: - [Generics, Picks, and Interfaces (kind of)](./Generics) - [Exceptions](./Exceptions) +Standard library modules: + +- [Command-Line Arguments](./Args) + ## References - [The Limbo Programming Language](http://doc.cat-v.org/inferno/4th_edition/limbo_language/limbo) |
