diff options
author | Matthias Andreas Benkard <matthias@benkard.de> | 2008-06-27 12:44:25 +0200 |
---|---|---|
committer | Matthias Andreas Benkard <matthias@benkard.de> | 2008-06-27 12:44:25 +0200 |
commit | cb23a76bbd3b7b1ccf4a5ec8894437e449a9047d (patch) | |
tree | c3a2a88747a51bf02a4ca028b9a12462eb549ec7 /MLKCons.m | |
parent | 01703b9a42e4dac6ae83127ba8fc224e6f581c92 (diff) |
MLKInterpreter: Implement the %LAMBDA operator.
Diffstat (limited to 'MLKCons.m')
-rw-r--r-- | MLKCons.m | 26 |
1 files changed, 25 insertions, 1 deletions
@@ -26,7 +26,7 @@ @implementation MLKCons +(MLKCons*) cons:(id)car with:(id)cdr { - return AUTORELEASE ([[MLKCons alloc] initWithCar:car cdr:cdr]); + return AUTORELEASE ([[self alloc] initWithCar:car cdr:cdr]); } -(MLKCons*) initWithCar:(id)car cdr:(id)cdr @@ -37,6 +37,30 @@ return self; } ++(MLKCons*) listWithArray:(NSArray *)array +{ + MLKCons *cons, *tail; + int i; + + cons = nil; + tail = nil; + + for (i = 0; i < [array count]; i++) + { + id item = [array objectAtIndex:i]; + if (!tail) + { + cons = tail = [MLKCons cons:item with:nil]; + } + else + { + [tail setCdr:[MLKCons cons:item with:nil]]; + tail = [tail cdr]; + } + } + + return cons; +} -(id) car { |