From ab10720260e2c184b319026da89f4dfd338500bb Mon Sep 17 00:00:00 2001 From: Brian Cully Date: Wed, 2 Apr 2008 19:20:20 -0400 Subject: Initial commit --- LispSymbol.m | 136 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 LispSymbol.m (limited to 'LispSymbol.m') diff --git a/LispSymbol.m b/LispSymbol.m new file mode 100644 index 0000000..a73a420 --- /dev/null +++ b/LispSymbol.m @@ -0,0 +1,136 @@ +// +// LispSymbol.m +// Moxie +// +// Created by Brian Cully on Tue Sep 07 2004. +// Copyright (c) 2004 Brian Cully. All rights reserved. +// + +#import "LispSymbol.h" + +@implementation LispSymbol +LispSymbol *BIG_T = nil; +LispSymbol *BIG_NIL = nil; + ++ (LispSymbol *)symbolT +{ + if (BIG_T == nil) + BIG_T = [[self alloc] initWithName: @"T"]; + return BIG_T; +} + ++ (LispSymbol *)symbolNIL +{ + if (BIG_NIL == nil) + BIG_NIL = [[self alloc] initWithName: @"NIL"]; + return BIG_NIL; +} + ++ (LispSymbol *)symbolNamed: (NSString *)aName +{ + if ([aName caseInsensitiveCompare: @"T"] == NSOrderedSame) + return [LispSymbol symbolT]; + else if ([aName caseInsensitiveCompare: @"NIL"] == NSOrderedSame) + return [LispSymbol symbolNIL]; + else + return [[[self alloc] initWithName: aName] autorelease]; +} + +- (id)initWithName: (NSString *)aName +{ + self = [super init]; + if (self) { + [self setName: aName]; + } + return self; +} + +- (void)dealloc +{ + [self setName: nil]; + [super dealloc]; +} + +- (NSString *)description +{ + return [NSString stringWithFormat: @"#", [self name]]; +} + +- (BOOL)boolValue +{ + return [self isEqualToString: @"NIL"] == NO; +} + +- (double)doubleValue +{ + return [[self name] doubleValue]; +} + +- (float)floatValue +{ + return [[self name] floatValue]; +} + +- (int)intValue +{ + return [[self name] intValue]; +} + +- (NSString *)stringValue +{ + return [self name]; +} + +- (id)copyWithZone: (NSZone *)aZone +{ + LispSymbol *result; + + result = [[LispSymbol allocWithZone: aZone] init]; + [result setName: [self name]]; + return result; +} + +- (unsigned)hash +{ + return [[self name] hash]; +} + +- (BOOL)isEqual: (id)anObject +{ + BOOL result; + + if ([anObject isKindOfClass: [NSString class]]) + result = [self isEqualToString: anObject]; + else if ([anObject isKindOfClass: [self class]]) { + result = [self isEqualToString: [anObject name]]; + } else + result = [super isEqual: anObject]; + return result; +} + +- (NSString *)lispForm +{ + return [self name]; +} +@end + +@implementation LispSymbol (Accessors) +- (NSString *)name +{ + return theName; +} + +- (void)setName: (NSString *)aName +{ + [aName retain]; + [theName release]; + theName = aName; +} +@end + +@implementation LispSymbol (Comparators) +- (BOOL)isEqualToString: (NSString *)aString +{ + return ([[self name] caseInsensitiveCompare: aString] == NSOrderedSame); +} +@end \ No newline at end of file -- cgit v1.2.3