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 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'MLKInterpreter.m') 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]; -- cgit v1.2.3