summaryrefslogtreecommitdiff
path: root/MLKCons.m
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <matthias@benkard.de>2008-06-27 12:44:25 +0200
committerMatthias Andreas Benkard <matthias@benkard.de>2008-06-27 12:44:25 +0200
commitcb23a76bbd3b7b1ccf4a5ec8894437e449a9047d (patch)
treec3a2a88747a51bf02a4ca028b9a12462eb549ec7 /MLKCons.m
parent01703b9a42e4dac6ae83127ba8fc224e6f581c92 (diff)
MLKInterpreter: Implement the %LAMBDA operator.
Diffstat (limited to 'MLKCons.m')
-rw-r--r--MLKCons.m26
1 files changed, 25 insertions, 1 deletions
diff --git a/MLKCons.m b/MLKCons.m
index b2b3b8b..f56cfd7 100644
--- a/MLKCons.m
+++ b/MLKCons.m
@@ -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
{