Subject: Re: Novice question -- inserting element in list
From: Erik Naggum <erik@naggum.no>
Date: 1996/02/06
Newsgroups: comp.lang.lisp
Message-ID: <19960206T162730Z@arcana.naggum.no>

[Gregory Santos]

|   I would simply like to insert an element into the central portion of a
|   list (not the beginning or end) with the highest degree of efficiency
|   possible, knowing only the node after or before which I wish to insert
|   the new node.

(defun insert-after (newelt list index)
  "Insert NEWELT in LIST after the INDEXth cell.
Returns LIST."
  (let ((cell (nthcdr index list)))
    (setf (cdr cell) (cons newelt (cdr cell))))
  list)

#<Erik 3032612850517114>
-- 
BEOL and ENDOL: the ultimate general purpose programming languages