Sunday, February 28, 2010

Re: dictionary functions: Is there a "magic" missing-attribute method/function?

Tom Link wrote:
> I vaguely remember that such a thing exists but it could well be that
> I'm confusing vimscript with some other language.
>
> It there such a thing as a missing method/attribute function for
> dictionaries? So that I could write code like this:
[snip pseudo-code]
> Does such a fallback function exist? If not, is there a chance for it
> to be included in vimscript?


While I'm not sure I followed your pseudo-code (not being a ruby
programmer), I suspect you're reaching for the get() function
which allows an optional 3rd parameter for a default if the key
isn't in the dictionary:

let my_dict = {}
let non_existant_key = 'hello'
echo get(my_dict, non_existant_key, 42)
(prints "42")

which you can read about at

:help get()

Hope this helps,

-tim


--
You received this message from the "vim_use" 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

No comments: