ZyX wrote:

> пятница, 31 мая 2013 г., 17:14:17 UTC+4 пользователь mattn написал:
> > Hi all.
> > 
> > filter() or map() is given {string} expression to compare the items. But 
> > sort() is given function name or funcref for that.
> > I hope to give expression to {func}.
> > 
> > I guess this is useful to call sort().
> > 
> > :echo sort([{"foo":3},{"foo":2},{"foo":4}], "v:lhs.foo - v:rhs.foo")
> > [{'foo': 2}, {'foo': 3}, {'foo': 4}]
> > 
> > Below is a patch. Please check and include.
> > This patch still allow to give string for function name.
> > 
> > https://gist.github.com/mattn/5684747
> > 
> > Thanks.
> > - Yasuhiro Matsumoto
> 
> I would prefer a patch for adding support for funcrefs in map/filter instead.
> 
> And it is also bad idea to only overload strings: if you need
> expressions here use special value (like "expr") in place of {dict},
> add second optional argument or whatever, but **do not silently allow
> invalid function names taking them as expression**. There already is a
> lot of places where vim shows strange behavior with otherwise invalid
> input, don't add yet another one.

Using strings here was just a quick way of making it work.  What we
would really need is some kind of lambda function.  So the argument
would be one of three types:
        expression - mainly for backwards compatibility, but also allows
                     building the functionality from pieces.
        function name or reference - for bigger functions
        lamba function - for small functions

That could be used in several places.

Implementing a lambda function is not trivial though.

-- 
Due knot trussed yore spell chequer two fined awl miss steaks.

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Raspunde prin e-mail lui