Ken Takata wrote:

> 2016/7/18 Mon 11:26:23 UTC+9 Ken Takata wrote:
> > Hi,
> > 
> > 2016/7/17 Sun 21:26:29 UTC+9 itchyny wrote:
> > > I additionally submit another test case.
> > > 
> > > let Y = {f -> (({x -> f ({y -> x(x)(y)})}) ({x -> f ({y -> x(x)(y)})}))}
> > > let Fact = {f -> {x -> (x == 0 ? 1 : x * f(x - 1))}}
> > > echo Y(Fact)(5)
> > > 
> > > I expect this script prints 120 but I got E110: Missing ')' in 7.4.2049 
> > > (and also with the experimental patch).
> > > Is there something wrong with the above code or is there some bug in the 
> > > parsing code in eval.c?
> > > 
> > > Here are the counterparts in Python
> > > Y = lambda f: (lambda x: f (lambda y: x(x)(y))) (lambda x: f (lambda y: 
> > > x(x)(y)))
> > > Fact = lambda f: lambda x: (1 if x == 0 else x * f(x - 1))
> > > print Y(Fact)(5)
> > > 
> > > and in JavaScript
> > > var Y = function(f){ return (function(x){ return f (function(y){ return 
> > > x(x)(y); }); }) (function(x){ return f (function(y){ return x(x)(y); }); 
> > > }); };
> > > var Fact = function(f){ return function(x){ return (x == 0 ? 1 : x * f(x 
> > > - 1)); }; };
> > > console.log(Y(Fact)(5));
> > > 
> > > reference: 
> > > https://en.wikipedia.org/wiki/Lambda_calculus#Recursion_and_fixed_points, 
> > > https://en.wikipedia.org/wiki/Fixed-point_combinator#Fixed_point_combinators_in_lambda_calculus
> > 
> > I have updated the patch for the latest code:
> > https://bitbucket.org/k_takata/vim-ktakata-mq/src/006cdbbeef26201154d04b7dfe1aed119321acb1/lambda-update.patch?at=default
> > 
> > The SEGV on test_alot.vim seems fixed.
> > 
> > 
> > > let Y = {f -> (({x -> f ({y -> x(x)(y)})}) ({x -> f ({y -> x(x)(y)})}))}
> > 
> > This still causes errors. Not sure why. Simpler example would be better.
> 
> I have updated the patch:
> https://bitbucket.org/k_takata/vim-ktakata-mq/src/29d0a0ecfa23f70852fa3f5c33e15ea629cd17b4/lambda-update.patch?fileviewer=file-view-default
> 
> Now lambda expressions can access outer arguments. E.g.:
> 
>       :function Foo(arg)
>       :  return {x -> x + a:arg}
>       :endfunction
>       :let Bar = Foo(5)
>       :echo Bar(2)
>       7
> 
> And now I disable the "a:" prefix for the lambda's arguments:
> 
>       :function Foo(arg)
>       :  return {x -> a:x + a:arg}  " Error
>       :endfunction
> 
> "a:" is now used for outer arguments only.
> 
> 
> > > let Y = {f -> (({x -> f ({y -> x(x)(y)})}) ({x -> f ({y -> x(x)(y)})}))}
> > > let Fact = {f -> {x -> (x == 0 ? 1 : x * f(x - 1))}}
> > > echo Y(Fact)(5)
> 
> The above doesn't work, but the following works now:
> 
>    :let Y = {f -> (({x -> f ({y -> x(x)(y)})})({x -> f ({y -> x(x)(y)})}))}
>    :let Fact = {f -> {x -> (x == 0 ? 1 : x * f(x - 1))}}
>    :echo Y(Fact)(5)
>    120
> 
> The difference is a space between a lambda expression and its arguments.
> A similar example is here:
> 
>    let x = function('sin') (1) " E15
>    let x = function('sin')(1)  " OK
> 
> I'm not sure this is intended.

Yes, there should not be a space between the function and the (args).

> BTW, I will update the tests later.

Thanks, will look at it then.

-- 
    [clop clop]
MORTICIAN:  Who's that then?
CUSTOMER:   I don't know.
MORTICIAN:  Must be a king.
CUSTOMER:   Why?
MORTICIAN:  He hasn't got shit all over him.
                                  The Quest for the Holy Grail (Monty Python)

 /// 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/d/optout.

Raspunde prin e-mail lui