2016-07-13 19:17 GMT+03:00 mattn <[email protected]>:
> On Wednesday, July 13, 2016 at 4:11:59 AM UTC+9, Bram Moolenaar wrote:
>
> Well, I wonder this lambda will be useful. At the first, we hoped to call
> statements in lambda. But the implementation you will include into vim can't
> do because it only allow expressions. It's similar to python's lambda.
> python's one doesn't allow statements. So usecase are limited to use. I don't
> have strong opinion but I'm thinking that this is an new expresssion or
> language for the lambda. It will demand to learn the new expression for the
> users.
Vim has `execute()`. Python-3 has `exec()` function (Python-2 has it
as a statement). Lambdas do not usually allow statements because they
are to be used in contexts which requires return value (e.g. in Python
this is sorted()/list.sort(), defaultdict(), re.sub[n] (BTW, it is
good idea to have `substitute(s, pattern, funcref, flags)` to work
like `substitute(s, pattern, '\=funcref(submatch(0), submatch(1), …)',
flags)`)). Lambdas are also used as a replacement for
`functools.partial` (python)/`function(fref, args, self)` (VimL) in
cases when they do not apply (e.g. when one needs to fix not the
first, but second or other arguments), but this requires closures.
If you need lambda with statement then most likely you are going to
create unreadable code. Good lambdas are *small*, all examples you
have shown in documentation are either
1. More readable with new lambda style. It is absolutely not needed to
write `return` and `a:` in `sort()` or `map()` callbacks.
2. Not practical. I still want to see an example of timer callback
which is used for more practical applications then testing timers
(like your echo) and yet is more readable with your variant of lambda
among variants a) :function, b) new lambda style (+ execute()!) and c)
your lambda style.
3. Needs closures and not lambdas. I would not really say that your
example with multiline lambda used for counter generator is better
then with :function. Though it actually needs no closures in the
current state:
function s:counter(x)
let d = {'x': a:x}
function d.counter()
let self.x += 1
return self.x
endfunction
return d.counter
endfunction
And there is no new language, expressions are already used in a number
of places.
>
> - mattn
--
--
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/d/optout.