nconc can be Dangerous

Consider the following function:

(define (surprise! lst)
  (if (pair? lst)
      (nconc '(a b c) lst)

What happens when this function is used?

> (surprise! '(d))
(a b c d)

> (surprise! '(e f)) (a b c d e f)

> (surprise! '(what??)) (a b c d e f what??)

Rule: Do not use constant data as the first argument of nconc.

Contents    Page-10    Prev    Next    Page+10    Index