[インデックス 14595] ファイルの概要
コミット
commit 9c9e811bb34dc48abf256aae91af9199fb9f0f71
Author: Robert Griesemer <gri@golang.org>
Date: Mon Dec 10 11:55:57 2012 -0800
spec: consistently use "indices" (rather than "indexes")
We have been using all three terms "indices", "indexes",
and "index expressions" indiscriminatly for index values.
With this change, "index" refers to an index value,
"indices" is the plural of "index", and "index expression"
refers to an array, slice, or map indexed by an index: a[x].
R=r, rsc, iant, ken, mtj
CC=golang-dev
https://golang.org/cl/6912056
GitHub上でのコミットページへのリンク
https://github.com/golang/go/commit/9c9e811bb34dc48abf256aae91af9199fb9f0f71
元コミット内容
spec: consistently use "indices" (rather than "indexes")
We have been using all three terms "indices", "indexes",
and "index expressions" indiscriminatly for index values.
With this change, "index" refers to an index value,
"indices" is the plural of "index", and "index expression"
refers to an array, slice, or map indexed by an index: a[x].
R=r, rsc, iant, ken, mtj
CC=golang-dev
https://golang.org/cl/6912056
変更の背景
このコミットは、Go言語の仕様書(doc/go_spec.html
)における用語の不統一を解消することを目的としています。具体的には、「indices」、「indexes」、「index expressions」という3つの用語が、インデックス値を示すために無秩序に使用されていた状況を改善します。
プログラミング言語の仕様書は、その言語の挙動を正確かつ曖昧さなく定義する非常に重要な文書です。用語の不統一は、読者の混乱を招き、誤解を生む可能性があります。特に、Go言語のように厳密な型システムと明確なセマンティクスを持つ言語においては、仕様書の記述の正確性が極めて重要です。
この変更により、以下の明確な定義が導入されます。
- index: 単一のインデックス値(例:配列の
a[0]
における0
) - indices:
index
の複数形 - index expression: 配列、スライス、マップがインデックスによってアクセスされる式全体(例:
a[x]
)
この用語の統一は、仕様書の可読性と正確性を向上させ、Go言語の学習者や開発者がより明確に言語の挙動を理解できるようにすることを意図しています。
前提知識の解説
1. プログラミング言語の仕様書
プログラミング言語の仕様書は、その言語の構文、セマンティクス(意味論)、標準ライブラリの動作などを厳密に記述した公式文書です。これは、コンパイラやインタプリタの実装者、そして言語を使用する開発者にとって、言語の「真実」を定義する唯一の権威ある情報源となります。仕様書が曖昧であったり、用語が不統一であったりすると、異なる実装間で互換性の問題が生じたり、開発者が言語の挙動を誤解したりする原因となります。
2. Go言語におけるインデックスと式
Go言語では、配列、スライス、文字列、マップといったデータ構造に対して、特定の要素にアクセスするためにインデックスを使用します。
- 配列 (Arrays): 固定長で、同じ型の要素のシーケンスです。
a[i]
のように、整数インデックスi
で要素にアクセスします。 - スライス (Slices): 配列の上に構築された、可変長のシーケンスです。配列と同様に
s[i]
で要素にアクセスできますが、s[low:high]
のようなスライス式で部分スライスを作成することもできます。 - 文字列 (Strings): Go言語の文字列はバイトのシーケンスであり、UTF-8でエンコードされています。
s[i]
で個々のバイトにアクセスできます。 - マップ (Maps): キーと値のペアを格納するハッシュテーブルです。
m[key]
のように、キーを使って値にアクセスします。
これらのデータ構造へのアクセスにおいて、a[x]
のような形式は「インデックス式 (index expression)」と呼ばれます。この式の中で、x
の部分が「インデックス値 (index value)」に相当します。
3. 用語の選択:「indices」 vs 「indexes」
英語において、「index」の複数形は「indices」と「indexes」の両方が存在します。
- Indices: より伝統的で、学術的・技術的な文脈で好まれる傾向があります。特に数学や科学、コンピュータサイエンスの分野でよく使われます。
- Indexes: より一般的で、日常的な文脈や、書籍の索引(index)の複数形として使われることが多いです。
このコミットでは、Go言語の仕様書という技術文書の性質上、より厳密で学術的な響きを持つ「indices」に統一することで、文書全体の専門性と一貫性を高める意図があります。
技術的詳細
このコミットの技術的詳細は、Go言語の公式仕様書であるdoc/go_spec.html
ファイル内の特定の用語の置換に集約されます。変更は主に以下のパターンに従っています。
-
見出しの変更:
id="Indexes"
を持つ<h3>
タグがid="Index_expressions"
に変更されました。これにより、インデックスに関するセクション全体が「インデックス式」というより包括的で正確な概念を扱うことを明確にしています。
-
用語の置換:
§<a href="#Indexes">Indexes</a>
というリンクが、§<a href="#Index_expressions">indices</a>
または単に<a href="#Index_expressions">indices</a>
に変更されました。これは、リンク先のセクション名が変更されたことに対応しつつ、文脈に応じて「indexes」を「indices」に、または「index expressions」に置き換えることを示しています。- 「integer indices」という表現が、文字列、配列、スライスの要素アクセスに関する記述で一貫して使用されるようになりました。
- マップのリテラル定義において、「an index expression for array and slice literals」が「an index for array and slice literals」に変更されました。これは、リテラルにおけるキーが「インデックス値」そのものであることを明確にするためです。
- スライス操作に関する記述で、「index expressions
low
andhigh
」が「indiceslow
andhigh
」に変更されました。これは、low
とhigh
がインデックス値そのものを指すためです。 - 同様に、「missing
low
index」が「missinglow
indices」に変更されました。 - 代入文のフェーズに関する記述で、「operands of index expressions」が「operands of index expressions」に変更されました。これは、リンク先の変更に対応するものです。
これらの変更は、単なるスペル修正や表記揺れの統一以上の意味を持ちます。Go言語の仕様書は、言語のセマンティクスを定義する上で非常に厳密であるため、各用語が指す概念を明確に区別することが不可欠です。このコミットは、index
(単一の数値)、indices
(その複数形)、index expression
(a[x]
のような式全体)という3つの概念を明確に分離し、それぞれが適切な文脈で使用されるようにすることで、仕様書の曖昧さを排除し、正確性を高めています。
コアとなるコードの変更箇所
変更はdoc/go_spec.html
ファイルのみで行われています。
--- a/doc/go_spec.html
+++ b/doc/go_spec.html
@@ -1,6 +1,6 @@
<!--{
"Title": "The Go Programming Language Specification",
- "Subtitle": "Version of December 6, 2012",
+ "Subtitle": "Version of December 10, 2012",
"Path": "/ref/spec"
}-->
@@ -791,8 +791,8 @@ The predeclared string type is <code>string</code>.
The length of a string <code>s</code> (its size in bytes) can be discovered using
the built-in function <a href="#Length_and_capacity"><code>len</code></a>.
The length is a compile-time constant if the string is a constant.\n-A string\'s bytes can be accessed by integer indices 0 through
-<code>len(s)-1</code> (§<a href="#Indexes">Indexes</a>).\n+A string\'s bytes can be accessed by integer <a href="#Index_expressions">indices</a>\n+0 through <code>len(s)-1</code>.\n It is illegal to take the address of such an element; if
<code>s[i]</code> is the <code>i</code>\'th byte of a
string, <code>&s[i]</code> is invalid.\n@@ -819,8 +819,8 @@ The length is part of the array\'s type and must be a
<a href="#Constant_expressions">constant expression</a> that evaluates to a non-negative
integer value. The length of array <code>a</code> can be discovered
using the built-in function <a href="#Length_and_capacity"><code>len</code></a>.\n-The elements can be indexed by integer
-indices 0 through <code>len(a)-1</code> (§<a href="#Indexes">Indexes</a>).\n+The elements can be addressed by integer <a href="#Index_expressions">indices</a>\n+indices 0 through <code>len(a)-1</code>.\n Array types are always one-dimensional but may be composed to form
multi-dimensional types.\n </p>\n@@ -850,8 +850,8 @@ SliceType = "[" "]" ElementType .\n Like arrays, slices are indexable and have a length. The length of a\n slice <code>s</code> can be discovered by the built-in function\n <a href="#Length_and_capacity"><code>len</code></a>; unlike with arrays it may change during\n-execution. The elements can be addressed by integer indices 0\n-through <code>len(s)-1</code> (§<a href="#Indexes">Indexes</a>). The slice index of a\n+execution. The elements can be addressed by integer <a href="#Index_expressions">indices</a>\n+0 through <code>len(s)-1</code>. The slice index of a\n given element may be less than the index of the same element in the\n underlying array.\n </p>\n@@ -1257,7 +1257,7 @@ For a map <code>m</code>, it can be discovered using the\n built-in function <a href="#Length_and_capacity"><code>len</code></a>\n and may change during execution. Elements may be added during execution\n using <a href="#Assignments">assignments</a> and retrieved with\n-<a href="#Indexes">index</a> expressions; they may be removed with the\n+<a href="#Index_expressions">index expressions</a>; they may be removed with the\n <a href="#Deletion_of_map_elements"><code>delete</code></a> built-in function.\n </p>\n <p>\n@@ -2120,7 +2120,7 @@ The types of the expressions must be <a href="#Assignability">assignable</a>\n to the respective field, element, and key types of the LiteralType;\n there is no additional conversion.\n The key is interpreted as a field name for struct literals,\n-an index expression for array and slice literals, and a key for map literals.\n+an index for array and slice literals, and a key for map literals.\n For map literals, all elements must have a key. It is an error\n to specify multiple elements with the same field name or\n constant key value.\n@@ -2480,7 +2480,7 @@ TODO: Specify what happens to receivers.\n -->\n \n \n-<h3 id=\"Indexes\">Indexes</h3>\n+<h3 id=\"Index_expressions\">Index expressions</h3>\n \n <p>\n A primary expression of the form\n@@ -2596,7 +2596,7 @@ a[low : high]\n </pre>\n \n <p>\n-constructs a substring or slice. The index expressions <code>low</code> and\n+constructs a substring or slice. The indices <code>low</code> and\n <code>high</code> select which elements appear in the result. The result has\n indices starting at 0 and length equal to\n <code>high</code> - <code>low</code>.\n@@ -2619,7 +2619,7 @@ s[2] == 4\n </pre>\n \n <p>\n-For convenience, any of the index expressions may be omitted. A missing <code>low</code>\n+For convenience, any of the indices may be omitted. A missing <code>low</code>\n index defaults to zero; a missing <code>high</code> index defaults to the length of the\n sliced operand:\n </p>\n@@ -4010,7 +4010,7 @@ operand on the left.\n \n <p>\n The assignment proceeds in two phases.\n-First, the operands of <a href=\"#Indexes\">index expressions</a>\n+First, the operands of <a href=\"#Index_expressions\">index expressions</a>\n and <a href=\"#Address_operators\">pointer indirections</a>\n (including implicit pointer indirections in <a href=\"#Selectors\">selectors</a>)\n on the left and the expressions on the right are all\n```
## コアとなるコードの解説
このコミットは、Go言語の仕様書である`doc/go_spec.html`ファイル内の特定のHTML要素とテキストを修正することで、用語の統一を図っています。
1. **仕様書バージョンの更新**:
* `Subtitle`メタデータが`Version of December 6, 2012`から`Version of December 10, 2012`に更新されています。これは、このコミットが2012年12月10日に行われたことを反映しており、仕様書の内容がこの日付で更新されたことを示します。
2. **見出しの変更**:
* `id="Indexes"`を持つ`<h3>`タグが、`id="Index_expressions"`に変更されました。これは、インデックスに関するセクションの主題が、単なる「インデックス」ではなく、「インデックス式」というより広範な概念であることを明確にするための変更です。これにより、セクションの内容と見出しがより正確に一致するようになります。
3. **用語の置換とリンクの更新**:
* 文字列、配列、スライスに関する記述において、要素へのアクセス方法を説明する際に使用されていた「integer indices」という表現が、一貫して「integer <a href="#Index_expressions">indices</a>」という形式に変更されました。これにより、インデックス値が「インデックス式」のセクションで定義されている概念であることを明示し、読者が関連情報を参照しやすくなっています。
* 特に、以前は`§<a href="#Indexes">Indexes</a>`のように、古い見出しへのリンクが含まれていましたが、これが新しい見出し`#Index_expressions`へのリンクに更新され、かつリンクテキストも文脈に応じて「indices」または「index expressions」に修正されています。
* マップの要素追加に関する記述では、`retrieved with <a href="#Indexes">index</a> expressions`が`retrieved with <a href="#Index_expressions">index expressions</a>`に変更されました。ここでも、リンク先の見出しと用語が更新されています。
* リテラルに関する記述では、配列とスライスのリテラルにおけるキーが「an index expression」から「an index」に変更されました。これは、リテラル内で指定されるのが式全体ではなく、単一のインデックス値であることを明確にするためです。
* スライス操作(`a[low : high]`)に関する記述では、「The index expressions `low` and `high`」が「The indices `low` and `high`」に変更されました。これは、`low`と`high`がインデックス値そのものを指すため、より正確な表現に修正されたものです。同様に、「A missing `low` index」も「A missing `low` indices」に修正されています。
* 代入文の動作に関する記述でも、`operands of <a href="#Indexes">index expressions</a>`が`operands of <a href="#Index_expressions">index expressions</a>`に更新され、リンクの一貫性が保たれています。
これらの変更は、Go言語の仕様書における用語の厳密性と一貫性を高めるためのものであり、言語の正確な理解を促進することを目的としています。
## 関連リンク
* Go CL 6912056: [https://golang.org/cl/6912056](https://golang.org/cl/6912056)
## 参考にした情報源リンク
* 特になし(コミット情報とGo言語の一般的な知識に基づいています)