From 4b925e5add92bbf0c11ac06721f6e752878cc712 Mon Sep 17 00:00:00 2001 From: h-east Date: Mon, 31 Mar 2025 23:03:28 +0900 Subject: [PATCH 1/4] Translate before *tuple* --- doc/eval.jax | 76 +++++++++++++++++++++++++++++----------------------- en/eval.txt | 42 +++++++++++++++++------------ 2 files changed, 68 insertions(+), 50 deletions(-) diff --git a/doc/eval.jax b/doc/eval.jax index bcf30a62b..d3bd74e18 100644 --- a/doc/eval.jax +++ b/doc/eval.jax @@ -1,4 +1,4 @@ -*eval.txt* For Vim バージョン 9.1. Last change: 2025 Feb 23 +*eval.txt* For Vim バージョン 9.1. Last change: 2025 Mar 30 VIMリファレンスマニュアル by Bram Moolenaar @@ -19,9 +19,10 @@ Note: 式の評価はコンパイル時に無効化できる。無効化され 1.1 変数の型 1.2 関数への参照 |Funcref| 1.3 リスト |Lists| - 1.4 辞書 |Dictionaries| - 1.5 Blobs |Blobs| - 1.6 変数について補足 |more-variables| + 1.4 Tuple |Tuples| + 1.5 辞書 |Dictionaries| + 1.6 Blob |Blobs| + 1.7 変数について補足 |more-variables| 2. 式の文法 |expression-syntax| 3. 内部変数 |internal-variables| 4. 組み込み関数 |functions| @@ -44,8 +45,8 @@ Note: 式の評価はコンパイル時に無効化できる。無効化され 1.1 変数の型 ~ *E712* *E896* *E897* *E899* *E1098* - *E1107* *E1135* *E1138* -変数には10種類の型がある: + *E1107* *E1135* *E1138* *E1523* +変数には11種類の型がある: *Number* *Integer* 数値 32ビットまたは64ビットの符号有整数。|expr-number| @@ -61,6 +62,10 @@ Note: 式の評価はコンパイル時に無効化できる。無効化され リスト 要素の順序つきの列。詳細は |List| を参照。 例: [1, 2, ['a', 'b']] +Tuple 順序付けられた不変の項目のシーケンス。詳細については |Tuple| + を参照。 + 例: (1, 2, ('a', 'b')) + 辞書 順序を持たない連想配列: 各要素はキーと値を持つ。|Dictionary| 例: {'blue': "#0000ff", 'red': "#ff0000"} @@ -159,16 +164,17 @@ Note: " " と "0" も空文字列ではないので、TRUE と見なされる。 *E611* *E745* *E728* *E703* *E729* *E730* *E731* *E908* *E910* *E913* *E974* *E975* *E976* *E1319* *E1320* *E1321* *E1322* - *E1323* *E1324* -リスト |List|, 辞書 |Dictionary|, |Funcref|, ジョブ |Job|, チャネル |Channel|, -|Blob|, クラス |Class| および |object| は自動的に変換されない。 + *E1323* *E1324* *E1520* *E1522* +|List|、|Tuple|、|Dictionary|、|Funcref|、|Job|、|Channel|、|Blob|、|Class| +および |object| 型は自動的に変換されない。 *E805* *E806* *E808* 数値と浮動小数点数をまぜると浮動小数点数になる。それ以外には浮動小数点数への自 動的な変換は存在しない。文字列から浮動小数点数へは str2float() を使い、浮動小 数点数から文字列へは printf() を、浮動小数点数から数値へは float2nr() を使う。 - *E362* *E891* *E892* *E893* *E894* *E907* *E911* *E914* + *E362* *E891* *E892* *E893* *E894* + *E907* *E911* *E914* *E1521* 浮動小数点数が予期されているところでは数値も使用可能だが、それ以外は使用できな い。 @@ -260,9 +266,9 @@ Note 関数の辞書へのバインドは、その関数が辞書のメンバー リストの作成 ~ *E696* *E697* -リストを作るには、[]の中にコンマで区切って要素を書く。 +リストは、角括弧で囲まれたコンマで区切られた一連の項目で作成される。 例: > - :let mylist = [1, two, 3, "four"] + :let mylist = [1, "two", 3, "four"] :let emptylist = [] 要素はどんな式でもよい。要素としてリストを指定すると、リストのリストができる: @@ -309,29 +315,31 @@ Note 関数の辞書へのバインドは、その関数が辞書のメンバー 部分リスト ~ *sublist* -リストの一部分を取り出すには、[]の中に始点と終点のインデックスを書き、コロンで -区切る: > - :let shortlist = mylist[2:-1] " リスト[3, "four"]を得る - -始点のインデックスを省略すると0となる。終点のインデックスを省略すると-1となる > - :let endlist = mylist[2:] " 2番目から最後まで: [3, "four"] - :let shortlist = mylist[2:2] " 1個の要素からなるリスト: [3] +リストの一部を取得するには、角括弧でコロンで区切られた開始のインデックスと終了 +のインデックスを指定する: > + :let shortlist = mylist[2:-1] " リスト [3, "four"] を得る + +開始のインデックスを省略すると、0 と同じになる。終了のインデックスを省略する +と、-1 と同じになる。 > + :let endlist = mylist[2:] " 項目 2 から最後まで: [3, "four"] + :let shortlist = mylist[2:2] " 1 項目のリスト: [3] :let otherlist = mylist[:] " リストのコピーを作る -最後のインデックスが含まれることに注意。排他的なインデックスを利用するなら -|slice()| メソッドを利用する。 +終了のインデックスは包括的であることに注意。排他的インデックスを使用する場合 +は、|slice()| 関数を使用する。 -終点のインデックスが始点のインデックスよりも前になってしまった場合は空リストと -なる。エラーメッセージは表示されない。 +開始のインデックスがリストの終了の項目を超えている場合、または終了のインデック +スが開始の項目より前である場合、結果は空のリストになる。エラーメッセージは表示 +されない。 -終点のインデックスがリストの長さより大きい場合は、長さ-1を指定したときと同じに -なる: > +最後のインデックスがリストの長さ以上である場合は、長さから 1 を引いた値が使用 +される: > :let mylist = [0, 1, 2, 3] :echo mylist[2:8] " 結果: [2, 3] -NOTE: mylist[s:e]と書くと変数 "s:e" をインデックスとして使ったと解釈される。 -":" の前に1文字の変数を使うときは十分注意すること。必要ならこのようにスペース -を入れるとよい: mylist[s : e]. +NOTE: mylist[s:e] と書くと変数 "s:e" をインデックスとして使ったと解釈される。 +":" の前に1文字の変数を使うときは十分注意すること。必要であればこのようにスペー +スを入れるとよい: mylist[s : e]. リストの同一性 ~ @@ -344,9 +352,9 @@ NOTE: mylist[s:e]と書くと変数 "s:e" をインデックスとして使っ :echo bb < [1, 2, 3, 4] -リストのコピーを作るには関数|copy()|を使う。前述の通り[:]を使ってもできる。こ -れは浅いコピーである。つまりリストの要素であるリストに変更を加えると、コピーさ -れたリスト内の同じ要素も変更される: > +リストのコピーを作るには関数 |copy()| を使う。前述の通り [:] を使ってもできる。 +これは浅いコピーである。つまりリストの要素であるリストに変更を加えると、コピー +されたリスト内の同じ要素も変更される: > :let aa = [[1, 'a'], 2, 3] :let bb = copy(aa) :call add(aa, 4) @@ -448,8 +456,8 @@ Note リストの比較について注意: 2つのリストは、同じ長さを for ループ ~ -|:for| ループは、リスト、文字列または Blob の各要素に対してコマンドを実行する。 -変数に各要素が順番に代入される。リストを使った例: > +|:for| ループは、リスト、Tuple、文字列または Blob の各要素に対してコマンドを実 +行する。変数に各要素が順番に代入される。リストを使った例: > :for item in mylist : call Doit(item) :endfor @@ -482,6 +490,8 @@ for ループ ~ : endif :endfor +Tuple の場合、一度に 1 つのタプル項目が使用される。 + Blob の場合、一度に 1 バイトが使われる。 文字列の場合、任意の合成文字を含む 1 文字が文字列として使われる。例: > diff --git a/en/eval.txt b/en/eval.txt index 0ada1b215..4e919ae65 100644 --- a/en/eval.txt +++ b/en/eval.txt @@ -1,4 +1,4 @@ -*eval.txt* For Vim version 9.1. Last change: 2025 Feb 23 +*eval.txt* For Vim version 9.1. Last change: 2025 Mar 30 VIM REFERENCE MANUAL by Bram Moolenaar @@ -21,9 +21,10 @@ a remark is given. 1.1 Variable types 1.2 Function references |Funcref| 1.3 Lists |Lists| - 1.4 Dictionaries |Dictionaries| - 1.5 Blobs |Blobs| - 1.6 More about variables |more-variables| + 1.4 Tuples |Tuples| + 1.5 Dictionaries |Dictionaries| + 1.6 Blobs |Blobs| + 1.7 More about variables |more-variables| 2. Expression syntax |expression-syntax| 3. Internal variable |internal-variables| 4. Builtin Functions |functions| @@ -46,8 +47,8 @@ Profiling is documented at |profiling|. 1.1 Variable types ~ *E712* *E896* *E897* *E899* *E1098* - *E1107* *E1135* *E1138* -There are ten types of variables: + *E1107* *E1135* *E1138* *E1523* +There are eleven types of variables: *Number* *Integer* Number A 32 or 64 bit signed number. |expr-number| @@ -63,6 +64,10 @@ String A NUL terminated string of 8-bit unsigned characters (bytes). List An ordered sequence of items, see |List| for details. Example: [1, 2, ['a', 'b']] +Tuple An ordered immutable sequence of items, see |Tuple| for + details. + Example: (1, 2, ('a', 'b')) + Dictionary An associative, unordered array: Each entry has a key and a value. |Dictionary| Examples: @@ -165,16 +170,17 @@ A List, Dictionary or Float is not a Number or String, thus evaluate to FALSE. *E611* *E745* *E728* *E703* *E729* *E730* *E731* *E908* *E910* *E913* *E974* *E975* *E976* *E1319* *E1320* *E1321* *E1322* - *E1323* *E1324* -|List|, |Dictionary|, |Funcref|, |Job|, |Channel|, |Blob|, |Class| and -|object| types are not automatically converted. + *E1323* *E1324* *E1520* *E1522* +|List|, |Tuple|, |Dictionary|, |Funcref|, |Job|, |Channel|, |Blob|, |Class| +and |object| types are not automatically converted. *E805* *E806* *E808* When mixing Number and Float the Number is converted to Float. Otherwise there is no automatic conversion of Float. You can use str2float() for String to Float, printf() for Float to String and float2nr() for Float to Number. - *E362* *E891* *E892* *E893* *E894* *E907* *E911* *E914* + *E362* *E891* *E892* *E893* *E894* + *E907* *E911* *E914* *E1521* When expecting a Float a Number can also be used, but nothing else. *no-type-checking* @@ -267,9 +273,9 @@ position in the sequence. List creation ~ *E696* *E697* -A List is created with a comma-separated list of items in square brackets. +A List is created with a comma-separated sequence of items in square brackets. Examples: > - :let mylist = [1, two, 3, "four"] + :let mylist = [1, "two", 3, "four"] :let emptylist = [] An item can be any expression. Using a List for an item creates a @@ -327,13 +333,13 @@ similar to -1. > :let otherlist = mylist[:] " make a copy of the List Notice that the last index is inclusive. If you prefer using an exclusive -index use the |slice()| method. +index use the |slice()| function. -If the first index is beyond the last item of the List or the second item is +If the first index is beyond the last item of the List or the last index is before the first item, the result is an empty list. There is no error message. -If the second index is equal to or greater than the length of the list the +If the last index is equal to or greater than the length of the list the length minus one is used: > :let mylist = [0, 1, 2, 3] :echo mylist[2:8] " result: [2, 3] @@ -463,8 +469,8 @@ Changing the order of items in a list: > For loop ~ -The |:for| loop executes commands for each item in a List, String or Blob. -A variable is set to each item in sequence. Example with a List: > +The |:for| loop executes commands for each item in a List, Tuple, String or +Blob. A variable is set to each item in sequence. Example with a List: > :for item in mylist : call Doit(item) :endfor @@ -497,6 +503,8 @@ It is also possible to put remaining items in a List variable: > : endif :endfor +For a Tuple one tuple item at a time is used. + For a Blob one byte at a time is used. For a String one character, including any composing characters, is used as a From d5ccdfbef7bda90b956db091dd9ea1212610fe30 Mon Sep 17 00:00:00 2001 From: h-east Date: Sun, 13 Apr 2025 01:00:02 +0900 Subject: [PATCH 2/4] Translation done. --- doc/eval.jax | 546 ++++++++++++++++++++++++++++++++++++--------------- en/eval.txt | 333 ++++++++++++++++++++++++++----- 2 files changed, 676 insertions(+), 203 deletions(-) diff --git a/doc/eval.jax b/doc/eval.jax index d3bd74e18..4d8132e2f 100644 --- a/doc/eval.jax +++ b/doc/eval.jax @@ -1,4 +1,4 @@ -*eval.txt* For Vim バージョン 9.1. Last change: 2025 Mar 30 +*eval.txt* For Vim バージョン 9.1. Last change: 2025 Apr 02 VIMリファレンスマニュアル by Bram Moolenaar @@ -59,14 +59,14 @@ Note: 式の評価はコンパイル時に無効化できる。無効化され 文字列 終端がNUL文字である8ビットの符号無し文字(バイト)。 |expr-string| 例: "ab\txx\"--" 'x-z''a,c' -リスト 要素の順序つきの列。詳細は |List| を参照。 +リスト 項目の順序つきの列。詳細は |List| を参照。 例: [1, 2, ['a', 'b']] Tuple 順序付けられた不変の項目のシーケンス。詳細については |Tuple| を参照。 例: (1, 2, ('a', 'b')) -辞書 順序を持たない連想配列: 各要素はキーと値を持つ。|Dictionary| +辞書 順序を持たない連想配列: 各項目はキーと値を持つ。|Dictionary| 例: {'blue': "#0000ff", 'red': "#ff0000"} #{blue: "0000ff", red: "ff0000"} @@ -259,8 +259,8 @@ Note 関数の辞書へのバインドは、その関数が辞書のメンバー 1.3 リスト ~ *list* *List* *Lists* *E686* -リストとは順序を保つ要素の列である。要素はどんな型でもよい。要素へはインデック -ス番号を使ってアクセスする。列の任意の位置に要素を追加したり削除することができ +リストとは順序を保つ項目の列である。項目はどんな型でもよい。項目へはインデック +ス番号を使ってアクセスする。列の任意の位置に項目を追加したり削除することができ る。 @@ -271,26 +271,26 @@ Note 関数の辞書へのバインドは、その関数が辞書のメンバー :let mylist = [1, "two", 3, "four"] :let emptylist = [] -要素はどんな式でもよい。要素としてリストを指定すると、リストのリストができる: +項目はどんな式でもよい。項目としてリストを指定すると、リストのリストができる: > :let nestlist = [[11, 12], [21, 22], [31, 32]] -最後の要素の後に余分なコンマがあると無視される。 +最後の項目の後に余分なコンマがあると無視される。 リストのインデックス ~ *list-index* *E684* -リストの要素にアクセスするには、リスト名の後に[]を書き、その中にインデックスを -書く。インデックスは0基点(つまり最初の要素のインデックスは0)である。 > - :let item = mylist[0] " 最初の要素(1)を取得 - :let item = mylist[2] " 3番目の要素(3)を取得 +リストの項目にアクセスするには、リスト名の後に[]を書き、その中にインデックスを +書く。インデックスは0基点(つまり最初の項目のインデックスは0)である。 > + :let item = mylist[0] " 最初の項目(1)を取得 + :let item = mylist[2] " 3番目の項目(3)を取得 -取得した要素がリストならば、さらに続けてインデックスを書くことができる: > - :let item = nestlist[0][1] " 最初のリストの2番目の要素(12)を取得 +取得した項目がリストならば、さらに続けてインデックスを書くことができる: > + :let item = nestlist[0][1] " 最初のリストの2番目の項目(12)を取得 < 負のインデックスを指定すると、リストの末尾から数えられる。インデックス-1は最後 -の要素を示し、-2は最後から2番目を指す > - :let last = mylist[-1] " 最後の要素("four")を取得 +の項目を示し、-2は最後から2番目を指す > + :let last = mylist[-1] " 最後の項目("four")を取得 無効なインデックスによるエラーを回避するには関数|get()|を使う。するとインデッ クスが無効な場合は、0かまたは自分で指定した既定値が返る: > @@ -303,7 +303,7 @@ Note 関数の辞書へのバインドは、その関数が辞書のメンバー 2つのリストを連結するには演算子 "+" を使う: > :let longlist = mylist + [5, 6] :let longlist = [5, 6] + mylist -1個の要素を先頭または末尾に付け加えるには、[]で囲んでリストにして連結する。 +1個の項目を先頭または末尾に付け加えるには、[]で囲んでリストにして連結する。 リストは |:let+=| もしくは |extend()| を使うことで、他のリストとその場で連結す ることができる: > @@ -353,8 +353,8 @@ NOTE: mylist[s:e] と書くと変数 "s:e" をインデックスとして使っ < [1, 2, 3, 4] リストのコピーを作るには関数 |copy()| を使う。前述の通り [:] を使ってもできる。 -これは浅いコピーである。つまりリストの要素であるリストに変更を加えると、コピー -されたリスト内の同じ要素も変更される: > +これは浅いコピーである。つまりリストの項目であるリストに変更を加えると、コピー +されたリスト内の同じ項目も変更される: > :let aa = [[1, 'a'], 2, 3] :let bb = copy(aa) :call add(aa, 4) @@ -364,7 +364,7 @@ NOTE: mylist[s:e] と書くと変数 "s:e" をインデックスとして使っ :echo bb < [[1, aaa], 2, 3] -完全に独立したコピーを作るには|deepcopy()|を使う。これは再帰的にリストの要素の +完全に独立したコピーを作るには|deepcopy()|を使う。これは再帰的にリストの項目の コピーを作る。ただし深さは100レベルまでである。 2つの変数が同じリストを指しているかは演算子 "is" で判定できる。"isnot" はその @@ -376,7 +376,7 @@ NOTE: mylist[s:e] と書くと変数 "s:e" をインデックスとして使っ :echo alist == blist < 1 -Note リストの比較について注意: 2つのリストは、同じ長さを持ち、全要素が "==" の +Note リストの比較について注意: 2つのリストは、同じ長さを持ち、全項目が "==" の 意味で等しいとき、等しいとみなされる。ただ、1つ例外がある: 数値と文字列を比較 するとそれらは異なるとみなされる。変数に対して "==" で比較したときに行われるよ うな自動的な型変換は行われない。例: > @@ -398,10 +398,10 @@ Note リストの比較について注意: 2つのリストは、同じ長さを リストのアンパック ~ -リストの要素を個々の変数としてアンパックするには、[]の中に変数を書く: > +リストの項目を個々の変数としてアンパックするには、[]の中に変数を書く: > :let [var1, var2] = mylist -変数の個数とリストの要素数が一致しないときはエラーになる。リストにある余分な要 +変数の個数とリストの項目数が一致しないときはエラーになる。リストにある余分な要 素をまとめて受け取るには、";" と受け取る変数名を書いておく: > :let [var1, var2; rest] = mylist @@ -410,20 +410,20 @@ Note リストの比較について注意: 2つのリストは、同じ長さを :let var2 = mylist[1] :let rest = mylist[2:] -要素が 2 つしかないときでもエラーにはならない。"rest" は空リストになる。 +項目が 2 つしかないときでもエラーにはならない。"rest" は空リストになる。 リストの変更 ~ *list-modification* -リストの中の特定の要素を変更するには次のように|:let|を使う: > +リストの中の特定の項目を変更するには次のように|:let|を使う: > :let list[4] = "four" :let listlist[0][3] = item 始点と終点を指定してリストの一部分を変更することができる。代入する値は、少なく -とも削除する範囲の要素数と同じ数だけ必要である: > +とも削除する範囲の項目数と同じ数だけ必要である: > :let list[3:5] = [3, 4, 5] -リストに要素をその場で追加するには、|:let+=| (|list-concatenation|) を使うこと +リストに項目をその場で追加するには、|:let+=| (|list-concatenation|) を使うこと ができる: > :let listA = [1, 2] :let listA += [3, 4] @@ -436,28 +436,28 @@ Note リストの比較について注意: 2つのリストは、同じ長さを :echo listA [1, 2, 3, 4] < -リストに要素を追加したり削除するには関数を使う。いくつか例を示す: > - :call insert(list, 'a') " 先頭に要素 'a' を挿入する - :call insert(list, 'a', 3) " 要素 'a' をlist[3]の前に挿入する - :call add(list, "new") " 文字列の要素を最後に追加する - :call add(list, [1, 2]) " 1個の要素としてリストを追加する - :call extend(list, [1, 2]) " 2個の要素からなるリストを連結する - :let i = remove(list, 3) " 要素3を削除する +リストに項目を追加したり削除するには関数を使う。いくつか例を示す: > + :call insert(list, 'a') " 先頭に項目 'a' を挿入する + :call insert(list, 'a', 3) " 項目 'a' をlist[3]の前に挿入する + :call add(list, "new") " 文字列の項目を最後に追加する + :call add(list, [1, 2]) " 1個の項目としてリストを追加する + :call extend(list, [1, 2]) " 2個の項目からなるリストを連結する + :let i = remove(list, 3) " 項目3を削除する :unlet list[3] " 同上 - :let l = remove(list, 3, -1) " 要素3から最後までを削除する + :let l = remove(list, 3, -1) " 項目3から最後までを削除する :unlet list[3 : ] " 同上 - :call filter(list, 'v:val !~ "x"') " 要素 'x' を削除 + :call filter(list, 'v:val !~ "x"') " 項目 'x' を削除 -要素の順番を変更する: > +項目の順番を変更する: > :call sort(list) " リストをアルファベット順にソート - :call reverse(list) " 要素の順序を反転させる + :call reverse(list) " 項目の順序を反転させる :call uniq(sort(list)) " ソートして重複を削除する for ループ ~ -|:for| ループは、リスト、Tuple、文字列または Blob の各要素に対してコマンドを実 -行する。変数に各要素が順番に代入される。リストを使った例: > +|:for| ループは、リスト、Tuple、文字列または Blob の各項目に対してコマンドを実 +行する。変数に各項目が順番に代入される。リストを使った例: > :for item in mylist : call Doit(item) :endfor @@ -470,7 +470,7 @@ for ループ ~ : let index = index + 1 :endwhile -やりたいことがリストの各要素を変更するだけなら、forループを使うより関数|map()| +やりたいことがリストの各項目を変更するだけなら、forループを使うより関数|map()| を使った方がよりシンプルになる。 |:let|コマンドと同じように、|:for|は変数のリストをループ変数にすることができる。 @@ -479,7 +479,7 @@ for ループ ~ : call Doit(lnum, col) :endfor -これはリストの各要素に対して|:let|コマンドを実行するかのように実行される。また +これはリストの各項目に対して|:let|コマンドを実行するかのように実行される。また この場合も引数の型は全て同じでないとエラーになる。 引数の残りを1個のリスト変数に代入することもできる: > @@ -490,7 +490,7 @@ for ループ ~ : endif :endfor -Tuple の場合、一度に 1 つのタプル項目が使用される。 +Tuple の場合、一度に 1 つの tuple 項目が使用される。 Blob の場合、一度に 1 バイトが使われる。 @@ -505,7 +505,7 @@ Blob の場合、一度に 1 バイトが使われる。 以下はリスト操作に使える関数である: > :let r = call(funcname, list) " 引数リストをつけて関数を呼び出す :if empty(list) " リストが空かどうか判定する - :let l = len(list) " リストの要素数 + :let l = len(list) " リストの項目数 :let big = max(list) " リスト中の最大値 :let small = min(list) " リスト中の最小値 :let xs = count(list, 'x') " 'x' の出現回数を数える @@ -513,30 +513,232 @@ Blob の場合、一度に 1 バイトが使われる。 :let lines = getline(1, 10) " バッファから10行を取得 :call append('$', lines) " バッファに行を追加する :let list = split("a b c") " 文字列を分割してリストにする - :let string = join(list, ', ') " リストの要素を連結して文字列にする + :let string = join(list, ', ') " リストの項目を連結して文字列にする :let s = string(list) " リストの文字列表現 - :call map(list, '">> " .. v:val') " 各要素の前に ">> " をつける + :call map(list, '">> " .. v:val') " 各項目の前に ">> " をつける 機能を組み合わせると、処理を単純に記述できることを覚えておくとよい。例えば、リ スト中の全ての数値の和を求める例: > :exe 'let sum = ' .. join(nrlist, '+') +1.4 Tuples ~ + *tuple* *Tuple* *Tuples* + *E1532* *E1533* +Tuple は、順序付けられた項目のシーケンスである。項目は任意の型にすることができ +る。項目にはインデックス番号でアクセスできる。Tuple は不変である。 -1.4 辞書 ~ +Tuple はリストに似ているが、メモリ使用量が少なく項目の検索時間は O(1) である。 + +Tuple の作成 ~ + *E1526* *E1527* +Tuple は、括弧で囲まれた項目のコンマ区切りのシーケンスで作成される。例: > + :let mytuple = (1, "two", 3, "four") + :let tuple = (5,) + :let emptytuple = () + +項目には任意の式を指定できる。tuple に項目が 1 つしかない場合は、その項目の後 +にカンマを付ける必要がある。 + +項目に Tuple を使用すると、Tuple の Tuple が作成される: > + :let nesttuple = ((11, 12), (21, 22), (31, 32)) + + +Tuple のインデックス ~ + *tuple-index* *E1519* +Tuple 内の項目にアクセスするには、Tuple の後に角括弧で囲んだインデックスを指定 +する。インデックスは 0 から始まるため、最初の項目のインデックスは 0 になる。 > + :let item = mytuple[0] " 最初の項目を取得: 1 + :let item = mytuple[2] " 最初の項目を取得: 3 + +結果の項目が tuple の場合、これを繰り返すことができる: > + :let item = nesttuple[0][1] " 最初の Tuple の 2 番目の項目: 12 +< +負のインデックスは末尾からカウントされる。インデックス -1 は Tuple の最後の項 +目、-2 は最後から 1 つ前の項目、というようにカウントされる。 > + :let last = mytuple[-1] " 最後の項目を取得: "four" + +無効なインデックスによるエラーを回避するには、|get()| 関数を使用する。項目が使 +用できない場合は、ゼロまたは指定したデフォルト値を返す: > + :echo get(mytuple, idx) + :echo get(mytuple, idx, "NONE") + + +Tuple の変更 + *tuple-modification* +tuple は不変であり、tuple に項目を追加したり削除したりすることはできない。ただ +し、tuple 内のリストと辞書の項目は変更できる: > + :let tuple = (1, [2, 3], {'a': 4}) + :let tuple[1][0] = 10 + :let tuple[2]['a'] = 20 + + +Tuple の連結 ~ + *tuple-concatenation* +2 つの tuple は "+" 演算子で連結できる: > + :let longtuple = mytuple + (5, 6) + :let longtuple = (5, 6) + mytuple +項目を先頭または末尾に追加するには、項目を () で囲んで tuple に変換する。項目 +の後にカンマを付ける必要がある。 + + *E1540* +同じ項目の型を持つ 2 つの可変長 tuple は連結できるが、異なる項目の型を持つ +tuple は連結できない。例: > + var a: tuple<...list> = (1, 2) + var b: tuple<...list> = ('a', 'b') + echo a + b # 許可されていない + + var a: tuple = (1, 2) + var b: tuple<...list> = ('a', 'b') + echo a + b # 許可されている + + var a: tuple<...list> = (1, 2) + var b: tuple = (3, 4) + echo a + b # 許可されていない + + var a: tuple<...list> = (1, 2) + var b: tuple> = (3, 4) + echo a + b # 許可されていない +< +Note Tuple は不変であり、tuple に項目を追加したり、tuple から項目を削除したり +できないことに注意。 + + +部分 tuple ~ + *subtuple* +Tuple の一部を取得するには、角括弧でコロンで区切られた最初のインデックスと最後 +のインデックスを指定する: > + :let shorttuple = mytuple[2:-1] " Tuple (3, "four") を取得 + +最初のインデックスを省略すると 0 と同じになる。最後のインデックスを省略すると +-1 と同じになる。 > + :let endtuple = mytuple[2:] " 項目 2 から最後まで: (3, "four") + :let shorttuple = mytuple[2:2] " 1 つの項目の Tuple: (3,) + :let othertuple = mytuple[:] " Tuple のコピーを作成 + +最後のインデックスは包含的であることに注意。排他的インデックスを使用する場合 +は、|slice()| 関数を使用する。 + +最初のインデックスが Tuple の最後の項目を超えている場合、または最後のインデッ +クスが最初の項目より前にある場合、結果は空の tuple になる。エラーメッセージは +表示されない。 + +最後のインデックスが tuple の長さ以上である場合は、長さから 1 を引いた値が使用 +される: > + :let mytuple = (0, 1, 2, 3) + :echo mytuple[2:8] " 結果 (2, 3) + +NOTE: mytuple[s:e] は、変数 "s:e" をインデックスとして使用することを意味する。 +":" の前に 1 文字の変数を使用することに注意。必要に応じてスペースを挿入する: +mytuple[s : e]。 + + +Tuple の同一性 ~ + *tuple-identity* +変数 "aa" が tuple で、それを別の変数 "bb" に割り当てると、両方の変数は同じ +tuple を参照する: > + :let aa = (1, 2, 3) + :let bb = aa +< + +tuple のコピーは |copy()| 関数で行う。[:] も上記で説明したように使用できる。こ +れは tuple の浅いコピーを作成する。例えば、tuple 内のリスト項目を変更すると、 +コピー元の tuple 内の項目も変更される: > + :let aa = ([1, 'a'], 2, 3) + :let bb = copy(aa) + :let aa[0][1] = 'aaa' + :echo aa +< ([1, aaa], 2, 3) > + :echo bb +< ([1, aaa], 2, 3) + +完全に独立した tuple を作成するには、|deepcopy()| を使用する。これも tuple 内 +の値を再帰的にコピーする。最大 100 階層までコピー可能である。 + +演算子 "is" は、2 つの変数が同じ Tuple を参照しているかどうかを確認するために +使用できる。"isnot" はその逆を行う。一方、"==" は 2 つの tuple が同じ値を持つ +かどうかを比較する。 > + :let atuple = (1, 2, 3) + :let btuple = (1, 2, 3) + :echo atuple is btuple +< 0 > + :echo atuple == btuple +< 1 + +Note tuple の比較に関する注意: 2 つの tuple の長さが同じで、すべての項目が +"==" を使用した場合と同様に等しい場合、それらは等しいとみなされる。ただし、例 +外が 1 つある。数値と文字列を比較する場合はそれらは異なるとみなされる。変数に +"==" を使用した場合と同様に自動的な型変換は行われない。例: > + echo 4 == "4" +< 1 > + echo (4,) == ("4",) +< 0 + +したがって、Tuple の比較は数値や文字列の比較よりも厳密である。単純な値も、 +tuple に格納することで同じように比較できる: > + + :let a = 5 + :let b = "5" + :echo a == b +< 1 > + :echo (a,) == (b,) +< 0 + + +Tuple アンパック ~ + +tuple 内の項目を個々の変数に展開するには、リスト項目のように変数を角括弧で囲む: +> + :let [var1, var2] = mytuple + +変数の数が tuple 内の項目数と一致しない場合、エラーが発生する。tuple の余分な +項目を処理するには、";" と変数名 (tuple 型になる)を追加する: > + :let [var1, var2; rest] = mytuple + +これは以下のように動作する: > + :let var1 = mytuple[0] + :let var2 = mytuple[1] + :let rest = mytuple[2:] + +ただし、項目が 2 つしかない場合はエラーは発生しない。その場合、"rest" は空の +tuple になる。 + + +Tuple 操作関数 ~ + *E1536* +Tuple で役立つ関数: > + :let xs = count(tuple, 'x') " Tuple 内の 'x' の数を数える + :if empty(tuple) " tuple が空かどうかを確認する + :let i = index(tuple, 'x') " tuple の最初の 'x' のインデックス + :let l = items(tuple) " tuple 内の項目の一覧 + :let string = join(tuple, ', ') " tuple 項目群から文字列を作成する + :let l = len(tuple) " tuple の項目数 + :let big = max(tuple) " tuple 中の最大値 + :let small = min(tuple) " tuple 中の最小値 + :let r = repeat(tuple, n) " tuple を n 回繰り返す + :let r = reverse(tuple) " tuple を反転する + :let s = slice(tuple, n1, n2) " tuple のスライス + :let s = string(tuple) " tuple の文字列表現 + :let l = tuple2list(tuple) " tuple をリストに変換する + :let t = list2tuple(list) " リストを tuple に変換する +< + *E1524* +tuple は |map()|、|mapnew()| および |filter()| 関数では使用できない。 + +1.5 辞書 ~ *dict* *Dict* *Dictionaries* *Dictionary* -辞書とは連想配列である。各要素はキーと値を持つ。要素はキーによって特定できる。 -要素は特に順序を持たずに保持される。 +辞書とは連想配列である。各項目はキーと値を持つ。項目はキーによって特定できる。 +項目は特に順序を持たずに保持される。 辞書の作成 ~ *E720* *E721* *E722* *E723* -辞書を作るには、{}の中にコンマで区切って要素を書く。各要素のキーと値はコロンで -区切る。それぞれのキーは1度しか現れてはならない。例: > - :let mydict = {1: 'one', 2: 'two', 3: 'three'} +辞書は、中括弧で囲まれた項目をコンマで区切って並べることで作成される。各項目は +キーと値を持ち、コロンで区切られる。各キーは一度だけ出現する。例: > + :let mydict = {'one': 1, 'two': 2, 'three': 3} :let emptydict = {} < *E713* *E716* *E717* キーは必ず文字列である。数値を使うこともできるが、自動的に文字列に変換される。 -よって文字列 '4' のキーと数値4のキーは同一の要素を参照する。 +よって文字列 '4' のキーと数値4のキーは同一の項目を参照する。 Note 文字列 '04' と数値04は異なることに注意。先頭の0が削除されてから数値が文字 列 '4' に変換されるためである。空文字列もまたキーとして使用できる。 @@ -556,30 +758,33 @@ Note ここでは 333 は 文字列 "333" であることに注意。空のキ 値はどんな式でもよい。辞書を値にすると、ネストした辞書ができる: > :let nestdict = {1: {11: 'a', 12: 'b'}, 2: {21: 'c'}} -最後の要素の後に余分なコンマがあると無視される。 +最後の項目の後に余分なコンマがあると無視される。 -要素にアクセスする ~ +項目にアクセスする ~ -通常、要素にアクセスするには[]の中にキーを書く: > +通常、項目にアクセスするには[]の中にキーを書く: > + :let mydict = {'one': 1, 'two': 2, 'three': 3} :let val = mydict["one"] :let mydict["four"] = 4 + :let val = mydict.one + :let mydict.four = 4 -また、この書き方で既存の辞書に要素を追加できる。この点はリストと異なる。 +また、この書き方で既存の辞書に項目を追加できる。この点はリストと異なる。 キー名がアルファベット、数字、アンダースコアだけからなる場合は、以下の形式が使 える|expr-entry|: > :let val = mydict.one :let mydict.four = 4 -要素はリストや辞書を含むどんな型でもよいため、インデックス参照とキー参照を続け +項目はリストや辞書を含むどんな型でもよいため、インデックス参照とキー参照を続け て書くことができる: > :echo dict.key[idx].key 辞書からリストへの変換 ~ -辞書の全要素に対してループを行いたい場合がある。そのためには辞書をリストに変換 +辞書の全項目に対してループを行いたい場合がある。そのためには辞書をリストに変換 し、そのリストに対して|:for|ループを行う。 多くの場合はキーに対してループを行う。これには関数|keys()|を使う: > @@ -595,7 +800,7 @@ Note ここでは 333 は 文字列 "333" であることに注意。空のキ : echo "value: " .. v :endfor -キーと値両方を得るには関数|items()|を使う。この関数は、キーと値の2個の要素から +キーと値両方を得るには関数|items()|を使う。この関数は、キーと値の2個の項目から なるリストのリストを返す: > :for [key, value] in items(mydict) : echo key .. ': ' .. value @@ -618,11 +823,11 @@ Note ここでは 333 は 文字列 "333" であることに注意。空のキ 辞書の変更 ~ *dict-modification* -辞書の要素を変更したり、新しい要素を追加するには|:let|を使う: > +辞書の項目を変更したり、新しい項目を追加するには|:let|を使う: > :let dict[4] = "four" :let dict['one'] = item -辞書から要素を取り除くには|remove()|か|:unlet|を使う。以下のように辞書からキー +辞書から項目を取り除くには|remove()|か|:unlet|を使う。以下のように辞書からキー "aaa" を取り除くには3つの方法がある: > :let i = remove(dict, 'aaa') :unlet dict.aaa @@ -630,15 +835,15 @@ Note ここでは 333 は 文字列 "333" であることに注意。空のキ 2つの辞書を併合させるには|extend()|を使う: > :call extend(adict, bdict) -上のコマンドはbdictの全ての要素をadictに追加する。キーが重複した要素はbdictの -要素により上書きされる。この動作は3番目の引数により変更できる。 -Note 辞書の要素間に順序は定まっていない。そのため ":echo adict" としたとき、も -ともとadictにあった要素が先に、bdictから追加された要素が後に表示されると考えて +上のコマンドはbdictの全ての項目をadictに追加する。キーが重複した項目はbdictの +項目により上書きされる。この動作は3番目の引数により変更できる。 +Note 辞書の項目間に順序は定まっていない。そのため ":echo adict" としたとき、も +ともとadictにあった項目が先に、bdictから追加された項目が後に表示されると考えて はならない。 -辞書から条件を指定して要素を取り除くには|filter()|が使える: > +辞書から条件を指定して項目を取り除くには|filter()|が使える: > :call filter(dict, 'v:val =~ "x"') -このコマンドは "dict" から 'x' にマッチしない要素を全て取り除く。 +このコマンドは "dict" から 'x' にマッチしない項目を全て取り除く。 このコマンドで全てのエントリを除去することもできる: > call filter(dict, 0) @@ -655,7 +860,7 @@ Note 辞書の要素間に順序は定まっていない。そのため ":echo a :let mydict = {'data': [0, 1, 2, 3], 'len': function("Mylen")} :echo mydict.len() -これはオブジェクト指向プログラミングのメソッドに似ている。この辞書の要素は +これはオブジェクト指向プログラミングのメソッドに似ている。この辞書の項目は |Funcref|である。暗黙に定義されるローカル変数 "self" は、この関数を呼び出した 辞書を参照している。|Vim9| script 使用時は、クラスとオブジェクトを使うことがで きる、`:class` を参照。 @@ -686,17 +891,17 @@ Note 辞書の要素間に順序は定まっていない。そのため ":echo a 辞書操作関数 ~ *E715* 以下は辞書操作に使える関数である: > - :if has_key(dict, 'foo') " 辞書がキー "foo" の要素を持つなら真 + :if has_key(dict, 'foo') " 辞書がキー "foo" の項目を持つなら真 :if empty(dict) " 辞書が空なら真 - :let l = len(dict) " 辞書の要素数 + :let l = len(dict) " 辞書の項目数 :let big = max(dict) " 辞書中の最大値 :let small = min(dict) " 辞書中の最小値 :let xs = count(dict, 'x') " 'x' の出現回数を数える :let s = string(dict) " 辞書の文字列表現 - :call map(dict, '">> " .. v:val') " 各要素の前に ">> " をつける + :call map(dict, '">> " .. v:val') " 各項目の前に ">> " をつける -1.5 Blobs ~ +1.6 Blobs ~ *blob* *Blob* *Blobs* *E978* Blobは、バイナリオブジェクトである。例えば、ファイルから画像を読んでチャネルを 通し送信することなどに使える。 @@ -800,7 +1005,7 @@ Blobの一部を変更するには、変更する最初と最後のバイトを イト数は同じでなければならない: > :let blob[3:5] = 0z334455 -Blob に要素をその場で追加するには、|:let+=| (|blob-concatenation|)を使うことが +Blob に項目をその場で追加するには、|:let+=| (|blob-concatenation|)を使うことが できる: > :let blobA = 0z1122 :let blobA += 0z3344 @@ -844,7 +1049,7 @@ Blobのコピーを作成するには、|copy()| 関数を使用する。[:] を たように動作する。 -1.6 変数について補足 ~ +1.7 変数について補足 ~ *more-variables* 変数や式の結果の型を知りたいのならば、関数|type()|を使う。 @@ -894,9 +1099,9 @@ MY_VAR_6 viminfoファイル etc. 上記の各式は大小文字の区別を、?を付加すると行 わず、#を付加すると行う - expr5 is expr5 同一のリスト |List|、辞書 |Dictionary| または + expr5 is expr5 同一の |List|、|Tuple|、|Dictionary| または |Blob| のインスタンス - expr5 isnot expr5 異なるリスト |List|、辞書 |Dictionary| または + expr5 isnot expr5 異なる |List|、|Tuple|、|Dictionary| または |Blob| のインスタンス |expr5| expr6 @@ -904,7 +1109,7 @@ MY_VAR_6 viminfoファイル expr6 >> expr6 ビット単位の右シフト |expr6| expr7 - expr7 + expr7 ... 足し算、リストまたはBlobの連結 + expr7 + expr7 ... 足し算、リスト、Tuple または Blob の連結 expr7 - expr7 ... 引き算 expr7 . expr7 ... 文字列の連結 expr7 .. expr7 ... 文字列の連結 @@ -923,9 +1128,11 @@ MY_VAR_6 viminfoファイル + expr9 単項のプラス |expr10| expr11 - expr10[expr1] 文字列のバイト、またはリストの要素 - expr10[expr1 : expr1] 文字列の部分文字列、またはリストの部分リスト - expr10.name 辞書 |Dictionary| の要素 + expr10[expr1] 文字列のバイト、または |List| または |Tuple| + の項目 + expr10[expr1 : expr1] 文字列の部分文字列、またはリストの部分リストま + たは |Tuple| のスライス + expr10.name |Dictionary| の項目 expr10(expr1, ...) |Funcref| 変数による関数呼び出し expr10->name(expr1, ...) |method| 呼び出し @@ -933,9 +1140,10 @@ MY_VAR_6 viminfoファイル |expr11| number 数定数 "string" 文字列定数。バックスラッシュは特別な意味を持つ 'string' リテラル文字列定数。'を含めるには2重にする - [expr1, ...] リスト |List| - {expr1: expr1, ...} 辞書 |Dictionary| - #{key: expr1, ...} 旧来の辞書 |Dictionary| + [expr1, ...] |List| + (expr1, ...) |Tuple| + {expr1: expr1, ...} |Dictionary| + #{key: expr1, ...} 旧来の |Dictionary| &option オプション変数 (expr1) 式の入れ子 variable 内部変数 @@ -1087,14 +1295,15 @@ script では結果を |true| または |false| で返す。 "abc" == "Abc" 'ignorecase' が設定されていれば1と、でなければ0と評価 NOTE: |Vim9| script では 'ignorecase' を使用しない。 - *E691* *E692* + *E691* *E692* *E1517* *E1518* リスト|List|はリストとだけ比較可能で、==系、!=系、is、isnotのみ利用できる。 -これらはそれぞれのリストの値を再帰的に比較する。大文字小文字無視にすると要素を +これらはそれぞれのリストの値を再帰的に比較する。大文字小文字無視にすると項目を 比較するときに大文字小文字を無視する。 +|Tuple| にも同じことが適用される。 *E735* *E736* 辞書|Dictionary|は辞書とだけ比較可能で、==系、!=系、is、isnotのみ利用できる。 -これらは辞書のキー/値を再帰的に比較する。大文字小文字無視にすると要素を +これらは辞書のキー/値を再帰的に比較する。大文字小文字無視にすると項目を 比較するときに大文字小文字を無視する。 *E694* @@ -1108,12 +1317,12 @@ NOTE: |Vim9| script では 'ignorecase' を使用しない。 if get(Part1, 'name') == get(Part2, 'name') " Part1 と Part2 は同じ関数を指している < *E1037* -リスト |List| 、辞書 |Dictionary| または |Blob| に対して "is" や "isnot" を使 -うと、それらの式が同じリスト、辞書 または |Blob| のインスタンスを参照している -か判定される。リストのコピーと元のリストは異なると判定される。リスト、辞書また -は |Blob| 以外に対して "is" は "equal" と同じで、"isnot" は "not equal" と同じ -である。ただし "is"、"isnot" は型が異なると値が等しくない点が "==" とは異なる: -> +|List|、|Tuple|、|Dictionary|、|Blob| で "is" または "isnot" を使用すると、式 +が同じ |List|、|Tuple|、|Dictionary|、|Blob| インスタンスを参照しているかどう +かがチェックされる。|List| または |Tuple| のコピーは、元の |List| または +|Tuple| とは異なる。|List|、|Tuple|、|Dictionary|、|Blob| 以外で "is" を使用し +た場合は "equal" を使用したのと同じになり、"isnot" を使用した場合は "not equal" +を使用したのと同じになる。ただし、型が異なる場合は値が異なる: > echo 4 == '4' 1 echo 4 is '4' @@ -1130,7 +1339,7 @@ NOTE: |Vim9| script では 'ignorecase' を使用しない。 なぜなら、'x' は数値のゼロに変換されるからである。しかし、 > echo [0] == ['x'] 0 -リストや辞書の中ではこの変換は行われない。 +リストや Tuple や辞書の中ではこの変換は行われない。 |Vim9| script では型が一致しなくてはならない。 @@ -1171,13 +1380,14 @@ expr6 >> expr6 ビット単位の右シフト *expr->>* expr6 and expr7 *expr6* *expr7* *E1036* *E1051* --------------- -expr7 + expr7 足し算、リスト |List| または |Blob| の連結 *expr-+* + *expr-+* +expr7 + expr7 足し算、|List| または |Tuple| または |Blob| の連結 expr7 - expr7 引き算 *expr--* expr7 . expr7 文字列の連結 *expr-.* expr7 .. expr7 文字列の連結 *expr-..* リストに対しては "+" のみ可能で、expr7 は両方ともリストでなければならない。結 -果は2つのリストを連結した新しいリスト。 +果は2つのリストを連結した新しいリスト。|Tuple| の場合も同様。 文字列の連結には ".." が推奨される。"." はあいまいで、|Dict| メンバーアクセス と浮動小数点数にも使用される。 @@ -1272,7 +1482,8 @@ expr10 *expr10* expr10->(expr1, ...)[expr1] 評価は常に左から右に行われる。 -expr10[expr1] 文字列またはリストの要素 *expr-[]* *E111* + *expr-[]* *E111* +expr10[expr1] 文字列または |List| または |Tuple| の項目 *E909* *subscript* *E1062* 旧来の Vim script では: expr10 が数値か文字列ならば、この値は文字列 expr10 の第 expr1 番目のバイトから @@ -1296,14 +1507,16 @@ expr10 が文字列ならば、この値は文字列 expr10 の第 expr1 番目 Vim9 script では負数のインデックスはリストと同様に使用され、終端からのカウント になる。 -expr10 がリスト|List|ならばインデックスexpr1の要素が返る。取りうるインデックス +expr10 がリスト|List|ならばインデックスexpr1の項目が返る。取りうるインデックス の値については|list-index|を参照。インデックスが範囲を超えている場合はエラーと なる。例: > - :let item = mylist[-1] " 最後の要素を取得 + :let item = mylist[-1] " 最後の項目を取得 一般的には、インデックスが正でリストの長さ以上または、負でリストの長さ×-1より 小さいときエラーとなる。 +|Tuple| インデックスは、上で説明した |List| インデックスに似ている。 + *expr-[:]* *substring* expr10[expr1a : expr1b] 部分文字列または部分リスト(|sublist|) @@ -1340,12 +1553,13 @@ expr1aが省略されたときは0となる。expr1bが省略されたときは :let s = s[:-3] " 最後の2文字を削除する < *slice* -expr10 が |List| ならば、インデックスexpr1aとexpr1bの間の要素からなる新しい +expr10 が |List| ならば、インデックスexpr1aとexpr1bの間の項目からなる新しい |List| となる。すぐ上で説明した文字列の場合と同様である。部分リスト|sublist|も 参照のこと。例: > - :let l = mylist[:3] " 最初の4個の要素 - :let l = mylist[4:4] " 1個の要素からなるリスト + :let l = mylist[:3] " 最初の4個の項目 + :let l = mylist[4:4] " 1個の項目からなるリスト :let l = mylist[:] " リストの浅いコピー +|Tuple| のスライスは |List| のスライスに似ている。 expr10 が |Blob| ならば、インデックス expr1a と expr1b のバイト数を含む新しい |Blob| となる。例: > @@ -1361,7 +1575,7 @@ expr10 が |Blob| ならば、インデックス expr1a と expr1b のバイト mylist[s:] " スコープs:を使うとエラー! -expr10.name 辞書|Dictionary|の要素 *expr-entry* +expr10.name 辞書|Dictionary|の項目 *expr-entry* *E1203* *E1229* expr10 が辞書 |Dictionary| のとき、ドットをつけるとその後に書かれた名前が辞書 のキーと見なされる。例: expr10[name]。 @@ -2103,7 +2317,7 @@ v:errmsg 最後に表示されたエラーメッセージ。この変数は代 v:errors |assert_true()|のような、テスト用関数によって見つかったエラー。 これは文字列のリストである。 テスト用関数はテストに失敗した時にエラーを末尾に追加する。 - 戻り値が示すもの: 要素が v:errors に追加された場合 1 が返る。 + 戻り値が示すもの: 項目が v:errors に追加された場合 1 が返る。 それ以外では 0 が返る。 古い結果を削除する方法はこの変数を空にする: > :let v:errors = [] @@ -2239,7 +2453,7 @@ v:insertmode 自動コマンドイベント|InsertEnter|と|InsertChange|用。 v 仮想置換モード *v:key* *key-variable* -v:key 辞書|Dictionary|の現在の要素のキー。|map()|と|filter()|で使わ +v:key 辞書|Dictionary|の現在の項目のキー。|map()|と|filter()|で使わ れる式を評価している最中のみ有効。 読出し専用。 @@ -2288,7 +2502,7 @@ v:mouse_col |getchar()|でマウスクリックイベントが発生したとき いときは0となる。 *v:none* *none-variable* *None* -v:none 空の文字列。JSONでは空の要素として使われる。 +v:none 空の文字列。JSONでは空の項目として使われる。 |json_encode()|を参照。 これは関数の引数のデフォルト値に使うこともできる、 |none-function_argument| を参照。 @@ -2557,6 +2771,8 @@ v:t_typealias |typealias| 型の値。読出し専用。 参照: |type()| v:t_enum |enum| 型の値。読出し専用。 参照: |type()| *v:t_enumvalue* *t_enumvalue-variable* v:t_enumvalue |enumvalue| 型の値。読出し専用。 参照: |type()| + *v:t_tuple* *t_tuple-variable* +v:t_tuple |Tuple| 型の値。読出し専用。 参照: |type()| *v:termresponse* *termresponse-variable* v:termresponse termcapのエントリ|t_RV|で端末から返されるエスケープシーケンス。 @@ -2644,7 +2860,7 @@ v:true 数値1。JSONでは "true" として使われる。|json_encode()|を うにするためである。読出し専用。 |Vim9| script では、真偽値型として "true" を使用できる。 *v:val* *val-variable* -v:val リスト|List|もしくは辞書|Dictionary|の現在の要素の値。|map()| +v:val リスト|List|もしくは辞書|Dictionary|の現在の項目の値。|map()| と|filter()|で使われる式を評価している最中のみ有効。読出し専 用。 @@ -2764,11 +2980,11 @@ Note: |Vim9| script では、`:let` は使用されない。`:var` は変数宣 がまだ存在しない場合、新たに作成される。 :let {var-name}[{idx}] = {expr1} *E689* *E1141* - リストの要素に式{expr1}の結果をセットする。{var-name} + リストの項目に式{expr1}の結果をセットする。{var-name} はリストを参照し、{idx}はそのリストの有効なインデック スでなければならない。ネストしたリストに対してはイン デックスを繰り返すことができる。 - このコマンドはリストに要素を追加するためには使えない。 + このコマンドはリストに項目を追加するためには使えない。 文字列の i バイト目をセットするためにも使えない。それ には次のようにする: > :let var = var[0:2] .. 'X' .. var[4:] @@ -2778,10 +2994,10 @@ Note: |Vim9| script では、`:let` は使用されない。`:var` は変数宣 *E711* *E719* *E1165* *E1166* *E1183* :let {var-name}[{idx1}:{idx2}] = {expr1} *E708* *E709* *E710* リスト|List|の一部を式{expr}の値で置き換える。{expr}の - 値は正しい個数の要素を持つリストでなければならない。 + 値は正しい個数の項目を持つリストでなければならない。 {idx1}を省略すると0となる。 {idx2}を省略するとリストの末尾となる。 - 指定された範囲の一部がリストの末尾を越える場合、要素が + 指定された範囲の一部がリストの末尾を越える場合、項目が 追加される。 *:let+=* *:let-=* *:letstar=* *:let/=* *:let%=* @@ -2867,14 +3083,14 @@ Note: |Vim9| script では、`:let` は使用されない。`:var` は変数宣 上と同様だが、オプションのグローバルな値だけをセットす る(グローバルな値があるならば)。|:setglobal|と同様に働 く。 - *E1093* + *E1093* *E1537* *E1538* *E1535* :let [{name1}, {name2}, ...] = {expr1} *:let-unpack* *E687* *E688* - {expr1}の値はリスト|List|でなければならない。そのリス - トの最初の要素が{name1}に代入され、2番目の要素が - {name2}に代入される。以下同様。 - nameの個数がリスト|List|の要素の個数に一致しなければな - らない。 - 前述のように各nameは ":let" コマンドの要素の1つになる + {expr1} は |List| または |Tuple| に評価される必要があ + る。リストまたは tuple の最初の項目は {name1} に、2 番 + 目の項目は {name2} に代入され、以下同様に処理される。 + name の個数が |List| または |Tuple| の項目の個数に一致 + しなければならない。 + 前述のように各nameは ":let" コマンドの項目の1つになる ことができる。 例: > :let [s, item] = GetItem(s) @@ -2890,21 +3106,26 @@ Note: |Vim9| script では、`:let` は使用されない。`:var` は変数宣 :let [{name1}, {name2}, ...] .= {expr1} :let [{name1}, {name2}, ...] += {expr1} :let [{name1}, {name2}, ...] -= {expr1} - 上と同様だが、リスト|List|の各要素に対し連結・足し算・ - 引き算を行う。 +:let [{name1}, {name2}, ...] *= {expr1} +:let [{name1}, {name2}, ...] /= {expr1} +:let [{name1}, {name2}, ...] %= {expr1} + 上記と同様だが、各 |List| または |Tuple| 項目の値を追 + 加、加算、減算、乗算、除算、または剰余する。 :let [{name}, ..., ; {lastname}] = {expr1} *E452* - |:let-unpack|と同様だが、リスト|List|の要素数がnamesの - 数より多くてもよい。余った要素のリストが{lastname}に代 - 入される。要素の余りがないとき{lastname}は空リストにな - る。 + 上記の |:let-unpack| と同様だが、|List| または |Tuple| + には名前の数よりも多くの項目が含まれる場合がある。残り + の項目のリストまたは tuple が {lastname} に代入される。 + 残りの項目がない場合、{lastname} には空のリストまたは + tuple が設定される。 例: > :let [a, b; rest] = ["aval", "bval", 3, 4] + :let [a, b; rest] = ("aval", "bval", 3, 4) < :let [{name}, ..., ; {lastname}] .= {expr1} :let [{name}, ..., ; {lastname}] += {expr1} :let [{name}, ..., ; {lastname}] -= {expr1} - 上と同様だが、リスト|List|の各要素に対して連結・足し算 + 上と同様だが、リスト|List|の各項目に対して連結・足し算 ・引き算を行う。 *:let=<<* *:let-heredoc* @@ -3008,14 +3229,14 @@ text... :unl[et][!] {name} ... *:unlet* *:unl* *E108* *E795* *E1081* 内部変数{name}を削除する。複数の変数名を指定すると、そ れらが全て削除される。名前はリスト|List|や辞書 - |Dictionary|の要素でもよい。 + |Dictionary|の項目でもよい。 [!]をつけると存在しない変数に対するエラーメッセージを 表示しない。 - リスト|List|から1個以上の要素を削除することができる: > - :unlet list[3] " 4番目の要素を削除 - :unlet list[3:] " 4番目から最後までの要素を + リスト|List|から1個以上の項目を削除することができる: > + :unlet list[3] " 4番目の項目を削除 + :unlet list[3:] " 4番目から最後までの項目を 削除 -< 辞書からは一度に1個の要素を削除することができる: > +< 辞書からは一度に1個の項目を削除することができる: > :unlet dict['two'] :unlet dict.two < グローバル変数とスクリプトローカル変数をクリーンアップ @@ -3089,20 +3310,24 @@ text... エラーメッセージ "E940: Cannot lock or unlock variable {name}" が表示される。 - [depth]はリスト|List|や辞書|Dictionary|をロックすると - きに意味がある。どれだけ深くロックするかを指定する: + [depth] は、|List|、|Tuple|、または |Dictionary| をロッ + クする際に関係する。これはロックの深さを指定する: 0 変数 {name} をロックするが値はロックし ない。 - 1 リストや辞書それ自身をロックする。要素 - を追加したり削除はできないが、要素の値 - を変えることはできる。 - 2 要素の値もロックする。その要素がリスト - や辞書である場合、その中の要素の追加や - 削除はできないが、値の変更はできる。 - 3 2と同様だが、リスト・辞書内のリスト・ - 辞書に対してもあてはまる。1レベル深い。 - [depth]の既定値は2であり、{name}がリストまたは辞書であ - る場合、その値は変更できない。 + 1 |List| または |Tuple| または + |Dictionary| 自体をロックする。項目を + 追加または削除することはできないが、値 + を変更することはできる。 + 2 値もロックされ、項目を変更できなくな + る。項目が |List|、|Tuple|、また + は|Dictionary| の場合、項目の追加や削 + 除はできないが、値の変更は可能である。 + 3 2 と同様だが、|List| / |Tuple| / + |Dictionary| 内の |List| / |Tuple| / + |Dictionary| は 1 レベル深くなる。 + デフォルトの [depth] は 2 である。したがって、{name} + が |List|、|Tuple| または |Dictionary| の場合、値を変 + 更することはできない。 [depth] 0 の例: > let mylist = [1, 2, 3] @@ -3204,23 +3429,23 @@ text... :for {var} in {object} *:for* *E690* *E732* :endfo[r] *:endfo* *:endfor* - {object}の各要素に対し、`:for` と `:endfor` の間のコマ - ンドを繰り返す。{object}はリスト |List|、|Blob|、また - は文字列 |String| である。 *E1177* + {object}の各項目に対し、`:for` と `:endfor` の間のコマ + ンドを繰り返す。{object}は |List|、|Tuple|、|Blob| ま + たは |String| である。 *E1177* - 変数{var}に各要素の値がセットされる。 + 変数{var}に各項目の値がセットされる。 |Vim9| script ではループ変数がグローバル/ウィンドウ/タ ブ/バッファ変数でない限り、未宣言である必要がある。 ループの内側のコマンドでエラーが検出されたときは `endfor` の後から実行が継続される。 - ループの内側で{object}を変更するとどの要素が使われるか + ループの内側で{object}を変更するとどの項目が使われるか に影響を与える。それを望まない場合はコピーを作ること: > :for item in copy(mylist) < {object}が |List| でコピーを作らない場合、旧来のスクリ - プトではVimは現在の要素に対してコマンドを実行する前に、 - |List| の次の要素への参照を保存する。そのため副作用な - しに現在の要素を削除することができる。それ以降の要素を + プトではVimは現在の項目に対してコマンドを実行する前に、 + |List| の次の項目への参照を保存する。そのため副作用な + しに現在の項目を削除することができる。それ以降の項目を 変更すると、それが見つからなくなる。つまり以下の例は動 作する(|List| を空にする非効率な方法): > for item in mylist @@ -3228,14 +3453,14 @@ text... endfor < Note |List| を並べ替える(例えばsort()やreverse()で)と 予期しない結果になることがある。 - |Vim9| script では index が使用される。現在の要素よりも - 前の要素が削除された場合、次の要素はスキップされる。 + |Vim9| script では index が使用される。現在の項目よりも + 前の項目が削除された場合、次の項目はスキップされる。 {object} が |Blob| の場合、Vimは常にコピーを作成して繰 り返す。|List| とは異なり、|Blob| を変更しても繰り返し には影響しない。 - {object} が |String| の場合は各要素は1つの文字、それと + {object} が |String| の場合は各項目は1つの文字、それと 任意の結合文字による文字列になる。 |Vim9| script では、スクリプトの可読性向上のため @@ -3243,8 +3468,8 @@ text... :for [{var1}, {var2}, ...] in {listlist} :endfo[r] *E1140* - 上の `:for` と同様だが、{listlist}の各要素がリストでな - ければならない点が異なる。そのリストの各要素が{var1}, + 上の `:for` と同様だが、{listlist}の各項目がリストでな + ければならない点が異なる。そのリストの各項目が{var1}, {var2}などに代入される。例: > :for [lnum, col] in [[1, 3], [2, 5], [3, 8]] :echo getline(lnum)[col] @@ -4563,7 +4788,7 @@ matchstr()やsubstitute()を使えば実現できる。以下の例は、"foobar :let mx='\(\f\+\),\s*\(\d\+\),\s*\(\d\+\)' :" 正規表現全体にマッチする部分を取り出す :let l = matchstr(line, mx) - :" マッチ結果から各要素を取り出す + :" マッチ結果から各項目を取り出す :let file = substitute(l, mx, '\1', '') :let lnum = substitute(l, mx, '\2', '') :let col = substitute(l, mx, '\3', '') @@ -4774,7 +4999,7 @@ dist#vim9#IsSafeExecutable(filetype:string, executable:string): bool ~ filetype string executable string - *dist#vim9#Open()* *:Open* + *dist#vim9#Open()* *:Open* *:URLOpen* *g:Openprg* *gx* dist#vim9#Open(file: string) ~ @@ -4782,6 +5007,8 @@ dist#vim9#Open(file: string) ~ Linux の `xdg-open` 等) を使用して `path` を開く。変数 |g:Openprg| が存在する 場合は、代わりに変数で指定された文字列が使用される。 +|:Open| ユーザーコマンドは引数としてファイル補完を使用する。 + この関数は、デフォルトでは gx マッピングを使用して呼び出される。ビジュアルモー ドでは、視覚的に選択されたテキストを開こうとする。 @@ -4800,13 +5027,18 @@ NOTE: パスのエスケープは自動的に適用される。 :call dist#vim9#Open() :Open < + *package-open* +|:Open| および |:Launch| コマンドは、同梱のプラグイン +$VIMRUNTIME/plugin/openPlugin.vim によって提供される。 - *dist#vim9#Launch()* *:Launch* + *dist#vim9#Launch()* *:Launch* dist#vim9#Launch(file: string) ~ 適切なシステムプログラムを使用して を起動する。Vim 内で GUI プログラム を起動することを目的としている。 +|:Launch| ユーザーコマンドは、最初の引数にシェル補完を使用する。 + NOTE: のエスケープはユーザーに任される 例: >vim diff --git a/en/eval.txt b/en/eval.txt index 4e919ae65..170d2d037 100644 --- a/en/eval.txt +++ b/en/eval.txt @@ -1,4 +1,4 @@ -*eval.txt* For Vim version 9.1. Last change: 2025 Mar 30 +*eval.txt* For Vim version 9.1. Last change: 2025 Apr 02 VIM REFERENCE MANUAL by Bram Moolenaar @@ -535,8 +535,216 @@ Don't forget that a combination of features can make things simple. For example, to add up all the numbers in a list: > :exe 'let sum = ' .. join(nrlist, '+') +1.4 Tuples ~ + *tuple* *Tuple* *Tuples* + *E1532* *E1533* +A Tuple is an ordered sequence of items. An item can be of any type. Items +can be accessed by their index number. A Tuple is immutable. -1.4 Dictionaries ~ +A Tuple is similar to a List but uses less memory and provides O(1) lookup +time for an item. + +Tuple creation ~ + *E1526* *E1527* +A Tuple is created with a comma-separated sequence of items in parentheses. +Examples: > + :let mytuple = (1, "two", 3, "four") + :let tuple = (5,) + :let emptytuple = () + +An item can be any expression. If there is only one item in the tuple, then +the item must be followed by a comma. + +Using a Tuple for an item creates a Tuple of Tuples: > + :let nesttuple = ((11, 12), (21, 22), (31, 32)) + + +Tuple index ~ + *tuple-index* *E1519* +An item in the Tuple can be accessed by putting the index in square brackets +after the Tuple. Indexes are zero-based, thus the first item has index zero. +> + :let item = mytuple[0] " get the first item: 1 + :let item = mytuple[2] " get the third item: 3 + +When the resulting item is a tuple this can be repeated: > + :let item = nesttuple[0][1] " get the first tuple, second item: 12 +< +A negative index is counted from the end. Index -1 refers to the last item in +the Tuple, -2 to the last but one item, etc. > + :let last = mytuple[-1] " get the last item: "four" + +To avoid an error for an invalid index use the |get()| function. When an item +is not available it returns zero or the default value you specify: > + :echo get(mytuple, idx) + :echo get(mytuple, idx, "NONE") + + +Tuple modification ~ + *tuple-modification* +A tuple is immutable and items cannot be added or removed from a tuple. But +List and Dict items within a tuple can be modified: > + :let tuple = (1, [2, 3], {'a': 4}) + :let tuple[1][0] = 10 + :let tuple[2]['a'] = 20 + + +Tuple concatenation ~ + *tuple-concatenation* +Two tuples can be concatenated with the "+" operator: > + :let longtuple = mytuple + (5, 6) + :let longtuple = (5, 6) + mytuple +To prepend or append an item, turn it into a tuple by putting () around it. +The item must be followed by a comma. + + *E1540* +Two variadic tuples with same item type can be concatenated but with different +item types cannot be concatenated. Examples: > + var a: tuple<...list> = (1, 2) + var b: tuple<...list> = ('a', 'b') + echo a + b # not allowed + + var a: tuple = (1, 2) + var b: tuple<...list> = ('a', 'b') + echo a + b # allowed + + var a: tuple<...list> = (1, 2) + var b: tuple = (3, 4) + echo a + b # not allowed + + var a: tuple<...list> = (1, 2) + var b: tuple> = (3, 4) + echo a + b # not allowed +< +Note that a tuple is immutable and items cannot be added or removed from a +tuple. + + +Subtuple ~ + *subtuple* +A part of the Tuple can be obtained by specifying the first and last index, +separated by a colon in square brackets: > + :let shorttuple = mytuple[2:-1] " get Tuple (3, "four") + +Omitting the first index is similar to zero. Omitting the last index is +similar to -1. > + :let endtuple = mytuple[2:] " from item 2 to the end: (3, "four") + :let shorttuple = mytuple[2:2] " Tuple with one item: (3,) + :let othertuple = mytuple[:] " make a copy of the Tuple + +Notice that the last index is inclusive. If you prefer using an exclusive +index, use the |slice()| function. + +If the first index is beyond the last item of the Tuple or the last index is +before the first item, the result is an empty tuple. There is no error +message. + +If the last index is equal to or greater than the length of the tuple, the +length minus one is used: > + :let mytuple = (0, 1, 2, 3) + :echo mytuple[2:8] " result: (2, 3) + +NOTE: mytuple[s:e] means using the variable "s:e" as index. Watch out for +using a single letter variable before the ":". Insert a space when needed: +mytuple[s : e]. + + +Tuple identity ~ + *tuple-identity* +When variable "aa" is a tuple and you assign it to another variable "bb", both +variables refer to the same tuple: > + :let aa = (1, 2, 3) + :let bb = aa +< + +Making a copy of a tuple is done with the |copy()| function. Using [:] also +works, as explained above. This creates a shallow copy of the tuple: For +example, changing a list item in the tuple will also change the item in the +copied tuple: > + :let aa = ([1, 'a'], 2, 3) + :let bb = copy(aa) + :let aa[0][1] = 'aaa' + :echo aa +< ([1, aaa], 2, 3) > + :echo bb +< ([1, aaa], 2, 3) + +To make a completely independent tuple, use |deepcopy()|. This also makes a +copy of the values in the tuple, recursively. Up to a hundred levels deep. + +The operator "is" can be used to check if two variables refer to the same +Tuple. "isnot" does the opposite. In contrast, "==" compares if two tuples +have the same value. > + :let atuple = (1, 2, 3) + :let btuple = (1, 2, 3) + :echo atuple is btuple +< 0 > + :echo atuple == btuple +< 1 + +Note about comparing tuples: Two tuples are considered equal if they have the +same length and all items compare equal, as with using "==". There is one +exception: When comparing a number with a string they are considered +different. There is no automatic type conversion, as with using "==" on +variables. Example: > + echo 4 == "4" +< 1 > + echo (4,) == ("4",) +< 0 + +Thus comparing Tuples is more strict than comparing numbers and strings. You +can compare simple values this way too by putting them in a tuple: > + + :let a = 5 + :let b = "5" + :echo a == b +< 1 > + :echo (a,) == (b,) +< 0 + + +Tuple unpack ~ + +To unpack the items in a tuple to individual variables, put the variables in +square brackets, like list items: > + :let [var1, var2] = mytuple + +When the number of variables does not match the number of items in the tuple +this produces an error. To handle any extra items from the tuple, append ";" +and a variable name (which will then be of type tuple): > + :let [var1, var2; rest] = mytuple + +This works like: > + :let var1 = mytuple[0] + :let var2 = mytuple[1] + :let rest = mytuple[2:] + +Except that there is no error if there are only two items. "rest" will be an +empty tuple then. + + +Tuple functions ~ + *E1536* +Functions that are useful with a Tuple: > + :let xs = count(tuple, 'x') " count number of 'x's in tuple + :if empty(tuple) " check if tuple is empty + :let i = index(tuple, 'x') " index of first 'x' in tuple + :let l = items(tuple) " list of items in a tuple + :let string = join(tuple, ', ') " create string from tuple items + :let l = len(tuple) " number of items in tuple + :let big = max(tuple) " maximum value in tuple + :let small = min(tuple) " minimum value in tuple + :let r = repeat(tuple, n) " repeat a tuple n times + :let r = reverse(tuple) " reverse a tuple + :let s = slice(tuple, n1, n2) " slice a tuple + :let s = string(tuple) " String representation of tuple + :let l = tuple2list(tuple) " convert a tuple to list + :let t = list2tuple(list) " convert a list to tuple +< + *E1524* +A tuple cannot be used with the |map()|, |mapnew()| and |filter()| functions. + +1.5 Dictionaries ~ *dict* *Dict* *Dictionaries* *Dictionary* A Dictionary is an associative array: Each entry has a key and a value. The entry can be located with the key. The entries are stored without a specific @@ -545,10 +753,10 @@ ordering. Dictionary creation ~ *E720* *E721* *E722* *E723* -A Dictionary is created with a comma-separated list of entries in curly +A Dictionary is created with a comma-separated sequence of entries in curly braces. Each entry has a key and a value, separated by a colon. Each key can only appear once. Examples: > - :let mydict = {1: 'one', 2: 'two', 3: 'three'} + :let mydict = {'one': 1, 'two': 2, 'three': 3} :let emptydict = {} < *E713* *E716* *E717* A key is always a String. You can use a Number, it will be converted to a @@ -578,8 +786,11 @@ An extra comma after the last entry is ignored. Accessing entries ~ The normal way to access an entry is by putting the key in square brackets: > + :let mydict = {'one': 1, 'two': 2, 'three': 3} :let val = mydict["one"] :let mydict["four"] = 4 + :let val = mydict.one + :let mydict.four = 4 You can add new entries to an existing Dictionary this way, unlike Lists. @@ -717,7 +928,7 @@ Functions that can be used with a Dictionary: > :call map(dict, '">> " .. v:val') " prepend ">> " to each item -1.5 Blobs ~ +1.6 Blobs ~ *blob* *Blob* *Blobs* *E978* A Blob is a binary object. It can be used to read an image from a file and send it over a channel, for example. @@ -864,7 +1075,7 @@ Making a copy of a Blob is done with the |copy()| function. Using [:] also works, as explained above. -1.6 More about variables ~ +1.7 More about variables ~ *more-variables* If you need to know the type of a variable or expression, use the |type()| function. @@ -915,16 +1126,18 @@ Expression syntax summary, from least to most significant: etc. As above, append ? for ignoring case, # for matching case - expr5 is expr5 same |List|, |Dictionary| or |Blob| instance - expr5 isnot expr5 different |List|, |Dictionary| or |Blob| + expr5 is expr5 same |List|, |Tuple|, |Dictionary| or |Blob| instance + expr5 isnot expr5 different |List|, |Tuple|, |Dictionary| or + |Blob| instance |expr5| expr6 expr6 << expr6 bitwise left shift expr6 >> expr6 bitwise right shift |expr6| expr7 - expr7 + expr7 ... number addition, list or blob concatenation + expr7 + expr7 ... number addition, list or tuple or blob + concatenation expr7 - expr7 ... number subtraction expr7 . expr7 ... string concatenation expr7 .. expr7 ... string concatenation @@ -943,8 +1156,10 @@ Expression syntax summary, from least to most significant: + expr9 unary plus |expr10| expr11 - expr10[expr1] byte of a String or item of a |List| + expr10[expr1] byte of a String or item of a |List| or + |Tuple| expr10[expr1 : expr1] substring of a String or sublist of a |List| + or a slice of a |Tuple| expr10.name entry in a |Dictionary| expr10(expr1, ...) function call with |Funcref| variable expr10->name(expr1, ...) |method| call @@ -953,6 +1168,7 @@ Expression syntax summary, from least to most significant: "string" string constant, backslash is special 'string' string constant, ' is doubled [expr1, ...] |List| + (expr1, ...) |Tuple| {expr1: expr1, ...} |Dictionary| #{key: expr1, ...} legacy |Dictionary| &option option value @@ -1109,10 +1325,11 @@ Examples: "abc" == "Abc" evaluates to 1 if 'ignorecase' is set, 0 otherwise NOTE: In |Vim9| script 'ignorecase' is not used. - *E691* *E692* + *E691* *E692* *E1517* *E1518* A |List| can only be compared with a |List| and only "equal", "not equal", "is" and "isnot" can be used. This compares the values of the list, recursively. Ignoring case means case is ignored when comparing item values. +Same applies for a |Tuple|. *E735* *E736* A |Dictionary| can only be compared with a |Dictionary| and only "equal", "not @@ -1132,12 +1349,13 @@ Dictionary and arguments, use |get()| to get the function name: > if get(Part1, 'name') == get(Part2, 'name') " Part1 and Part2 refer to the same function < *E1037* -Using "is" or "isnot" with a |List|, |Dictionary| or |Blob| checks whether -the expressions are referring to the same |List|, |Dictionary| or |Blob| -instance. A copy of a |List| is different from the original |List|. When -using "is" without a |List|, |Dictionary| or |Blob|, it is equivalent to -using "equal", using "isnot" equivalent to using "not equal". Except that -a different type means the values are different: > +Using "is" or "isnot" with a |List|, |Tuple|, |Dictionary| or |Blob| checks +whether the expressions are referring to the same |List|, |Tuple|, +|Dictionary| or |Blob| instance. A copy of a |List| or |Tuple| is different +from the original |List| or |Tuple|. When using "is" without a |List|, +|Tuple|, |Dictionary| or |Blob|, it is equivalent to using "equal", using +"isnot" is equivalent to using "not equal". Except that a different type +means the values are different: > echo 4 == '4' 1 echo 4 is '4' @@ -1155,7 +1373,7 @@ that: > because 'x' converted to a Number is zero. However: > echo [0] == ['x'] 0 -Inside a List or Dictionary this conversion is not used. +Inside a List or Tuple or Dictionary this conversion is not used. In |Vim9| script the types must match. @@ -1199,13 +1417,14 @@ topmost bit (sometimes called the sign bit) is cleared. If the right operand expr6 and expr7 *expr6* *expr7* *E1036* *E1051* --------------- -expr7 + expr7 Number addition, |List| or |Blob| concatenation *expr-+* + *expr-+* +expr7 + expr7 Number addition, |List| or |Tuple| or |Blob| concatenation expr7 - expr7 Number subtraction *expr--* expr7 . expr7 String concatenation *expr-.* expr7 .. expr7 String concatenation *expr-..* For |Lists| only "+" is possible and then both expr7 must be a list. The -result is a new list with the two lists Concatenated. +result is a new list with the two lists concatenated. Same for a |Tuple|. For String concatenation ".." is preferred, since "." is ambiguous, it is also used for |Dict| member access and floating point numbers. @@ -1303,7 +1522,8 @@ in any order. E.g., these are all possible: expr10->(expr1, ...)[expr1] Evaluation is always from left to right. -expr10[expr1] item of String or |List| *expr-[]* *E111* + *expr-[]* *E111* +expr10[expr1] item of String or |List| or |Tuple| *E909* *subscript* *E1062* In legacy Vim script: If expr10 is a Number or String this results in a String that contains the @@ -1336,6 +1556,8 @@ Generally, if a |List| index is equal to or higher than the length of the |List|, or more negative than the length of the |List|, this results in an error. +A |Tuple| index is similar to a |List| index as explained above. + expr10[expr1a : expr1b] substring or |sublist| *expr-[:]* *substring* @@ -1377,6 +1599,7 @@ just above. Also see |sublist| below. Examples: > :let l = mylist[:3] " first four items :let l = mylist[4:4] " List with one item :let l = mylist[:] " shallow copy of a List +A |Tuple| slice is similar to a |List| slice. If expr10 is a |Blob| this results in a new |Blob| with the bytes in the indexes expr1a and expr1b, inclusive. Examples: > @@ -2623,6 +2846,8 @@ v:t_typealias Value of |typealias| type. Read-only. See: |type()| v:t_enum Value of |enum| type. Read-only. See: |type()| *v:t_enumvalue* *t_enumvalue-variable* v:t_enumvalue Value of |enumvalue| type. Read-only. See: |type()| + *v:t_tuple* *t_tuple-variable* +v:t_tuple Value of |Tuple| type. Read-only. See: |type()| *v:termresponse* *termresponse-variable* v:termresponse The escape sequence returned by the terminal for the |t_RV| @@ -2942,13 +3167,13 @@ declarations and assignments do not use a command. |vim9-declaration| :let &g:{option-name} -= {expr1} Like above, but only set the global value of an option (if there is one). Works like |:setglobal|. - *E1093* + *E1093* *E1537* *E1538* *E1535* :let [{name1}, {name2}, ...] = {expr1} *:let-unpack* *E687* *E688* - {expr1} must evaluate to a |List|. The first item in - the list is assigned to {name1}, the second item to - {name2}, etc. + {expr1} must evaluate to a |List| or a |Tuple|. The + first item in the list or tuple is assigned to + {name1}, the second item to {name2}, etc. The number of names must match the number of items in - the |List|. + the |List| or |Tuple|. Each name can be one of the items of the ":let" command as mentioned above. Example: > @@ -2965,16 +3190,22 @@ declarations and assignments do not use a command. |vim9-declaration| :let [{name1}, {name2}, ...] .= {expr1} :let [{name1}, {name2}, ...] += {expr1} :let [{name1}, {name2}, ...] -= {expr1} - Like above, but append/add/subtract the value for each - |List| item. +:let [{name1}, {name2}, ...] *= {expr1} +:let [{name1}, {name2}, ...] /= {expr1} +:let [{name1}, {name2}, ...] %= {expr1} + Like above, but append, add, subtract, multiply, + divide, or modulo the value for each |List| or |Tuple| + item. :let [{name}, ..., ; {lastname}] = {expr1} *E452* - Like |:let-unpack| above, but the |List| may have more - items than there are names. A list of the remaining - items is assigned to {lastname}. If there are no - remaining items {lastname} is set to an empty list. + Like |:let-unpack| above, but the |List| or |Tuple| + may have more items than there are names. A list or a + tuple of the remaining items is assigned to + {lastname}. If there are no remaining items, + {lastname} is set to an empty list or tuple. Example: > :let [a, b; rest] = ["aval", "bval", 3, 4] + :let [a, b; rest] = ("aval", "bval", 3, 4) < :let [{name}, ..., ; {lastname}] .= {expr1} :let [{name}, ..., ; {lastname}] += {expr1} @@ -3169,23 +3400,26 @@ text... get an error message: "E940: Cannot lock or unlock variable {name}". - [depth] is relevant when locking a |List| or - |Dictionary|. It specifies how deep the locking goes: + [depth] is relevant when locking a |List|, a |Tuple| + or a |Dictionary|. It specifies how deep the locking + goes: 0 Lock the variable {name} but not its value. - 1 Lock the |List| or |Dictionary| itself, - cannot add or remove items, but can - still change their values. + 1 Lock the |List| or |Tuple| or + |Dictionary| itself, cannot add or + remove items, but can still change + their values. 2 Also lock the values, cannot change the items. If an item is a |List| or - |Dictionary|, cannot add or remove - items, but can still change the + |Tuple| or |Dictionary|, cannot add or + remove items, but can still change the values. - 3 Like 2 but for the |List| / - |Dictionary| in the |List| / + 3 Like 2 but for the |List| / |Tuple| / + |Dictionary| in the |List| / |Tuple| / |Dictionary|, one level deeper. - The default [depth] is 2, thus when {name} is a |List| - or |Dictionary| the values cannot be changed. + The default [depth] is 2, thus when {name} is a + |List|, a |Tuple| or a |Dictionary| the values cannot + be changed. Example with [depth] 0: > let mylist = [1, 2, 3] @@ -3290,7 +3524,7 @@ text... :endfo[r] *:endfo* *:endfor* Repeat the commands between `:for` and `:endfor` for each item in {object}. {object} can be a |List|, - a |Blob| or a |String|. *E1177* + a |Tuple|, a |Blob| or a |String|. *E1177* Variable {var} is set to the value of each item. In |Vim9| script the loop variable must not have been @@ -4915,7 +5149,7 @@ executable. It takes the following arguments: filetype string executable string - *dist#vim9#Open()* *:Open* + *dist#vim9#Open()* *:Open* *:URLOpen* *g:Openprg* *gx* dist#vim9#Open(file: string) ~ @@ -4923,6 +5157,8 @@ Opens `path` with the system default handler (macOS `open`, Windows `explorer.exe`, Linux `xdg-open`, …). If the variable |g:Openprg| exists the string specified in the variable is used instead. +The |:Open| user command uses file completion for its argument. + This function is by default called using the gx mapping. In visual mode tries to open the visually selected text. @@ -4941,13 +5177,18 @@ Usage: >vim :call dist#vim9#Open() :Open < + *package-open* +The |:Open| and |:Launch| command are provided by the included plugin +$VIMRUNTIME/plugin/openPlugin.vim - *dist#vim9#Launch()* *:Launch* + *dist#vim9#Launch()* *:Launch* dist#vim9#Launch(file: string) ~ Launches with the appropriate system programs. Intended for launching GUI programs within Vim. +The |:Launch| user command uses shell completion for its first argument. + NOTE: escaping of is left to the user Examples: >vim From 92b54fba5370fa0ec5c2dd051fec53d6796e54c8 Mon Sep 17 00:00:00 2001 From: h-east Date: Sun, 13 Apr 2025 01:04:36 +0900 Subject: [PATCH 3/4] Fix by nvcheck --- doc/eval.jax | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/eval.jax b/doc/eval.jax index 4d8132e2f..37f5bc202 100644 --- a/doc/eval.jax +++ b/doc/eval.jax @@ -537,7 +537,7 @@ Tuple は、括弧で囲まれた項目のコンマ区切りのシーケンス :let emptytuple = () 項目には任意の式を指定できる。tuple に項目が 1 つしかない場合は、その項目の後 -にカンマを付ける必要がある。 +にコンマを付ける必要がある。 項目に Tuple を使用すると、Tuple の Tuple が作成される: > :let nesttuple = ((11, 12), (21, 22), (31, 32)) @@ -578,7 +578,7 @@ Tuple の連結 ~ :let longtuple = mytuple + (5, 6) :let longtuple = (5, 6) + mytuple 項目を先頭または末尾に追加するには、項目を () で囲んで tuple に変換する。項目 -の後にカンマを付ける必要がある。 +の後にコンマを付ける必要がある。 *E1540* 同じ項目の型を持つ 2 つの可変長 tuple は連結できるが、異なる項目の型を持つ From 7d0a93f8cb577b7979ed62df866551a4d16485d0 Mon Sep 17 00:00:00 2001 From: h_east Date: Sun, 13 Apr 2025 15:36:31 +0900 Subject: [PATCH 4/4] Update doc/eval.jax Co-authored-by: Tsuyoshi CHO --- doc/eval.jax | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/eval.jax b/doc/eval.jax index 37f5bc202..b7cc07f22 100644 --- a/doc/eval.jax +++ b/doc/eval.jax @@ -364,8 +364,8 @@ NOTE: mylist[s:e] と書くと変数 "s:e" をインデックスとして使っ :echo bb < [[1, aaa], 2, 3] -完全に独立したコピーを作るには|deepcopy()|を使う。これは再帰的にリストの項目の -コピーを作る。ただし深さは100レベルまでである。 +完全に独立したコピーを作るには |deepcopy()| を使う。これは再帰的にリストの項目 +のコピーを作る。ただし深さは100レベルまでである。 2つの変数が同じリストを指しているかは演算子 "is" で判定できる。"isnot" はその 逆である。一方、"==" は2つのリストが同じ値を持っているかを判定する。 >