Subject: Re: how to append an item to a list ?
From: Erik Naggum <>
Date: 2000/01/20
Newsgroups: comp.lang.lisp
Message-ID: <>

* Arseny Slobodjuck
| Actually i need something like push, but unlike push it have to insert
| new item to the end of list.

  if you don't need a list, consider VECTOR-PUSH.

| So, i need an equivalent to 
|        (setq a (concatenate 'list a (list b)))

(append a (list b))

|       (rplacd (last a) (list b))

(setf (setf tail (cdr tail)) (cons b nil))

  is better, once you keep two variables to point into the list:

(setf tail (cons nil nil))
(setf head (cdr tail))

  you might want to do this in a structure or class to capture it in a
  unit, but most of the time, you can use this technique in a short piece
  of code without the overhead of extra datatypes and their accessors.

  however, the most common way to do this is to collect the items in a list
  in reverse, and then reverse the list (destructively, with NREVERSE).
  this won't work if you need access to the list elements along the way, in
  which case only the HEAD/TAIL approach outlined above will do.