From 5458d9ab8b91c0eacc012ad188fc0b63846adf3f Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Sun, 27 Jul 2008 19:05:08 +0200 Subject: Add FUNCTION. --- MLKInterpreter.m | 28 ++++++++++++++++++++++++++++ MLKPackage.m | 1 + 2 files changed, 29 insertions(+) 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 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"]]; -- cgit v1.2.3