Skip to content

Commit ef976bd

Browse files
committed
Update
1 parent 0177438 commit ef976bd

2 files changed

Lines changed: 68 additions & 67 deletions

File tree

doc/vim9.jax

Lines changed: 66 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -2126,20 +2126,20 @@ Vimは "b:two" の型を知らないため、式は list<any> となる。実行
21262126
var s = 'yes' | echo $"{s} \t {s->type()} \t {s->typename()}"
21272127
var t = (42, ) | echo $"{t} \t {t->type()} \t {t->typename()}"
21282128
<
2129-
The type of a list, tuple, or dictionary is inferred from the common type of
2130-
its values. When the values are all the same type, that type is used.
2131-
If there is a mix of types, the "any" type is used. In the following example,
2132-
the echoed |typename()| for each literal demonstrates these points: >vim9
2129+
リスト、Tuple、または辞書の型は、その値の共通の型から推論される。値がすべて同
2130+
じ型の場合、その型が使用される。
2131+
複数の型が混在する場合は、"any" 型が使用される。以下の例では、各リテラルに対し
2132+
て echo された |typename()| がこれらのポイントを示している: >vim9
21332133

21342134
vim9script
21352135
echo [1, 2]->typename() # list<number>
21362136
echo [1, 'x']->typename() # list<any>
21372137
echo {ints: [1, 2], bools: [false]}->typename() # dict<list<any>>
21382138
echo (true, false)->typename() # tuple<bool, bool>
21392139
<
2140-
The common type of function references, when they do not all have the same
2141-
number of arguments, is indicated with "(...)", meaning the number of
2142-
arguments is unequal. This script demonstrates a "list<func(...): void>": >vim9
2140+
関数参照の一般的な型では、引数の数が異なる場合、"(...)" で示される。これは引数
2141+
の数が不揃いであることを意味する。このスクリプトは "list<func(...): void>" の
2142+
例である: >vim9
21432143

21442144
vim9script
21452145
def Foo(x: bool): void
@@ -2149,8 +2149,8 @@ arguments is unequal. This script demonstrates a "list<func(...): void>": >vim9
21492149
var funclist = [Foo, Bar]
21502150
echo funclist->typename()
21512151
<
2152-
Script-local variables in a Vim9 script are type checked. The type is
2153-
also checked for variables declared in a legacy function. For example: >vim9
2152+
Vim9 script 内のスクリプトローカル変数は型チェックされる。また、旧来の関数内で
2153+
宣言された変数についても型チェックが行われる。例: >vim9
21542154

21552155
vim9script
21562156
var my_local = (1, 2)
@@ -2162,35 +2162,35 @@ also checked for variables declared in a legacy function. For example: >vim9
21622162
echo $"{b:legacy} is type {b:legacy->type()} ({b:legacy->typename()})"
21632163
<
21642164
*E1013*
2165-
When a type is declared for a List, Tuple, or Dictionary, the type is attached
2166-
to it. Similarly, if a type is not declared, the type Vim infers is attached.
2167-
In either case, if an expression attempts to change the type, E1013 results.
2168-
This example has its type inferred and demonstrates E1013: >vim9
2165+
リスト、Tuple、または辞書の型が宣言されると、その型が関連付けられる。同様に、
2166+
型が宣言されていない場合は、Vim が推論した型が関連付けられる。どちらの場合も、
2167+
式によって型が変更されると、E1013 が発生する。以下の例では、型が推論され、
2168+
E1013 が発生する: >vim9
21692169

21702170
vim9script
2171-
var lb = [true, true] # Two bools, so Vim infers list<bool> type
2172-
echo lb->typename() # Echoes list<bool>
2171+
var lb = [true, true] # 2 つの bool なので Vim list<bool> 型と推測
2172+
echo lb->typename() # list<bool> を表示
21732173
lb->extend([0]) # E1013 Argument 2: type mismatch, ...
21742174
<
2175-
If you want a permissive list, either explicitly use <any> or declare an
2176-
empty list initially (or both, i.e., `list<any> = []`). Examples: >vim9
2175+
許容的なリストが必要な場合は、<any> を明示的に使用するか、最初に空のリストを宣
2176+
言する (または両方、つまり `list<any> = []`)。例: >vim9
21772177

