Hari Krishna Dara wrote:

> I have been wanting this function for over 3years now, as a simpler
> workaround for the |todo| item:
> 
> 8   ":let Func().foo = value" should work, also when "foo" doesn't exist.
> 
> The idea is that when Func() returns a dict(), you should be able to
> set its "foo" key's value. With the set(), we can now achieve the same
> and even more (if set() returns the original list or dictionary for
> call chaining). E.g.,
> 
> call set(set(Func(), 'foo', 'foovalue'), 'bar', 'barvalue')
> 
> I was planning for an API for one of my plugins that returns
> dictionaries, and using this API and assembling the objects becomes
> unwieldy with all the temporary variables and assignments that are
> required without such a function.
> 
> Here is a patch that adds this function.  Bram, please accept this
> patch into official source if you don't see any issues with it.

Hmm, set() sounds very generic, setItem() might be better.

For the list situation, what does it add over the use of an index:

        call set(list, idx, val)
        let list[idx] = val

Don't these two commands do exactly the same?

Similarly, for at dict:
        call set(dict, key, val)
        let dict[key] = val

The problem is that using a function doesn't work:
        let GetList()[idx] = val
        let GetDict()[key] = val

Instead of implementing set(), wouldn't it be better to implement this?


-- 
Eight Megabytes And Continually Swapping.

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\        download, build and distribute -- http://www.A-A-P.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Raspunde prin e-mail lui