From 5fa9211d806a675131b44cc49a694a4fd6a38f2a Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Sun, 6 Jul 2008 20:08:58 +0200 Subject: Implement STRING and FIND-PACKAGE. --- MLKRoot.m | 37 +++++++++++++++++++++++++------------ util.h | 18 ++++++++++++++++++ 2 files changed, 43 insertions(+), 12 deletions(-) diff --git a/MLKRoot.m b/MLKRoot.m index e3dca4f..4ba7ac7 100644 --- a/MLKRoot.m +++ b/MLKRoot.m @@ -26,6 +26,7 @@ #import "MLKInteger.h" #import "MLKSingleFloat.h" #import "MLKDoubleFloat.h" +#import "NSObject-MLKPrinting.h" #import "runtime-compatibility.h" #import "util.h" @@ -48,19 +49,8 @@ static id truify (BOOL value) return (value ? (id) [cl intern:@"T"] : nil); } -static id stringify (id thing) -{ - // FIXME. - if (!thing) - return @"NIL"; - if ([thing isKindOfClass:[NSString class]]) - return thing; - else if ([thing isKindOfClass:[MLKSymbol class]]) - return [thing name]; -} - #define RETURN_VALUE(thing) \ - return [NSArray arrayWithObject:nullify(thing)]; + { return [NSArray arrayWithObject:nullify(thing)]; } @implementation MLKRoot @@ -311,4 +301,27 @@ static id stringify (id thing) RETURN_VALUE ([cl intern:@"T"]); } + ++(NSArray *) find_package:(NSArray *)args +{ + NSString *name = stringify (denullify ([args objectAtIndex:0])); + MLKPackage *package = [MLKPackage findPackage:name]; + + if (package) + { + RETURN_VALUE (package); + } + else + { + [NSException raise:@"MLKNoSuchPackageError" + format:@"The package %@ does not exist", + [name descriptionForLisp]]; + return nil; + } +} + ++(NSArray *) string:(NSArray *)args +{ + RETURN_VALUE (stringify (denullify ([args objectAtIndex:0]))); +} @end diff --git a/util.h b/util.h index 71dc3d6..0e27fc0 100644 --- a/util.h +++ b/util.h @@ -1,4 +1,5 @@ #include "runtime-compatibility.h" +#include #include #define DEFINE_GMP_OPERATION(SIGNATURE, TYPE, GMPOP, OBJTYPE, CONSTRUCTOR) \ @@ -18,6 +19,7 @@ static id nullify (id value) __attribute__ ((pure, unused)); static id denullify (id value) __attribute__ ((pure, unused)); +static id stringify (id value) __attribute__ ((pure, unused)); static id nullify (id value) { @@ -34,3 +36,19 @@ static id denullify (id value) else return value; } + +static id stringify (id thing) +{ + // FIXME: Some cases may be missing. + if (!thing) + return @"NIL"; + if ([thing isKindOfClass:[NSString class]]) + return thing; + else if ([thing isKindOfClass:[MLKSymbol class]]) + return [thing name]; + + [NSException raise:@"MLKTypeError" format:@"Can't coerce %@ to a string.", + [thing descriptionForLisp]]; + + return nil; +} -- cgit v1.2.3