# HG changeset patch # User Steve Losh # Date 1478193945 0 # Node ID 1c26cbbe73b692f177cd66755c8603a83b75ec88 # Parent b7509448269edf9f895836b11ba4108d6f3f1b8c Make sure we're portable diff -r b7509448269e -r 1c26cbbe73b6 losh.lisp --- 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)))))