From 475dd63b41774c96289df54c7987de95faa55099 Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Thu, 3 Jul 2008 20:17:10 +0200 Subject: Implement MACROEXPAND-1. --- MLKPackage.m | 1 + MLKRoot.m | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/MLKPackage.m b/MLKPackage.m index 4673f0e..bb6e2db 100644 --- a/MLKPackage.m +++ b/MLKPackage.m @@ -99,6 +99,7 @@ static NSMutableDictionary *packages = nil; [sys export:[sys intern:@"MULTIPLY"]]; [sys export:[sys intern:@"DIVIDE"]]; [sys export:[sys intern:@"LIST"]]; + [sys export:[sys intern:@"MACROEXPAND-1"]]; [tlUser usePackage:clUser]; } diff --git a/MLKRoot.m b/MLKRoot.m index cafafe1..a9e15d3 100644 --- a/MLKRoot.m +++ b/MLKRoot.m @@ -209,4 +209,22 @@ static id truify (BOOL value) { RETURN_VALUE ([MLKCons listWithArray:args]); } + ++(NSArray *) macroexpand_1:(NSArray *)args +{ + id form = [args objectAtIndex:0]; + id env = [args count] > 1 ? [args objectAtIndex:1] : nil; + MLKLexicalContext *context = env ? (id)env : (id)[MLKLexicalContext globalContext]; + + if ([context symbolNamesMacro:[form car]]) + { + id macrofun = [context macroForSymbol:[form car]]; + form = denullify ([[macrofun applyToArray: + [NSArray arrayWithObjects: + form, context, nil]] + objectAtIndex:0]); + } + + RETURN_VALUE (form); +} @end -- cgit v1.2.3