It is great to see the numbers. @Bram What about something like this so it
is 100% backwards compatible. The best part is that it works in current
vim8 without any errors.
function! s:greet(name) abort
"use strict"
echom a:name
endfunction
call s:greet('Vim9')
Javascript does this too.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode.
Here is their exact quotes from the website.
> Strict mode makes several changes to normal JavaScript semantics:
>
> 1. Eliminates some JavaScript silent errors by changing them to throw
> errors.
>
>
> 1. Fixes mistakes that make it difficult for JavaScript engines to
> perform optimizations: strict mode code can sometimes be made to run
> faster
> than identical code that's not strict mode.
>
>
> 1. Prohibits some syntax likely to be defined in future versions of
> ECMAScript.
>
>
Basically in strict mode it would still use a:name as the variable name but
it is no longer a dictionary. This way all new vimscript is 100% compatible
with old vimscript < 9
This one didn't work.
function! s:greet(name) strict
"use strict"
echom a:name
endfunction
call s:greet('Vim9')
The reason first one works without errors is because we are using " which
is a start of a comment.
Another option would be to do something like this so you don't have to peek
to the next line.
function! s:greet(name) abort " use strict
echom a:name
endfunction
call s:greet('Vim9')
We can come up with some magic comment to opt in to strict mode.
As for a:000 compatibility, that list can only exist in strict mode when
using ...
function! s:greet(name, ...) abort " use strict
echom a:name . json_encode(a:000)
endfunction
We could do the same with l:variables. In strict mode it is no longer a
dictionary but a direct ref.
To me backwards compatibility would be very important.
On Thursday, January 2, 2020 at 11:44:10 AM UTC-8, Bram Moolenaar wrote:
>
>
> I have created a repository for the Vim9 script experiments:
> https://github.com/brammool/vim9
>
> I did another measurement for a more realistic example, re-indenting a
> large number of lines. In old Vim script it would be:
>
> let totallen = 0
> for i in range(1, 100000)
> call setline(i, ' ' .. getline(i))
> let totallen += len(getline(i))
> endfor
>
> The timing differences are much smaller than for the computational
> example, but Vim9 script is clearly the fastest:
>
> Vim old: 0.853752
> Python: 0.304584
> Lua: 0.286573
> Vim new: 0.190276
>
> Compared to legacy Vim script it is a 4 times faster.
>
> If you want to look at the instructions that are used internally, the
> ":disassemble" command shows what's the compilation result. For
> example, this function:
>
> def VimNew(): number
> let totallen = 0
> for i in range(1, 100000)
> setline(i, ' ' .. getline(i))
> totallen += len(getline(i))
> }
> return totallen
> enddef
>
> Results in this:
>
> let totallen = 0
> 0 STORE 0 in $0
>
> for i in range(1, 100000)
> 1 STORE -1 in $1
> 2 PUSHNR 1
> 3 PUSHNR 100000
> 4 BCALL range(argc 2)
> 5 FOR $1 -> 21
> 6 STORE $2
>
> setline(i, ' ' .. getline(i))
> 7 LOAD $2
> 8 PUSHS " "
> 9 LOAD $2
> 10 BCALL getline(argc 1)
> 11 CONCAT
> 12 BCALL setline(argc 2)
> 13 DROP
>
> totallen += len(getline(i))
> 14 LOAD $0
> 15 LOAD $2
> 16 BCALL getline(argc 1)
> 17 BCALL len(argc 1)
> 18 ADDNR
> 19 STORE $0
>
> }
> 20 JUMP -> 5
> 21 DROP
>
> return totallen
> 22 LOAD $0
> 23 RETURN
>
>
> Obviously there is still an awful lot of work to be done. Fortunately,
> the numbers show it's worth it.
>
> --
> The Law of VIM:
> For each member b of the possible behaviour space B of program P, there
> exists
> a finite time t before which at least one user u in the total user space U
> of
> program P will request b becomes a member of the allowed behaviour space
> B'
> (B' <= B).
> In other words: Sooner or later everyone wants everything as an option.
> -- Vince Negri
>
> /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net
> \\\
> /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/
> \\\
> \\\ an exciting new programming language -- http://www.Zimbu.org
> ///
> \\\ help me help AIDS victims -- http://ICCF-Holland.org
> ///
>
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/e473cdff-da8a-41b3-bf65-25e419b0d2ad%40googlegroups.com.