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

Last change on this file since 8501 was 8501, checked in by piso, 16 years ago

Section 5.1.3.

File size: 2.0 KB
Line 
1;;; remf.lisp
2;;;
3;;; Copyright (C) 2003-2005 Peter Graves
4;;; $Id: remf.lisp,v 1.2 2005-02-07 17:48:02 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;;; Adapted from SBCL.
21
22(defmacro remf (place indicator &environment env)
23  "Place may be any place expression acceptable to SETF, and is expected
24   to hold a property list or (). This list is destructively altered to
25   remove the property specified by the indicator. Returns T if such a
26   property was present, NIL if not."
27  (multiple-value-bind (dummies vals newval setter getter)
28      (get-setf-expansion place env)
29    (do* ((d dummies (cdr d))
30    (v vals (cdr v))
31    (let-list nil)
32    (ind-temp (gensym))
33    (local1 (gensym))
34    (local2 (gensym)))
35   ((null d)
36          ;; See ANSI 5.1.3 for why we do out-of-order evaluation
37    (push (list ind-temp indicator) let-list)
38    (push (list (car newval) getter) let-list)
39    `(let* ,(nreverse let-list)
40       (do ((,local1 ,(car newval) (cddr ,local1))
41      (,local2 nil ,local1))
42     ((atom ,local1) nil)
43         (cond ((atom (cdr ,local1))
44          (error "Odd-length property list in REMF."))
45         ((eq (car ,local1) ,ind-temp)
46          (cond (,local2
47           (rplacd (cdr ,local2) (cddr ,local1))
48           (return t))
49          (t (setq ,(car newval) (cddr ,(car newval)))
50             ,setter
51             (return t))))))))
52      (push (list (car d) (car v)) let-list))))
Note: See TracBrowser for help on using the repository browser.