summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <matthias@benkard.de>2008-07-03 17:23:37 +0200
committerMatthias Andreas Benkard <matthias@benkard.de>2008-07-03 17:23:37 +0200
commit88ce45f2cd65cf619ead6a07e69d7c8be55cebec (patch)
treed450a2c496a8d32f30eec935a060a4e0969d1a34
parent75996fc51d22cfdcd8b212ce975b703b0ea32c60 (diff)
Add system functions ADD, ATOM, CONSP, DIVIDE, LISTP, MULTIPLY, NULL, SUBTRACT, and SYMBOLP.
-rw-r--r--MLKPackage.m9
-rw-r--r--MLKRoot.m73
2 files changed, 74 insertions, 8 deletions
diff --git a/MLKPackage.m b/MLKPackage.m
index 1fa668d..205dea1 100644
--- a/MLKPackage.m
+++ b/MLKPackage.m
@@ -89,6 +89,15 @@ static NSMutableDictionary *packages = nil;
[sys export:[sys intern:@"CONS"]];
[sys export:[sys intern:@"LOAD"]];
[sys export:[sys intern:@"EQ"]];
+ [sys export:[sys intern:@"ATOM"]];
+ [sys export:[sys intern:@"LISTP"]];
+ [sys export:[sys intern:@"CONSP"]];
+ [sys export:[sys intern:@"SYMBOLP"]];
+ [sys export:[sys intern:@"NULL"]];
+ [sys export:[sys intern:@"ADD"]];
+ [sys export:[sys intern:@"SUBTRACT"]];
+ [sys export:[sys intern:@"MULTIPLY"]];
+ [sys export:[sys intern:@"DIVIDE"]];
[tlUser usePackage:clUser];
}
diff --git a/MLKRoot.m b/MLKRoot.m
index 72bf73f..5c8b4b8 100644
--- a/MLKRoot.m
+++ b/MLKRoot.m
@@ -22,6 +22,9 @@
#import "MLKRoot.h"
#import "MLKStream.h"
#import "MLKSymbol.h"
+#import "MLKInteger.h"
+#import "MLKSingleFloat.h"
+#import "MLKDoubleFloat.h"
#import "runtime-compatibility.h"
#import <Foundation/NSArray.h>
@@ -55,6 +58,15 @@ static MLKPackage *sys;
static MLKPackage *cl;
+static id truify (BOOL value)
+{
+ return (value ? (id) [cl intern:@"T"] : nil);
+}
+
+#define RETURN_VALUE(thing) \
+ return [NSArray arrayWithObject:nullify(thing)];
+
+
@implementation MLKRoot
+(void) initialize
{
@@ -150,17 +162,62 @@ static MLKPackage *cl;
[input close];
- if (success)
- return [NSArray arrayWithObject:[cl intern:@"T"]];
- else
- return [NSArray arrayWithObject:[NSNull null]];
+ RETURN_VALUE (truify (success));
}
+(NSArray *) eq:(NSArray *)args
{
- if ([args objectAtIndex:0] == [args objectAtIndex:1])
- return [NSArray arrayWithObject:[cl intern:@"T"]];
- else
- return [NSArray arrayWithObject:[NSNull null]];
+ RETURN_VALUE (truify ([args objectAtIndex:0] == [args objectAtIndex:1]));
+}
+
++(NSArray *) symbolp:(NSArray *)args
+{
+ id arg0 = [args objectAtIndex:0];
+ RETURN_VALUE (truify (arg0 == [NSNull null]
+ || [arg0 isKindOfClass:[MLKSymbol class]]));
+}
+
++(NSArray *) listp:(NSArray *)args
+{
+ id arg0 = [args objectAtIndex:0];
+ RETURN_VALUE (truify (arg0 == [NSNull null]
+ || [arg0 isKindOfClass:[MLKCons class]]));
+}
+
++(NSArray *) consp:(NSArray *)args
+{
+ id arg0 = [args objectAtIndex:0];
+ RETURN_VALUE (truify ([arg0 isKindOfClass:[MLKCons class]]));
+}
+
++(NSArray *) atom:(NSArray *)args
+{
+ id arg0 = [args objectAtIndex:0];
+ RETURN_VALUE (truify (![arg0 isKindOfClass:[MLKCons class]]));
+}
+
++(NSArray *) null:(NSArray *)args
+{
+ RETURN_VALUE (truify ([args objectAtIndex:0] == [NSNull null]));
+}
+
++(NSArray *) add:(NSArray *)args
+{
+ RETURN_VALUE ([[args objectAtIndex:0] add:[args objectAtIndex:1]]);
+}
+
++(NSArray *) subtract:(NSArray *)args
+{
+ RETURN_VALUE ([[args objectAtIndex:0] subtract:[args objectAtIndex:1]]);
+}
+
++(NSArray *) multiply:(NSArray *)args
+{
+ RETURN_VALUE ([[args objectAtIndex:0] multiplyWith:[args objectAtIndex:1]]);
+}
+
++(NSArray *) divide:(NSArray *)args
+{
+ RETURN_VALUE ([[args objectAtIndex:0] divideBy:[args objectAtIndex:1]]);
}
@end