@@ -123,36 +123,35 @@ Vim9 script の変数は一度だけ `:let` もしくは `:const` コマンド
123
123
に変換し、そして任意の文字列は数値ではないため結果が0になるのです!
124
124
125
125
`:def ` だと型チェックが関数のコンパイル時に行われます。それによってあなたは引
126
- 数の型と戻り値の型の指定が必要になります。また引数は "a:" のプリフィックスが不
127
- 要だと注意されます : >
126
+ 数の型と戻り値の型の指定が必要になります。また引数は "a:" のプリフィックス無し
127
+ で使われることに注意してください : >
128
128
let s:collected = ''
129
129
def ExtendAndReturn(add: string): string
130
130
s:collected += add
131
131
return s:collected
132
132
enddef
133
133
defcompile
134
134
135
- Here we use `:defcompile ` to do the compilation right away, without it the
136
- compilation would happen when the function is called. Vim will tell you what
137
- you did wrong: >
135
+ ここで利用している `:defcompile ` はコンパイルするたの手段で、コンパイルさせる
136
+ のに関数を呼ばなくていいです。Vim はあなたが間違っていると警告します: >
138
137
E1013: type mismatch, expected number but got string
139
138
140
- Vim9 script is strict, it uses the "+" operator only for numbers and floats.
141
- For string concatenation ".." must be used. This avoids mistakes and avoids
142
- the automatic conversion that gave a surprising result above. So you change
143
- the first line of the function to : >
139
+ Vim9 script は厳密で、 "+" 演算子は数値か浮動小数点数でしか使えません。文字の結
140
+ 合であれば ".." を使わなくてはなりません。これが間違いの回避と上にあるような驚
141
+ きの結果をもたらす自動型変換を回避します。そして関数の最初の行をこう変化させれ
142
+ ば : >
144
143
s:collected ..= add
145
- And now it works.
144
+ 動くようになります。
146
145
147
- If the function does not return anything, just leave out the return type : >
146
+ もし関数がなにも返さないなら、戻り値の型は無くてよいです : >
148
147
def ReportResult(result: string)
149
148
echo 'The result is: ' .. result
150
149
enddef
151
150
152
- This is also checked, if you try to return a value you'll get an error.
151
+ これもまたチェックされ、もし値を返そうとすると、エラーとなるでしょう。
153
152
154
- In case you don't care about types or have a function that does work with
155
- multiple types, you can use the "any" type: >
153
+ あなたが型をケアしない場合や関数が多型で動くなら、"any" 型を使うことができます:
154
+ >
156
155
def Store(key: string, value: any)
157
156
resultDict[key] = value
158
157
enddef
0 commit comments