@@ -145,20 +145,20 @@ Vi において # は行番号付きでテキストを表示します。Vim9 scr
145
145
var name = value # コメント
146
146
var name = value# エラー!
147
147
< *E1170*
148
- Do not start a comment with #{, it looks like the legacy dictionary literal
149
- and produces an error where this might be confusing. #{{ or #{{{ are OK,
150
- these can be used to start a fold.
151
-
152
- When starting to read a script file Vim doesn't know it is | Vim9 | script until
153
- the ` vim9script ` command is found. Until that point you would need to use
154
- legacy comments : >
155
- " legacy comment
148
+ コメントを #{ で始めてはいけません。旧来の Vim script の辞書リテラルとにてお
149
+ り、どちらか判別がつきにくいところではエラーになるからです。折り畳みの開始に使
150
+ える #{{ や #{{{ はコメントの始まりになっても良いです。
151
+
152
+ スクリプトファイルの先頭では、 Vim は ` vim9script ` コマンドが見つかるまでそのス
153
+ クリプトが | Vim9 | スクリプトかを知るすべがありません。なのでその行までは旧来の
154
+ コメントを使う必要があります。 : >
155
+ " 旧来のコメント
156
156
vim9script
157
- # Vim9 comment
157
+ # Vim9 のコメント
158
158
159
- That looks ugly, better put `vim9script ` in the very first line : >
159
+ これは不恰好なので、 `vim9script ` を一番最初の行に書くのが良いでしょう : >
160
160
vim9script
161
- # Vim9 comment
161
+ # Vim9 コメント
162
162
163
163
旧来の Vim script では # は代替ファイル名としても使われます。Vim9 scriptでは、
164
164
代わりに %% を使う必要があります。## の代わりに %%% を使います。(すべての引数
@@ -175,34 +175,39 @@ Vim9 関数 ~
175
175
176
176
コンパイルは以下のいずれかのタイミングで実行されます:
177
177
- 関数が最初に呼び出されるとき
178
- - when the `:defcompile ` command is encountered in the script after the
179
- function was defined
178
+ - 関数が定義された後ろの位置で、スクリプト中に `:defcompile ` コマンドが見つ
179
+ かったとき
180
180
- 関数に対してコマンド `:disassemble ` が実行されたとき
181
181
- コンパイルされた関数から呼び出されたり、関数リファレンスとして使用されたとき
182
182
(引数と戻り値の型をチェックできるようにするため)
183
183
*E1091* *E1191*
184
- If compilation fails it is not tried again on the next call, instead this
185
- error is given: "E1091: Function is not compiled: {name} ".
186
- Compilation will fail when encountering a user command that has not been
187
- created yet. In this case you can call `execute ()` to invoke it at runtime. >
184
+ もし関数のコンパイルに失敗した場合は、次その関数が呼ばれるときまで再度コンパイ
185
+ ルを試みることはなく、代わりに "E1091: Function is not compiled: {name} " とい
186
+ うエラーを発生させます。
187
+ {訳注: 日本語メッセージの場合: "E1091: 関数はコンパイルされていません: {name} "}
188
+ コンパイルはまだ作成されていないユーザーコマンドと遭遇したときに失敗するでしょ
189
+ う。この場合は `execute ()` を使うことでエラーを関数の実行時に発生するようにす
190
+ ることができます。 >
188
191
def MyFunc()
189
192
execute('DefinedLater')
190
193
enddef
191
194
192
- `:def ` has no options like `:function ` does: "range", "abort", "dict" or
193
- "closure". A `:def ` function always aborts on an error (unless `:silent ! ` was
194
- used for the command or the error was caught a `:try ` block), does not get a
195
- range passed, cannot be a "dict" function, and can always be a closure.
195
+ `:def ` は `:function ` が持っているようなオプションを持っていません:
196
+ "range"、"abort"、"dict" や "closure" のこと。`:def ` で定義される関数は常にエ
197
+ ラーが発生し次第、実行を中断します (`:silent ! ` がコマンドに対して使われた場合
198
+ やエラーが `:try ` ブロック内で捕捉された場合でない限り) 。また与えられた「範
199
+ 囲」も受け取らず、"dict" 属性を持つ関数になることもできません。そして常にク
200
+ ロージャとなれます。
196
201
*vim9-no-dict-function*
197
- Later classes will be added, which replaces the "dict function" mechanism.
198
- For now you will need to pass the dictionary explicitly : >
202
+ いずれ、「辞書関数」機構を置き換えるクラスが追加されるでしょう。当面は明示的に
203
+ 辞書を渡す必要があります。 : >
199
204
def DictFunc(self: dict<any>, arg: string)
200
205
echo self[arg]
201
206
enddef
202
207
var ad = {item: 'value', func: DictFunc}
203
208
ad.func(ad, 'item')
204
209
205
- You can call a legacy dict function though : >
210
+ 一方、旧来の辞書関数を呼ぶことはできます : >
206
211
func Legacy() dict
207
212
echo self.value
208
213
endfunc
@@ -224,32 +229,32 @@ You can call a legacy dict function though: >
224
229
for item in itemlist
225
230
...
226
231
227
- When a function argument is optional (it has a default value) passing `v: none `
228
- as the argument results in using the default value. This is useful when you
229
- want to specify a value for an argument that comes after an argument that
230
- should use its default value. Example: >
232
+ 関数の引数が任意 (引数に規定値が指定されいる場合) のときは、その引数に
233
+ `v: none ` を渡すことでその規定値を使うことができる。これは規定値を使いたい引数
234
+ の後ろの引数に値を指定したいときに便利です。例: >
231
235
def MyFunc(one = 'one', last = 'last')
232
236
...
233
237
enddef
234
- MyFunc(v:none, 'LAST') # first argument uses default value 'one'
238
+ MyFunc(v:none, 'LAST') # 第一引数は規定値の 'one' を使う
235
239
<
236
240
*vim9-ignored-argument* *E1181*
237
- The argument "_" (an underscore) can be used to ignore the argument. This is
238
- most useful in callbacks where you don't need it, but do need to give an
239
- argument to match the call. E.g. when using map() two arguments are passed,
240
- the key and the value, to ignore the key : >
241
+ 引数 "_" (アンダースコア) は引数を無視するのに使えます。これは使わないが呼び出
242
+ す際に一致するように引数を与えないといけないようなコールバックにおいて一番便利
243
+ です。たとえば、 map() を使っていて、キーと値の 2 つの引数が与えられる時に引数
244
+ のキーを無視するには : >
241
245
map(numberList, (_, v) => v * 2)
242
- There is no error for using the "_" argument multiple times. No type needs to
243
- be given.
246
+ 引数に "_" を複数回使ってもエラーにはなりません。また、型も指定する必要はあり
247
+ ません。
244
248
245
249
246
250
関数と変数はデフォルトでスクリプトローカル ~
247
251
*vim9-scopes*
248
- Vim9 script でスクリプト直下に `:function ` や `:def ` を使って関数を定義すると、
249
- 関数はプリフィックス "s:" をつけた際のように、スクリプトローカルで定義されま
250
- す。グローバルスコープの関数や変数を定義するにはプリフィックス "g:" をつける必
251
- 要があります。 For functions in a script that is to be imported and in an
252
- autoload script "export" needs to be used for those to be used elsewhere. >
252
+ Vim9 script でスクリプト直下に `:function ` や `:def ` を使って関数を定義する
253
+ と、関数はプリフィックス "s:" をつけた際のように、スクリプトローカルで定義され
254
+ ます。グローバルスコープの関数や変数を定義するにはプリフィックス "g:" をつける
255
+ 必要があります。 スクリプト内の関数のうち他のスクリプトからインポートされるも
256
+ のとオートロードスクリプト内の関数について、他のスクリプトで利用できるようにす
257
+ るためには "export" をつける必要があります。 >
253
258
def ThisFunction() # スクリプトローカル
254
259
def g:ThatFunction() # グローバル
255
260
export def Function() # for import and import autoload
0 commit comments