I'm not talking about how you can do it. And I don't hope to discuss
about MapSort. We should discuss how sort function is improvable to do
it without copying your MapSort every time.

On 10/16/14, Andy Wokula <anw...@yahoo.de> wrote:
> Am 22.08.2014 um 02:05 schrieb mattn:
>> It need to do like below with MapSort()
>>
>> echo MapSort([{"foo":{"bar": "3"}}, {"foo":{"bar": "3 0"}}], '0 +
>> v:val["foo"]["bar"]')
>>
>> If using my patch, it is possible easy to avoid this.
>>
>> :echo sort(["3 0", "3 0 1"], "a:lhs < a:rhs")
>
> I suppose your examples should read as follows (?):
>      :echo MapSort([{"foo":{"bar": "3"}}, {"foo":{"bar": "3 0"}}],
> 'v:val.foo.bar')
>      :echo    sort([{"foo":{"bar": "3"}}, {"foo":{"bar": "3 0"}}],
> 'v:lhs.foo.bar < v:rhs.foo.bar')
>
> With MapSort(), you have to derive strings from you list items, as plain
> sort() can only compare strings.
>
> It's easy to turn positive integers into strings for comparison.
> (It's hard to turn floats into strings for comparison.)
>
>> And MapSort() can't look local variable in the expression. For example,
>> this doesn't work.
>
>> ---------------------------------------------------
>> function! s:foo()
>>    let rank = {"queen": 12, "king": 13}
>>    return MapSort(["queen", "king"], 'rank[v:val]')
>> endfunction
>> echo s:foo()
>
> It can use local variables, with a little change to the func sig:
>      MapSort(list, selexpr, ...)
> now you can place a:1, a:2, ... in your map expression:
>
> function! s:foo()
>      let rank = {"queen": 9, "king": 10}
>      return MapSort(["queen", "king"], 'NumStr(a:1[v:val])', rank)
> endfunction
> echo s:foo()
>
> (where NumStr() turns 9 into 'A9' and 10 into 'B10')
>
> --
> Andy
>


-- 
- Yasuhiro Matsumoto

-- 
-- 
You received this message from the "vim_dev" 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 because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to