From f13a809597991b705db6f185bd356c34eca967be Mon Sep 17 00:00:00 2001 From: Cliff Click Date: Mon, 11 Nov 2024 11:39:32 -0800 Subject: Allow pre-inc/dec on variables --- chapter17/README.md | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'chapter17/README.md') diff --git a/chapter17/README.md b/chapter17/README.md index b9733873..fa268293 100644 --- a/chapter17/README.md +++ b/chapter17/README.md @@ -1,7 +1,7 @@ # Chapter 17: Syntax Sugar -## Post-increment +## Pre/Post-increment 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 @@ -9,6 +9,8 @@ as `(arg--)-arg`. Also allows `s.fld++` and `ary[idx]++`, and their `--` variants. +Allow pre-increment for identifiers only, for now: `--pc`. + ## var & val @@ -19,7 +21,7 @@ value), whose type will be inferred from the initalizing expression. 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. +`flt` respectively. Reference types will always infer as nullable, so e.g. `var s = new S;` @@ -93,12 +95,10 @@ return p.x; ```cpp struct Bar { int x; }; -Bar b = new Bar; /* b = null; *//* b.x++; */ // immutable & deep immutable -Bar !b = new Bar; b = null; /* b.x++; */ // mutable & deep immutable -Bar b! = new Bar; /* b = null; */ b.x++; // immutable & deep mutable -Bar !b! = new Bar; b = null; b.x++; // mutable & deep mutable (ignoring NPE) -val b = new Bar; /* b = null; *//* b.x++; */ // immutable & deep immutable -var b = new Bar; b = null; b.x++; // mutable & inherits deep mutability from RHS +Bar b = new Bar; /* b = new Bar; *//* b.x++; */ // immutable & deep immutable +Bar !b = new Bar; b = new Bar; b.x++; // mutable & deep mutable +val b = new Bar; /* b = new Bar; *//* b.x++; */ // immutable & deep immutable +var b = new Bar; b = new Bar; b.x++; // mutable & inherits deep mutability from RHS ``` @@ -114,6 +114,8 @@ Allow C/C++ style `for` loops: `for( init; test; next ) body` +Example: + ```cpp int sum=0; for( int i=0; i