source: trunk/j/src/org/armedbear/lisp/rotatef.lisp @ 7353

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

Initial checkin.

File size: 1.6 KB
Line 
1;;; rotatef.lisp
2;;;
3;;; Copyright (C) 2004 Peter Graves
4;;; $Id: rotatef.lisp,v 1.1 2004-08-02 19:20:23 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(in-package "SYSTEM")
23
24(require '#:collect)
25
26(defmacro rotatef (&rest args &environment env)
27  (when args
28    (collect ((let*-bindings) (mv-bindings) (setters) (getters))
29      (dolist (arg args)
30  (multiple-value-bind (temps subforms store-vars setter getter)
31      (get-setf-expansion arg env)
32    (loop
33      for temp in temps
34      for subform in subforms
35      do (let*-bindings `(,temp ,subform)))
36    (mv-bindings store-vars)
37    (setters setter)
38    (getters getter)))
39      (setters nil)
40      (getters (car (getters)))
41      (labels ((thunk (mv-bindings getters)
42     (if mv-bindings
43         `((multiple-value-bind ,(car mv-bindings) ,(car getters)
44       ,@(thunk (cdr mv-bindings) (cdr getters))))
45         (setters))))
46  `(let* ,(let*-bindings)
47     ,@(thunk (mv-bindings) (cdr (getters))))))))
Note: See TracBrowser for help on using the repository browser.