summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--MLKInterpreter.m24
1 files changed, 18 insertions, 6 deletions
diff --git a/MLKInterpreter.m b/MLKInterpreter.m
index e03df1d..247bc8e 100644
--- a/MLKInterpreter.m
+++ b/MLKInterpreter.m
@@ -136,7 +136,7 @@ static MLKSymbol *_LAMBDA;
{
id car = [program car];
- if ([car isKindOfClass:[MLKSymbol class]])
+ if ([car isKindOfClass:[MLKSymbol class]] || !car)
{
if (car == APPLY)
{
@@ -145,10 +145,13 @@ static MLKSymbol *_LAMBDA;
withEnvironment:lexenv]
objectAtIndex:0]);
- id <MLKFuncallable> function = denullify([[self eval:[[program cdr] car]
- inLexicalContext:context
- withEnvironment:lexenv]
- objectAtIndex:0]);
+ id function = denullify([[self eval:[[program cdr] car]
+ inLexicalContext:context
+ withEnvironment:lexenv]
+ objectAtIndex:0]);
+
+ if ([function isKindOfClass:[MLKSymbol class]])
+ function = [lexenv functionForSymbol:function];
return [function applyToArray:(rest
? (id)[rest array]
@@ -530,12 +533,19 @@ static MLKSymbol *_LAMBDA;
}
}
}
- else if (![car isKindOfClass:[MLKCons class]] && [car car] == LAMBDA)
+ else if ([car isKindOfClass:[MLKCons class]] && [car car] == LAMBDA)
{
return [self eval:[MLKCons cons:FUNCALL with:program]
inLexicalContext:context
withEnvironment:lexenv];
}
+ else
+ {
+ [NSException raise:@"MLKInvalidExpressionException"
+ format:@"%@ is not a valid operator name.",
+ [car descriptionForLisp]];
+ return nil;
+ }
}
}
@@ -554,6 +564,7 @@ static MLKSymbol *_LAMBDA;
preserveWhitespace:NO];
//NSLog (@"%@", code);
+ //NSLog (@"%@", [code descriptionForLisp]);
//NSLog (@"%@", stream);
//NSLog (@"...");
@@ -565,6 +576,7 @@ static MLKSymbol *_LAMBDA;
eval:code
inLexicalContext:[MLKLexicalContext globalContext]
withEnvironment:[MLKLexicalEnvironment globalEnvironment]];
+ //NSLog (@"; LOAD: Top-level form evaluated.");
if (print)
{