Hi Bram and all,

2016/7/10 Sun 3:49:40 UTC+9 Bram Moolenaar wrote:
> Ken Takata wrote:
> 
> [...]
> 
> > > I do think that the backslash (or any other special character that might
> > > be available) makes it ugly.
> > > 
> > > Although we can find the end of the expression without the "}", mistakes
> > > will be very hard to figure out.  Also reading back a lambda that's
> > > passed as an agument to a function with many arguments will make the {}
> > > part easy to spot.  I have done this in Zimbu and I'm happy with how it
> > > looks.
> > > 
> > > I don't think it's hard to implement: When finding a "{" look forward,
> > > skipping over [a-zA-Z0-9 ], if "->" is found it's a lambda.
> > 
> > Here is an experimental patch:
> > 
> > https://bitbucket.org/k_takata/vim-ktakata-mq/src/90ea467da862bc2eaf59454f75b8faea34604a1e/lambda2.patch?fileviewer=file-view-default
> > 
> > * Support only one expression.
> > * The "a:" prefix cannot be omitted.
> > * No closures.
> > * Inefficient "{" parser.
> > 
> > Both mattn's patch and ZyX's code are partly used.
> > Nested lambdas are also supported like ZyX's example:
> > 
> >   :echo {a -> {tmp -> [a:tmp, a:tmp + 2, a:tmp + 5]}(a:a * 5)}(2)
> >   [10, 12, 15]
> > 
> > Hmm, it's hard to read.
> 
> Thanks for making the patch.  I think at a high level it looks good.
> 
> Like I mentioned, I don't think we should require "a:arg", just "arg".
> Perhaps in the function, instead of using a dict for local variables,
> use the dict for arguments.  After all, there are no local variables.
> 
> Seeing the documentation, and perhaps a few tests, may trigger some fine
> tuning.  So I hope you can do that.

I have updated the experimental patch:
https://bitbucket.org/k_takata/vim-ktakata-mq/src/6d421eab8842ba93c115d57c42fd9eabfa328851/lambda2.patch?fileviewer=file-view-default

Changes from the previous patches are:

* Supports both "a:arg" and "arg".  Named arguments are also added to the "l:"
  dictionary.
* Document update.

Maybe the following patch is also needed:
https://bitbucket.org/k_takata/vim-ktakata-mq/src/6d421eab8842ba93c115d57c42fd9eabfa328851/func-refcount.patch?fileviewer=file-view-default

This fix the reference counters for callbacks.


Lambda examples:
        :echo map([1, 2, 3], {idx, val -> val + 1})
        [2, 3, 4]

        :echo sort([3,7,2,1,4], {a, b -> a - b})
        [1, 2, 3, 4, 7]

        :echo {a -> {tmp -> [tmp, tmp + 2, tmp + 5]}(a * 5)}(2)
        [10, 12, 15]

        :let timer = timer_start(500,
                        \ {-> execute("echo 'Handler called'", "")},
                        \ {'repeat': 3})
        Handler called
        Handler called
        Handler called

Regards,
Ken Takata

-- 
-- 
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.

Raspunde prin e-mail lui