added mappend\!

svn: r8326

original commit: 6267a1912236745a97366e122de2779282eb1c22
This commit is contained in:
John Clements 2008-01-14 23:07:24 +00:00
parent 61121abe07
commit 317205cbed

View File

@ -6,6 +6,7 @@
mlist? mlist?
mlength mlength
mappend mappend
mappend!
mreverse mreverse
mlist-tail mlist-tail
mlist-ref mlist-ref
@ -95,6 +96,19 @@
(mcons (mcar a) (loop (mcdr a)))))] (mcons (mcar a) (loop (mcdr a)))))]
[(a . l) (mappend a (apply mappend l))])) [(a . l) (mappend a (apply mappend l))]))
;; mappend! : like append, but mutate each list to refer to the next.
;; modeled loosely on the v372 behavior
(define mappend!
(case-lambda
[() null]
[(a) a]
[(a b) (let loop ([atail a])
(cond [(null? atail) b]
[(null? (mcdr atail)) (set-mcdr! atail b) a]
[else (loop (mcdr atail))]))]
[(a . l) (mappend! a (apply mappend! l))]))
(define (mreverse l) (define (mreverse l)
(let loop ([l l][a null]) (let loop ([l l][a null])
(cond (cond