21782178
vim9script
21792179
final la: list<any> = []
21802180
echo la->extend(['two', 1])
21812181
final le = []
21822182
echo le->extend(la)
21832183
<
2184-
Similarly for a permissive dictionary: >vim9
2184+
許容的な辞書の場合も同様: >vim9
21852185

21862186
vim9script
21872187
final da: dict<any> = {}
21882188
echo da->extend({2: 2, 1: 'One'})
21892189
final de = {}
21902190
echo de->extend(da)->string()
21912191
<
2192-
And, although tuples themselves are immutable, permissive tuple concatenation
2193-
can be achieved with either "any" or an empty tuple: >vim9
2192+
また、Tuple 自体は不変だが、"any" または空の Tuple のいずれかを使用して、許容
2193+
的な Tuple の連結を実現できる: >vim9
21942194

21952195
vim9script
21962196
var t_any: tuple<...list<any>> = (3, '2')
@@ -2200,8 +2200,8 @@ can be achieved with either "any" or an empty tuple: >vim9
22002200
t_dec_empty = t_dec_empty + (3, '2', true)
22012201
echo t_dec_empty
22022202
<
2203-
If a list literal or dictionary literal is not bound to a variable, its type
2204-
may change, as this example shows: >vim9
2203+
リストリテラルまたは辞書リテラルが変数にバインドされていない場合、以下の例に示
2204+
すように、その型が変更される場合がある: >vim9
22052205

22062206
vim9script
22072207
echo [3, 2, 1]->typename() # list<number>
@@ -2210,50 +2210,49 @@ may change, as this example shows: >vim9
22102210
echo {1: ['One']}->extend({2: [2]})->typename() # dict<list<any>>
22112211
<
22122212

2213-
Stricter type checking ~
2213+
より厳密な型チェック ~
22142214
*type-checking*
2215-
In legacy Vim script, where a number was expected, a string would be
2216-
automatically converted to a number. This was convenient for an actual number
2217-
such as "123", but leads to unexpected problems (and no error message) if the
2218-
string doesn't start with a number. Quite often this leads to hard-to-find
2219-
bugs. For example, in legacy Vim script this echoes "1": >vim
2215+
旧来の Vim script では、数値が期待される文字列は自動的に数値に変換されていた。
2216+
これは "123" のような実際の数値であれば便利だったが、文字列が数値で始まってい
2217+
ない場合、予期せぬ問題が発生する (エラーメッセージも表示されない)。これは多く
2218+
の場合、見つけにくいバグにつながる。例えば、旧来の Vim script では、これは "1"
2219+
と表示される: >vim
22202220

22212221
echo 123 == '123'
22222222
<
2223-
However, if an unintended space is included, "0" is echoed: >vim
2223+
ただし、意図しないスペースが含まれている場合は、"0" が表示される: >vim
22242224

22252225
echo 123 == ' 123'
22262226
<
22272227
*E1206*
2228-
In Vim9 script this has been made stricter. In most places it works just as
2229-
before if the value used matches the expected type. For example, in both
2230-
legacy Vim script and Vim9 script trying to use anything other than a
2231-
dictionary when it is required: >vim
2228+
Vim9 script では、この制限がより厳格になった。ほとんどの箇所では、使用される値
2229+
が期待される型と一致する場合、以前と同じように動作する。例えば、旧来の Vim
2230+
script Vim9 script の両方で、辞書以外の値が必要なときに、辞書以外の値を使用
2231+
しようとすると、以下のようになる: >vim
22322232

22332233
echo [8, 9]->keys()
22342234
vim9cmd echo [8, 9]->keys() # E1206: Dictionary required
22352235
<
22362236
*E1023* *E1024* *E1029* *E1030*
22372237
*E1174* *E1175* *E1210* *E1212*
2238-
However, sometimes there will be an error in Vim9 script, which breaks
2239-
backwards compatibility. The following examples illustrate various places
2240-
this happens. The legacy Vim script behavior, which does not fail, is shown
2241-
first. It is followed by the error that occurs if the same command is used
2242-
in Vim9 script.
2238+
しかし、Vim9 script ではエラーが発生し、後方互換性が損なわれることがある。以下
2239+
の例は、この問題が発生する様々な場所を示しています。まず、旧来の Vim script の
2240+
動作(エラーは発生しない) を示す。次に、同じコマンドを Vim9 script で使用した場
2241+
合に発生するエラーを示す。
22432242

