Skip to content

Commit d4218b2

Browse files
authored
Merge pull request #1 from puruslang/fix/bare-reassignment-examples
docs: fix bare reassignment examples to match compiler behavior
2 parents 55e96ba + b8cd576 commit d4218b2

8 files changed

Lines changed: 18 additions & 12 deletions

File tree

‎src/content/docs/getting-started/hello-world.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ purus run hello.purus
5252
```purus
5353
const x be 42
5454
let y be 3.14
55-
y be 100
55+
y add be 1 -- y += 1 (compound assignment)
5656
```
5757

5858
## Functions

‎src/content/docs/ja/getting-started/hello-world.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ purus run hello.purus
5252
```purus
5353
const x be 42
5454
let y be 3.14
55-
y be 100
55+
y add be 1 -- y += 1(複合代入)
5656
```
5757

5858
## 関数

‎src/content/docs/ja/reference/control-flow.mdx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,15 +119,15 @@ for (const item of list) {
119119

120120
```purus
121121
while i lt 10
122-
i be i add 1
122+
i add be 1
123123
124124
until finished
125125
do-work[]
126126
```
127127

128128
```js
129129
while (i < 10) {
130-
i = i + 1;
130+
i += 1;
131131
}
132132
while (!(finished)) {
133133
do_work();

‎src/content/docs/ja/reference/functions.mdx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,15 +296,15 @@ fn count-up limit
296296
let i be 0
297297
while i lt limit
298298
yield i
299-
i be i add 1
299+
i add be 1
300300
```
301301

302302
```js
303303
function* countUp(limit) {
304304
let i = 0;
305305
while (i < limit) {
306306
yield i;
307-
i = i + 1;
307+
i += 1;
308308
}
309309
}
310310
```

‎src/content/docs/ja/reference/operators.mdx‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,12 @@ data.method(arg)
4747
```purus
4848
const x be 42
4949
let y be 10
50-
y be 20
5150
```
5251

52+
:::caution
53+
裸の識別子への再代入(`y be 20`)は**コンパイルエラー**です([構文の概要](/ja/reference/syntax/)参照)。プロパティ・インデックス(`obj.x be 1`、`arr[\0] be 1`)と分割代入(`[a; b] be [b; a]`)は宣言キーワードなしで代入でき、可変の変数の更新には複合代入(`y add be 10`)を使います。
54+
:::
55+
5356
## 複合代入
5457

5558
算術演算と代入を組み合わせた複合代入演算子:

‎src/content/docs/reference/control-flow.mdx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,15 +119,15 @@ for (const item of list) {
119119

120120
```purus
121121
while i lt 10
122-
i be i add 1
122+
i add be 1
123123
124124
until finished
125125
do-work[]
126126
```
127127

128128
```js
129129
while (i < 10) {
130-
i = i + 1;
130+
i += 1;
131131
}
132132
while (!(finished)) {
133133
do_work();

‎src/content/docs/reference/functions.mdx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,15 +296,15 @@ fn count-up limit
296296
let i be 0
297297
while i lt limit
298298
yield i
299-
i be i add 1
299+
i add be 1
300300
```
301301

302302
```js
303303
function* countUp(limit) {
304304
let i = 0;
305305
while (i < limit) {
306306
yield i;
307-
i = i + 1;
307+
i += 1;
308308
}
309309
}
310310
```

‎src/content/docs/reference/operators.mdx‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,12 @@ data.method(arg)
4747
```purus
4848
const x be 42
4949
let y be 10
50-
y be 20
5150
```
5251

52+
:::caution
53+
Reassigning a bare identifier (`y be 20`) is a **compile error** — see [Syntax Overview](/reference/syntax/). Property and index targets (`obj.x be 1`, `arr[\0] be 1`) and destructuring (`[a; b] be [b; a]`) assign without a declaration keyword, and mutable variables are updated with compound assignment (`y add be 10`).
54+
:::
55+
5356
## Compound Assignment
5457

5558
Compound assignment operators combine an arithmetic operation with assignment:

0 commit comments

Comments
 (0)