# HG changeset patch # User John W. Eaton # Date 1328737060 18000 # Node ID 4687ecec05862ad052989af3ee22b509d29b50d9 # Parent a8a2d5def558816bdc7fcd71f67dc02c6eca0e98 make test for bug 31371 work * test_bug_31371.m: Use fcn instead of f to avoid apparent conflict when running test suite. Use proper paren nesting for assert call. diff -r a8a2d5def558 -r 4687ecec0586 test/test_bug_31371.m --- a/test/test_bug_31371.m Sun Feb 05 23:37:36 2012 -0500 +++ b/test/test_bug_31371.m Wed Feb 08 16:37:40 2012 -0500 @@ -1,19 +1,20 @@ %!test %! % Work around MATLAB bug where f(x)(y) is invalid syntax %! % (This bug does not apply to Octave) -%! C = @(f,x) f(x); -%! C2 = @(f,x,y) f(x,y); +%! +%! C = @(fcn,x) fcn(x); +%! C2 = @(fcn,x,y) fcn(x,y); %! %! % Church Booleans %! T = @(t,f) t; %! F = @(t,f) f; %! %! % Church Numerals -%! Zero = @(f,x) x; -%! One = @(f,x) f(x); -%! Two = @(f,x) f(f(x)); -%! Three = @(f,x) f(f(f(x))); -%! Four = @(f,x) f(f(f(f(x)))); +%! Zero = @(fcn,x) x; +%! One = @(fcn,x) fcn(x); +%! Two = @(fcn,x) fcn(fcn(x)); +%! Three = @(fcn,x) fcn(fcn(fcn(x))); +%! Four = @(fcn,x) fcn(fcn(fcn(fcn(x)))); %! %! % Arithmetic Operations %! Inc = @(a) @(f,x) f(a(f,x)); % Increment @@ -23,18 +24,18 @@ %! Sub = @(a,b) b(Dec, a); %! %! % Renderer - Convert church numeral to "real" number -%! render = @(n) n(@(n) n+1,0); +%! Render = @(n) n(@(n) n+1,0); %! %! % Predicates -%! iszero = @(n) n(@(x) F, T); +%! Iszero = @(n) n(@(x) F, T); %! %! % Y combinator implements recursion -%! Y = @(f) C(@(g) f(@(x) C(g(g), x)), ... -%! @(g) f(@(x) C(g(g), x))); +%! Ycomb = @(f) C(@(g) f(@(x) C(g(g), x)), ... +%! @(g) f(@(x) C(g(g), x))); +%! +%! Factorial = Ycomb(@(f) @(n) C(C2(Iszero(n), ... +%! @(d) One, @(d) Mult(n, f(Dec(n)))),0)); %! -%! Factorial = Y(@(f) @(n) C(C2(iszero(n), ... -%! @(d) One, @(d) Mult(n, f(Dec(n)))),0)); -%! -%! assert (render(Factorial(Two), 2)) -%! assert (render(Factorial(Three), 3)) -%! assert (render(Factorial(Four), 12)) +%! assert (Render (Factorial (Two)), 2) +%! assert (Render (Factorial (Three)), 6) +%! assert (Render (Factorial (Four)), 24)