#lang racket ;; appending two lists using list surgery (define (append! xs ys) (cond [(null? xs) ys] [else (set-mcdr! (lastcell xs) ys) xs])) (define (lastcell xs) (if (null? (mcdr xs)) xs (lastcell (mcdr xs)))) ; utility function to make a mutable list (like the existing 'list' procedure) ; this takes a variable number of arguments (including 0) (define (mlist . args) (if (null? args) null (mcons (car args) (apply mlist (cdr args))))) (define j (mlist 1 2 3)) (define k (mlist 10 11 12 13 14 15)) ; now try (append! j k) ; look at the result and also j and k