From e2b4ef8369024d4cc4749f4262e8d39a59e3859d Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Tue, 1 Jul 2008 22:33:04 +0200 Subject: Interpreter: Implement IF. --- MLKInterpreter.m | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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 -- cgit v1.2.3