1c26cbbe73b6

Make sure we're portable
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Thu, 03 Nov 2016 17:25:45 +0000
parents b7509448269e
children 784e50fe72f6
branches/tags (none)
files losh.lisp

Changes

--- a/losh.lisp	Tue Nov 01 15:51:05 2016 +0000
+++ b/losh.lisp	Thu Nov 03 17:25:45 2016 +0000
@@ -1468,6 +1468,16 @@
         (ecase ,message
           ,@(mapcar #'parse-clause clauses))))))
 
+(defmacro with-flexible-accessors (slot-entries instance-form &rest body)
+  (with-gensyms (instance)
+    `(let ((,instance ,instance-form))
+      (declare (ignorable ,instance))
+      (symbol-macrolet
+          ,(iterate (for (symbol accessor) :in slot-entries)
+                    (collect `(,symbol (,accessor ,instance))))
+        ,@body))))
+
+
 (defmacro define-with-macro (type-and-options &rest slots)
   "Define a with-`type` macro for the given `type` and `slots`.
 
@@ -1521,7 +1531,7 @@
                                         :for accessor :in accessors
                                         :collect ``(,,arg ,',accessor))))
       `(defmacro ,macro-name ,macro-arglist
-        `(with-accessors ,,`(list ,@accessor-binding-list)
+        `(with-flexible-accessors ,,`(list ,@accessor-binding-list)
           ,,type
           ,@body)))))