Marc Chantreux schrieb:
> hello Andy and thanks for reply.
>
> On Mon, Nov 09, 2009 at 06:33:24PM +0100, Andy Wokula wrote:
>> It is possible, the second argument to map() must be a string:
>> :h map()
>> :let t = map(["foo", "bar"], '{v:val : 1}')
>
> i tried this solution but the result is
>
> [{'foo': 1}, {'bar': 1}]
>
> when i expect
>
> {'foo': 1, 'bar': 1 }
>
> regards
>
> marc
Sorry, I didn't understand (dunno Perl).
I think you can't do it so nicely in Vim, but you can try the
following:
" helper to keep the list unchanged (not required):
func! KeepVal(_)
return v:val
endfunc
let in_list = ["foo", "bar"]
let out_dict = {}
call map(in_list, 'KeepVal(extend(out_dict, {v:val : 1}))')
" not so nice:
" - extra command for initialising out_dict
" - return value of map() is useless here
--
Andy
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---