diff options
Diffstat (limited to 'chapter17')
| -rw-r--r-- | chapter17/README.md | 25 | ||||
| -rw-r--r-- | chapter17/src/test/java/com/seaofnodes/simple/Chapter17Test.java | 2 |
2 files changed, 24 insertions, 3 deletions
diff --git a/chapter17/README.md b/chapter17/README.md index 6c70f022..5a7f48d3 100644 --- a/chapter17/README.md +++ b/chapter17/README.md @@ -6,12 +6,33 @@ Allow `arg++` and `arg--` with the usual meanings; the value is updated and the expression is the pre-update value. Greedy match is used so `arg---arg` parses as `(arg--)-arg`. +Also allows `s.fld++` and `ary[idx]++`, and their `--` variants. + +# var & val + +`var` can be used in the `type` position to indicate a "variable" (mutable +value), whose type will be inferred from the initalizing expression. + +`val` is the same as `var`, except its a "value" (not mutable). + +The inferred value is the `glb` of the peephole type, which means `var` and +`val` will not infer types like `u8` or `f32`, instead inferring `int` and +`flt` respectively. Struct types will always infer as nullable, so e.g. + +`var s = new S;` + +infers as + +`S s? = new S;` + + + -var/val invert ! C++-style for-loop for-interator - +trinary +switch diff --git a/chapter17/src/test/java/com/seaofnodes/simple/Chapter17Test.java b/chapter17/src/test/java/com/seaofnodes/simple/Chapter17Test.java index ffb9bfc2..96f12480 100644 --- a/chapter17/src/test/java/com/seaofnodes/simple/Chapter17Test.java +++ b/chapter17/src/test/java/com/seaofnodes/simple/Chapter17Test.java @@ -117,7 +117,7 @@ return sum; } @Test - public void sieveOEratosthenes() { + public void sieveOfEratosthenes() { Parser parser = new Parser( """ val ary = new bool[arg], primes = new int[arg]; |
