source: trunk/j/src/org/armedbear/lisp/remf.lisp @ 3819

Last change on this file since 3819 was 3819, checked in by piso, 18 years ago

Initial checkin.

File size: 2.2 KB
Line 
1;;; remf.lisp
2;;;
3;;; Copyright (C) 2003 Peter Graves
4;;; $Id: remf.lisp,v 1.1 2003-09-16 16:47:49 piso Exp $
5;;;
6;;; This program is free software; you can redistribute it and/or
7;;; modify it under the terms of the GNU General Public License
8;;; as published by the Free Software Foundation; either version 2
9;;; of the License, or (at your option) any later version.
10;;;
11;;; This program is distributed in the hope that it will be useful,
12;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14;;; GNU General Public License for more details.
15;;;
16;;; You should have received a copy of the GNU General Public License
17;;; along with this program; if not, write to the Free Software
18;;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19
20;;; REMF (from OpenMCL)
21(defmacro remf (place indicator &environment env)
22  "Place may be any place expression acceptable to SETF, and is expected
23   to hold a property list or ().  This list is destructively altered to
24   remove the property specified by the indicator.  Returns T if such a
25   property was present, NIL if not."
26  (multiple-value-bind (dummies vals newval setter getter)
27    (get-setf-expansion place env)
28    (do* ((d dummies (cdr d))
29          (v vals (cdr v))
30          (let-list nil)
31          (ind-temp (gensym))
32          (local1 (gensym))
33          (local2 (gensym)))
34         ((null d)
35          (push (list (car newval) getter) let-list)
36          (push (list ind-temp indicator) let-list)
37          `(let* ,(nreverse let-list)
38             (do ((,local1 ,(car newval) (cddr ,local1))
39                  (,local2 nil ,local1))
40                 ((atom ,local1) nil)
41               (cond ((atom (cdr ,local1))
42                      (error "odd-length property list in REMF"))
43                     ((eq (car ,local1) ,ind-temp)
44                      (cond (,local2
45                             (rplacd (cdr ,local2) (cddr ,local1))
46                             (return t))
47                            (t (setq ,(car newval) (cddr ,(car newval)))
48                               ,setter
49                               (return t))))))))
50      (push (list (car d) (car v)) let-list))))
Note: See TracBrowser for help on using the repository browser.