summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <matthias@benkard.de>2008-07-01 22:33:04 +0200
committerMatthias Andreas Benkard <matthias@benkard.de>2008-07-01 22:33:04 +0200
commite2b4ef8369024d4cc4749f4262e8d39a59e3859d (patch)
tree8cc7542297bf06a79463a924c4bf3b408d90bb8a
parentfd32c174266aa00a09fd04f5705257855b9e8324 (diff)
Interpreter: Implement IF.
-rw-r--r--MLKInterpreter.m19
1 files changed, 19 insertions, 0 deletions
diff --git a/MLKInterpreter.m b/MLKInterpreter.m
index cf12d6d..95381d0 100644
--- a/MLKInterpreter.m
+++ b/MLKInterpreter.m
@@ -190,6 +190,25 @@ static MLKSymbol *_LAMBDA;
withEnvironment:[MLKLexicalEnvironment
globalEnvironment]];
}
+ else if (car == IF)
+ {
+ id condition = [[program cdr] car];
+ id consequent = [[[program cdr] cdr] car];
+ // Incidentally works for the two-clause case:
+ id alternative = [[[[program cdr] cdr] cdr] car];
+
+ NSArray *values = [self eval:condition
+ inLexicalContext:context
+ withEnvironment:lexenv];
+ if ([values objectAtIndex:0] == [NSNull null])
+ return [self eval:alternative
+ inLexicalContext:context
+ withEnvironment:lexenv];
+ else
+ return [self eval:consequent
+ inLexicalContext:context
+ withEnvironment:lexenv];
+ }
else if (car == _LAMBDA)
{
// A bare-bones LAMBDA without a real lambda list. What