Skip to content

Commit 4be236d

Browse files
docs: add subtraction spacing gotcha
Document the 'a - b needs spaces both sides' convention so site visitors hit the same explanation as the new ILO-P001 hint in the compiler. Covers the three idiomatic shapes: canonical spaces-both subtraction, parenthesised negation, and the load-bearing glued -N for call args / list elements / binop operands.
1 parent ef0dcca commit 4be236d

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

src/content/docs/docs/reference/gotchas.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,33 @@ f x:_>t;?x{n v:"number";t v:"text";_:"other"}
2323
```
2424

2525
Here `_` after `:` is the any type, `?` starts a match, and `_:` in the match is the wildcard arm.
26+
27+
## Subtraction spacing: `a - b` needs spaces both sides
28+
29+
The lexer packs a leading `-` (no preceding space) into the number token, so `a -1.5` is `Number(a), Number(-1.5)` not `a, Minus, 1.5`. This is deliberate so call args and list elements read naturally:
30+
31+
```ilo
32+
mod n -2 -- mod(n, -2) - glued -2 is the call's second arg
33+
sub 5 -3 -- sub(5, -3)
34+
[1 -2 3] -- list of [1, -2, 3]
35+
+a -3 -- a + (-3) - glued -3 is the binop's second operand
36+
```
37+
38+
The downside: `0 -1.5` at statement position is **not** subtraction. The parser sees `Number(0), Number(-1.5)` and errors with:
39+
40+
```
41+
ILO-P001: expected declaration, got number `-1.5`
42+
hint: for subtraction, write `a - b` with spaces both sides (e.g. `0 - 1.5`).
43+
for a negative value as an expression, wrap in parens: `(-1.5)`.
44+
```
45+
46+
Three idiomatic shapes:
47+
48+
```ilo
49+
0 - 1.5 -- canonical subtraction (spaces both sides)
50+
(-1.5) -- bare negative value as an expression
51+
mod n -2 -- glued -N as call arg / list element / binop operand (load-bearing)
52+
```
53+
54+
The lexer auto-splits `-N` back into `Minus + Number` when the previous token introduces a fresh-expression position (`;`, newline, `=`, `{`, `(`, or `-`), so `-0 v` at the start of a body, `r=-1 x`, `{-1}`, and `(-1)` all work. After an Ident, `[`, or another prefix binop, the glued form is preserved.
55+

0 commit comments

Comments
 (0)