summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <matthias@benkard.de>2008-07-27 19:05:08 +0200
committerMatthias Andreas Benkard <matthias@benkard.de>2008-07-27 19:05:08 +0200
commit5458d9ab8b91c0eacc012ad188fc0b63846adf3f (patch)
treecd3f68da945134cb9a6e89c0add87a691af66b33
parent2e2b608c4f04f9a5591f354029c257453b6c31cf (diff)
Add FUNCTION.
-rw-r--r--MLKInterpreter.m28
-rw-r--r--MLKPackage.m1
2 files changed, 29 insertions, 0 deletions
diff --git a/MLKInterpreter.m b/MLKInterpreter.m
index 46b8676..8237f7b 100644
--- a/MLKInterpreter.m
+++ b/MLKInterpreter.m
@@ -54,6 +54,7 @@ static MLKSymbol *LAMBDA;
static MLKSymbol *LET;
static MLKSymbol *APPLY;
static MLKSymbol *FUNCALL;
+static MLKSymbol *FUNCTION;
static MLKSymbol *EVAL;
static MLKSymbol *QUOTE;
static MLKSymbol *SETQ;
@@ -85,6 +86,8 @@ static MLKSymbol *_LAMBDA;
LET = [cl intern:@"LET"];
APPLY = [cl intern:@"APPLY"];
EVAL = [cl intern:@"EVAL"];
+ FUNCALL = [cl intern:@"FUNCALL"];
+ FUNCTION = [cl intern:@"FUNCTION"];
QUOTE = [cl intern:@"QUOTE"];
SETQ = [cl intern:@"SETQ"];
SETF = [cl intern:@"SETF"];
@@ -317,6 +320,31 @@ static MLKSymbol *_LAMBDA;
withEnvironment:[MLKLexicalEnvironment
globalEnvironment]];
}
+ else if (car == FUNCTION)
+ {
+ id functionName = [[program cdr] car];
+
+ if ([functionName isKindOfClass:[MLKCons class]]
+ && ([functionName car] == LAMBDA
+ || [functionName car] == _LAMBDA))
+ {
+ return [self eval:functionName
+ inLexicalContext:context
+ withEnvironment:lexenv
+ expandOnly:expandOnly];
+ }
+ else if (expandOnly)
+ {
+ RETURN_VALUE (program);
+ }
+ else
+ {
+ // FIXME: Function names need not be symbols.
+ id <MLKFuncallable> function =
+ [lexenv functionForSymbol:functionName];
+ RETURN_VALUE (function);
+ }
+ }
else if (car == IF)
{
id condition = [[program cdr] car];
diff --git a/MLKPackage.m b/MLKPackage.m
index 3d94d69..93dece3 100644
--- a/MLKPackage.m
+++ b/MLKPackage.m
@@ -73,6 +73,7 @@ static NSMutableDictionary *packages = nil;
[cl export:[cl intern:@"LET"]];
[cl export:[cl intern:@"LAMBDA"]];
[cl export:[cl intern:@"FUNCALL"]];
+ [cl export:[cl intern:@"FUNCTION"]];
[cl export:[cl intern:@"PROGN"]];
[cl export:[cl intern:@"APPLY"]];
[cl export:[cl intern:@"PROGV"]];