March 2014 update
This commit is contained in:
parent
09687c4926
commit
a25938f123
1846 changed files with 21876 additions and 5203 deletions
|
|
@ -16,27 +16,27 @@ Func fix (FuncFunc f) {
|
|||
}
|
||||
|
||||
int main (int argc, const char *argv[]) {
|
||||
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
|
||||
@autoreleasepool {
|
||||
|
||||
FuncFunc almost_fac = ^Func(Func f) {
|
||||
return [[^(int n) {
|
||||
if (n <= 1) return 1;
|
||||
return n * f(n - 1);
|
||||
} copy] autorelease];
|
||||
};
|
||||
FuncFunc almost_fac = ^Func(Func f) {
|
||||
return ^(int n) {
|
||||
if (n <= 1) return 1;
|
||||
return n * f(n - 1);
|
||||
};
|
||||
};
|
||||
|
||||
FuncFunc almost_fib = ^Func(Func f) {
|
||||
return [[^(int n) {
|
||||
if (n <= 2) return 1;
|
||||
return f(n - 1) + f(n - 2);
|
||||
} copy] autorelease];
|
||||
};
|
||||
FuncFunc almost_fib = ^Func(Func f) {
|
||||
return ^(int n) {
|
||||
if (n <= 2) return 1;
|
||||
return f(n - 1) + f(n - 2);
|
||||
};
|
||||
};
|
||||
|
||||
Func fib = fix(almost_fib);
|
||||
Func fac = fix(almost_fac);
|
||||
NSLog(@"fib(10) = %d", fib(10));
|
||||
NSLog(@"fac(10) = %d", fac(10));
|
||||
Func fib = fix(almost_fib);
|
||||
Func fac = fix(almost_fac);
|
||||
NSLog(@"fib(10) = %d", fib(10));
|
||||
NSLog(@"fac(10) = %d", fac(10));
|
||||
|
||||
[pool release];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
14
Task/Y-combinator/TXR/y-combinator.txr
Normal file
14
Task/Y-combinator/TXR/y-combinator.txr
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
@(do
|
||||
;; The Y combinator:
|
||||
(defun y (f)
|
||||
[(op @1 @1)
|
||||
(op f (op [@@1 @@1]))])
|
||||
|
||||
;; The Y-combinator-based factorial:
|
||||
(defun fac (f)
|
||||
(do if (zerop @1)
|
||||
1
|
||||
(* @1 [f (- @1 1)])))
|
||||
|
||||
;; Test:
|
||||
(format t "~s\n" [[y fac] 4]))
|
||||
9
Task/Y-combinator/XQuery/y-combinator-1.xquery
Normal file
9
Task/Y-combinator/XQuery/y-combinator-1.xquery
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
let $Y := function($f) {
|
||||
(function($x) { ($x)($x) })( function($g) { $f( (function($a) { $g($g) ($a)}) ) } )
|
||||
}
|
||||
let $fac := $Y(function($f) { function($n) { if($n < 2) then 1 else $n * $f($n - 1) } })
|
||||
let $fib := $Y(function($f) { function($n) { if($n <= 1) then $n else $f($n - 1) + $f($n - 2) } })
|
||||
return (
|
||||
$fac(6),
|
||||
$fib(6)
|
||||
)
|
||||
1
Task/Y-combinator/XQuery/y-combinator-2.xquery
Normal file
1
Task/Y-combinator/XQuery/y-combinator-2.xquery
Normal file
|
|
@ -0,0 +1 @@
|
|||
720 8
|
||||
Loading…
Add table
Add a link
Reference in a new issue