2244-
- Using a number (except 0 or 1) where a bool is expected: >vim
2243+
- bool が期待される場所で数値 (0 または 1 以外) を使用する: >vim
22452244

22462245
echo v:version ? v:true : v:false
22472246
vim9cmd echo v:version ? true : false # E1023: Using a Number as a...
22482247
<
2249-
- Using a number where a string is expected: >vim
2248+
- 文字列が期待される場所で数値を使用する: >vim
22502249

22512250
echo filter([1, 2], 0)
22522251
vim9cmd echo filter([1, 2], 0) # E1024: Using a Number as a String
22532252
<
2254-
- Not using a number where a number is expected: >vim
2253+
- 数字が期待されるところで数字を使用していない: >vim
22552254

2256-
" In this example, Vim script treats v:false as 0
2255+
" この例では、Vim script v:false を 0 として扱う
22572256
function Not1029()
22582257
let b:l = [42] | unlet b:l[v:false]
22592258
endfunction
@@ -2265,88 +2264,90 @@ in Vim9 script.
22652264
enddef
22662265
E1029() # E1029: Expected number but got bool
22672266
<
2268-
- Using a string as a number: >vim
2267+
- 文字列を数値として使用する: >vim
22692268

22702269
let b:l = [42] | unlet b:l['#'] | echo b:l
22712270
vim9cmd b:l = [42] | vim9cmd unlet b:l['#'] # E1030: Using a string...
22722271
<
2273-
- Not using a string where an argument requires a string: >vim9
2272+
- 引数に文字列が必要な場合に文字列を使用しない: >vim9
22742273

22752274
echo substitute('Hallo', 'a', 'e', v:true)
22762275
vim9cmd echo substitute('Hallo', 'a', 'e', true) # E1174: String...
22772276
<
2278-
- Using an empty string in an argument that requires a non-empty string: >vim9
2277+
- 空でない文字列を必要とする引数で空の文字列を使用する: >vim9
22792278

22802279
echo exepath('')
22812280
vim9cmd echo exepath('') # E1175: Non-empty string required for arg...
22822281
<
2283-
- Not using a number when it is required: >vim
2282+
- 必要なときに数字を使用しない: >vim
22842283

22852284
echo gettabinfo('a')
22862285
vim9cmd echo gettabinfo('a') # E1210: Number required for argument 1
22872286
<
2288-
- Not using a bool when it is required: >vim
2287+
- 必要なときに真偽値を使用しない: >vim
22892288

22902289
echo char2nr('¡', 2)
22912290
vim9cmd echo char2nr('¡', 2) # E1212: Bool required for argument 2
22922291
<
2293-
- Not using a number when a number is required (|E521|): >vim
2292+
- 数字が必要なときに数字を使用しない (|E521|): >vim
22942293

22952294
let &laststatus='2'
22962295
vim9cmd &laststatus = '2'
22972296
<
2298-
- Not using a string when a string is required (|E928|): >vim
2297+
- 文字列が必要なときに文字列を使用しない (|E928|): >vim
22992298

23002299
let &langmenu = 42
23012300
vim9cmd &langmenu = 42 # E928: String required
23022301
<
2303-
- Comparing a |Special| with 'is' fails in some instances (|E1037|, |E1072|): >vim
2302+
- |Special| 'is' の比較は、場合によっては失敗する (|E1037|, |E1072|): >vim
23042303

