Re: Patch 8.2.4526

2022-03-08 Fir de Conversatie Ernie Rael

On 3/8/22 11:44 AM, Bram Moolenaar wrote:

On 3/8/22 5:20 AM, Bram Moolenaar wrote:

Patch 8.2.4526
Problem:Vim9: cannot set variables to a null value.
Solution:   Add null_list, null_job, etc.

How about an "is_null(t: any): bool" method, (or "isnull()")? I could
roll my own, but the "if else if else ..." seems expensive. (unless it
gets optimized internally into a switch-case :-) )

What is it you want to do?  We recently added support for comparing with
"null".  That will match all the null_* values.  Thus allo of these are
true:
null == null_string
null == null_blob
null == null_list
null == null_function
null == null_job


In the previous discussion I had thought that givenĀ  var t:string,
it was necessary to do "if t is null_string" to test if it is
really null. I'm looking for a way to test for really null uniformly
no matter the type, and without noting if I need to use "is".

I'll build a new vim today and run some experiments, which I should
have done before posting the message.

-ernie


Still need to add some more tests.  It worked with the functions before,
so it should work with the value as well.



--
--
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 vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/7892cf16-45c8-1dab-845f-0df5189f35d2%40raelity.com.


Re: Patch 8.2.4526

2022-03-08 Fir de Conversatie Bram Moolenaar


> On 3/8/22 5:20 AM, Bram Moolenaar wrote:
> > Patch 8.2.4526
> > Problem:Vim9: cannot set variables to a null value.
> > Solution:   Add null_list, null_job, etc.
> 
> How about an "is_null(t: any): bool" method, (or "isnull()")? I could 
> roll my own, but the "if else if else ..." seems expensive. (unless it 
> gets optimized internally into a switch-case :-) )

What is it you want to do?  We recently added support for comparing with
"null".  That will match all the null_* values.  Thus allo of these are
true:
null == null_string
null == null_blob
null == null_list
null == null_function
null == null_job

Still need to add some more tests.  It worked with the functions before,
so it should work with the value as well.

-- 
hundred-and-one symptoms of being an internet addict:
206. You religiously respond immediately to e-mail, while ignoring
 your growing pile of snail mail.

 /// Bram Moolenaar -- b...@moolenaar.net -- http://www.Moolenaar.net   \\\
///  \\\
\\\sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\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 vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20220308194413.7925E1C0A2F%40moolenaar.net.


Re: Patch 8.2.4526

2022-03-08 Fir de Conversatie Ernie Rael

On 3/8/22 5:20 AM, Bram Moolenaar wrote:

Patch 8.2.4526
Problem:Vim9: cannot set variables to a null value.
Solution:   Add null_list, null_job, etc.


How about an "is_null(t: any): bool" method, (or "isnull()")? I could 
roll my own, but the "if else if else ..." seems expensive. (unless it 
gets optimized internally into a switch-case :-) )


-ernie

--
--
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 vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/b5ff48fa-c857-ecab-9aef-ed0b807aabd7%40raelity.com.


Patch 8.2.4526

2022-03-08 Fir de Conversatie Bram Moolenaar


Patch 8.2.4526
Problem:Vim9: cannot set variables to a null value.
Solution:   Add null_list, null_job, etc.
Files:  runtime/doc/vim9.txt, src/eval.c, src/proto/eval.pro,
src/vim9expr.c, src/vim9script.c, src/vim9instr.c,
src/vim9compile.c, src/vim9execute.c, src/vim9.h, src/vim9type.c,
src/evalvars.c, src/testdir/test_vim9_assign.vim,
src/testdir/test_vim9_disassemble.vim,
src/testdir/test_vim9_func.vim, src/testdir/test_expr.vim


*** ../vim-8.2.4525/runtime/doc/vim9.txt2022-02-22 20:42:50.382992530 
+
--- runtime/doc/vim9.txt2022-03-07 21:26:34.420871466 +
***
*** 94,101 
def CallMe(count: number, message: string): bool
  - Call functions without `:call`: >
