From b8cd576b2db2eb4bf21d0f18f18dae77cd70f6e4 Mon Sep 17 00:00:00 2001 From: otnc Date: Tue, 14 Jul 2026 13:51:43 +0900 Subject: [PATCH] docs: fix bare reassignment examples to match compiler behavior MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bare identifier reassignment (`y be 20`) is not supported (RFC 6.4) and is now reported as a compile error (puruslang/purus#8), but several examples still used it — those examples silently dropped the assignment (the while loops would infinite-loop): - reference/operators: remove `y be 20` from Assignment; add a caution pointing to property/index/destructuring targets and compound assignment - reference/control-flow: while example `i be i add 1` -> `i add be 1` - reference/functions: generator example `i be i add 1` -> `i add be 1` - getting-started/hello-world: `y be 100` -> `y add be 1` The for-loop update clause (`for let i be 0; i lt 5; i be i add 1`) is special-cased by the parser and remains valid, so those examples are unchanged. Both en and ja pages updated. --- src/content/docs/getting-started/hello-world.mdx | 2 +- src/content/docs/ja/getting-started/hello-world.mdx | 2 +- src/content/docs/ja/reference/control-flow.mdx | 4 ++-- src/content/docs/ja/reference/functions.mdx | 4 ++-- src/content/docs/ja/reference/operators.mdx | 5 ++++- src/content/docs/reference/control-flow.mdx | 4 ++-- src/content/docs/reference/functions.mdx | 4 ++-- src/content/docs/reference/operators.mdx | 5 ++++- 8 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/content/docs/getting-started/hello-world.mdx b/src/content/docs/getting-started/hello-world.mdx index cb05b6d..fa131f0 100644 --- a/src/content/docs/getting-started/hello-world.mdx +++ b/src/content/docs/getting-started/hello-world.mdx @@ -52,7 +52,7 @@ purus run hello.purus ```purus const x be 42 let y be 3.14 -y be 100 +y add be 1 -- y += 1 (compound assignment) ``` ## Functions diff --git a/src/content/docs/ja/getting-started/hello-world.mdx b/src/content/docs/ja/getting-started/hello-world.mdx index 4b6b745..0e92993 100644 --- a/src/content/docs/ja/getting-started/hello-world.mdx +++ b/src/content/docs/ja/getting-started/hello-world.mdx @@ -52,7 +52,7 @@ purus run hello.purus ```purus const x be 42 let y be 3.14 -y be 100 +y add be 1 -- y += 1(複合代入) ``` ## 関数 diff --git a/src/content/docs/ja/reference/control-flow.mdx b/src/content/docs/ja/reference/control-flow.mdx index 2cc6a9b..20392f6 100644 --- a/src/content/docs/ja/reference/control-flow.mdx +++ b/src/content/docs/ja/reference/control-flow.mdx @@ -119,7 +119,7 @@ for (const item of list) { ```purus while i lt 10 - i be i add 1 + i add be 1 until finished do-work[] @@ -127,7 +127,7 @@ until finished ```js while (i < 10) { - i = i + 1; + i += 1; } while (!(finished)) { do_work(); diff --git a/src/content/docs/ja/reference/functions.mdx b/src/content/docs/ja/reference/functions.mdx index ec8b186..5f36fd9 100644 --- a/src/content/docs/ja/reference/functions.mdx +++ b/src/content/docs/ja/reference/functions.mdx @@ -296,7 +296,7 @@ fn count-up limit let i be 0 while i lt limit yield i - i be i add 1 + i add be 1 ``` ```js @@ -304,7 +304,7 @@ function* countUp(limit) { let i = 0; while (i < limit) { yield i; - i = i + 1; + i += 1; } } ``` diff --git a/src/content/docs/ja/reference/operators.mdx b/src/content/docs/ja/reference/operators.mdx index cb68af6..88628b0 100644 --- a/src/content/docs/ja/reference/operators.mdx +++ b/src/content/docs/ja/reference/operators.mdx @@ -47,9 +47,12 @@ data.method(arg) ```purus const x be 42 let y be 10 -y be 20 ``` +:::caution +裸の識別子への再代入(`y be 20`)は**コンパイルエラー**です([構文の概要](/ja/reference/syntax/)参照)。プロパティ・インデックス(`obj.x be 1`、`arr[\0] be 1`)と分割代入(`[a; b] be [b; a]`)は宣言キーワードなしで代入でき、可変の変数の更新には複合代入(`y add be 10`)を使います。 +::: + ## 複合代入 算術演算と代入を組み合わせた複合代入演算子: diff --git a/src/content/docs/reference/control-flow.mdx b/src/content/docs/reference/control-flow.mdx index a652d60..3b6236d 100644 --- a/src/content/docs/reference/control-flow.mdx +++ b/src/content/docs/reference/control-flow.mdx @@ -119,7 +119,7 @@ for (const item of list) { ```purus while i lt 10 - i be i add 1 + i add be 1 until finished do-work[] @@ -127,7 +127,7 @@ until finished ```js while (i < 10) { - i = i + 1; + i += 1; } while (!(finished)) { do_work(); diff --git a/src/content/docs/reference/functions.mdx b/src/content/docs/reference/functions.mdx index 6895ceb..9d98570 100644 --- a/src/content/docs/reference/functions.mdx +++ b/src/content/docs/reference/functions.mdx @@ -296,7 +296,7 @@ fn count-up limit let i be 0 while i lt limit yield i - i be i add 1 + i add be 1 ``` ```js @@ -304,7 +304,7 @@ function* countUp(limit) { let i = 0; while (i < limit) { yield i; - i = i + 1; + i += 1; } } ``` diff --git a/src/content/docs/reference/operators.mdx b/src/content/docs/reference/operators.mdx index 2dbb884..e41b37a 100644 --- a/src/content/docs/reference/operators.mdx +++ b/src/content/docs/reference/operators.mdx @@ -47,9 +47,12 @@ data.method(arg) ```purus const x be 42 let y be 10 -y be 20 ``` +:::caution +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`). +::: + ## Compound Assignment Compound assignment operators combine an arithmetic operation with assignment: