

| |||||||
|
You are here: Root > Software > Development > Code Snippets
The DROP macro removes an element from a list in a place.
This code snippset has been posted by Erik Naggum in comp.lang.lisp. The original post is here
(defmacro drop (object place &rest keys &key key test test-not &environment environment)
"Drop a particular OBJECT from list in PLACE. (Intended as counterpart to PUSH/-NEW.)
Copyright 1999 by Erik Naggum. Verbatim inclusion and redistribution permitted.
For any other use, contact Erik Naggum."
(declare (ignore key test test-not))
(multiple-value-bind (vars vals store-vars writer reader)
(get-setf-expansion place environment)
(let ((evaled-value (gensym))
(store-var (first store-vars)))
(if (cdr store-vars)
`(let* ((,evaled-value ,object)
,@(mapcar #'list vars vals))
(multiple-value-bind ,store-vars ,reader
(setq ,store-var (delete ,evaled-value ,store-var :count 1 ,@keys))
,writer))
`(let* ((,evaled-value ,object)
,@(mapcar #'list vars vals)
(,store-var (delete ,evaled-value ,reader :count 1 ,@keys)))
,writer)))))
You must be logged to add a note
You must be logged to add a comment