Prabir Shrestha wrote:

> 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

I don't see that.  If a: is no longer available as a dictionary it won't
be 100% compatible.  There are other subtle assumptions, e.g. about how
error messages are handled.  It will work like "abort" was present.
 
> 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.

An even easier way would be to try compile the function and if it fails
then assume it's not compatible.  Thus it is 100% backwards compatible,
and it will be faster without changing it to a "def" function.  It will
not be as fast as a "def" function, because types have to be checked at
runtime.  But it should be a lot faster than not compiling at all.

I'm not sure this is possible.  It will require very accurate checking
of the syntax.  We can give this a try at some point.  I first want to
make the "def" function compile, that is still quite a bit of work.


> 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.

It sounds more like forward compatibility: old code works better.

-- 
If cars evolved at the same rate as computers have, they'd cost five euro, 
run for a year on a couple of liters of petrol, and explode once a day.

 /// 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/202001031002.003A235C004401%40masaka.moolenaar.net.

Raspunde prin e-mail lui