2016-04-20 12:35 GMT+03:00 Bram Moolenaar <[email protected]>:
>
> Bjorn Linse wrote:
>
>> > Internally a list with a NULL pointer is supposed to be handled like an
>> > empty list. This is efficient, but tricky. Nikolai just sent a patch,
>> > hopefully that helps.
>>
>> Good, but I wonder if it is not better for getreg("a",1,1) to always
>> return a mutable list (an empty mutable list in this case)? Because as
>> it returns a mutable list for a register with contents (
>> setreg("a",'x') ) or an empty one ( setreg("a",'') ) a plugin writer
>> might come to expect that it always returns a fresh mutable list, but
>> this then fails for an undefined register ( setreg("a",[]) ). Isn't
>> API consistency better that a little bit of efficiency, in this case?
>
> The NULL is supposed to be the same as an empty, mutable list. This is
> tricky, because code that expects a list needs to check for the NULL and
> create the list if needed.
This really cannot be mutable. In many cases all function has is
typval_T* pointing to a copy of typval_T that is allocated on a stack:
e.g. `func_call` does this. Obviously changes to such typval_T* do not
affect what is stored in tho original variable. I guess fixing this
will be a major refactoring.
In addition to this
let foo = v:_null_list
let bar = foo
call add(foo, 1)
What should `bar` contain? If it is mutable empty list then it should
contain `[1]` like in
let foo = []
let bar = foo
call add(foo, 1)
but how you are going to implement this with NULL list?
>
> An alternative would be to create an empty list instead of using a NULL.
> However, that requires memory allocation and there will still always be
> the chance of getting a NULL anyway (out of memory, mistake in the code).
>
> We could also consider NULL and invalid list, but I would think that
> puts the burden on the script writer.
>
> --
> GUARD #1: What, ridden on a horse?
> ARTHUR: Yes!
> GUARD #1: You're using coconuts!
> ARTHUR: What?
> GUARD #1: You've got two empty halves of coconut and you're bangin' 'em
> together.
> The Quest for the Holy Grail (Monty Python)
>
> /// 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].
> For more options, visit https://groups.google.com/d/optout.
--
--
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].
For more options, visit https://groups.google.com/d/optout.