diff options
author | Matthias Andreas Benkard <matthias@benkard.de> | 2008-06-17 16:11:43 +0200 |
---|---|---|
committer | Matthias Andreas Benkard <matthias@benkard.de> | 2008-06-17 16:11:43 +0200 |
commit | d6d73cfbcfd4eae88e53c4c30e221a66daade5e1 (patch) | |
tree | 844f1974e5d2fe9e5859ea6e7ddf6e506fc64e54 | |
parent | 1cf2f94d79396d81bdc798768687c1bef86a9102 (diff) |
MLKCons, MLKSymbol: Override -descriptionForLisp.
-rw-r--r-- | MLKCons.h | 5 | ||||
-rw-r--r-- | MLKCons.m | 21 | ||||
-rw-r--r-- | MLKSymbol.h | 2 | ||||
-rw-r--r-- | MLKSymbol.m | 8 |
4 files changed, 36 insertions, 0 deletions
@@ -34,5 +34,10 @@ -(void) setCar:(id)value; -(void) setCdr:(id)value; +-(NSString *)bareDescriptionForLisp; // description without + // parentheses, for internal use + // only +-(NSString *)descriptionForLisp; + -(void) dealloc; @end @@ -18,6 +18,8 @@ #import "MLKCons.h" +#import <Foundation/NSString.h> + @implementation MLKCons +(MLKCons*) cons:(id)car with:(id)cdr @@ -54,6 +56,25 @@ ASSIGN (_cdr, value); } +-(NSString *)bareDescriptionForLisp +{ + if (!_cdr) + return [NSString stringWithFormat:@"%@", [_car descriptionForLisp]]; + else if (![_cdr isKindOfClass:[MLKCons class]]) + return [NSString stringWithFormat:@"%@ %@", + [_car descriptionForLisp], + [_cdr bareDescriptionForLisp]]; + else + return [NSString stringWithFormat:@"%@ . %@", + [_car descriptionForLisp], + [_cdr descriptionForLisp]]; +} + +-(NSString *)descriptionForLisp +{ + return [NSString stringWithFormat:@"(%@)", [self bareDescriptionForLisp]]; +} + -(void) dealloc { RELEASE (_car); diff --git a/MLKSymbol.h b/MLKSymbol.h index 6fe3eb6..82526d2 100644 --- a/MLKSymbol.h +++ b/MLKSymbol.h @@ -33,5 +33,7 @@ -(MLKPackage *) homePackage; -(void) setHomePackage:(MLKPackage *)aPackage; +-(NSString *)descriptionForLisp; + -(void) dealloc; @end diff --git a/MLKSymbol.m b/MLKSymbol.m index 3443e37..42a7141 100644 --- a/MLKSymbol.m +++ b/MLKSymbol.m @@ -18,6 +18,8 @@ #import "MLKSymbol.h" +#import <Foundation/NSString.h> + @implementation MLKSymbol -(MLKSymbol *) initWithName:(id)aName package:(id)aPackage @@ -43,6 +45,12 @@ ASSIGN (homePackage, aPackage); } +-(NSString *)descriptionForLisp +{ + // FIXME: This is wrong in more than one way. + return [NSString stringWithFormat:@"|%@|", name]; +} + -(void) dealloc { RELEASE (name); |