2016-07-19 17:15 GMT+03:00 Nikolay Aleksandrovich Pavlov <[email protected]>:
> 2016-07-19 16:46 GMT+03:00 Ken Takata <[email protected]>:
>> Hi,
>>
>> 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
>
> What happens in case of
>
> function Foo(arg)
> let d = {}
> let d.f = {-> d}
> return d.f
> endfunction
> let i = 0
> while i < 1000000 | call Foo() | endwhile
>
> ? Specifically I suspect memory leak here because lambdas now are
> (implicit) containers, but you did not touch GC.
Forgot `let i += 1`. Though it should still be interruptible by
`<C-c>`, so `while 1` may even be better for a quick test: if
everything is fine, memory usage will drop after `<C-c>`, but may
increase before (AFAIR, by default full GC which checks for cycles is
run at main loop when waiting for characters). If not, it will not.
>
> Also you should not omit using dict_alloc(). `copy_vars()` looks like
> something that should be in dict.c. Also it looks like something that
> is already implemented: looks much like extend(), so you probably just
> need to employ `dict_extend()`. Probably modifying it, but I doubt
> that `copyitem = FALSE` is valid, wanting to see whether your example
> works with `let Bar = Foo("test: using allocated string")`.
>
> And, I guess, Bram will reject this because you copy the whole l: and
> a: dictionaries.
>
>>
>> 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.
>> BTW, I will update the tests later.
>>
>> 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.
--
--
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.