I wrote:

> Patch 8.2.2204
> Problem:    Vim9: using -> both for method and lambda is confusing.
> Solution:   Use => for lambda in :def function.
> Files:      runtime/doc/vim9.txt, src/vim9compile.c, src/userfunc.c,
>             src/testdir/test_vim9_expr.vim

I thought I would give this a go and see how it works out.

The main advantage is that -> is only used for a method call, there is
no confusion with a lambda inside a dictionary literal.  And it mostly
looks like how Javascript does this:
        mapnew(list, (i, v) => i .. ": " .. v)


One problem I found is that supporting a statement block in {} is
interfering with a lambda that has only an expression and it is a
dictionary:

        var Lambda = (a) => {key: a}

        var Lambda = (a) => { command }

I think we can separate the two by requiring white space after the { for
a statement block, and requiring the key to be following the {
immediately for a dictionary.  That feels natural.

In case putting the key right after the { is a problem, it's always
possible to use a return statement:

        var Lambda = (a) => {
                return { key: a }
            }

Another thing is defining a lambda and calling it right away.
Previously the surrounding {} made it clear where the expression ends:
        list->{a -> a + b}()

Now it becomes ambiguous:
        list->(a) => a + b()

I think we can solve this by requiring putting the lambda in
parenthesis:
        list->((a) => a + b)()

This then also supports another form of getting a function reference:
        list->(Refs[1])()
This wasn't implemented yet.

Unless there are other doubts, I'll continue implementing lambda with =>
also at the script level, and later with the statement block.
And later remove the support for lambda with -> in Vim9 script.


-- 
hundred-and-one symptoms of being an internet addict:
28. You have comandeered your teenager's phone line for the net and even his
    friends know not to call on his line anymore.

 /// 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].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/202012241527.0BOFR7Sq3227458%40masaka.moolenaar.net.

Raspunde prin e-mail lui