writefile(['done'], 'file.txt')
! - You cannot use old Ex commands `:xit`, `:t`, `:k`, `:append`, `:change`,
!   `:insert`, `:open`, and `:s` or `:d` with only flags.
  - You cannot use curly-braces names.
  - A range before a command must be prefixed with a colon: >
:%s/this/that
--- 94,113 
def CallMe(count: number, message: string): bool
  - Call functions without `:call`: >
writefile(['done'], 'file.txt')
! - You cannot use old Ex commands:
!   `:Print`
!   `:append`
!   `:change`
!   `:d`  directly followed by 'd' or 'p'.
!   `:insert`
!   `:k`
!   `:mode`
!   `:open`
!   `:s`  with only flags
!   `:t`
!   `:xit`
! - Some commands, especially those used for flow control, cannot be shortened.
!   E.g., `:throw` cannot be written as `:th`. *E839*
  - You cannot use curly-braces names.
  - A range before a command must be prefixed with a colon: >
:%s/this/that
***
*** 923,933 
  
  Simple types are Number, Float, Special and Bool.  For other types |string()|
  should be used.
!   *false* *true* *null*
! In Vim9 script one can use "true" for v:true, "false" for v:false and "null"
! for v:null.  When converting a boolean to a string "false" and "true" are
! used, not "v:false" and "v:true" like in legacy script.  "v:none" is not
! changed, it is only used in JSON and has no equivalent in other languages.
  
  Indexing a string with [idx] or taking a slice with [idx : idx] uses character
  indexes instead of byte indexes.  Composing characters are included.
--- 966,1003 
  
  Simple types are Number, Float, Special and Bool.  For other types |string()|
  should be used.
!   *false* *true* *null* *E1034*
! In Vim9 script one can use the following predefined values: >
!   true
!   false
!   null
!   null_blob
!   null_channel
!   null_dict
!   null_function
!   null_job
!   null_list
!   null_partial
!   null_string
! `true` is the same as `v:true`, `false` the same as `v:false`, `null` the same
! as `v:null`.
! 
! While `null` has the type "special", the other "null_" types have the type
! indicated by their name.  Quite often a null value is handled the same as an
! empty value, but not always.  The values can be useful to clear a script-local
! variable, since they cannot be deleted with `:unlet`.  E.g.: >
!   var theJob = job_start(...)
!   # let the job do its work
!   theJob = null_job
! 
! The values can also be useful as the default value for an argument: >
!   def MyFunc(b: blob = null_blob)
!  if b == null_blob
! # b argument was not given
! 
! When converting a boolean to a string `false` and `true` are used, not
! `v:false` and `v:true` like in legacy script.  `v:none` has no `none`
! replacement, it has no equivalent in other languages.
  
  Indexing a string with [idx] or taking a slice with [idx : idx] uses character
  indexes instead of byte indexes.  Composing characters are included.
*** ../vim-8.2.4525/src/eval.c  2022-02-13 21:51:02.392484124 +
--- src/eval.c  2022-03-07 21:40:00.798772322 +
***
*** 943,948 
--- 943,949 
type_list = _ITEM(current_sctx.sc_sid)->sn_type_list;
else
{
+   // TODO: should we give an error here?
type_list = _type_list;
ga_init2(type_list, sizeof(type_T), 10);
}
***
*** 3483,3488 
--- 3484,3583 
  }
  
  /*
+  * Check for a predefined value "true", "false" and "null.*".
+  * Return OK when recognized.
+  */
+ int
+ handle_predefined(char_u *s, int len, typval_T *rettv)
+ {
+ switch (len)
+ {
+   case 4: if (STRNCMP(s, "true", 4) == 0)
+   {
+   rettv->v_type = VAR_BOOL;
+   rettv->vval.v_number = VVA