@@ -28,6 +28,73 @@ cargo install val
28
28
Pre-built binaries for Linux, MacOS, and Windows can be found on [ the releases
29
29
page] ( https://github.com/terror/val/releases ) .
30
30
31
+ ## Usage
32
+
33
+ The primary way to use ** val** is via the provided command-line interface. There
34
+ is currently ongoing work on a Rust library and web playground, which will
35
+ provide a few extra ways to interact with the runtime.
36
+
37
+ Below is the output of ` val --help ` , which describes some of the
38
+ arguments/options we support:
39
+
40
+ ``` present cargo run -- --help
41
+ Usage: val [OPTIONS] [FILENAME]
42
+
43
+ Arguments:
44
+ [FILENAME]
45
+
46
+ Options:
47
+ -e, --expression <EXPRESSION>
48
+ -h, --help Print help
49
+ -V, --version Print version
50
+ ```
51
+
52
+ Running ** val** on its own will spawn a repl (read–eval–print loop) environment,
53
+ where you can evaluate arbitrary ** val** code and see its output immediately. We
54
+ use [ rustyline] ( https://github.com/kkawakam/rustyline ) for its implementation,
55
+ and we support a few quality of life features:
56
+
57
+ - Syntax highlighting (see image above)
58
+ - Persistent command history
59
+ - Emacs-style editing support by default
60
+ - Filename completions
61
+ - Hints (virtual text pulled from history)
62
+
63
+ The ** val** language supports not only expressions, but quite a few
64
+ [ statements] ( https://github.com/terror/val/blob/ea0c163934ee3f4afe118384b1281d296f116539/src/ast.rs#L35 ) as well.
65
+ You may want to save ** val** programs and execute them later, so
66
+ the command-line interface provides a way to evaluate entire files.
67
+
68
+ For instance, lets say you have the following ** val** program at
69
+ ` factorial.val ` :
70
+
71
+ ``` rust
72
+ fn factorial (n ) {
73
+ if (n <= 1 ) {
74
+ return 1
75
+ } else {
76
+ return n * factorial (n - 1 )
77
+ }
78
+ }
79
+
80
+ println (factorial (5 ));
81
+ ```
82
+
83
+ You can execute this program by running ` val factorial.val ` , which will write to
84
+ standard output ` 120 ` .
85
+
86
+ Lastly, you may want to evaluate a val expression and use it within another
87
+ program. The tool supports executing arbitrary expressions inline using the
88
+ ` --expression ` or ` -e ` option:
89
+
90
+ ``` bash
91
+ val -e ' sin(2) * e ^ pi * cos(sum([1, 2, 3]))'
92
+ 16.481455793912883
93
+ ```
94
+
95
+ ** n.b.** The ` --expression ` option and ` filename ` argument are mutually
96
+ exclusive.
97
+
31
98
## Prior Art
32
99
33
100
[ bc(1)] ( https://linux.die.net/man/1/bc ) - An arbitrary precision calculator
0 commit comments