Procedure NCONC
Destructively concatenate two lists by creating a pointer from the CDR of the last cons in the first list to the first cons of the second list.
> (define (nconc l1 l2)
(cond ((null? l1) ())
((pair? (cdr l1)) (nconc (cdr l1) l2))
(#t (set-cdr! l1 l2)) ) )
> (define lst1 '(a b c))
> (define lst2 ‘(d e f))
> (nconc lst1 lst2)
> lst1
(A B C D E F)
Previous slide
Next slide
Back to first slide
View graphic version