You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Copy file name to clipboardExpand all lines: src/content/docs/docs/guide/prefix-notation.md
+21Lines changed: 21 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -162,6 +162,27 @@ Read left-to-right. Each operator grabs the next two values (which may themselve
162
162
163
163
This is equivalent to `(((a + b) * c) - d) / e` in infix - note how 4 pairs of parentheses disappear entirely.
164
164
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
+
165
186
### Operand rules
166
187
167
188
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