Skip to content

Commit 57bf147

Browse files
docs: note same-precedence prefix-pair trap in prefix-notation guide
Adds a section explaining that '*/a b c' parses as '(a/b)*c' (not '(a*b)/c') because the outer prefix op binds the inner subexpression as its left operand. Same trap for '/*', '+-', '-+'. The ilo runtime now emits a hint on these four shapes after a successful run. Mirrors the SPEC.md / ai.txt / SKILL.md additions in ilo-lang PR for the 'fix/mul-div-precedence-diag' branch.
1 parent 45133a5 commit 57bf147

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

src/content/docs/docs/guide/prefix-notation.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,27 @@ Read left-to-right. Each operator grabs the next two values (which may themselve
162162

163163
This is equivalent to `(((a + b) * c) - d) / e` in infix - note how 4 pairs of parentheses disappear entirely.
164164

165+
### Same-precedence prefix-pair trap
166+
167+
The outer prefix op binds the inner prefix subexpression as its **left** operand, regardless of operator precedence. With two same-precedence ops side by side this disagrees with the natural left-to-right reading:
168+
169+
```ilo
170+
*/a b c -- (a/b) * c ← NOT (a*b)/c
171+
/*a b c -- (a*b) / c ← NOT (a/b)*c
172+
+-a b c -- (a-b) + c ← NOT (a+b)-c
173+
-+a b c -- (a+b) - c ← NOT (a-b)+c
174+
```
175+
176+
The ilo runtime emits a `hint:` diagnostic on these four shapes after a successful run. To force the other grouping, either swap the operator pair or bind the inner result first:
177+
178+
```ilo
179+
-- Want (a*b)/c with a=6, b=2, c=3:
180+
r=*a b;/r c -- bind, then divide → 4
181+
/*a b c -- equivalent, swapping the prefix-pair order
182+
```
183+
184+
Different-precedence pairs like `+*a b c` (= `(a*b)+c`) and same-op repeats like `++a b c` (= `(a+b)+c`) match the left-to-right reading naturally and don't fire the hint.
185+
165186
### Operand rules
166187

167188
Operator operands must be atoms (literals, variable references, field access) or nested prefix operators. Function calls are not valid operands - bind their results first:

0 commit comments

Comments
 (0)