On 13 August 2010 00:55, Tom Link <[email protected]> wrote: >> Or is there an alternate method to accessing dictionary when the key >> is not found >> , instead of showing error directly? > > You can use get() -- see :help get() > > I have once created a simple prototype-like library that provides for > defining a method that returns default values: > http://github.com/tomtom/prototype_vim > > Example (fib with memoization): > > let x = prototype#New() > let ncalls = 0 > function! x.__Default(n) dict > let g:ncalls += 1 > if a:n <= 1 > let self[a:n] = a:n > else > let self[a:n] = self.__Get(a:n - 2) + self.__Get(a:n - 1) > endif > endfunction > Should be equal map(range(0, 10), 'x.__Get(v:val)'), > \ [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55] > Should be equal x.__Get(10), 55 > Should be equal ncalls, 11 > > If that was, what you were asking for.
Thanks so much. I will study the code. > > -- > 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 > -- 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
