summaryrefslogtreecommitdiff
path: root/chapter17
diff options
context:
space:
mode:
authorCliff Click <cliffc@acm.org>2024-11-07 16:42:58 -0800
committerCliff Click <cliffc@acm.org>2024-11-23 09:03:20 -0800
commitbaa84f5eb99cd21f6704e71515b6ec7bbd78624f (patch)
treebfc2efb1991db38b345f76ff70b8bdc9a203104a /chapter17
parentefc81d5afc9983258db267894ce3f141962793a5 (diff)
downloadSimple-baa84f5eb99cd21f6704e71515b6ec7bbd78624f.tar.gz
Simple-baa84f5eb99cd21f6704e71515b6ec7bbd78624f.zip
some docs
Diffstat (limited to 'chapter17')
-rw-r--r--chapter17/README.md25
-rw-r--r--chapter17/src/test/java/com/seaofnodes/simple/Chapter17Test.java2
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];