source: trunk/j/src/org/armedbear/lisp/psetf.lisp @ 8450

Last change on this file since 8450 was 8450, checked in by piso, 17 years ago

"args" => "arguments"

File size: 2.2 KB
Line 
1;;; psetf.lisp
2;;;
3;;; Copyright (C) 2003-2005 Peter Graves
4;;; $Id: psetf.lisp,v 1.3 2005-02-02 16:54:13 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;;; From CMUCL.
21
22(in-package #:system)
23
24(require '#:collect)
25
26(defmacro psetf (&rest args &environment env)
27  "This is to SETF as PSETQ is to SETQ.  Args are alternating place
28   expressions and values to go into those places.  All of the subforms and
29   values are determined, left to right, and only then are the locations
30   updated.  Returns NIL."
31  (collect ((let*-bindings) (mv-bindings) (setters))
32           (do ((a args (cddr a)))
33               ((endp a))
34             (when (endp (cdr a))
35               (error 'simple-program-error
36                      :format-control "Odd number of arguments to PSETF."))
37             (multiple-value-bind
38               (dummies vals newval setter getter)
39               (get-setf-expansion (car a) env)
40               (declare (ignore getter))
41               (let*-bindings (mapcar #'list dummies vals))
42               (mv-bindings (list newval (cadr a)))
43               (setters setter)))
44           (labels ((thunk (let*-bindings mv-bindings)
45                           (if let*-bindings
46                               `(let* ,(car let*-bindings)
47                                  (multiple-value-bind ,@(car mv-bindings)
48                                    ,(thunk (cdr let*-bindings) (cdr mv-bindings))))
49                               `(progn ,@(setters) nil))))
50                   (thunk (let*-bindings) (mv-bindings)))))
Note: See TracBrowser for help on using the repository browser.