Directory | Tags | Index | LinkIt | Submit   | Help
    Monday, 01 September 2014 - anonymous
Login/Register to vote and to have access to more features

You are here: Root > Software > Development > Code Snippets

DROP: a push/pushnew complement
Created by marc.battyani on: Sun, 02 Jul 2006 19:24:42 GMT, Last modification: Sun, 02 Jul 2006 19:24:42 GMT

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))))) 

Tags

Code Snippets | Utilities

0 Notes and 0 comments

0 Notes

You must be logged to add a note


0 Comments

You must be logged to add a comment