March 2014 update
This commit is contained in:
parent
09687c4926
commit
a25938f123
1846 changed files with 21876 additions and 5203 deletions
|
|
@ -5,21 +5,22 @@ int fib(int n) {
|
|||
@throw [NSException exceptionWithName:NSInvalidArgumentException
|
||||
reason:@"fib: no negative numbers"
|
||||
userInfo:nil];
|
||||
__block int (^f)(int);
|
||||
f = ^(int n) {
|
||||
int (^f)(int);
|
||||
__block __weak int (^weak_f)(int); // block cannot capture strong reference to itself
|
||||
weak_f = f = ^(int n) {
|
||||
if (n < 2)
|
||||
return 1;
|
||||
else
|
||||
return f(n-1) + f(n-2);
|
||||
return weak_f(n-1) + weak_f(n-2);
|
||||
};
|
||||
return f(n);
|
||||
}
|
||||
|
||||
int main (int argc, const char *argv[]) {
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
@autoreleasepool {
|
||||
|
||||
NSLog(@"%d", fib(8));
|
||||
NSLog(@"%d", fib(8));
|
||||
|
||||
[pool release];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue