From 3329eeafa1f08c5b9d410e57f761011d2e1ac1d6 Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Thu, 7 Aug 2008 14:21:27 +0200 Subject: Centralise declaration and documentation string handling. --- MLKCons.m | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) (limited to 'MLKCons.m') diff --git a/MLKCons.m b/MLKCons.m index ba543b9..67aba08 100644 --- a/MLKCons.m +++ b/MLKCons.m @@ -98,7 +98,42 @@ return array; } --(NSString *)bareDescriptionForLisp +-(void) appendObject:(id)object +{ + MLKCons *rest; + + rest = self; + while (rest->_cdr) + { + rest = rest->_cdr; + } + + LASSIGN (rest->_cdr, object); +} + +-(MLKCons *) listByAppendingObject:(id)object +{ + MLKCons *rest = _cdr; + MLKCons *new_list = [MLKCons cons:_car with:nil]; + MLKCons *tail = new_list; + + while (rest) + { + LASSIGN (tail->_cdr, [MLKCons cons:rest->_car with:nil]); + tail = tail->_cdr; + } + + LASSIGN (tail->_cdr, object); + + return new_list; +} + +-(MLKCons *) copyList +{ + return [self listByAppendingObject:nil]; +} + +-(NSString *) bareDescriptionForLisp { if (!_cdr) return [NSString stringWithFormat:@"%@", @@ -130,6 +165,15 @@ return [NSString stringWithFormat:@"(%@)", [self bareDescriptionForLisp]]; } +-(BOOL) isEqual:(id)object +{ + if ([object isKindOfClass:[MLKCons class]]) + return ([((MLKCons*)object)->_car isEqual:_car] + && [((MLKCons*)object)->_cdr isEqual:_cdr]); + else + return NO; +} + -(id) copyWithZone:(NSZone *)zone { MLKCons *copy = [MLKCons allocWithZone:zone]; -- cgit v1.2.3