From 317205cbede05a944c9d783df15fba1016dc89d4 Mon Sep 17 00:00:00 2001 From: John Clements Date: Mon, 14 Jan 2008 23:07:24 +0000 Subject: [PATCH] added mappend\! svn: r8326 original commit: 6267a1912236745a97366e122de2779282eb1c22 --- collects/scheme/mpair.ss | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/collects/scheme/mpair.ss b/collects/scheme/mpair.ss index f6b6e3c..01c0d41 100644 --- a/collects/scheme/mpair.ss +++ b/collects/scheme/mpair.ss @@ -6,6 +6,7 @@ mlist? mlength mappend + mappend! mreverse mlist-tail mlist-ref @@ -95,6 +96,19 @@ (mcons (mcar a) (loop (mcdr a)))))] [(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) (let loop ([l l][a null]) (cond