comparison README_VIM9.md @ 22958:e7c125224b1a

Update runtime files Commit: https://github.com/vim/vim/commit/4466ad6baa22485abb1147aca3340cced4778a66 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Nov 21 13:16:30 2020 +0100 Update runtime files
author Bram Moolenaar <Bram@vim.org>
date Sat, 21 Nov 2020 13:30:04 +0100
parents 17c4178f26ea
children ef454a7f485d
comparison
equal deleted inserted replaced
22957:80212aa40750 22958:e7c125224b1a
157 mechanisms that are commonly known, ideally with the same syntax. One 157 mechanisms that are commonly known, ideally with the same syntax. One
158 thing I have been thinking of is assignments without ":let". I often 158 thing I have been thinking of is assignments without ":let". I often
159 make that mistake (after writing JavaScript especially). I think it is 159 make that mistake (after writing JavaScript especially). I think it is
160 possible, if we make local variables shadow commands. That should be OK, 160 possible, if we make local variables shadow commands. That should be OK,
161 if you shadow a command you want to use, just rename the variable. 161 if you shadow a command you want to use, just rename the variable.
162 Using "let" and "const" to declare a variable, like in JavaScript and 162 Using "var" and "const" to declare a variable, like in JavaScript and
163 TypeScript, can work: 163 TypeScript, can work:
164 164
165 165
166 ``` vim 166 ``` vim
167 def MyFunction(arg: number): number 167 def MyFunction(arg: number): number
168 let local = 1 168 var local = 1
169 let todo = arg 169 var todo = arg
170 const ADD = 88 170 const ADD = 88
171 while todo > 0 171 while todo > 0
172 local += ADD 172 local += ADD
173 --todo 173 todo -= 1
174 endwhile 174 endwhile
175 return local 175 return local
176 enddef 176 enddef
177 ``` 177 ```
178 178
190 function and export it: 190 function and export it:
191 191
192 ``` vim 192 ``` vim
193 vim9script " Vim9 script syntax used here 193 vim9script " Vim9 script syntax used here
194 194
195 let local = 'local variable is not exported, script-local' 195 var local = 'local variable is not exported, script-local'
196 196
197 export def MyFunction() " exported function 197 export def MyFunction() " exported function
198 ... 198 ...
199 199
200 def LocalFunction() " not exported, script-local 200 def LocalFunction() " not exported, script-local
246 end 246 end
247 END 247 END
248 return luaeval('sum') 248 return luaeval('sum')
249 endfunc 249 endfunc
250 250
251 def VimNew() 251 def VimNew(): number
252 let sum = 0 252 var sum = 0
253 for i in range(1, 2999999) 253 for i in range(1, 2999999)
254 let sum += i 254 sum += i
255 endfor 255 endfor
256 return sum 256 return sum
257 enddef 257 enddef
258 258
259 let start = reltime() 259 let start = reltime()
275 275
276 ## Code for indent time measurements 276 ## Code for indent time measurements
277 277
278 ``` vim 278 ``` vim
279 def VimNew(): number 279 def VimNew(): number
280 let totallen = 0 280 var totallen = 0
281 for i in range(1, 100000) 281 for i in range(1, 100000)
282 setline(i, ' ' .. getline(i)) 282 setline(i, ' ' .. getline(i))
283 totallen += len(getline(i)) 283 totallen += len(getline(i))
284 endfor 284 endfor
285 return totallen 285 return totallen