2305-
" 1 is echoed because these are both true
2304+
" 両方とも真なので 1 が表示される
23062305
echo v:null is v:null && v:none is v:none
2307-
" 0 is echoed because all these expressions are false
2306+
" これらの式はすべて偽なので、0 が表示される
23082307
echo v:none is v:null || v:none is 8 || v:true is v:none
23092308
" All these are errors in Vim9 script
2309+
" これらはすべて Vim9 script のエラー
23102310
vim9cmd echo v:null is v:null # E1037: Cannot use 'is' with special
23112311
vim9cmd echo v:none is v:none # E1037: Cannot use 'is' with special
23122312
vim9cmd echo v:none is v:null # E1037: Cannot use 'is' with special
23132313
vim9cmd echo v:none is 8 # E1072: Cannot compare special with numb
23142314
vim9cmd echo v:true is v:none # E1072: Cannot compare bool with special
23152315
<
2316-
Note: Although the last two Vim9 script examples above error using
2317-
`v:none`, they return `false` using `null` (which is the same
2318-
as `v:null` - see |v:null|): >vim9
2316+
Note: 上記の最後の 2 つの Vim9 script の例では、`v:none` を使用する
2317+
とエラーが発生するが、`null` を使用すると `false` が返される
2318+
(これは `v:null` と同じである - |v:null| を参照): >vim9
23192319

23202320
vim9script
23212321
echo null is 8 # false
23222322
echo true is null # false
23232323
<
2324-
- Using a string where a bool is required (|E1135|): >vim
2324+
- 真偽値が必要な場所で文字列を使用する (|E1135|): >vim
23252325

23262326
echo '42' ? v:true : v:false
23272327
vim9cmd echo '42' ? true : false # E1135: Using a String as a Bool
23282328
<
2329-
- Using a bool as a number (|E1138|): >vim
2329+
- 真偽値を数値として使用する (|E1138|): >vim
23302330

23312331
let &laststatus=v:true
23322332
vim9cmd &laststatus = true
23332333
<
2334-
- Not using a string where an argument requires a string (|E1174|) >vim
2334+
- 引数に文字列が必要な場合に文字列を使用しない (|E1174|) >vim
23352335

23362336
echo substitute('Hallo', 'a', 'e', v:true)
23372337
vim9cmd echo substitute('Hallo', 'a', 'e', true) # E1174: String...
23382338
<
2339-
One consequence is that the item type of a list or dict given to |map()| must
2340-
not change when its type is either declared or inferred. For example, this
2341-
gives an error in Vim9 script, whereas in legacy Vim script it is allowed: >vim
2339+
結果として、|map()| に渡されるリストまたは辞書の項目の型は、その型が宣言または
2340+
推論された場合でも変更してはいけない。例えば、これは Vim9 script ではエラーに
2341+
なるが、旧来の Vim script では許可される: >vim
23422342

2343-
" legacy Vim script changes s:mylist to ['item 0', 'item 1']
2343+
" 旧来の Vim script s:mylist ['item 0', 'item 1'] に変更する
23442344
let s:mylist = [0, 1]
23452345
call map(s:mylist, {i -> $"item {i}"})
23462346
echo s:mylist
23472347
< >vim9
23482348
vim9script
2349-
var mylist = [0, 1] # Vim infers mylist is list<number>
2349+
var mylist = [0, 1] # Vim は mylist が list<number>
2350+
# あると推測する
23502351
map(mylist, (i, _) => $"item {i}") # E1012: type mismatch...
23512352
<
23522353
The error occurs because `map()` tries to modify the list elements to strings,
@@ -2850,13 +2851,13 @@ U、Aなど)。複数の文字で構成されている場合もあるが、名
28502851

28512852
vim9script
28522853
My1558<number>()
2853-
# Vim(eval):E1558: Unknown generic function: My1558
2854+
# E1558: Unknown generic function: My1558
28542855
< >vim9
28552856
vim9script
28562857
def My1560(): void
28572858
enddef
28582859
My1560<string>()
2859-
# Vim(echo):E1560: Not a generic function: My1560
2860+
# E1560: Not a generic function: My1560
28602861
<
28612862
*E1561*
28622863
型パラメータ名は他の識別子と競合してはならない: >vim9

en/vim9.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2876,13 +2876,13 @@ errors: >vim9
28762876

28772877
vim9script
28782878
My1558<number>()
2879-
# Vim(eval):E1558: Unknown generic function: My1558
2879+
# E1558: Unknown generic function: My1558
28802880
< >vim9
28812881
vim9script
28822882
def My1560(): void
28832883
enddef
28842884
My1560<string>()
2885-
# Vim(echo):E1560: Not a generic function: My1560
2885+
# E1560: Not a generic function: My1560
28862886
<
28872887
*E1561*
28882888
Type parameter names must not clash with other identifiers: >vim9

0 commit comments

Comments
 (0)