Skip to content

Instantly share code, notes, and snippets.

@spacebat
Created April 8, 2013 22:57
Show Gist options
  • Select an option

  • Save spacebat/5341291 to your computer and use it in GitHub Desktop.

Select an option

Save spacebat/5341291 to your computer and use it in GitHub Desktop.
Insert an element before another in a list
(let ((data '((a 1 2 3)(c 5 6 7)))
(insert '(b x y z)))
(loop for prev on data
for next on (cdr data)
if (and next (eq (caar next) 'c))
do (let ((newcons (cons insert next)))
(setcdr prev newcons)))
data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment