[pure-lang-svn] SF.net SVN: pure-lang: [108] pure/trunk/test
Status: Beta
Brought to you by:
agraef
From: <ag...@us...> - 2008-05-23 01:24:15
|
Revision: 108 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=108&view=rev Author: agraef Date: 2008-05-22 18:24:21 -0700 (Thu, 22 May 2008) Log Message: ----------- Rename regression tests, so that they are executed in the right order. Added Paths: ----------- pure/trunk/test/test001.log pure/trunk/test/test001.pure pure/trunk/test/test002.log pure/trunk/test/test002.pure pure/trunk/test/test003.log pure/trunk/test/test003.pure pure/trunk/test/test004.log pure/trunk/test/test004.pure pure/trunk/test/test005.log pure/trunk/test/test005.pure pure/trunk/test/test006.log pure/trunk/test/test006.pure pure/trunk/test/test007.log pure/trunk/test/test007.pure pure/trunk/test/test008.log pure/trunk/test/test008.pure pure/trunk/test/test009.log pure/trunk/test/test009.pure pure/trunk/test/test010.log pure/trunk/test/test010.pure Removed Paths: ------------- pure/trunk/test/test1.log pure/trunk/test/test1.pure pure/trunk/test/test10.log pure/trunk/test/test10.pure pure/trunk/test/test2.log pure/trunk/test/test2.pure pure/trunk/test/test3.log pure/trunk/test/test3.pure pure/trunk/test/test4.log pure/trunk/test/test4.pure pure/trunk/test/test5.log pure/trunk/test/test5.pure pure/trunk/test/test6.log pure/trunk/test/test6.pure pure/trunk/test/test7.log pure/trunk/test/test7.pure pure/trunk/test/test8.log pure/trunk/test/test8.pure pure/trunk/test/test9.log pure/trunk/test/test9.pure Copied: pure/trunk/test/test001.log (from rev 88, pure/trunk/test/test1.log) =================================================================== --- pure/trunk/test/test001.log (rev 0) +++ pure/trunk/test/test001.log 2008-05-23 01:24:21 UTC (rev 108) @@ -0,0 +1,194 @@ +square x/*0:1*/ = x/*0:1*/*x/*0:1*/; +{ + rule #0: square x = x*x + state 0: #0 + <var> state 1 + state 1: #0 +} +square 5; +25 +fact1 n/*0:1*/ = n/*0:1*/*fact1 (n/*0:1*/-1) if n/*0:1*/>0; +fact1 n/*0:1*/ = 1; +{ + rule #0: fact1 n = n*fact1 (n-1) if n>0 + rule #1: fact1 n = 1 + state 0: #0 #1 + <var> state 1 + state 1: #0 #1 +} +{ + rule #0: x = fact1 10 + state 0: #0 + <var> state 1 + state 1: #0 +} +let x = fact1 10; +x; +3628800 +fact2 n/*0:1*/ = case n/*0:1*/ of n/*0:*/ = n/*0:*/*fact2 (n/*0:*/-1) if n/*0:*/>0; n/*0:*/ = 1 { + rule #0: n = n*fact2 (n-1) if n>0 + rule #1: n = 1 + state 0: #0 #1 + <var> state 1 + state 1: #0 #1 +} end; +fact3 n/*0:1*/ = case n/*0:1*/ of 0 = 1; n/*0:*/ = n/*0:*/*fact3 (n/*0:*/-1) if n/*0:*/>0 { + rule #0: 0 = 1 + rule #1: n = n*fact3 (n-1) if n>0 + state 0: #0 #1 + <var> state 1 + 0::int state 2 + state 1: #1 + state 2: #0 #1 +} end; +fact4 n/*0:1*/ = if n/*0:1*/>0 then n/*0:1*/*fact4 (n/*0:1*/-1) else 1; +fact5 = \n/*0:*/ -> if n/*0:*/>0 then n/*0:*/*fact5 (n/*0:*/-1) else 1 { + rule #0: n = if n>0 then n*fact5 (n-1) else 1 + state 0: #0 + <var> state 1 + state 1: #0 +}; +{ + rule #0: fact2 n = case n of n = n*fact2 (n-1) if n>0; n = 1 end + state 0: #0 + <var> state 1 + state 1: #0 +} +{ + rule #0: fact3 n = case n of 0 = 1; n = n*fact3 (n-1) if n>0 end + state 0: #0 + <var> state 1 + state 1: #0 +} +{ + rule #0: fact4 n = if n>0 then n*fact4 (n-1) else 1 + state 0: #0 + <var> state 1 + state 1: #0 +} +{ + rule #0: fact5 = \n -> if n>0 then n*fact5 (n-1) else 1 + state 0: #0 +} +fact2 10; +3628800 +fact3 10; +3628800 +fact4 10; +3628800 +fact5 10; +3628800 +fact n/*0:1*/::int = fact (bigint n/*0:1*/); +fact n/*0:1*/::bigint = n/*0:1*/*fact (n/*0:1*/-1) if n/*0:1*/>0; +fact n/*0:1*/::bigint = 1; +{ + rule #0: fact n::int = fact (bigint n) + rule #1: fact n::bigint = n*fact (n-1) if n>0 + rule #2: fact n::bigint = 1 + state 0: #0 #1 #2 + <var>::int state 1 + <var>::bigint state 2 + state 1: #0 + state 2: #1 #2 +} +fact 50; +30414093201713378043612608166064768844377641568960512000000000000L +fib1 0 = 0; +fib1 1 = 1; +fib1 n/*0:1*/ = fib1 (n/*0:1*/-2)+fib1 (n/*0:1*/-1) if n/*0:1*/>1; +fib2 n/*0:1*/ = case fibs/*0*/ n/*0:1*/ of a/*0:01*/,b/*0:1*/ = a/*0:01*/ { + rule #0: a,b = a + state 0: #0 + <app> state 1 + state 1: #0 + <app> state 2 + state 2: #0 + , state 3 + state 3: #0 + <var> state 4 + state 4: #0 + <var> state 5 + state 5: #0 +} end with fibs n/*0:1*/ = 0,1 if n/*0:1*/<=0; fibs n/*0:1*/ = case fibs/*1*/ (n/*0:1*/-1) of a/*0:01*/,b/*0:1*/ = b/*0:1*/,a/*0:01*/+b/*0:1*/ { + rule #0: a,b = b,a+b + state 0: #0 + <app> state 1 + state 1: #0 + <app> state 2 + state 2: #0 + , state 3 + state 3: #0 + <var> state 4 + state 4: #0 + <var> state 5 + state 5: #0 +} end { + rule #0: fibs n = 0,1 if n<=0 + rule #1: fibs n = case fibs (n-1) of a,b = b,a+b end + state 0: #0 #1 + <var> state 1 + state 1: #0 #1 +} end; +fib3 n/*0:1*/ = a/*0:01*/ when a/*0:01*/,b/*0:1*/ = fibs/*0*/ n/*0:1*/ { + rule #0: a,b = fibs n + state 0: #0 + <app> state 1 + state 1: #0 + <app> state 2 + state 2: #0 + , state 3 + state 3: #0 + <var> state 4 + state 4: #0 + <var> state 5 + state 5: #0 +} end with fibs n/*0:1*/ = 0,1 if n/*0:1*/<=0; fibs n/*0:1*/ = b/*0:1*/,a/*0:01*/+b/*0:1*/ when a/*0:01*/,b/*0:1*/ = fibs/*1*/ (n/*0:1*/-1) { + rule #0: a,b = fibs (n-1) + state 0: #0 + <app> state 1 + state 1: #0 + <app> state 2 + state 2: #0 + , state 3 + state 3: #0 + <var> state 4 + state 4: #0 + <var> state 5 + state 5: #0 +} end { + rule #0: fibs n = 0,1 if n<=0 + rule #1: fibs n = b,a+b when a,b = fibs (n-1) end + state 0: #0 #1 + <var> state 1 + state 1: #0 #1 +} end; +{ + rule #0: fib1 0 = 0 + rule #1: fib1 1 = 1 + rule #2: fib1 n = fib1 (n-2)+fib1 (n-1) if n>1 + state 0: #0 #1 #2 + <var> state 1 + 0::int state 2 + 1::int state 3 + state 1: #2 + state 2: #0 #2 + state 3: #1 #2 +} +{ + rule #0: fib2 n = case fibs n of a,b = a end with fibs n = 0,1 if n<=0; fibs n = case fibs (n-1) of a,b = b,a+b end end + state 0: #0 + <var> state 1 + state 1: #0 +} +{ + rule #0: fib3 n = a when a,b = fibs n end with fibs n = 0,1 if n<=0; fibs n = b,a+b when a,b = fibs (n-1) end end + state 0: #0 + <var> state 1 + state 1: #0 +} +map fib1 (1..10); +[1,1,2,3,5,8,13,21,34,55] +map fib2 (1..10); +[1,1,2,3,5,8,13,21,34,55] +map fib3 (1..10); +[1,1,2,3,5,8,13,21,34,55] Copied: pure/trunk/test/test001.pure (from rev 88, pure/trunk/test/test1.pure) =================================================================== --- pure/trunk/test/test001.pure (rev 0) +++ pure/trunk/test/test001.pure 2008-05-23 01:24:21 UTC (rev 108) @@ -0,0 +1,82 @@ + +// A simple script with some function and variable definitions. +// This is used to test the guts of the interpreter. + +square x = x*x; + +/* a multiline + comment */ + +square 5; + +// Factorial, with guarded rules. + +fact1 n = n*fact1 (n-1) if n>0; + = 1 otherwise; + +let x = fact1 10; x; + +// Factorial, using case. + +fact2 n = case n of + n = n*fact2 (n-1) if n>0; + = 1 otherwise; + end; + +// Factorial, yet another one. + +fact3 n = case n of + 0 = 1; + n = n*fact3 (n-1) if n>0; + end; + +// Factorial, with if-then-else. + +fact4 n = if n>0 then n*fact4 (n-1) else 1; + +// Factorial, with lambda ("pointless style"). + +fact5 = \n -> if n>0 then n*fact5 (n-1) else 1; + +fact2 10; +fact3 10; +fact4 10; +fact5 10; + +// Factorial, using bigints. + +fact n::int = fact (bigint n); +fact n::bigint = n*fact (n-1) if n>0; + = 1 otherwise; + +fact 50; + +// Fibonacci function, naive O(fib n) implementation. + +fib1 0 = 0; +fib1 1 = 1; +fib1 n = fib1 (n-2) + fib1 (n-1) if n>1; + +// Fibonacci function, O(n) implementation. + +fib2 n = case fibs n of + a, b = a; + end + with + fibs n = 0, 1 if n<=0; + = case fibs (n-1) of + a, b = b, a+b; + end otherwise; + end; + +// Fibonacci function, another O(N) implementation. + +fib3 n = a when a, b = fibs n end + with fibs n = 0, 1 if n<=0; + = b, a+b when a, b = fibs (n-1) end + otherwise; + end; + +map fib1 (1..10); +map fib2 (1..10); +map fib3 (1..10); Copied: pure/trunk/test/test002.log (from rev 88, pure/trunk/test/test2.log) =================================================================== --- pure/trunk/test/test002.log (rev 0) +++ pure/trunk/test/test002.log 2008-05-23 01:24:21 UTC (rev 108) @@ -0,0 +1,63 @@ +fib n/*0:1*/ = a/*0:01*/ when a/*0:01*/,b/*0:1*/ = fibs/*0*/ n/*0:1*/ { + rule #0: a,b = fibs n + state 0: #0 + <app> state 1 + state 1: #0 + <app> state 2 + state 2: #0 + , state 3 + state 3: #0 + <var> state 4 + state 4: #0 + <var> state 5 + state 5: #0 +} end with fibs n/*0:1*/ = 0,1 if n/*0:1*/<=0; fibs n/*0:1*/ = b/*0:1*/,a/*0:01*/+b/*0:1*/ when a/*0:01*/,b/*0:1*/ = fibs/*1*/ (n/*0:1*/-1) { + rule #0: a,b = fibs (n-1) + state 0: #0 + <app> state 1 + state 1: #0 + <app> state 2 + state 2: #0 + , state 3 + state 3: #0 + <var> state 4 + state 4: #0 + <var> state 5 + state 5: #0 +} end { + rule #0: fibs n = 0,1 if n<=0 + rule #1: fibs n = b,a+b when a,b = fibs (n-1) end + state 0: #0 #1 + <var> state 1 + state 1: #0 #1 +} end; +fib2 n/*0:1*/ = a/*0:01*/ when a/*0:01*/,b/*0:1*/ = fibs/*0*/ (0L,1L) n/*0:1*/ { + rule #0: a,b = fibs (0L,1L) n + state 0: #0 + <app> state 1 + state 1: #0 + <app> state 2 + state 2: #0 + , state 3 + state 3: #0 + <var> state 4 + state 4: #0 + <var> state 5 + state 5: #0 +} end with fibs (a/*0:0101*/,b/*0:011*/) n/*0:1*/ = a/*0:0101*/,b/*0:011*/ if n/*0:1*/<=0; fibs (a/*0:0101*/,b/*0:011*/) n/*0:1*/ = fibs/*1*/ (b/*0:011*/,a/*0:0101*/+b/*0:011*/) (n/*0:1*/-1) { + rule #0: fibs (a,b) n = a,b if n<=0 + rule #1: fibs (a,b) n = fibs (b,a+b) (n-1) + state 0: #0 #1 + <app> state 1 + state 1: #0 #1 + <app> state 2 + state 2: #0 #1 + , state 3 + state 3: #0 #1 + <var> state 4 + state 4: #0 #1 + <var> state 5 + state 5: #0 #1 + <var> state 6 + state 6: #0 #1 +} end; Copied: pure/trunk/test/test002.pure (from rev 88, pure/trunk/test/test2.pure) =================================================================== --- pure/trunk/test/test002.pure (rev 0) +++ pure/trunk/test/test002.pure 2008-05-23 01:24:21 UTC (rev 108) @@ -0,0 +1,12 @@ +fib n = a when a, b = fibs n end + with fibs n = 0, 1 if n<=0; + = b, a+b when a, b = fibs (n-1) end + otherwise; + end; + +// tail-recursive version, using bigints + +fib2 n = a when a, b = fibs (0L, 1L) n end + with fibs (a, b) n = a, b if n<=0; + = fibs (b, a+b) (n-1) otherwise; + end; Copied: pure/trunk/test/test003.log (from rev 88, pure/trunk/test/test3.log) =================================================================== --- pure/trunk/test/test003.log (rev 0) +++ pure/trunk/test/test003.log 2008-05-23 01:24:21 UTC (rev 108) @@ -0,0 +1,20 @@ +fibs n/*0:1*/ = 0,1 if n/*0:1*/<=0; +fibs n/*0:1*/ = b/*0:1*/,a/*0:01*/+b/*0:1*/ when m/*0:*/ = n/*0:1*/-1; a/*0:01*/,b/*0:1*/ = fibs m/*0:*/ { + rule #0: a,b = fibs m + state 0: #0 + <app> state 1 + state 1: #0 + <app> state 2 + state 2: #0 + , state 3 + state 3: #0 + <var> state 4 + state 4: #0 + <var> state 5 + state 5: #0 +} { + rule #0: m = n-1 + state 0: #0 + <var> state 1 + state 1: #0 +} end; Copied: pure/trunk/test/test003.pure (from rev 88, pure/trunk/test/test3.pure) =================================================================== --- pure/trunk/test/test003.pure (rev 0) +++ pure/trunk/test/test003.pure 2008-05-23 01:24:21 UTC (rev 108) @@ -0,0 +1,3 @@ +fibs n = 0, 1 if n<=0; + = b, a+b when m = n-1; a, b = fibs m end + otherwise; Copied: pure/trunk/test/test004.log (from rev 88, pure/trunk/test/test4.log) =================================================================== --- pure/trunk/test/test004.log (rev 0) +++ pure/trunk/test/test004.log 2008-05-23 01:24:21 UTC (rev 108) @@ -0,0 +1,99 @@ +foo x/*0:1*/ = bar/*0*/ with bar = x/*1:1*/ { + rule #0: bar = x + state 0: #0 +} end; +foo2 x/*0:1*/ = bar/*0*/ x/*0:1*/ with bar 99 = bar/*1*/ (x/*1:1*/+1) { + rule #0: bar 99 = bar (x+1) + state 0: #0 + 99::int state 1 + state 1: #0 +} end; +foo3 x/*0:1*/ = bar/*0*/ with bar y/*0:1*/ = bar/*1*/ (y/*0:1*/+1) if y/*0:1*/==x/*1:1*/ { + rule #0: bar y = bar (y+1) if y==x + state 0: #0 + <var> state 1 + state 1: #0 +} end; +{ + rule #0: foo x = bar with bar = x end + state 0: #0 + <var> state 1 + state 1: #0 +} +{ + rule #0: foo2 x = bar x with bar 99 = bar (x+1) end + state 0: #0 + <var> state 1 + state 1: #0 +} +{ + rule #0: foo3 x = bar with bar y = bar (y+1) if y==x end + state 0: #0 + <var> state 1 + state 1: #0 +} +foo 99; +99 +foo2 99; +bar 100 +foo2 98; +bar 98 +foo3 99; +bar +foo3 99 98; +bar 98 +foo3 99 99; +bar 100 +loop = loop; +count n/*0:1*/ = ct/*0*/ n/*0:1*/ with ct n/*0:1*/::int = n/*0:1*/ if n/*0:1*/<=0; ct n/*0:1*/::int = ct/*1*/ (n/*0:1*/-1) { + rule #0: ct n::int = n if n<=0 + rule #1: ct n::int = ct (n-1) + state 0: #0 #1 + <var>::int state 1 + state 1: #0 #1 +} end; +{ + rule #0: loop = loop + state 0: #0 +} +{ + rule #0: count n = ct n with ct n::int = n if n<=0; ct n::int = ct (n-1) end + state 0: #0 + <var> state 1 + state 1: #0 +} +count 100; +0 +count2 n/*0:1*/::int = n/*0:1*/ if n/*0:1*/<=0; +count2 n/*0:1*/::int = count2 (n/*0:1*/-1); +{ + rule #0: count2 n::int = n if n<=0 + rule #1: count2 n::int = count2 (n-1) + state 0: #0 #1 + <var>::int state 1 + state 1: #0 #1 +} +count2 100; +0 +test x/*0:1*/::int = t/*0*/ x/*0:1*/ with t n/*0:1*/::int = t/*1*/ (-n/*0:1*/) if n/*0:1*/<0; t n/*0:1*/::int = u/*0*/ (n/*0:1*/+2) with u _/*0:1*/ = n/*1:1*/+1 { + rule #0: u _ = n+1 + state 0: #0 + <var> state 1 + state 1: #0 +} end { + rule #0: t n::int = t (-n) if n<0 + rule #1: t n::int = u (n+2) with u _ = n+1 end + state 0: #0 #1 + <var>::int state 1 + state 1: #0 #1 +} end; +{ + rule #0: test x::int = t x with t n::int = t (-n) if n<0; t n::int = u (n+2) with u _ = n+1 end end + state 0: #0 + <var>::int state 1 + state 1: #0 +} +test 98; +99 +test (-97); +98 Copied: pure/trunk/test/test004.pure (from rev 88, pure/trunk/test/test4.pure) =================================================================== --- pure/trunk/test/test004.pure (rev 0) +++ pure/trunk/test/test004.pure 2008-05-23 01:24:21 UTC (rev 108) @@ -0,0 +1,52 @@ + +// Local function with environment test. + +foo x = bar with bar = x end; +foo2 x = bar x with bar 99 = bar (x+1) end; +foo3 x = bar with bar y = bar (y+1) if y==x end; + +foo 99; +foo2 99; foo2 98; +foo3 99; foo3 99 98; foo3 99 99; + +// Tail recursion. + +loop = loop; + +// If LLVM supports proper tail calls on your platform, the following should +// loop forever. +//loop; + +// Tail recursion in a local function. + +count n = ct n with + ct n::int = n if n<=0; + = ct (n-1) otherwise; + end; + +// This should always work. +count 100; +// If proper tail calls are supported, this should work, too, no matter what +// your stack size is. +//count 10000000; + +// Tail recursion in a global function. + +count2 n::int = n if n<=0; + = count2 (n-1) otherwise; + +// This should always work. +count2 100; +// Again, this should work if proper tail calls are supported, no matter what +// your stack size is. +//count2 10000000; + +// Trivial tail-recursive local function which passes an environment to +// another local function. Note that the callee can never be tail-called in +// such a situation because it needs the extra environment parameter which is +// allocated on the caller's stack in the current implementation. + +test x::int = t x +with t n::int = t (-n) if n<0; = u (n+2) with u _ = n+1 end end; + +test 98; test (-97); Copied: pure/trunk/test/test005.log (from rev 88, pure/trunk/test/test5.log) =================================================================== --- pure/trunk/test/test005.log (rev 0) +++ pure/trunk/test/test005.log 2008-05-23 01:24:21 UTC (rev 108) @@ -0,0 +1,13 @@ +fact 0 = 1; +fact n/*0:1*/ = n/*0:1*/*fact (n/*0:1*/-1); +{ + rule #0: fact 0 = 1 + rule #1: fact n = n*fact (n-1) + state 0: #0 #1 + <var> state 1 + 0::int state 2 + state 1: #1 + state 2: #0 #1 +} +fact 4; +24 Copied: pure/trunk/test/test005.pure (from rev 88, pure/trunk/test/test5.pure) =================================================================== --- pure/trunk/test/test005.pure (rev 0) +++ pure/trunk/test/test005.pure 2008-05-23 01:24:21 UTC (rev 108) @@ -0,0 +1,4 @@ +fact 0 = 1; +fact n = n * fact (n-1); +fact 4; + Copied: pure/trunk/test/test006.log (from rev 88, pure/trunk/test/test6.log) =================================================================== --- pure/trunk/test/test006.log (rev 0) +++ pure/trunk/test/test006.log 2008-05-23 01:24:21 UTC (rev 108) @@ -0,0 +1,11 @@ +fact n/*0:1*/ = 1 if n/*0:1*/==0; +fact n/*0:1*/ = n/*0:1*/*fact (n/*0:1*/-1); +{ + rule #0: fact n = 1 if n==0 + rule #1: fact n = n*fact (n-1) + state 0: #0 #1 + <var> state 1 + state 1: #0 #1 +} +fact 4; +24 Copied: pure/trunk/test/test006.pure (from rev 88, pure/trunk/test/test6.pure) =================================================================== --- pure/trunk/test/test006.pure (rev 0) +++ pure/trunk/test/test006.pure 2008-05-23 01:24:21 UTC (rev 108) @@ -0,0 +1,3 @@ +fact n = 1 if n==0; + = n * fact (n-1) otherwise; +fact 4; Copied: pure/trunk/test/test007.log (from rev 88, pure/trunk/test/test7.log) =================================================================== --- pure/trunk/test/test007.log (rev 0) +++ pure/trunk/test/test007.log 2008-05-23 01:24:21 UTC (rev 108) @@ -0,0 +1,19 @@ +{ + rule #0: y = \a -> \b -> a+b + state 0: #0 + <var> state 1 + state 1: #0 +} +let y = \a/*0:*/ -> \b/*0:*/ -> a/*1:*/+b/*0:*/ { + rule #0: b = a+b + state 0: #0 + <var> state 1 + state 1: #0 +} { + rule #0: a = \b -> a+b + state 0: #0 + <var> state 1 + state 1: #0 +}; +y 1 5; +6 Copied: pure/trunk/test/test007.pure (from rev 88, pure/trunk/test/test7.pure) =================================================================== --- pure/trunk/test/test007.pure (rev 0) +++ pure/trunk/test/test007.pure 2008-05-23 01:24:21 UTC (rev 108) @@ -0,0 +1,2 @@ +let y = (\a b -> a+b); +y 1 5; Copied: pure/trunk/test/test008.log (from rev 88, pure/trunk/test/test8.log) =================================================================== --- pure/trunk/test/test008.log (rev 0) +++ pure/trunk/test/test008.log 2008-05-23 01:24:21 UTC (rev 108) @@ -0,0 +1,36 @@ +Binomial n/*0:01*/ k/*0:1*/ = Binomial n/*0:01*/ (n/*0:01*/-k/*0:1*/) if n/*0:01*/-k/*0:1*/<k/*0:1*/; +Binomial n/*0:01*/ 0L = 1L; +Binomial n/*0:01*/ 0 = 1; +Binomial n/*0:01*/ 1L = n/*0:01*/; +Binomial n/*0:01*/ 1 = n/*0:01*/; +Binomial n/*0:01*/ k/*0:1*/ = Binomial nm2/*0:*/ (k/*1:1*/-2)+2*Binomial nm2/*0:*/ (k/*1:1*/-1)+Binomial nm2/*0:*/ k/*1:1*/ when nm2/*0:*/ = n/*0:01*/-2 { + rule #0: nm2 = n-2 + state 0: #0 + <var> state 1 + state 1: #0 +} end; +{ + rule #0: Binomial n k = Binomial n (n-k) if n-k<k + rule #1: Binomial n 0L = 1L + rule #2: Binomial n 0 = 1 + rule #3: Binomial n 1L = n + rule #4: Binomial n 1 = n + rule #5: Binomial n k = Binomial nm2 (k-2)+2*Binomial nm2 (k-1)+Binomial nm2 k when nm2 = n-2 end + state 0: #0 #1 #2 #3 #4 #5 + <var> state 1 + state 1: #0 #1 #2 #3 #4 #5 + <var> state 2 + 0::int state 3 + 1::int state 4 + 0L::bigint state 5 + 1L::bigint state 6 + state 2: #0 #5 + state 3: #0 #2 #5 + state 4: #0 #4 #5 + state 5: #0 #1 #5 + state 6: #0 #3 #5 +} +Binomial 5 2; +10 +Binomial 5L 2L; +10L Copied: pure/trunk/test/test008.pure (from rev 88, pure/trunk/test/test8.pure) =================================================================== --- pure/trunk/test/test008.pure (rev 0) +++ pure/trunk/test/test008.pure 2008-05-23 01:24:21 UTC (rev 108) @@ -0,0 +1,13 @@ +Binomial n k = Binomial n (n-k) if n-k < k; +Binomial n 0L = 1L; +Binomial n 0 = 1; +Binomial n 1L = n; +Binomial n 1 = n; +Binomial n k = + Binomial nm2 (k-2) + + 2 * Binomial nm2 (k-1) + + Binomial nm2 k + when nm2 = n-2 end; + +Binomial 5 2; +Binomial 5L 2L; Copied: pure/trunk/test/test009.log (from rev 88, pure/trunk/test/test9.log) =================================================================== --- pure/trunk/test/test009.log (rev 0) +++ pure/trunk/test/test009.log 2008-05-23 01:24:21 UTC (rev 108) @@ -0,0 +1,108 @@ +fib2 n/*0:1*/ = a/*0:01*/ when a/*0:01*/,b/*0:1*/ = fibs/*0*/ n/*0:1*/ { + rule #0: a,b = fibs n + state 0: #0 + <app> state 1 + state 1: #0 + <app> state 2 + state 2: #0 + , state 3 + state 3: #0 + <var> state 4 + state 4: #0 + <var> state 5 + state 5: #0 +} end with fibs n/*0:1*/ = 0,1 if n/*0:1*/<=0; fibs n/*0:1*/ = b/*0:1*/,a/*0:01*/+b/*0:1*/ when a/*0:01*/,b/*0:1*/ = fibs/*1*/ (n/*0:1*/-1) { + rule #0: a,b = fibs (n-1) + state 0: #0 + <app> state 1 + state 1: #0 + <app> state 2 + state 2: #0 + , state 3 + state 3: #0 + <var> state 4 + state 4: #0 + <var> state 5 + state 5: #0 +} end { + rule #0: fibs n = 0,1 if n<=0 + rule #1: fibs n = b,a+b when a,b = fibs (n-1) end + state 0: #0 #1 + <var> state 1 + state 1: #0 #1 +} end; +fib2 n/*0:1*/ = a/*0:01*/ when a/*0:01*/,b/*0:1*/ = fibs/*0*/ n/*0:1*/ { + rule #0: a,b = fibs n + state 0: #0 + <app> state 1 + state 1: #0 + <app> state 2 + state 2: #0 + , state 3 + state 3: #0 + <var> state 4 + state 4: #0 + <var> state 5 + state 5: #0 +} end with fibs n/*0:1*/ = 0,1 if n/*0:1*/<=0; fibs n/*0:1*/ = b/*0:1*/,a/*0:01*/+b/*0:1*/ when a/*0:01*/,b/*0:1*/ = fibs/*1*/ (n/*0:1*/-1) { + rule #0: a,b = fibs (n-1) + state 0: #0 + <app> state 1 + state 1: #0 + <app> state 2 + state 2: #0 + , state 3 + state 3: #0 + <var> state 4 + state 4: #0 + <var> state 5 + state 5: #0 +} end { + rule #0: fibs n = 0,1 if n<=0 + rule #1: fibs n = b,a+b when a,b = fibs (n-1) end + state 0: #0 #1 + <var> state 1 + state 1: #0 #1 +} end; +{ + rule #0: fib2 n = a when a,b = fibs n end with fibs n = 0,1 if n<=0; fibs n = b,a+b when a,b = fibs (n-1) end end + rule #1: fib2 n = a when a,b = fibs n end with fibs n = 0,1 if n<=0; fibs n = b,a+b when a,b = fibs (n-1) end end + state 0: #0 #1 + <var> state 1 + state 1: #0 #1 +} +warning: rule never reduced: fib2 n/*0:1*/ = a/*0:01*/ when a/*0:01*/,b/*0:1*/ = fibs/*0*/ n/*0:1*/ { + rule #0: a,b = fibs n + state 0: #0 + <app> state 1 + state 1: #0 + <app> state 2 + state 2: #0 + , state 3 + state 3: #0 + <var> state 4 + state 4: #0 + <var> state 5 + state 5: #0 +} end with fibs n/*0:1*/ = 0,1 if n/*0:1*/<=0; fibs n/*0:1*/ = b/*0:1*/,a/*0:01*/+b/*0:1*/ when a/*0:01*/,b/*0:1*/ = fibs/*1*/ (n/*0:1*/-1) { + rule #0: a,b = fibs (n-1) + state 0: #0 + <app> state 1 + state 1: #0 + <app> state 2 + state 2: #0 + , state 3 + state 3: #0 + <var> state 4 + state 4: #0 + <var> state 5 + state 5: #0 +} end { + rule #0: fibs n = 0,1 if n<=0 + rule #1: fibs n = b,a+b when a,b = fibs (n-1) end + state 0: #0 #1 + <var> state 1 + state 1: #0 #1 +} end; +map fib2 (1..10); +[1,1,2,3,5,8,13,21,34,55] Copied: pure/trunk/test/test009.pure (from rev 88, pure/trunk/test/test9.pure) =================================================================== --- pure/trunk/test/test009.pure (rev 0) +++ pure/trunk/test/test009.pure 2008-05-23 01:24:21 UTC (rev 108) @@ -0,0 +1,11 @@ +fib2 n = a when a, b = fibs n end + with fibs n = 0, 1 if n<=0; + = b, a+b when a, b = fibs (n-1) end + otherwise; + end; +fib2 n = a when a, b = fibs n end + with fibs n = 0, 1 if n<=0; + = b, a+b when a, b = fibs (n-1) end + otherwise; + end; +map fib2 (1..10); Copied: pure/trunk/test/test010.log (from rev 107, pure/trunk/test/test10.log) =================================================================== --- pure/trunk/test/test010.log (rev 0) +++ pure/trunk/test/test010.log 2008-05-23 01:24:21 UTC (rev 108) @@ -0,0 +1,3 @@ +\x -> x!0==[0,1,0,0]; +eval "(\\x -> (x!0) == [0,1,0,0])" [[0,1,0,0],[1,1,2]]; +1 Copied: pure/trunk/test/test010.pure (from rev 107, pure/trunk/test/test10.pure) =================================================================== --- pure/trunk/test/test010.pure (rev 0) +++ pure/trunk/test/test010.pure 2008-05-23 01:24:21 UTC (rev 108) @@ -0,0 +1,2 @@ + +eval "(\\x -> (x!0) == [0,1,0,0])" [[0,1,0,0],[1,1,2]]; Deleted: pure/trunk/test/test1.log =================================================================== --- pure/trunk/test/test1.log 2008-05-23 01:15:11 UTC (rev 107) +++ pure/trunk/test/test1.log 2008-05-23 01:24:21 UTC (rev 108) @@ -1,194 +0,0 @@ -square x/*0:1*/ = x/*0:1*/*x/*0:1*/; -{ - rule #0: square x = x*x - state 0: #0 - <var> state 1 - state 1: #0 -} -square 5; -25 -fact1 n/*0:1*/ = n/*0:1*/*fact1 (n/*0:1*/-1) if n/*0:1*/>0; -fact1 n/*0:1*/ = 1; -{ - rule #0: fact1 n = n*fact1 (n-1) if n>0 - rule #1: fact1 n = 1 - state 0: #0 #1 - <var> state 1 - state 1: #0 #1 -} -{ - rule #0: x = fact1 10 - state 0: #0 - <var> state 1 - state 1: #0 -} -let x = fact1 10; -x; -3628800 -fact2 n/*0:1*/ = case n/*0:1*/ of n/*0:*/ = n/*0:*/*fact2 (n/*0:*/-1) if n/*0:*/>0; n/*0:*/ = 1 { - rule #0: n = n*fact2 (n-1) if n>0 - rule #1: n = 1 - state 0: #0 #1 - <var> state 1 - state 1: #0 #1 -} end; -fact3 n/*0:1*/ = case n/*0:1*/ of 0 = 1; n/*0:*/ = n/*0:*/*fact3 (n/*0:*/-1) if n/*0:*/>0 { - rule #0: 0 = 1 - rule #1: n = n*fact3 (n-1) if n>0 - state 0: #0 #1 - <var> state 1 - 0::int state 2 - state 1: #1 - state 2: #0 #1 -} end; -fact4 n/*0:1*/ = if n/*0:1*/>0 then n/*0:1*/*fact4 (n/*0:1*/-1) else 1; -fact5 = \n/*0:*/ -> if n/*0:*/>0 then n/*0:*/*fact5 (n/*0:*/-1) else 1 { - rule #0: n = if n>0 then n*fact5 (n-1) else 1 - state 0: #0 - <var> state 1 - state 1: #0 -}; -{ - rule #0: fact2 n = case n of n = n*fact2 (n-1) if n>0; n = 1 end - state 0: #0 - <var> state 1 - state 1: #0 -} -{ - rule #0: fact3 n = case n of 0 = 1; n = n*fact3 (n-1) if n>0 end - state 0: #0 - <var> state 1 - state 1: #0 -} -{ - rule #0: fact4 n = if n>0 then n*fact4 (n-1) else 1 - state 0: #0 - <var> state 1 - state 1: #0 -} -{ - rule #0: fact5 = \n -> if n>0 then n*fact5 (n-1) else 1 - state 0: #0 -} -fact2 10; -3628800 -fact3 10; -3628800 -fact4 10; -3628800 -fact5 10; -3628800 -fact n/*0:1*/::int = fact (bigint n/*0:1*/); -fact n/*0:1*/::bigint = n/*0:1*/*fact (n/*0:1*/-1) if n/*0:1*/>0; -fact n/*0:1*/::bigint = 1; -{ - rule #0: fact n::int = fact (bigint n) - rule #1: fact n::bigint = n*fact (n-1) if n>0 - rule #2: fact n::bigint = 1 - state 0: #0 #1 #2 - <var>::int state 1 - <var>::bigint state 2 - state 1: #0 - state 2: #1 #2 -} -fact 50; -30414093201713378043612608166064768844377641568960512000000000000L -fib1 0 = 0; -fib1 1 = 1; -fib1 n/*0:1*/ = fib1 (n/*0:1*/-2)+fib1 (n/*0:1*/-1) if n/*0:1*/>1; -fib2 n/*0:1*/ = case fibs/*0*/ n/*0:1*/ of a/*0:01*/,b/*0:1*/ = a/*0:01*/ { - rule #0: a,b = a - state 0: #0 - <app> state 1 - state 1: #0 - <app> state 2 - state 2: #0 - , state 3 - state 3: #0 - <var> state 4 - state 4: #0 - <var> state 5 - state 5: #0 -} end with fibs n/*0:1*/ = 0,1 if n/*0:1*/<=0; fibs n/*0:1*/ = case fibs/*1*/ (n/*0:1*/-1) of a/*0:01*/,b/*0:1*/ = b/*0:1*/,a/*0:01*/+b/*0:1*/ { - rule #0: a,b = b,a+b - state 0: #0 - <app> state 1 - state 1: #0 - <app> state 2 - state 2: #0 - , state 3 - state 3: #0 - <var> state 4 - state 4: #0 - <var> state 5 - state 5: #0 -} end { - rule #0: fibs n = 0,1 if n<=0 - rule #1: fibs n = case fibs (n-1) of a,b = b,a+b end - state 0: #0 #1 - <var> state 1 - state 1: #0 #1 -} end; -fib3 n/*0:1*/ = a/*0:01*/ when a/*0:01*/,b/*0:1*/ = fibs/*0*/ n/*0:1*/ { - rule #0: a,b = fibs n - state 0: #0 - <app> state 1 - state 1: #0 - <app> state 2 - state 2: #0 - , state 3 - state 3: #0 - <var> state 4 - state 4: #0 - <var> state 5 - state 5: #0 -} end with fibs n/*0:1*/ = 0,1 if n/*0:1*/<=0; fibs n/*0:1*/ = b/*0:1*/,a/*0:01*/+b/*0:1*/ when a/*0:01*/,b/*0:1*/ = fibs/*1*/ (n/*0:1*/-1) { - rule #0: a,b = fibs (n-1) - state 0: #0 - <app> state 1 - state 1: #0 - <app> state 2 - state 2: #0 - , state 3 - state 3: #0 - <var> state 4 - state 4: #0 - <var> state 5 - state 5: #0 -} end { - rule #0: fibs n = 0,1 if n<=0 - rule #1: fibs n = b,a+b when a,b = fibs (n-1) end - state 0: #0 #1 - <var> state 1 - state 1: #0 #1 -} end; -{ - rule #0: fib1 0 = 0 - rule #1: fib1 1 = 1 - rule #2: fib1 n = fib1 (n-2)+fib1 (n-1) if n>1 - state 0: #0 #1 #2 - <var> state 1 - 0::int state 2 - 1::int state 3 - state 1: #2 - state 2: #0 #2 - state 3: #1 #2 -} -{ - rule #0: fib2 n = case fibs n of a,b = a end with fibs n = 0,1 if n<=0; fibs n = case fibs (n-1) of a,b = b,a+b end end - state 0: #0 - <var> state 1 - state 1: #0 -} -{ - rule #0: fib3 n = a when a,b = fibs n end with fibs n = 0,1 if n<=0; fibs n = b,a+b when a,b = fibs (n-1) end end - state 0: #0 - <var> state 1 - state 1: #0 -} -map fib1 (1..10); -[1,1,2,3,5,8,13,21,34,55] -map fib2 (1..10); -[1,1,2,3,5,8,13,21,34,55] -map fib3 (1..10); -[1,1,2,3,5,8,13,21,34,55] Deleted: pure/trunk/test/test1.pure =================================================================== --- pure/trunk/test/test1.pure 2008-05-23 01:15:11 UTC (rev 107) +++ pure/trunk/test/test1.pure 2008-05-23 01:24:21 UTC (rev 108) @@ -1,82 +0,0 @@ - -// A simple script with some function and variable definitions. -// This is used to test the guts of the interpreter. - -square x = x*x; - -/* a multiline - comment */ - -square 5; - -// Factorial, with guarded rules. - -fact1 n = n*fact1 (n-1) if n>0; - = 1 otherwise; - -let x = fact1 10; x; - -// Factorial, using case. - -fact2 n = case n of - n = n*fact2 (n-1) if n>0; - = 1 otherwise; - end; - -// Factorial, yet another one. - -fact3 n = case n of - 0 = 1; - n = n*fact3 (n-1) if n>0; - end; - -// Factorial, with if-then-else. - -fact4 n = if n>0 then n*fact4 (n-1) else 1; - -// Factorial, with lambda ("pointless style"). - -fact5 = \n -> if n>0 then n*fact5 (n-1) else 1; - -fact2 10; -fact3 10; -fact4 10; -fact5 10; - -// Factorial, using bigints. - -fact n::int = fact (bigint n); -fact n::bigint = n*fact (n-1) if n>0; - = 1 otherwise; - -fact 50; - -// Fibonacci function, naive O(fib n) implementation. - -fib1 0 = 0; -fib1 1 = 1; -fib1 n = fib1 (n-2) + fib1 (n-1) if n>1; - -// Fibonacci function, O(n) implementation. - -fib2 n = case fibs n of - a, b = a; - end - with - fibs n = 0, 1 if n<=0; - = case fibs (n-1) of - a, b = b, a+b; - end otherwise; - end; - -// Fibonacci function, another O(N) implementation. - -fib3 n = a when a, b = fibs n end - with fibs n = 0, 1 if n<=0; - = b, a+b when a, b = fibs (n-1) end - otherwise; - end; - -map fib1 (1..10); -map fib2 (1..10); -map fib3 (1..10); Deleted: pure/trunk/test/test10.log =================================================================== --- pure/trunk/test/test10.log 2008-05-23 01:15:11 UTC (rev 107) +++ pure/trunk/test/test10.log 2008-05-23 01:24:21 UTC (rev 108) @@ -1,3 +0,0 @@ -\x -> x!0==[0,1,0,0]; -eval "(\\x -> (x!0) == [0,1,0,0])" [[0,1,0,0],[1,1,2]]; -1 Deleted: pure/trunk/test/test10.pure =================================================================== --- pure/trunk/test/test10.pure 2008-05-23 01:15:11 UTC (rev 107) +++ pure/trunk/test/test10.pure 2008-05-23 01:24:21 UTC (rev 108) @@ -1,2 +0,0 @@ - -eval "(\\x -> (x!0) == [0,1,0,0])" [[0,1,0,0],[1,1,2]]; Deleted: pure/trunk/test/test2.log =================================================================== --- pure/trunk/test/test2.log 2008-05-23 01:15:11 UTC (rev 107) +++ pure/trunk/test/test2.log 2008-05-23 01:24:21 UTC (rev 108) @@ -1,63 +0,0 @@ -fib n/*0:1*/ = a/*0:01*/ when a/*0:01*/,b/*0:1*/ = fibs/*0*/ n/*0:1*/ { - rule #0: a,b = fibs n - state 0: #0 - <app> state 1 - state 1: #0 - <app> state 2 - state 2: #0 - , state 3 - state 3: #0 - <var> state 4 - state 4: #0 - <var> state 5 - state 5: #0 -} end with fibs n/*0:1*/ = 0,1 if n/*0:1*/<=0; fibs n/*0:1*/ = b/*0:1*/,a/*0:01*/+b/*0:1*/ when a/*0:01*/,b/*0:1*/ = fibs/*1*/ (n/*0:1*/-1) { - rule #0: a,b = fibs (n-1) - state 0: #0 - <app> state 1 - state 1: #0 - <app> state 2 - state 2: #0 - , state 3 - state 3: #0 - <var> state 4 - state 4: #0 - <var> state 5 - state 5: #0 -} end { - rule #0: fibs n = 0,1 if n<=0 - rule #1: fibs n = b,a+b when a,b = fibs (n-1) end - state 0: #0 #1 - <var> state 1 - state 1: #0 #1 -} end; -fib2 n/*0:1*/ = a/*0:01*/ when a/*0:01*/,b/*0:1*/ = fibs/*0*/ (0L,1L) n/*0:1*/ { - rule #0: a,b = fibs (0L,1L) n - state 0: #0 - <app> state 1 - state 1: #0 - <app> state 2 - state 2: #0 - , state 3 - state 3: #0 - <var> state 4 - state 4: #0 - <var> state 5 - state 5: #0 -} end with fibs (a/*0:0101*/,b/*0:011*/) n/*0:1*/ = a/*0:0101*/,b/*0:011*/ if n/*0:1*/<=0; fibs (a/*0:0101*/,b/*0:011*/) n/*0:1*/ = fibs/*1*/ (b/*0:011*/,a/*0:0101*/+b/*0:011*/) (n/*0:1*/-1) { - rule #0: fibs (a,b) n = a,b if n<=0 - rule #1: fibs (a,b) n = fibs (b,a+b) (n-1) - state 0: #0 #1 - <app> state 1 - state 1: #0 #1 - <app> state 2 - state 2: #0 #1 - , state 3 - state 3: #0 #1 - <var> state 4 - state 4: #0 #1 - <var> state 5 - state 5: #0 #1 - <var> state 6 - state 6: #0 #1 -} end; Deleted: pure/trunk/test/test2.pure =================================================================== --- pure/trunk/test/test2.pure 2008-05-23 01:15:11 UTC (rev 107) +++ pure/trunk/test/test2.pure 2008-05-23 01:24:21 UTC (rev 108) @@ -1,12 +0,0 @@ -fib n = a when a, b = fibs n end - with fibs n = 0, 1 if n<=0; - = b, a+b when a, b = fibs (n-1) end - otherwise; - end; - -// tail-recursive version, using bigints - -fib2 n = a when a, b = fibs (0L, 1L) n end - with fibs (a, b) n = a, b if n<=0; - = fibs (b, a+b) (n-1) otherwise; - end; Deleted: pure/trunk/test/test3.log =================================================================== --- pure/trunk/test/test3.log 2008-05-23 01:15:11 UTC (rev 107) +++ pure/trunk/test/test3.log 2008-05-23 01:24:21 UTC (rev 108) @@ -1,20 +0,0 @@ -fibs n/*0:1*/ = 0,1 if n/*0:1*/<=0; -fibs n/*0:1*/ = b/*0:1*/,a/*0:01*/+b/*0:1*/ when m/*0:*/ = n/*0:1*/-1; a/*0:01*/,b/*0:1*/ = fibs m/*0:*/ { - rule #0: a,b = fibs m - state 0: #0 - <app> state 1 - state 1: #0 - <app> state 2 - state 2: #0 - , state 3 - state 3: #0 - <var> state 4 - state 4: #0 - <var> state 5 - state 5: #0 -} { - rule #0: m = n-1 - state 0: #0 - <var> state 1 - state 1: #0 -} end; Deleted: pure/trunk/test/test3.pure =================================================================== --- pure/trunk/test/test3.pure 2008-05-23 01:15:11 UTC (rev 107) +++ pure/trunk/test/test3.pure 2008-05-23 01:24:21 UTC (rev 108) @@ -1,3 +0,0 @@ -fibs n = 0, 1 if n<=0; - = b, a+b when m = n-1; a, b = fibs m end - otherwise; Deleted: pure/trunk/test/test4.log =================================================================== --- pure/trunk/test/test4.log 2008-05-23 01:15:11 UTC (rev 107) +++ pure/trunk/test/test4.log 2008-05-23 01:24:21 UTC (rev 108) @@ -1,99 +0,0 @@ -foo x/*0:1*/ = bar/*0*/ with bar = x/*1:1*/ { - rule #0: bar = x - state 0: #0 -} end; -foo2 x/*0:1*/ = bar/*0*/ x/*0:1*/ with bar 99 = bar/*1*/ (x/*1:1*/+1) { - rule #0: bar 99 = bar (x+1) - state 0: #0 - 99::int state 1 - state 1: #0 -} end; -foo3 x/*0:1*/ = bar/*0*/ with bar y/*0:1*/ = bar/*1*/ (y/*0:1*/+1) if y/*0:1*/==x/*1:1*/ { - rule #0: bar y = bar (y+1) if y==x - state 0: #0 - <var> state 1 - state 1: #0 -} end; -{ - rule #0: foo x = bar with bar = x end - state 0: #0 - <var> state 1 - state 1: #0 -} -{ - rule #0: foo2 x = bar x with bar 99 = bar (x+1) end - state 0: #0 - <var> state 1 - state 1: #0 -} -{ - rule #0: foo3 x = bar with bar y = bar (y+1) if y==x end - state 0: #0 - <var> state 1 - state 1: #0 -} -foo 99; -99 -foo2 99; -bar 100 -foo2 98; -bar 98 -foo3 99; -bar -foo3 99 98; -bar 98 -foo3 99 99; -bar 100 -loop = loop; -count n/*0:1*/ = ct/*0*/ n/*0:1*/ with ct n/*0:1*/::int = n/*0:1*/ if n/*0:1*/<=0; ct n/*0:1*/::int = ct/*1*/ (n/*0:1*/-1) { - rule #0: ct n::int = n if n<=0 - rule #1: ct n::int = ct (n-1) - state 0: #0 #1 - <var>::int state 1 - state 1: #0 #1 -} end; -{ - rule #0: loop = loop - state 0: #0 -} -{ - rule #0: count n = ct n with ct n::int = n if n<=0; ct n::int = ct (n-1) end - state 0: #0 - <var> state 1 - state 1: #0 -} -count 100; -0 -count2 n/*0:1*/::int = n/*0:1*/ if n/*0:1*/<=0; -count2 n/*0:1*/::int = count2 (n/*0:1*/-1); -{ - rule #0: count2 n::int = n if n<=0 - rule #1: count2 n::int = count2 (n-1) - state 0: #0 #1 - <var>::int state 1 - state 1: #0 #1 -} -count2 100; -0 -test x/*0:1*/::int = t/*0*/ x/*0:1*/ with t n/*0:1*/::int = t/*1*/ (-n/*0:1*/) if n/*0:1*/<0; t n/*0:1*/::int = u/*0*/ (n/*0:1*/+2) with u _/*0:1*/ = n/*1:1*/+1 { - rule #0: u _ = n+1 - state 0: #0 - <var> state 1 - state 1: #0 -} end { - rule #0: t n::int = t (-n) if n<0 - rule #1: t n::int = u (n+2) with u _ = n+1 end - state 0: #0 #1 - <var>::int state 1 - state 1: #0 #1 -} end; -{ - rule #0: test x::int = t x with t n::int = t (-n) if n<0; t n::int = u (n+2) with u _ = n+1 end end - state 0: #0 - <var>::int state 1 - state 1: #0 -} -test 98; -99 -test (-97); -98 Deleted: pure/trunk/test/test4.pure =================================================================== --- pure/trunk/test/test4.pure 2008-05-23 01:15:11 UTC (rev 107) +++ pure/trunk/test/test4.pure 2008-05-23 01:24:21 UTC (rev 108) @@ -1,52 +0,0 @@ - -// Local function with environment test. - -foo x = bar with bar = x end; -foo2 x = bar x with bar 99 = bar (x+1) end; -foo3 x = bar with bar y = bar (y+1) if y==x end; - -foo 99; -foo2 99; foo2 98; -foo3 99; foo3 99 98; foo3 99 99; - -// Tail recursion. - -loop = loop; - -// If LLVM supports proper tail calls on your platform, the following should -// loop forever. -//loop; - -// Tail recursion in a local function. - -count n = ct n with - ct n::int = n if n<=0; - = ct (n-1) otherwise; - end; - -// This should always work. -count 100; -// If proper tail calls are supported, this should work, too, no matter what -// your stack size is. -//count 10000000; - -// Tail recursion in a global function. - -count2 n::int = n if n<=0; - = count2 (n-1) otherwise; - -// This should always work. -count2 100; -// Again, this should work if proper tail calls are supported, no matter what -// your stack size is. -//count2 10000000; - -// Trivial tail-recursive local function which passes an environment to -// another local function. Note that the callee can never be tail-called in -// such a situation because it needs the extra environment parameter which is -// allocated on the caller's stack in the current implementation. - -test x::int = t x -with t n::int = t (-n) if n<0; = u (n+2) with u _ = n+1 end end; - -test 98; test (-97); Deleted: pure/trunk/test/test5.log =================================================================== --- pure/trunk/test/test5.log 2008-05-23 01:15:11 UTC (rev 107) +++ pure/trunk/test/test5.log 2008-05-23 01:24:21 UTC (rev 108) @@ -1,13 +0,0 @@ -fact 0 = 1; -fact n/*0:1*/ = n/*0:1*/*fact (n/*0:1*/-1); -{ - rule #0: fact 0 = 1 - rule #1: fact n = n*fact (n-1) - state 0: #0 #1 - <var> state 1 - 0::int state 2 - state 1: #1 - state 2: #0 #1 -} -fact 4; -24 Deleted: pure/trunk/test/test5.pure =================================================================== --- pure/trunk/test/test5.pure 2008-05-23 01:15:11 UTC (rev 107) +++ pure/trunk/test/test5.pure 2008-05-23 01:24:21 UTC (rev 108) @@ -1,4 +0,0 @@ -fact 0 = 1; -fact n = n * fact (n-1); -fact 4; - Deleted: pure/trunk/test/test6.log =================================================================== --- pure/trunk/test/test6.log 2008-05-23 01:15:11 UTC (rev 107) +++ pure/trunk/test/test6.log 2008-05-23 01:24:21 UTC (rev 108) @@ -1,11 +0,0 @@ -fact n/*0:1*/ = 1 if n/*0:1*/==0; -fact n/*0:1*/ = n/*0:1*/*fact (n/*0:1*/-1); -{ - rule #0: fact n = 1 if n==0 - rule #1: fact n = n*fact (n-1) - state 0: #0 #1 - <var> state 1 - state 1: #0 #1 -} -fact 4; -24 Deleted: pure/trunk/test/test6.pure =================================================================== --- pure/trunk/test/test6.pure 2008-05-23 01:15:11 UTC (rev 107) +++ pure/trunk/test/test6.pure 2008-05-23 01:24:21 UTC (rev 108) @@ -1,3 +0,0 @@ -fact n = 1 if n==0; - = n * fact (n-1) otherwise; -fact 4; Deleted: pure/trunk/test/test7.log =================================================================== --- pure/trunk/test/test7.log 2008-05-23 01:15:11 UTC (rev 107) +++ pure/trunk/test/test7.log 2008-05-23 01:24:21 UTC (rev 108) @@ -1,19 +0,0 @@ -{ - rule #0: y = \a -> \b -> a+b - state 0: #0 - <var> state 1 - state 1: #0 -} -let y = \a/*0:*/ -> \b/*0:*/ -> a/*1:*/+b/*0:*/ { - rule #0: b = a+b - state 0: #0 - <var> state 1 - state 1: #0 -} { - rule #0: a = \b -> a+b - state 0: #0 - <var> state 1 - state 1: #0 -}; -y 1 5; -6 Deleted: pure/trunk/test/test7.pure =================================================================== --- pure/trunk/test/test7.pure 2008-05-23 01:15:11 UTC (rev 107) +++ pure/trunk/test/test7.pure 2008-05-23 01:24:21 UTC (rev 108) @@ -1,2 +0,0 @@ -let y = (\a b -> a+b); -y 1 5; Deleted: pure/trunk/test/test8.log =================================================================== --- pure/trunk/test/test8.log 2008-05-23 01:15:11 UTC (rev 107) +++ pure/trunk/test/test8.log 2008-05-23 01:24:21 UTC (rev 108) @@ -1,36 +0,0 @@ -Binomial n/*0:01*/ k/*0:1*/ = Binomial n/*0:01*/ (n/*0:01*/-k/*0:1*/) if n/*0:01*/-k/*0:1*/<k/*0:1*/; -Binomial n/*0:01*/ 0L = 1L; -Binomial n/*0:01*/ 0 = 1; -Binomial n/*0:01*/ 1L = n/*0:01*/; -Binomial n/*0:01*/ 1 = n/*0:01*/; -Binomial n/*0:01*/ k/*0:1*/ = Binomial nm2/*0:*/ (k/*1:1*/-2)+2*Binomial nm2/*0:*/ (k/*1:1*/-1)+Binomial nm2/*0:*/ k/*1:1*/ when nm2/*0:*/ = n/*0:01*/-2 { - rule #0: nm2 = n-2 - state 0: #0 - <var> state 1 - state 1: #0 -} end; -{ - rule #0: Binomial n k = Binomial n (n-k) if n-k<k - rule #1: Binomial n 0L = 1L - rule #2: Binomial n 0 = 1 - rule #3: Binomial n 1L = n - rule #4: Binomial n 1 = n - rule #5: Binomial n k = Binomial nm2 (k-2)+2*Binomial nm2 (k-1)+Binomial nm2 k when nm2 = n-2 end - state 0: #0 #1 #2 #3 #4 #5 - <var> state 1 - state 1: #0 #1 #2 #3 #4 #5 - <var> state 2 - 0::int state 3 - 1::int state 4 - 0L::bigint state 5 - 1L::bigint state 6 - state 2: #0 #5 - state 3: #0 #2 #5 - state 4: #0 #4 #5 - state 5: #0 #1 #5 - state 6: #0 #3 #5 -} -Binomial 5 2; -10 -Binomial 5L 2L; -10L Deleted: pure/trunk/test/test8.pure =================================================================== --- pure/trunk/test/test8.pure 2008-05-23 01:15:11 UTC (rev 107) +++ pure/trunk/test/test8.pure 2008-05-23 01:24:21 UTC (rev 108) @@ -1,13 +0,0 @@ -Binomial n k = Binomial n (n-k) if n-k < k; -Binomial n 0L = 1L; -Binomial n 0 = 1; -Binomial n 1L = n; -Binomial n 1 = n; -Binomial n k = - Binomial nm2 (k-2) + - 2 * Binomial nm2 (k-1) + - Binomial nm2 k - when nm2 = n-2 end; - -Binomial 5 2; -Binomial 5L 2L; Deleted: pure/trunk/test/test9.log =================================================================== --- pure/trunk/test/test9.log 2008-05-23 01:15:11 UTC (rev 107) +++ pure/trunk/test/test9.log 2008-05-23 01:24:21 UTC (rev 108) @@ -1,108 +0,0 @@ -fib2 n/*0:1*/ = a/*0:01*/ when a/*0:01*/,b/*0:1*/ = fibs/*0*/ n/*0:1*/ { - rule #0: a,b = fibs n - state 0: #0 - <app> state 1 - state 1: #0 - <app> state 2 - state 2: #0 - , state 3 - state 3: #0 - <var> state 4 - state 4: #0 - <var> state 5 - state 5: #0 -} end with fibs n/*0:1*/ = 0,1 if n/*0:1*/<=0; fibs n/*0:1*/ = b/*0:1*/,a/*0:01*/+b/*0:1*/ when a/*0:01*/,b/*0:1*/ = fibs/*1*/ (n/*0:1*/-1) { - rule #0: a,b = fibs (n-1) - state 0: #0 - <app> state 1 - state 1: #0 - <app> state 2 - state 2: #0 - , state 3 - state 3: #0 - <var> state 4 - state 4: #0 - <var> state 5 - state 5: #0 -} end { - rule #0: fibs n = 0,1 if n<=0 - rule #1: fibs n = b,a+b when a,b = fibs (n-1) end - state 0: #0 #1 - <var> state 1 - state 1: #0 #1 -} end; -fib2 n/*0:1*/ = a/*0:01*/ when a/*0:01*/,b/*0:1*/ = fibs/*0*/ n/*0:1*/ { - rule #0: a,b = fibs n - state 0: #0 - <app> state 1 - state 1: #0 - <app> state 2 - state 2: #0 - , state 3 - state 3: #0 - <var> state 4 - state 4: #0 - <var> state 5 - state 5: #0 -} end with fibs n/*0:1*/ = 0,1 if n/*0:1*/<=0; fibs n/*0:1*/ = b/*0:1*/,a/*0:01*/+b/*0:1*/ when a/*0:01*/,b/*0:1*/ = fibs/*1*/ (n/*0:1*/-1) { - rule #0: a,b = fibs (n-1) - state 0: #0 - <app> state 1 - state 1: #0 - <app> state 2 - state 2: #0 - , state 3 - state 3: #0 - <var> state 4 - state 4: #0 - <var> state 5 - state 5: #0 -} end { - rule #0: fibs n = 0,1 if n<=0 - rule #1: fibs n = b,a+b when a,b = fibs (n-1) end - state 0: #0 #1 - <var> state 1 - state 1: #0 #1 -} end; -{ - rule #0: fib2 n = a when a,b = fibs n end with fibs n = 0,1 if n<=0; fibs n = b,a+b when a,b = fibs (n-1) end end - rule #1: fib2 n = a when a,b = fibs n end with fibs n = 0,1 if n<=0; fibs n = b,a+b when a,b = fibs (n-1) end end - state 0: #0 #1 - <var> state 1 - state 1: #0 #1 -} -warning: rule never reduced: fib2 n/*0:1*/ = a/*0:01*/ when a/*0:01*/,b/*0:1*/ = fibs/*0*/ n/*0:1*/ { - rule #0: a,b = fibs n - state 0: #0 - <app> state 1 - state 1: #0 - <app> state 2 - state 2: #0 - , state 3 - state 3: #0 - <var> state 4 - state 4: #0 - <var> state 5 - state 5: #0 -} end with fibs n/*0:1*/ = 0,1 if n/*0:1*/<=0; fibs n/*0:1*/ = b/*0:1*/,a/*0:01*/+b/*0:1*/ when a/*0:01*/,b/*0:1*/ = fibs/*1*/ (n/*0:1*/-1) { - rule #0: a,b = fibs (n-1) - state 0: #0 - <app> state 1 - state 1: #0 - <app> state 2 - state 2: #0 - , state 3 - state 3: #0 - <var> state 4 - state 4: #0 - <var> state 5 - state 5: #0 -} end { - rule #0: fibs n = 0,1 if n<=0 - rule #1: fibs n = b,a+b when a,b = fibs (n-1) end - state 0: #0 #1 - <var> state 1 - state 1: #0 #1 -} end; -map fib2 (1..10); -[1,1,2,3,5,8,13,21,34,55] Deleted: pure/trunk/test/test9.pure =================================================================== --- pure/trunk/test/test9.pure 2008-05-23 01:15:11 UTC (rev 107) +++ pure/trunk/test/test9.pure 2008-05-23 01:24:21 UTC (rev 108) @@ -1,11 +0,0 @@ -fib2 n = a when a, b = fibs n end - with fibs n = 0, 1 if n<=0; - = b, a+b when a, b = fibs (n-1) end - otherwise; - end; -fib2 n = a when a, b = fibs n end - with fibs n = 0, 1 if n<=0; - = b, a+b when a, b = fibs (n-1) end - otherwise; - end; -map fib2 (1..10); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |