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:
let x = {}
function! x.__Missing__(name) dict
if a:name <= 1
let self[a:name] = a:name
else
let self[a:name] = self[a:name - 2] + self[a:name - 1]
endif
endfunction
echo map(range(0, 10), 'x[v:val]')
The equivalent ruby code would be:
x = Hash.new do |h, k|
case k
when 0, 1
h[k] = k
else
h[k] = h[k-2] + h[k-1]
end
end
0.upto(10).map {|n| x[n]}
# => [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
Does such a fallback function exist? If not, is there a chance for it
to be included in vimscript?
Regards,
Tom
--
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:
Post a Comment