1. Partial function application.
2. Sorting with sort().
In frawor I constantly use generated functions that look like
function d.F(...)
return call(s:features['plugid'].name.func, [s:plugdicts['userplugid'], s:shadowdicts['userplugid']]+a:000, {})
endfunction
'plugid', .name, .func, 'userplugid' are all generated. This can be reduced to just "\...: call(feature[name].func, [plugdict, shadowdict]+a:000, {})". Still needs eval, unless p 1. is used, but already more lightweight.
Third use is completely hiding the variables: shadowdict in the example can be generated in the function that exports features and not ever recorded in any global.
Based on this uses I should stick with 1. If partial application is dropped or be considered to be allowed to be suboptimal sticking with 0. is an option.
By the way, the first person I saw requesting lambdas is Bram in discussion to sort() proposed patch that will make sort() accept expressions. Thus the main reasoning was "sort() and partial application are good, but not enough. As it is relatively simple to add lambdas to my patch let us add them and see whether they will make Bram accept patch faster." Patch is incomplete without making map() and filter() accept funcrefs, but this is really trivial. RFC is here because maybe Bram sees more uses for lambdas then me. Quote:
> 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.
> /lcd
Expressions are invalid for :execute. I do not understand how &*expr options are related.
Note that no string expressions take variable values with them. I am not much fond of the workaround where expression accesses them from some global variable. It is bad for GC: generally you cannot know when expression and attached variables are no longer needed. Globals are always bad for threading, if this will ever go into vim. It adds a bunch of unneeded code: generate global name, record value there, put name into the expression.
>
> Best regards,
> Tony.
> --
> "It is always tempting to divide men into two lots: Greeks and barbarians,
> Muslims and infidels, those who believe in God and those who don't. But who
> does not fear to understand things that threaten his beliefs? Of course,
> one is not consciously afraid; but everybody who is honest with himself
> finds that often he does not try very hard to understand what clashes
> with his deep convictions."
> [Walter Kaufmann, "The Faith of a Heretic"]
>
>
> --
> --
> 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+u...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
As I said earlier I do not need lambdas much. They are good for frawor, but I sometimes think about writing python version of frawor rather then improving its VimL variant.
I do find references to python callables handy though. Lambdas are an example of what one can relatively easy to do with a new branch which provides funcrefs to python functions. They also fulfill a request from Bram I quoted earlier. If I really was writing this for frawor then you would see some better designed code as a part of extended-funcref branch and no RFC.
> -- regards, ingo