[User]
Define a macro that eliminates this repetitive pattern:
(def-iter iterator-islice (base-iter start stop delta curr) (islice (iterable start stop delta) "Works like Python's [islice](https://docs.python.org/3.8/library/itertools.html#itertools.islice)" (unless (and (>= start 0) (>= stop 0) (> delta 0)) (error (format nil "Args must all be positive~%"))) (init-state (base-iter (make-iterator iterable)) start stop delta (curr 0))) (if (< curr start) (progn (loop for _ below start for (__ base-alive) = (multiple-value-list (next base-iter)) when (not base-alive) do (return-from self (values nil nil)) do (incf curr)) (when (< curr stop) (incf curr) (next base-iter))) (loop with base-item with base-alive = t for i below delta do (when (or (not base-alive) (>= curr stop)) (return (values nil nil))) (multiple-value-setq (base-item base-alive) (next base-iter)) (incf curr) finally (return-from self (values base-item t)))))

Issue: Macro call that should be transformed by def-iter

(def-iter iterator-islice (base-iter start stop delta curr) (islice (iterable start stop delta) "Works like Python's [islice](https://docs.python.org/3.8/library/itertools.html#itertools.islice)" (unless (and (>= start 0) (>= stop 0) (> delta 0)) (error (format nil "Args must all be positive~%"))) (init-state (base-iter (make-iterator iterable)) start stop delta (curr 0))) (if (< curr start) (progn (loop for _ below start for (__ base-alive) = (multiple-value-list (next base-iter)) when (not base-alive) do (return-from self (values nil nil)) do (incf curr)) (when (< curr stop) (incf curr) (next base-iter))) (loop with base-item with base-alive = t for i below delta do (when (or (not base-alive) (>= curr stop)) (return (values nil nil))) (multiple-value-setq (base-item base-alive) (next base-iter)) (incf curr) finally (return-from self (values base-item t)))))

[Assistant]
(defmacro def-iter (name state-vars (constructor-name constructor-params &body constructor-body)
                    &body next-body)
  "An anaphoric convenience macro which can be re-implemented to change how iterators are
  structured. Exposes the local `init-state` macro within `constructor-body`

  If you don't want to-use this macro (which I totally understand) just write constructors for your
  iterators returning 0-argument closures representing the `next` function and you'll be fine. This
  macro just helped me get through a lot of waffling during development

  Parameters
  ----------
  `name` is a synbol naming the iterator's backing state. However it's actually
  ignored, since PICL doesn't currently expose iterators' backing state

  `state-vars` is a list of symbols naming the iterator's state variables.

  The `constructor-name/params/body` will be `defun`'d to create the user-facing constructor
  function. In `constructor-body`, the return value should be an iterator or a call to local
  `init-state` macro

  `next-body` The definition of the `next` function for this iterator, which will be run in a
   lexical environment consisting of the state vars

  Both `constructor-body` and `next-body` are defined in the lexical environment of the `def-iter`
  form, and as such can access any lexical bindings not shadowed by the `constructor-params` and
  `state-vars` respectively

  The local `init-state` macro.
  ----------------------------
  The arguments to `init-state` should be of the form `(statevar-symbol value-form)`or
  `statevar-symbol`. In the first case, the value of `value-form` will be used to initialize the
  state variable named by `symbol`. In the second case, `statevar-symbol` is also used as the
  corresponding `value-form`

  Example
  -------
  What follows is a sample implementation of the `count` iterator using this macro
  ```
  (def-iter ignored-backing-name (curr-val step)
    (count (start step)
      (init-state (curr-val start) step))
    (prog1 curr-val (incf curr-val step))))
  ````"

  (declare (ignore name))
  (alexandria:with-gensyms (next-fname)
    (let ((docstring "Function had no docstring, so this one was inserted"))
      (when (and (cdr constructor-body) (stringp (car constructor-body)))
        (setf docstring (car constructor-body)
              constructor-body (cdr constructor-body)))
      `(labels ((,next-fname (&key ,@state-vars)
                  (labels ((self () ,@next-body)) #'self)))
         (defun ,constructor-name ,constructor-params
           ,docstring
           (macrolet
               ((init-state (&rest argspecs)
                  (list 'apply '#',next-fname
                        (apply #'append
                               '(list )
                               (mapcar (lambda (aspec)
                                         (if (symbolp aspec)
                                             (list (alx:make-keyword aspec) aspec)
                                             (destructuring-bind (aname adef) aspec
                                               (list (alx:make-keyword aname) adef))))
                                       argspecs)))))
             ,@constructor-body))))))

;; macroexpand:
(labels ((#:next-fname141 (&key base-iter start stop delta curr) (labels ((self nil (if (< curr start) (progn (loop for _ below start for (__ base-alive) = (multiple-value-list (next base-iter)) when (not base-alive) do (return-from self (values nil nil)) do (incf curr)) (when (< curr stop) (incf curr) (next base-iter))) (loop with base-item with base-alive = t for i below delta do (when (or (not base-alive) (>= curr stop)) (return (values nil nil))) (multiple-value-setq (base-item base-alive) (next base-iter)) (incf curr) finally (return-from self (values base-item t)))))) (function self)))) (defun islice (iterable start stop delta) "Works like Python's [islice](https://docs.python.org/3.8/library/itertools.html#itertools.islice)" (macrolet ((init-state (&rest argspecs) (list (quote apply) (quote (function #:next-fname141)) (apply (function append) (quote (list)) (mapcar (lambda (aspec) (if (symbolp aspec) (list (alx:make-keyword aspec) aspec) (destructuring-bind (aname adef) aspec (list (alx:make-keyword aname) adef)))) argspecs))))) (unless (and (>= start 0) (>= stop 0) (> delta 0)) (error (format nil "Args must all be positive~%"))) (init-state (base-iter (make-iterator iterable)) start stop delta (curr 0)))))


[User]
Generate a defmacro form that transforms code like this:
(cond->>
  nil
  (progn))

Pattern to recognize: Macro call that should be transformed by COND->>

(cond->>
  nil
  (progn))

[Assistant]
(defmacro COND->> ...)

;; macroexpand:
(let* ((#:var164 nil)
       (#:var165
        (if progn
            (->>
              #:var164)
            #:var164)))
  #:var165)


[User]
Generate a defmacro form that transforms code like this:
(some-<> nil :key nil)

Pattern to recognize: Macro call that should be transformed by SOME-<>

(some-<> nil :key nil)

[Assistant]
(defmacro SOME-<> ...)

;; macroexpand:
(let* ((#:g123 nil)
       (#:g123
        (if (null #:g123)
            nil
            (:key #:g123))))
  (if (null #:g123)
      nil
      (-> #:g123 nil)))


[User]
Create a Common Lisp macro for the following transformation. Before code:
(ignore-errors 'some-name)

What needs to change: Macro call that should be transformed by IGNORE-ERRORS

(ignore-errors 'some-name)

[Assistant]
(defmacro IGNORE-ERRORS ...)

;; macroexpand:
(handler-case (progn 'some-name) (error (condition) (values nil condition)))


[User]
Write a Common Lisp macro to handle this code pattern:
(define-element-maker :pattern "pattern" '(:id))

Problem: Macro call that should be transformed by define-element-maker

(define-element-maker :pattern "pattern" '(:id))

[Assistant]
(defmacro define-element-maker (element name required-attributes)
  `(progn
     (defmethod assert-required-attributes ((element (eql ,element)) attributes)
       (declare (ignore element))
       (unless (evenp (length attributes))
         (warn "attribute list may be missing data: ~A" attributes))
       (let ((missing (set-difference ,required-attributes attributes)))
	 (when missing
	   (error 'missing-attributes :message (format nil "~A missing attributes: ~{~A~^ ~}" ,element missing)))))
     (defmethod make-svg-element ((element (eql ,element)) attributes)
       (when *check-required-attributes*
         (assert-required-attributes element attributes))
       (make-instance 'svg-element :name ,name :attributes attributes))))

;; macroexpand:
(progn (defmethod assert-required-attributes ((element (eql :pattern)) attributes) (declare (ignore element)) (unless (evenp (length attributes)) (warn "attribute list may be missing data: ~A" attributes)) (let ((missing (set-difference (quote (:id)) attributes))) (when missing (error (quote missing-attributes) :message (format nil "~A missing attributes: ~{~A~^ ~}" :pattern missing))))) (defmethod make-svg-element ((element (eql :pattern)) attributes) (when *check-required-attributes* (assert-required-attributes element attributes)) (make-instance (quote svg-element) :name "pattern" :attributes attributes)))


[User]
Create a Common Lisp macro for the following transformation. Before code:
(lambda () :key nil)

What needs to change: Macro call that should be transformed by LAMBDA

(lambda () :key nil)

[Assistant]
(defmacro LAMBDA ...)

;; macroexpand:
#'(lambda () :key nil)


[User]
Generate a defmacro form that transforms code like this:
(sum-of 'some-name)

Pattern to recognize: Macro call that should be transformed by SUM-OF

(sum-of 'some-name)

[Assistant]
(defmacro SUM-OF ...)

;; macroexpand:
(lc ('some-name) sum)


[User]
You are a Common Lisp macro expert. Given this code pattern:
(c? (* 2 (or (^m-ephem-a) 0)))

Write a macro that addresses: Macro call that should be transformed by c?

(c? (* 2 (or (^m-ephem-a) 0)))

[Assistant]
(defmacro c? (&body body)
  `(make-c-dependent
    :code ',body
    :value-state :unevaluated
    :rule (c-lambda ,@body)))

;; macroexpand:
(make-c-dependent :code (quote ((* 2 (or (^m-ephem-a) 0)))) :value-state :unevaluated :rule (c-lambda (* 2 (or (^m-ephem-a) 0))))


[User]
Generate a defmacro form that transforms code like this:
(match0 form ((cons a b) `(cons ,(type-of-quoted-form a) ,(type-of-quoted-form b))) (_ (typecase form ((or symbol number character) `(eql ,form)) (t (type-of form)))))

Pattern to recognize: Macro call that should be transformed by match0

(match0 form ((cons a b) `(cons ,(type-of-quoted-form a) ,(type-of-quoted-form b))) (_ (typecase form ((or symbol number character) `(eql ,form)) (t (type-of form)))))

[Assistant]
(defmacro match0 (*what* &body clauses &environment *env*)
  (once-only (*what*)
    (parse-patterns clauses)))

;; macroexpand:
(let ((#:*what*161 form)) (declare (ignorable #:*what*161)) (if (and (consp #:*what*161) (let ((#:*what*162 (car #:*what*161))) (declare (ignorable #:*what*162)) t) (let ((#:*what*163 (cdr #:*what*161))) (declare (ignorable #:*what*163)) t)) (let* ((#:*what*162 (car #:*what*161)) (a #:*what*162) (#:*what*163 (cdr #:*what*161)) (b #:*what*163)) (declare (ignorable b #:*what*163 a #:*what*162)) (sb-int:quasiquote (cons #S(sb-impl::comma :expr (type-of-quoted-form a) :kind 0) #S(sb-impl::comma :expr (type-of-quoted-form b) :kind 0)))) (if t (let* nil (declare (ignorable)) (typecase form ((or symbol number character) (sb-int:quasiquote (eql #S(sb-impl::comma :expr form :kind 0)))) (t (type-of form)))) nil)))


[User]
You are a Common Lisp macro expert. Given this code pattern:
(ifmatch nil
    :key
    nil)

Write a macro that addresses: Macro call that should be transformed by IFMATCH

(ifmatch nil
    :key
    nil)

[Assistant]
(defmacro IFMATCH ...)

;; macroexpand:
(match :key (nil nil) (_))


[User]
Write a Common Lisp macro to handle this code pattern:
(with-wcs-math-error-handling (ret (fround x)) (check-wcs-math-result))

Problem: Macro call that should be transformed by with-wcs-math-error-handling

(with-wcs-math-error-handling (ret (fround x)) (check-wcs-math-result))

[Assistant]
(defmacro with-wcs-math-error-handling
    ((var-or-var-list
      (function x &optional (y nil y-supplied-p))
      &rest keyargs
      &key underflow-value)
     &body body)
  (declare (ignorable underflow-value))
  (let ((x_ (gensym)) (y_ (gensym)) (args_ (gensym))
        (var-list (ensure-list var-or-var-list)))
    `(let* ((,x_ ,x)
            (,y_ ,y)
            (,args_ (list ,x_ ,@(if y-supplied-p `(,y_)))))
       (declare (ignorable ,y_)
                (type list ,args_)
                (dynamic-extent ,args_))
       (catch 'return-from-with-wcs-math-error-handling
         (multiple-value-bind ,var-list
             (call-with-wcs-math-error-handler ',function ,args_
                                               ,@keyargs)
           (flet ((check-wcs-math-result
                      (&optional (ret ,(first var-list))
                                 (arg-list ,args_))
                    (check-wcs-math-result ret arg-list)))
             ,@body))))))

;; macroexpand:
(let* ((#:g248 x) (#:g249 nil) (#:g250 (list #:g248))) (declare (ignorable #:g249) (type list #:g250) (dynamic-extent #:g250)) (catch (quote return-from-with-wcs-math-error-handling) (multiple-value-bind (ret) (call-with-wcs-math-error-handler (quote fround) #:g250) (flet ((check-wcs-math-result (&optional (ret ret) (arg-list #:g250)) (check-wcs-math-result ret arg-list))) (check-wcs-math-result)))))


[User]
Define a macro that eliminates this repetitive pattern:
(with-component-testers (a b #'pathname-version) (and (null a) (null b)) (components-are-member '(:wild :newest :unspecific)) (and (integerp a) (integerp b) (= a b)))

Issue: Macro call that should be transformed by with-component-testers

(with-component-testers (a b #'pathname-version) (and (null a) (null b)) (components-are-member '(:wild :newest :unspecific)) (and (integerp a) (integerp b) (= a b)))

[Assistant]
(defmacro with-component-testers ((a b key) &body body)
  (let ((k (gensym)))
    `(let* ((,k ,key)
            (,a (funcall ,k ,a))
            (,b (funcall ,k ,b)))
       (labels ((components-are (test)
                  (and (funcall test ,a) (funcall test ,b)))
                (components-are-member (values)
                  (and (member ,a values :test #'eql)
                       (member ,b values :test #'eql)
                       (eql ,a ,b)))
                (components-are-string= ()
                  (and (stringp ,a) (stringp ,b) (string= ,a ,b)))
                (components-are-every (test)
                  (and (consp ,a)
                       (consp ,b)
                       (every test ,a ,b))))
         (declare (ignorable #'components-are #'components-are-member
                             #'components-are-string= #'components-are-every))
         (if (or ,@body)
             (values t ,a ,b)
             nil)))))

;; macroexpand:
(let* ((#:g148 (function pathname-version)) (a (funcall #:g148 a)) (b (funcall #:g148 b))) (labels ((components-are (test) (and (funcall test a) (funcall test b))) (components-are-member (values) (and (member a values :test (function eql)) (member b values :test (function eql)) (eql a b))) (components-are-string= nil (and (stringp a) (stringp b) (string= a b))) (components-are-every (test) (and (consp a) (consp b) (every test a b)))) (declare (ignorable (function components-are) (function components-are-member) (function components-are-string=) (function components-are-every))) (if (or (and (null a) (null b)) (components-are-member (quote (:wild :newest :unspecific))) (and (integerp a) (integerp b) (= a b))) (values t a b) nil)))


[User]
Define a macro that eliminates this repetitive pattern:
(define-bug return-set-mismatch () (form) "Type & Return sets don't match Our apologies for this mistake. If you have the time please raise an issue at https://github.com/cbaggers/varjo/issues including the code that triggered this issue. Problematic Definition: ~s" form)

Issue: Macro call that should be transformed by define-bug

(define-bug return-set-mismatch () (form) "Type & Return sets don't match Our apologies for this mistake. If you have the time please raise an issue at https://github.com/cbaggers/varjo/issues including the code that triggered this issue. Problematic Definition: ~s" form)

[Assistant]
(defmacro define-bug (name (&key (error-type 'varjo-error) (prefix "Varjo Bug"))
                            (&rest args) error-string &body body)
  `(defcondition ,name (:error-type ,error-type :prefix ,prefix) ,args
       ,error-string ,@body))

;; macroexpand:
(defcondition return-set-mismatch (:error-type varjo-error :prefix "Varjo Bug") (form) "Type & Return sets don't match Our apologies for this mistake. If you have the time please raise an issue at https://github.com/cbaggers/varjo/issues including the code that triggered this issue. Problematic Definition: ~s" form)


[User]
Generate a defmacro form that transforms code like this:
(js-inline 'some-name)

Pattern to recognize: Macro call that should be transformed by JS-INLINE

(js-inline 'some-name)

[Assistant]
(defmacro JS-INLINE ...)

;; macroexpand:
(js-inline* '(progn 'some-name))


[User]
Generate a defmacro form that transforms code like this:
(define-symbol-macro nil (progn))

Pattern to recognize: Macro call that should be transformed by DEFINE-SYMBOL-MACRO

(define-symbol-macro nil (progn))

[Assistant]
(defmacro DEFINE-SYMBOL-MACRO ...)

;; macroexpand:
(eval-when (:compile-toplevel :load-toplevel :execute)
  (sb-c::%define-symbol-macro 'nil '(progn) (sb-c:source-location)))


[User]
Define a macro that eliminates this repetitive pattern:
(define-hook (:build finalize-clos -10000000000) () (labels ((finalize-function (fun) (when (and (typep fun 'generic-function) (not (sb-pcl::special-case-for-compute-discriminating-function-p fun))) (multiple-value-bind (dfun cache info) (sb-pcl::make-final-dfun-internal fun) (sb-pcl::update-dfun fun dfun cache info)))) (finalize-class (class) (unless (sb-mop:class-finalized-p class) (sb-mop:finalize-inheritance class) (dolist (class (sb-mop:class-direct-subclasses class)) (finalize-class class))) (when (typep class 'standard-class) (sb-mop:compute-slots class)))) (do-all-symbols (symbol) (when (find-class symbol NIL) (handler-case (finalize-class (find-class symbol)) (error () (status 3 "Failed to finalize class ~a" symbol))))) (do-all-symbols (symbol) (when (fboundp symbol) (handler-case (finalize-function (fdefinition symbol)) (error () (status 3 "Failed to finalize function ~a" symbol)))) (when (fboundp `(setf ,symbol)) (handler-case (finalize-function (fdefinition `(setf ,symbol))) (error () (status 3 "Failed to finalize function ~a" `(setf ,symbol)))))) (loop for v being the hash-values of sb-pcl::*all-ctors* do (sb-pcl::install-initial-constructor v) (ignore-errors (ecase (sb-pcl::ctor-type v) (sb-pcl::ctor (sb-pcl::install-optimized-constructor v)) (sb-pcl::allocator (sb-pcl::install-optimized-allocator v)))))))

Issue: Macro call that should be transformed by define-hook

(define-hook (:build finalize-clos -10000000000) () (labels ((finalize-function (fun) (when (and (typep fun 'generic-function) (not (sb-pcl::special-case-for-compute-discriminating-function-p fun))) (multiple-value-bind (dfun cache info) (sb-pcl::make-final-dfun-internal fun) (sb-pcl::update-dfun fun dfun cache info)))) (finalize-class (class) (unless (sb-mop:class-finalized-p class) (sb-mop:finalize-inheritance class) (dolist (class (sb-mop:class-direct-subclasses class)) (finalize-class class))) (when (typep class 'standard-class) (sb-mop:compute-slots class)))) (do-all-symbols (symbol) (when (find-class symbol NIL) (handler-case (finalize-class (find-class symbol)) (error () (status 3 "Failed to finalize class ~a" symbol))))) (do-all-symbols (symbol) (when (fboundp symbol) (handler-case (finalize-function (fdefinition symbol)) (error () (status 3 "Failed to finalize function ~a" symbol)))) (when (fboundp `(setf ,symbol)) (handler-case (finalize-function (fdefinition `(setf ,symbol))) (error () (status 3 "Failed to finalize function ~a" `(setf ,symbol)))))) (loop for v being the hash-values of sb-pcl::*all-ctors* do (sb-pcl::install-initial-constructor v) (ignore-errors (ecase (sb-pcl::ctor-type v) (sb-pcl::ctor (sb-pcl::install-optimized-constructor v)) (sb-pcl::allocator (sb-pcl::install-optimized-allocator v)))))))

[Assistant]
(defmacro define-hook ((type name &optional (priority 0)) args &body body)
  (ecase type (:pre-load) (:load) (:build) (:deploy) (:boot) (:quit))
  (check-type name symbol)
  `(let ((,name (or (hook ,type ',name)
                    (make-instance 'hook :name ',name :type ,type))))
     (setf (hook-priority ,name) ,priority)
     (setf (hook-function ,name) (flet ((,name (&key ,@args &allow-other-keys)
                                          ,@body))
                                   #',name))
     (setf (hook ,type ',name) ,name)
     (setf (docstring ,name) ,(if (stringp (car body)) (car body)))
     ',name))

;; macroexpand:
(let ((finalize-clos (or (hook :build (quote finalize-clos)) (make-instance (quote hook) :name (quote finalize-clos) :type :build)))) (setf (hook-priority finalize-clos) -10000000000) (setf (hook-function finalize-clos) (flet ((finalize-clos (&key &allow-other-keys) (labels ((finalize-function (fun) (when (and (typep fun (quote generic-function)) (not (sb-pcl::special-case-for-compute-discriminating-function-p fun))) (multiple-value-bind (dfun cache info) (sb-pcl::make-final-dfun-internal fun) (sb-pcl::update-dfun fun dfun cache info)))) (finalize-class (class) (unless (sb-mop:class-finalized-p class) (sb-mop:finalize-inheritance class) (dolist (class (sb-mop:class-direct-subclasses class)) (finalize-class class))) (when (typep class (quote standard-class)) (sb-mop:compute-slots class)))) (do-all-symbols (symbol) (when (find-class symbol nil) (handler-case (finalize-class (find-class symbol)) (error nil (status 3 "Failed to finalize class ~a" symbol))))) (do-all-symbols (symbol) (when (fboundp symbol) (handler-case (finalize-function (fdefinition symbol)) (error nil (status 3 "Failed to finalize function ~a" symbol)))) (when (fboundp (sb-int:quasiquote (setf #S(sb-impl::comma :expr symbol :kind 0)))) (handler-case (finalize-function (fdefinition (sb-int:quasiquote (setf #S(sb-impl::comma :expr symbol :kind 0))))) (error nil (status 3 "Failed to finalize function ~a" (sb-int:quasiquote (setf #S(sb-impl::comma :expr symbol :kind 0)))))))) (loop for v being the hash-values of sb-pcl::*all-ctors* do (sb-pcl::install-initial-constructor v) (ignore-errors (ecase (sb-pcl::ctor-type v) (sb-pcl::ctor (sb-pcl::install-optimized-constructor v)) (sb-pcl::allocator (sb-pcl::install-optimized-allocator v)))))))) (function finalize-clos))) (setf (hook :build (quote finalize-clos)) finalize-clos) (setf (docstring finalize-clos) nil) (quote finalize-clos))


[User]
Generate a defmacro form that transforms code like this:
(augment-lexenv! :variable environment-var lexenv)

Pattern to recognize: Macro call that should be transformed by augment-lexenv!

(augment-lexenv! :variable environment-var lexenv)

[Assistant]
(defmacro augment-lexenv! (kind name env &rest other-datum)
  `(setf ,env (augment-lexenv ,kind ,name ,env ,@other-datum)))

;; macroexpand:
(setf lexenv (augment-lexenv :variable environment-var lexenv))


[User]
Generate a defmacro form that transforms code like this:
(ps-inline 'some-name)

Pattern to recognize: Macro call that should be transformed by PS-INLINE

(ps-inline 'some-name)

[Assistant]
(defmacro PS-INLINE ...)

;; macroexpand:
(concatenate 'string "javascript:" "\"someName\"")


[User]
Write a Common Lisp macro to handle this code pattern:
(sif (car x) (setf it :yes!) (setf it :oops))

Problem: Macro call that should be transformed by sif

(sif (car x) (setf it :yes!) (setf it :oops))

[Assistant]
(defmacro sif (test then &optional else)
  "Like IF, except binds the test form to IT (via SYMBOL-MACROLET) for
the scope of the then and else expressions. IT can be set with SETF"
  `(symbolic if ,test ,then ,else))

;; macroexpand:
(symbolic if (car x) (setf it :yes!) (setf it :oops))


[User]
Generate a defmacro form that transforms code like this:
(define-simple-type-map macro cl:macro-function)

Pattern to recognize: Macro call that should be transformed by define-simple-type-map

(define-simple-type-map macro cl:macro-function)

[Assistant]
(defmacro define-simple-type-map (class type)
  `(defmethod type ((,class ,class))
     ',type))

;; macroexpand:
(defmethod type ((macro macro)) (quote macro-function))


[User]
You are a Common Lisp macro expert. Given this code pattern:
(none-of nil
  nil)

Write a macro that addresses: Macro call that should be transformed by NONE-OF

(none-of nil
  nil)

[Assistant]
(defmacro NONE-OF ...)

;; macroexpand:
(lc (nil nil) never)


[User]
Write a Common Lisp macro to handle this code pattern:
(gather-result 'some-name)

Problem: Macro call that should be transformed by GATHER-RESULT

(gather-result 'some-name)

[Assistant]
(defmacro GATHER-RESULT ...)

;; macroexpand:
(common-lisp:funcall 'some-name nil t)


[User]
Create a Common Lisp macro for the following transformation. Before code:
(with-preprocessor-state-slots (state) (unless if-section-stack (error 'preprocess-error :format-control "#~A appeared outside of #if section." :format-arguments (list (symbol-name directive-symbol)))))

What needs to change: Macro call that should be transformed by with-preprocessor-state-slots

(with-preprocessor-state-slots (state) (unless if-section-stack (error 'preprocess-error :format-control "#~A appeared outside of #if section." :format-arguments (list (symbol-name directive-symbol)))))

[Assistant]
(defmacro with-preprocessor-state-slots ((state) &body body)
  `(with-accessors ((file-pathname pp-state-file-pathname)
                    (token-list pp-state-token-list)
                    (result-list pp-state-result-list)
                    (line-number pp-state-line-number)
                    (tokens-in-line pp-state-tokens-in-line)
                    (macro-alist pp-state-macro-alist)
                    (if-section-stack pp-state-if-section-stack)
                    (if-section-skip-reason pp-state-if-section-skip-reason)
                    (include-stack pp-state-include-stack))
       ,state
     ,@body))

;; macroexpand:
(with-accessors ((file-pathname pp-state-file-pathname) (token-list pp-state-token-list) (result-list pp-state-result-list) (line-number pp-state-line-number) (tokens-in-line pp-state-tokens-in-line) (macro-alist pp-state-macro-alist) (if-section-stack pp-state-if-section-stack) (if-section-skip-reason pp-state-if-section-skip-reason) (include-stack pp-state-include-stack)) state (unless if-section-stack (error (quote preprocess-error) :format-control "#~A appeared outside of #if section." :format-arguments (list (symbol-name directive-symbol)))))


[User]
Generate a defmacro form that transforms code like this:
(do-generators ((g (some-numbers)) (:list l data)) (yield (+ l g)))

Pattern to recognize: Macro call that should be transformed by do-generators

(do-generators ((g (some-numbers)) (:list l data)) (yield (+ l g)))

[Assistant]
(defmacro do-generators (genspecs &body body)
  "Simultaneously iterate through multiple generators at once. By default
do-generators terminates when the shortest generator ends, but individual
generators can be padded out with the :fill-value keyword. Do-generators can
also iterate over lists in parallel with generators. To use lists, start the genspec with the :list keyword. Eg:
  (do-generators ((a (repeat 2))
			 (:list b '(4 5 6))
			 (c (list->generator '(8 9)) :fill-value 30))
	   (print (* a (+ b c))))
24
28
72
NIL"
  (let ((genspecs (mapcar #'proc-list-spec genspecs))
	(genr (gensym))
	(data (gensym))
	(sig (gensym)))
    (multiple-value-bind (varnames specs)
	(process-genspecs genspecs)

      `(let ((,genr (multi-gen ,@specs)))
	 (loop do
	   (destructuring-bind (,sig . ,data)
	       (multiple-value-list (next-generator-value ,genr))
	     (unless ,sig
	       (return))
	     ,(bind-clause data varnames body)))))))

;; macroexpand:
(let ((#:g129 (multi-gen (some-numbers) (list->generator data)))) (loop do (destructuring-bind (#:g131 . #:g130) (multiple-value-list (next-generator-value #:g129)) (unless #:g131 (return)) (let ((g (elt (elt #:g130 0) 0)) (l (elt (elt #:g130 1) 0))) (yield (+ l g))))))


[User]
Generate a defmacro form that transforms code like this:
(lambda () (progn))

Pattern to recognize: Macro call that should be transformed by LAMBDA

(lambda () (progn))

[Assistant]
(defmacro LAMBDA ...)

;; macroexpand:
#'(lambda () (progn))


[User]
You are a Common Lisp macro expert. Given this code pattern:
(define-bug nil-emit-set () (form possible-set) "Could not establish emit-set. Our apologies for this mistake. If you have the time please raise an issue at https://github.com/cbaggers/varjo/issues including the code that triggered this issue. Problematic form: ~a Possible Set: ~a" form possible-set)

Write a macro that addresses: Macro call that should be transformed by define-bug

(define-bug nil-emit-set () (form possible-set) "Could not establish emit-set. Our apologies for this mistake. If you have the time please raise an issue at https://github.com/cbaggers/varjo/issues including the code that triggered this issue. Problematic form: ~a Possible Set: ~a" form possible-set)

[Assistant]
(defmacro define-bug (name (&key (error-type 'varjo-error) (prefix "Varjo Bug"))
                            (&rest args) error-string &body body)
  `(defcondition ,name (:error-type ,error-type :prefix ,prefix) ,args
       ,error-string ,@body))

;; macroexpand:
(defcondition nil-emit-set (:error-type varjo-error :prefix "Varjo Bug") (form possible-set) "Could not establish emit-set. Our apologies for this mistake. If you have the time please raise an issue at https://github.com/cbaggers/varjo/issues including the code that triggered this issue. Problematic form: ~a Possible Set: ~a" form possible-set)


[User]
Write a Common Lisp macro to handle this code pattern:
(define-api copy-named-readtable (named-readtable) (named-readtable-designator => readtable) "Like COPY-READTABLE but takes a NAMED-READTABLE-DESIGNATOR as argument." (copy-readtable (ensure-readtable named-readtable)))

Problem: Macro call that should be transformed by define-api

(define-api copy-named-readtable (named-readtable) (named-readtable-designator => readtable) "Like COPY-READTABLE but takes a NAMED-READTABLE-DESIGNATOR as argument." (copy-readtable (ensure-readtable named-readtable)))

[Assistant]
(defmacro define-api (name lambda-list type-list &body body)
  (flet ((parse-type-list (type-list)
           (let ((pos (position '=> type-list)))
             (assert pos () "You forgot to specify return type (`=>' missing.)")
             (values (subseq type-list 0 pos)
                     `(values ,@(nthcdr (1+ pos) type-list) &optional)))))
    (multiple-value-bind (body decls docstring)
        (parse-body body :documentation t :whole `(define-api ,name))
      (multiple-value-bind (arg-typespec value-typespec)
          (parse-type-list type-list)
        (multiple-value-bind (reqs opts rest keys)
            (parse-ordinary-lambda-list lambda-list)
          (declare (ignorable reqs opts rest keys))
          `(progn
             (declaim (ftype (function ,arg-typespec ,value-typespec) ,name))
             (locally
                 ;; Muffle the annoying "&OPTIONAL and &KEY found in
                 ;; the same lambda list" style-warning
                 #+sbcl (declare (sb-ext:muffle-conditions style-warning))
               (defun ,name ,lambda-list
                 ,docstring
                 ,@decls
                 (locally
                     #+sbcl (declare (sb-ext:unmuffle-conditions style-warning))

                     ;; SBCL will interpret the ftype declaration as
                     ;; assertion and will insert type checks for us.
                     #-sbcl
                     (progn
                       ;; CHECK-TYPE required parameters
                       ,@(loop for req-arg in reqs
                               for req-type = (pop type-list)
                               do (assert req-type)
                               collect `(check-type ,req-arg ,req-type))

                       ;; CHECK-TYPE optional parameters
                       ,@(progn
                           (assert (or (null opts)
                                       (eq (pop type-list) '&optional)))
                           (loop for (opt-arg . nil) in opts
                                 for opt-type = (pop type-list)
                                 do (assert opt-type)
                                 collect `(check-type ,opt-arg ,opt-type)))

                       ;; CHECK-TYPE rest parameter
                       ,@(when rest
                           (assert (eq (pop type-list) '&rest))
                           (let ((rest-type (pop type-list)))
                             (assert rest-type)
                             `((dolist (x ,rest)
                                 (check-type x ,rest-type)))))

                       ;; CHECK-TYPE key parameters
                       ,@(progn
                           (assert (or (null keys)
                                       (eq (pop type-list) '&key)))
                           (loop for ((keyword key-arg)  . nil) in keys
                                 for (nil key-type) = (find keyword type-list
                                                            :key #'car)
                                 collect `(check-type ,key-arg ,key-type))))

                     ,@body)))))))))

;; macroexpand:
(progn (declaim (ftype (function (named-readtable-designator) (values readtable &optional)) copy-named-readtable)) (locally (declare (sb-ext:muffle-conditions style-warning)) (defun copy-named-readtable (named-readtable) "Like COPY-READTABLE but takes a NAMED-READTABLE-DESIGNATOR as argument." (locally (declare (sb-ext:unmuffle-conditions style-warning)) (copy-readtable (ensure-readtable named-readtable))))))


[User]
Define a macro that eliminates this repetitive pattern:
(defmacro nil (progn))

Issue: Macro call that should be transformed by DEFMACRO

(defmacro nil (progn))

[Assistant]
(defmacro DEFMACRO ...)

;; macroexpand:
(progn
 (eval-when (:compile-toplevel)
   (sb-c::%compiler-defmacro :macro-function 'nil))
 (eval-when (:compile-toplevel :load-toplevel :execute)
   (sb-c::%defmacro 'nil
                    (sb-int:named-lambda (macro-function nil)
                        (#:expr #:env)
                      (declare (sb-c::lambda-list (progn)))
                      (declare (ignore #:env))
                      (sb-int:named-ds-bind (:macro nil . defmacro)
                          (progn)
                          (cdr #:expr)
                        (declare (sb-c::constant-value progn))))
                    (sb-c:source-location))))


[User]
Generate a defmacro form that transforms code like this:
(who-ps-html nil :key nil)

Pattern to recognize: Macro call that should be transformed by WHO-PS-HTML

(who-ps-html nil :key nil)

[Assistant]
(defmacro WHO-PS-HTML ...)

;; macroexpand:
(stringify nil #A((11) base-char . "<key></key>") nil)


[User]
Write a Common Lisp macro to handle this code pattern:
(fgatherlet nil)

Problem: Macro call that should be transformed by FGATHERLET

(fgatherlet nil)

[Assistant]
(defmacro FGATHERLET ...)

;; macroexpand:
(flet nil)


[User]
Write a Common Lisp macro to handle this code pattern:
(define-error setq-readonly () (var-name code) "You cannot setq ~a as it is readonly ~%This was attempted as follows ~a" var-name code)

Problem: Macro call that should be transformed by define-error

(define-error setq-readonly () (var-name code) "You cannot setq ~a as it is readonly ~%This was attempted as follows ~a" var-name code)

[Assistant]
(defmacro define-error (name (&key (error-type 'varjo-error) (prefix "Varjo"))
                            (&rest args) error-string &body body)
  `(defcondition ,name (:error-type ,error-type :prefix ,prefix) ,args
       ,error-string ,@body))

;; macroexpand:
(defcondition setq-readonly (:error-type varjo-error :prefix "Varjo") (var-name code) "You cannot setq ~a as it is readonly ~%This was attempted as follows ~a" var-name code)


[User]
You are a Common Lisp macro expert. Given this code pattern:
(->>
  'some-name)

Write a macro that addresses: Macro call that should be transformed by ->>

(->>
  'some-name)

[Assistant]
(defmacro ->> ...)

;; macroexpand:
'some-name


[User]
You are a Common Lisp macro expert. Given this code pattern:
(*> #'space #'rest)

Write a macro that addresses: Macro call that should be transformed by *>

(*> #'space #'rest)

[Assistant]
(defmacro *> (parser &rest parsers)
  "Combination of parsers yielding the result of the rightmost one."
  (let ((offset (gensym "*>-OFFSET")))
    `(lambda (,offset)
       ,(reduce (lambda (i p)
                  (let ((res  (gensym "*>-RES"))
                        (next (gensym "*>-NEXT")))
                    `(multiple-value-bind (,res ,next) ,i
                       (if (ok? ,res)
                           (funcall ,p ,next)
                           (fail ,next)))))
                parsers
                :initial-value `(funcall ,parser ,offset)))))

;; macroexpand:
(lambda (#:*>-offset218) (multiple-value-bind (#:*>-res219 #:*>-next220) (funcall (function space) #:*>-offset218) (if (ok? #:*>-res219) (funcall (function rest) #:*>-next220) (fail #:*>-next220))))


[User]
Define a macro that eliminates this repetitive pattern:
(let-syntax common-lisp:nil common-lisp:nil)

Issue: Macro call that should be transformed by LET-SYNTAX

(let-syntax common-lisp:nil common-lisp:nil)

[Assistant]
(defmacro LET-SYNTAX ...)

;; macroexpand:
(common-lisp:progn common-lisp:nil)


[User]
Create a Common Lisp macro for the following transformation. Before code:
(is (test-failure-p (first results)))

What needs to change: Macro call that should be transformed by is

(is (test-failure-p (first results)))

[Assistant]
(defmacro is (test &rest reason-args)
  "The DWIM checking operator.

If TEST returns a true value a test-passed result is generated,
otherwise a test-failure result is generated. The reason, unless
REASON-ARGS is provided, is generated based on the form of TEST:

 (predicate expected actual) - Means that we want to check
 whether, according to PREDICATE, the ACTUAL value is
 in fact what we EXPECTED.

 (predicate value) - Means that we want to ensure that VALUE
 satisfies PREDICATE.

 Wrapping the TEST form in a NOT simply produces a negated reason
 string."
  (assert (listp test)
          (test)
          "Argument to IS must be a list, not ~S" test)
  (let (bindings effective-test default-reason-args)
    (with-gensyms (e a v)
      (flet ((process-entry (predicate expected actual &optional negatedp)
               ;; make sure EXPECTED is holding the entry that starts with 'values
               (when (and (consp actual)
                          (eq (car actual) 'values))
                 (assert (not (and (consp expected)
                                   (eq (car expected) 'values))) ()
                                   "Both the expected and actual part is a values expression.")
                 (rotatef expected actual))
               (let ((setf-forms))
                 (if (and (consp expected)
                          (eq (car expected) 'values))
                     (progn
                       (setf expected (copy-list expected))
                       (setf setf-forms (loop for cell = (rest expected) then (cdr cell)
                                              for i from 0
                                              while cell
                                              when (eq (car cell) '*)
                                              collect `(setf (elt ,a ,i) nil)
                                              and do (setf (car cell) nil)))
                       (setf bindings (list (list e `(list ,@(rest expected)))
                                            (list a `(multiple-value-list ,actual)))))
                     (setf bindings (list (list e expected)
                                          (list a actual))))
                 (setf effective-test `(progn
                                         ,@setf-forms
                                         ,(if negatedp
                                              `(not (,predicate ,e ,a))
                                              `(,predicate ,e ,a)))))))
        (list-match-case test
          ((not (?predicate ?expected ?actual))
           (process-entry ?predicate ?expected ?actual t)
           (setf default-reason-args
                 (list "~2&~S~2% evaluated to ~2&~S~2% which is ~2&~S~2%to ~2&~S~2% (it should not be)"
                       `',?actual a `',?predicate e)))
          ((not (?satisfies ?value))
           (setf bindings (list (list v ?value))
                 effective-test `(not (,?satisfies ,v))
                 default-reason-args
                 (list "~2&~S~2% evaluated to ~2&~S~2% which satisfies ~2&~S~2% (it should not)"
                       `',?value v `',?satisfies)))
          ((?predicate ?expected ?actual)
           (process-entry ?predicate ?expected ?actual)
           (setf default-reason-args
                 (list "~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%"
                       `',?actual a `',?predicate e)))
          ((?satisfies ?value)
           (setf bindings (list (list v ?value))
                 effective-test `(,?satisfies ,v)
                 default-reason-args
                 (list "~2&~S~2% evaluated to ~2&~S~2% which does not satisfy ~2&~S~2%"
                       `',?value v `',?satisfies)))
          (?_
           (setf bindings '()
                 effective-test test
                 default-reason-args (list "~2&~S~2% was NIL." `',test)))))
      `(let ,bindings
         (if ,effective-test
             (add-result 'test-passed :test-expr ',test)
             (process-failure ',test
                              ,@(or reason-args default-reason-args)))))))

;; macroexpand:
(let ((#:v216 (first results))) (if (test-failure-p #:v216) (add-result (quote test-passed) :test-expr (quote (test-failure-p (first results)))) (process-failure (quote (test-failure-p (first results))) "~2&~S~2% evaluated to ~2&~S~2% which does not satisfy ~2&~S~2%" (quote (first results)) #:v216 (quote test-failure-p))))


[User]
Generate a defmacro form that transforms code like this:
(aand (incf x) t t (values t it))

Pattern to recognize: Macro call that should be transformed by aand

(aand (incf x) t t (values t it))

[Assistant]
(defmacro aand (first &rest rest)
  "Like AND, except binds the first argument to IT (via LET) for the
scope of the rest of the arguments."
  `(anaphoric and ,first ,@rest))

;; macroexpand:
(anaphoric and (incf x) t t (values t it))


[User]
Generate a defmacro form that transforms code like this:
(defclause-sequence nil nil)

Pattern to recognize: Macro call that should be transformed by DEFCLAUSE-SEQUENCE

(defclause-sequence nil nil)

[Assistant]
(defmacro DEFCLAUSE-SEQUENCE ...)

;; macroexpand:
(progn nil nil)


[User]
Create a Common Lisp macro for the following transformation. Before code:
(dlet 'some-name)

What needs to change: Macro call that should be transformed by DLET

(dlet 'some-name)

[Assistant]
(defmacro DLET ...)

;; macroexpand:
(dynamic-let 'some-name)


[User]
You are a Common Lisp macro expert. Given this code pattern:
(signal-syntax-error "Invalid range from ~S to ~S in char-class." from to)

Write a macro that addresses: Macro call that should be transformed by signal-syntax-error

(signal-syntax-error "Invalid range from ~S to ~S in char-class." from to)

[Assistant]
(defmacro signal-syntax-error (format-control &rest format-arguments)
  `(signal-syntax-error* nil ,format-control ,@format-arguments))

;; macroexpand:
(signal-syntax-error* nil "Invalid range from ~S to ~S in char-class." from to)


[User]
You are a Common Lisp macro expert. Given this code pattern:
(m nil
  nil)

Write a macro that addresses: Macro call that should be transformed by M

(m nil
  nil)

[Assistant]
(defmacro M ...)

;; macroexpand:
(lambda (&rest #:|macro-lambda-list121|)
  (destructuring-bind () #:|macro-lambda-list121| nil))


[User]
Write a Common Lisp macro to handle this code pattern:
(quasiquote-expand (progn (unread-char #\( stream) (read-preserving-whitespace stream t nil t))))

Problem: Macro call that should be transformed by quasiquote

(quasiquote-expand (progn (unread-char #\( stream) (read-preserving-whitespace stream t nil t))))

[Assistant]
(defmacro quasiquote (x) (quasiquote-expand x))

;; macroexpand:
(quasiquote-expand (progn (unread-char #\LEFT_PARENTHESIS stream) (read-preserving-whitespace stream t nil t)))


[User]
Define a macro that eliminates this repetitive pattern:
(with-unique-names (value) (values `((,name (,value) (incf ,var ,value))) `((inline ,name))))

Issue: Macro call that should be transformed by with-unique-names

(with-unique-names (value) (values `((,name (,value) (incf ,var ,value))) `((inline ,name))))

[Assistant]
(defmacro with-unique-names (names &body body)
  `(let ,(mapcar (lambda (sym)
                   `(,sym (gensym ,(symbol-name sym))))
                  names)
     ,@body))

;; macroexpand:
(let ((value (gensym #A((5) base-char . "VALUE")))) (values (quasiquote ((#S(sb-impl::comma :expr name :kind 0) (#S(sb-impl::comma :expr value :kind 0)) (incf #S(sb-impl::comma :expr var :kind 0) #S(sb-impl::comma :expr value :kind 0))))) (quasiquote ((inline #S(sb-impl::comma :expr name :kind 0))))))


[User]
You are a Common Lisp macro expert. Given this code pattern:
(dynamic-relet nil
  nil)

Write a macro that addresses: Macro call that should be transformed by DYNAMIC-RELET

(dynamic-relet nil
  nil)

[Assistant]
(defmacro DYNAMIC-RELET ...)

;; macroexpand:
(dynamic-wind
  :proceed
  #:proceed189
  (let ()
    (declare (special))
    (#:proceed189 nil)))


[User]
Write a Common Lisp macro to handle this code pattern:
(deferror "08004" sqlserver-rejected-establishment-of-sqlconnection)

Problem: Macro call that should be transformed by deferror

(deferror "08004" sqlserver-rejected-establishment-of-sqlconnection)

[Assistant]
(defmacro deferror (code typename &optional (superclass 'database-error))
  `(progn (define-condition ,typename (,superclass) ())
          (setf (gethash ,code *error-table*) ',typename)))

;; macroexpand:
(progn (define-condition sqlserver-rejected-establishment-of-sqlconnection (database-error) nil) (setf (gethash "08004" *error-table*) (quote sqlserver-rejected-establishment-of-sqlconnection)))


[User]
Create a Common Lisp macro for the following transformation. Before code:
(make-$instance 'some-name)

What needs to change: Macro call that should be transformed by MAKE-$INSTANCE

(make-$instance 'some-name)

[Assistant]
(defmacro MAKE-$INSTANCE ...)

;; macroexpand:
(let ((class (symbol-value 'some-name)))
  (funcall (mcs-slot-value class (index-of-basicnew-fn)) class))


[User]
Write a Common Lisp macro to handle this code pattern:
(eswitch ((first feature-expression) :test 'string=) (:and (every #'featurep (rest feature-expression))) (:or (some #'featurep (rest feature-expression))) (:not (assert (= 2 (length feature-expression))) (not (featurep (second feature-expression)))))

Problem: Macro call that should be transformed by eswitch

(eswitch ((first feature-expression) :test 'string=) (:and (every #'featurep (rest feature-expression))) (:or (some #'featurep (rest feature-expression))) (:not (assert (= 2 (length feature-expression))) (not (featurep (second feature-expression)))))

[Assistant]
(defmacro eswitch (&whole whole (object &key (test 'eql) (key 'identity))
                          &body clauses)
  "Like SWITCH, but signals an error if no key matches."
  (generate-switch-body whole object clauses test key '(error)))

;; macroexpand:
(let ((#:value131 (identity (first feature-expression)))) (cond ((string= #:value131 :and) (every (function featurep) (rest feature-expression))) ((string= #:value131 :or) (some (function featurep) (rest feature-expression))) ((string= #:value131 :not) (assert (= 2 (length feature-expression))) (not (featurep (second feature-expression)))) (t (error "No keys match in SWITCH. Testing against ~S with ~S." #:value131 (quote string=)))))


[User]
Create a Common Lisp macro for the following transformation. Before code:
(define-modf-rewrite cdddar (expr) `(cdr (cddar ,(second expr))))

What needs to change: Macro call that should be transformed by define-modf-rewrite

(define-modf-rewrite cdddar (expr) `(cdr (cddar ,(second expr))))

[Assistant]
(defmacro define-modf-rewrite (name (expr) &body body)
  "Define a new rewrite rule.  If a form starting with NAME is encountered, call
the defined function to return a form that we can deal with (i.e. one defined
via DEFINE-MODF-EXPANDER, DEFINE-MODF-FUNCTION, and DEFINE-MODF-METHOD)."
  `(eval-when (:compile-toplevel :load-toplevel :execute)
     (setf (gethash ',name *modf-rewrites*)
           (lambda (,expr)
             ,@body))))

;; macroexpand:
(eval-when (:compile-toplevel :load-toplevel :execute) (setf (gethash (quote cdddar) *modf-rewrites*) (lambda (expr) (sb-int:quasiquote (cdr (cddar #S(sb-impl::comma :expr (second expr) :kind 0)))))))


[User]
Create a Common Lisp macro for the following transformation. Before code:
(with-output-to-temporary-file (f) (write-string "hello" f))

What needs to change: Macro call that should be transformed by with-output-to-temporary-file

(with-output-to-temporary-file (f) (write-string "hello" f))

[Assistant]
(defmacro with-output-to-temporary-file ((stream &rest args) &body body)
  "Create a temporary file using OPEN-TEMPORARY with ARGS and run BODY
  with STREAM bound to the temporary file stream.  Returns the
  pathname of the file that has been created.  See OPEN-TEMPORARY for
  permitted options."
  `(with-open-stream (,stream (open-temporary ,@args))
     ,@body
     (pathname ,stream)))

;; macroexpand:
(with-open-stream (f (open-temporary)) (write-string "hello" f) (pathname f))


[User]
Create a Common Lisp macro for the following transformation. Before code:
(with-cache ("foo" :expire 2 :store storage) (error "MUST NOT BE ERROR"))

What needs to change: Macro call that should be transformed by with-cache

(with-cache ("foo" :expire 2 :store storage) (error "MUST NOT BE ERROR"))

[Assistant]
(defmacro with-cache ((key &key store expire) &body body)
  "If a cache indicated by KEY exists, this just returns the cache
value without evaluating BODY. Otherwise, this evaluates BODY and
stores the evaluated value into STORE with KEY and EXPIRE. KEY is a
form that an evaluated value indicates the cache key.

Example:

    (defun f (x)
      (with-cache (x *store*)
        (very-complex-computation x)))"
  (once-only (key store expire)
    (with-gensyms (value exists-p)
      `(multiple-value-bind (,value ,exists-p)
           (getcache ,key ,store)
         (if ,exists-p
             ,value
             (let ((,value (progn ,@body)))
               (setcache ,key ,value ,store :expire ,expire)
               ,value))))))

;; macroexpand:
(let ((#:key252 "foo") (#:store253 storage) (#:expire254 2)) (multiple-value-bind (#:value255 #:exists-p256) (getcache #:key252 #:store253) (if #:exists-p256 #:value255 (let ((#:value255 (progn (error "MUST NOT BE ERROR")))) (setcache #:key252 #:value255 #:store253 :expire #:expire254) #:value255))))


[User]
Create a Common Lisp macro for the following transformation. Before code:
(draw scene (:rect :x 0 :y 0 :height "100%" :width "100%") :fill (xlink-href rg))

What needs to change: Macro call that should be transformed by draw

(draw scene (:rect :x 0 :y 0 :height "100%" :width "100%") :fill (xlink-href rg))

[Assistant]
(defmacro draw (scene (shape &rest params) &rest opts)
  (let ((element (gensym)))
    `(let ((,element (funcall #'make-svg-element ,shape (append (list ,@params) (list ,@opts)))))
       (add-element ,scene ,element)
       ,element)))

;; macroexpand:
(let ((#:g160 (funcall (function make-svg-element) :rect (append (list :x 0 :y 0 :height "100%" :width "100%") (list :fill (xlink-href rg)))))) (add-element scene #:g160) #:g160)


[User]
You are a Common Lisp macro expert. Given this code pattern:
(define FOPEN_MAX 1024)

Write a macro that addresses: Macro call that should be transformed by define

(define FOPEN_MAX 1024)

[Assistant]
(defmacro define (name value &rest docstring)
  "Like a #define but also visible to Lisp code."
  `(progn
     (eval-when (:compile-toplevel :load-toplevel :execute)
       (defvar ,(pp-defines *package*) (make-hash-table))
       (setf (gethash ',name ,(pp-defines *package*)) ,(prin1-to-string value)))
     (defparameter ,name ,value ,@docstring)))

;; macroexpand:
(progn (eval-when (:compile-toplevel :load-toplevel :execute) (defvar *preprocessor-defines* (make-hash-table)) (setf (gethash (quote fopen_max) *preprocessor-defines*) #A((4) base-char . "1024"))) (defparameter fopen_max 1024))


[User]
Generate a defmacro form that transforms code like this:
(define-simple-object-lookup macro macro-function)

Pattern to recognize: Macro call that should be transformed by define-simple-object-lookup

(define-simple-object-lookup macro macro-function)

[Assistant]
(defmacro define-simple-object-lookup (class lookup-function &body body)
  `(defmethod object ((,class ,class))
     ,(if body
          `(let ((,(first lookup-function) ,class))
             ,@body)
          `(,lookup-function (designator ,class)))))

;; macroexpand:
(defmethod object ((macro macro)) (macro-function (designator macro)))


[User]
Create a Common Lisp macro for the following transformation. Before code:
($ nil nil)

What needs to change: Macro call that should be transformed by $

($ nil nil)

[Assistant]
(defmacro $ (&rest args)
  `(kv ,@args))

;; macroexpand:
(kv nil nil)


[User]
Write a Common Lisp macro to handle this code pattern:
(dletf* nil
  :key
  nil)

Problem: Macro call that should be transformed by DLETF*

(dletf* nil
  :key
  nil)

[Assistant]
(defmacro DLETF* ...)

;; macroexpand:
(progn :key nil)


[User]
Generate a defmacro form that transforms code like this:
(define-binary-op-mapping-definer define-comparison-ops `(progn (defmethod ,op ((x memptr) (y memptr)) (if (and (eq (memptr-mem x) (memptr-mem y)) (,cl (memptr-ptr x) (memptr-ptr y))) 1 0)) (defmethod ,op ((x number) (y number)) (if (,cl x y) 1 0))))

Pattern to recognize: Macro call that should be transformed by define

(define-binary-op-mapping-definer define-comparison-ops `(progn (defmethod ,op ((x memptr) (y memptr)) (if (and (eq (memptr-mem x) (memptr-mem y)) (,cl (memptr-ptr x) (memptr-ptr y))) 1 0)) (defmethod ,op ((x number) (y number)) (if (,cl x y) 1 0))))

[Assistant]
(defmacro define (name value &rest docstring)
  "Like a #define but also visible to Lisp code."
  `(progn
     (eval-when (:compile-toplevel :load-toplevel :execute)
       (defvar ,(pp-defines *package*) (make-hash-table))
       (setf (gethash ',name ,(pp-defines *package*)) ,(prin1-to-string value)))
     (defparameter ,name ,value ,@docstring)))

;; macroexpand:
(defmacro define-comparison-ops (&rest map) (sb-int:quasiquote (progn #S(sb-impl::comma :expr (loop for (vacietis cl) on map by (function cddr) collect (let ((op (find-symbol (symbol-name vacietis) (quote #:vacietis.c)))) (sb-int:quasiquote (progn (defmethod #S(sb-impl::comma :expr op :kind 0) ((x memptr) (y memptr)) (if (and (eq (memptr-mem x) (memptr-mem y)) (#S(sb-impl::comma :expr cl :kind 0) (memptr-ptr x) (memptr-ptr y))) 1 0)) (defmethod #S(sb-impl::comma :expr op :kind 0) ((x number) (y number)) (if (#S(sb-impl::comma :expr cl :kind 0) x y) 1 0)))))) :kind 2))))


[User]
Write a Common Lisp macro to handle this code pattern:
(with-unique-js-names nil nil)

Problem: Macro call that should be transformed by WITH-UNIQUE-JS-NAMES

(with-unique-js-names nil nil)

[Assistant]
(defmacro WITH-UNIQUE-JS-NAMES ...)

;; macroexpand:
(with-ps-gensyms nil
  nil)


[User]
Write a Common Lisp macro to handle this code pattern:
(yield-for-union-ops "UNION")

Problem: Macro call that should be transformed by yield-for-union-ops

(yield-for-union-ops "UNION")

[Assistant]
(defmacro yield-for-union-ops (keyword)
  `(multiple-value-bind (statements others)
      (loop for obj in (conjunctive-op-expressions op)
            if (sql-statement-p obj)
              collecting obj into statements
            else
              collecting obj into others
            finally (return (values statements others)))
     (with-yield-binds
       (format nil (if *inside-select*
                       "(~{~A~^ ~})"
                       "~{~A~^ ~}")
               (append (list (format nil ,(format nil "~~{~~A~~^ ~a ~~}" keyword)
                                     (mapcar #'yield statements)))
                       (when others
                         (list (format nil "~{~A~^ ~}"
                                       (mapcar #'yield others)))))))))

;; macroexpand:
(multiple-value-bind (statements others) (loop for obj in (conjunctive-op-expressions op) if (sql-statement-p obj) collecting obj into statements else collecting obj into others finally (return (values statements others))) (with-yield-binds (format nil (if *inside-select* "(~{~A~^ ~})" "~{~A~^ ~}") (append (list (format nil #A((15) base-char . "~{~A~^ UNION ~}") (mapcar (function yield) statements))) (when others (list (format nil "~{~A~^ ~}" (mapcar (function yield) others))))))))


[User]
Write a Common Lisp macro to handle this code pattern:
(defgenerator combinations (list r) "Emits every possible combination of the items in list in sets of size r. Eg: (combinations '(a b c d) 2) -(values)-> (a b) (a c) (a d) (b c) (b d) (c d)" (labels ((proc (data output r) (if (zerop r) (apply #'yield (reverse output)) (loop for d on data do (proc (cdr d) (cons (car d) output) (1- r)))))) (if (< (length list) r) (lambda () 'generator-stop) (proc list nil r))))

Problem: Macro call that should be transformed by defgenerator

(defgenerator combinations (list r) "Emits every possible combination of the items in list in sets of size r. Eg: (combinations '(a b c d) 2) -(values)-> (a b) (a c) (a d) (b c) (b d) (c d)" (labels ((proc (data output r) (if (zerop r) (apply #'yield (reverse output)) (loop for d on data do (proc (cdr d) (cons (car d) output) (1- r)))))) (if (< (length list) r) (lambda () 'generator-stop) (proc list nil r))))

[Assistant]
(defmacro defgenerator (name arguments &body body)
  (multiple-value-bind (remaining-forms declarations doc-string)
      (alexandria:parse-body body :documentation t)
    `(defun ,name ,arguments
       ,doc-string
       ,@declarations
       (with-yield
	 ,@remaining-forms))))

;; macroexpand:
(defun combinations (list r) "Emits every possible combination of the items in list in sets of size r. Eg: (combinations '(a b c d) 2) -(values)-> (a b) (a c) (a d) (b c) (b d) (c d)" (with-yield (labels ((proc (data output r) (if (zerop r) (apply (function yield) (reverse output)) (loop for d on data do (proc (cdr d) (cons (car d) output) (1- r)))))) (if (< (length list) r) (lambda nil (quote generator-stop)) (proc list nil r)))))


[User]
Create a Common Lisp macro for the following transformation. Before code:
(make-simple-appender-to-place 'some-name)

What needs to change: Macro call that should be transformed by MAKE-SIMPLE-APPENDER-TO-PLACE

(make-simple-appender-to-place 'some-name)

[Assistant]
(defmacro MAKE-SIMPLE-APPENDER-TO-PLACE ...)

;; macroexpand:
(progn
 (setf 'some-name (alexandria:ensure-list 'some-name))
 (let ((#:tail132 (last 'some-name)))
   (lambda (&rest values)
     (append-at-end 'some-name #:tail132 values)
     'some-name)))


[User]
Generate a defmacro form that transforms code like this:
(define-simple-documentation-lookup package T)

Pattern to recognize: Macro call that should be transformed by define-simple-documentation-lookup

(define-simple-documentation-lookup package T)

[Assistant]
(defmacro define-simple-documentation-lookup (class documentation-type)
  `(defmethod documentation ((,class ,class))
     ,(if (eql documentation-type T)
          `(cl:documentation (object ,class) 'T)
          `(cl:documentation (designator ,class) ',documentation-type))))

;; macroexpand:
(defmethod documentation ((package package)) (common-lisp:documentation (object package) (quote t)))


[User]
Create a Common Lisp macro for the following transformation. Before code:
(special-symbol-reprogv nil
    :key
  nil)

What needs to change: Macro call that should be transformed by SPECIAL-SYMBOL-REPROGV

(special-symbol-reprogv nil
    :key
  nil)

[Assistant]
(defmacro SPECIAL-SYMBOL-REPROGV ...)

;; macroexpand:
(let (#:symbol-list209)
  (tagbody
   #:retry210
    (setq #:symbol-list209 nil)
    (unless (every #'special-symbol-p #:symbol-list209)
      (cerror "Retry to rebind the place(s)."
              "Attempt at rebinding one or more non-special places: ~S" 'nil)
      (go #:retry210)))
  (dynamic-reprogv #:symbol-list209
      :key
    nil))


[User]
You are a Common Lisp macro expert. Given this code pattern:
(defmacro-clause 'some-name)

Write a macro that addresses: Macro call that should be transformed by DEFMACRO-CLAUSE

(defmacro-clause 'some-name)

[Assistant]
(defmacro DEFMACRO-CLAUSE ...)

;; macroexpand:
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defmacro clause-quote-1 (&key ((:quote some-name))))
  (iterate::install-clause-info '(quote) '(quote) 'clause-quote-1 nil nil)
  ''some-name)


[User]
Create a Common Lisp macro for the following transformation. Before code:
(define-modf-rewrite cdaar (expr) `(cdr (caar ,(second expr))))

What needs to change: Macro call that should be transformed by define-modf-rewrite

(define-modf-rewrite cdaar (expr) `(cdr (caar ,(second expr))))

[Assistant]
(defmacro define-modf-rewrite (name (expr) &body body)
  "Define a new rewrite rule.  If a form starting with NAME is encountered, call
the defined function to return a form that we can deal with (i.e. one defined
via DEFINE-MODF-EXPANDER, DEFINE-MODF-FUNCTION, and DEFINE-MODF-METHOD)."
  `(eval-when (:compile-toplevel :load-toplevel :execute)
     (setf (gethash ',name *modf-rewrites*)
           (lambda (,expr)
             ,@body))))

;; macroexpand:
(eval-when (:compile-toplevel :load-toplevel :execute) (setf (gethash (quote cdaar) *modf-rewrites*) (lambda (expr) (sb-int:quasiquote (cdr (caar #S(sb-impl::comma :expr (second expr) :kind 0)))))))


[User]
Define a macro that eliminates this repetitive pattern:
(trace$method 'some-name)

Issue: Macro call that should be transformed by TRACE$METHOD

(trace$method 'some-name)

[Assistant]
(defmacro TRACE$METHOD ...)

;; macroexpand:
(mcs-trace quote some-name)


[User]
Write a Common Lisp macro to handle this code pattern:
(bind (((:slots-r/o a c) (make-instance 'metabang-bind-class-1 :a 1 :b 2 :c 3))) (list a c))

Problem: Macro call that should be transformed by bind

(bind (((:slots-r/o a c) (make-instance 'metabang-bind-class-1 :a 1 :b 2 :c 3))) (list a c))

[Assistant]
(defmacro bind ((&rest bindings) &body body)
  "Bind is a replacement for let*, destructuring-bind, multiple-value-bind and more.

An example is probably the best way to describe its syntax:

    \(bind \(\(a 2\)
           \(\(b &rest args &key \(c 2\) &allow-other-keys\) '\(:a :c 5 :d 10 :e 54\)\)
           \(\(:values d e\) \(truncate 4.5\)\)
           \(\(:structure xxx- slot1 slot2\) \(make-xxx\)\)
           \(\(:flet name \(arg1 arg2\)\) \(+ arg1 arg2\)\)\)
         \(list a b c d e args\)\)

Simple bindings are as in let*. Destructuring is done if the first item
in a binding is a list. Multiple value binding is done if the first item
in a binding is a list and the first item in the list is ':values'. Other
forms have their own syntax. For example, :structure first has the conc
name and then slot names whereas :flet has the function name and a list
of arguments and then the function body (in an implicit progn)."
  (let (declarations)
    (loop while (and (consp (car body)) (eq (caar body) 'declare)) do
          (push (first body) declarations)
          (setf body (rest body)))
    (if bindings
	(let ((*all-declarations* (bind-expand-declarations (nreverse declarations))))
	  (prog1
	      (bind-macro-helper bindings body)
	    (check-for-unused-variable-declarations *all-declarations*)))
        `(locally
             ,@declarations
           ,@body))))

;; macroexpand:
(let* ((#:|values-172| (make-instance (quote metabang-bind-class-1) :a 1 :b 2 :c 3)) (a (slot-value #:|values-172| (quote a))) (c (slot-value #:|values-172| (quote c)))) (declare (ignorable #:|values-172|)) (progn (list a c)))


[User]
You are a Common Lisp macro expert. Given this code pattern:
(define-error invalid-context-symbol () (context-symb) "Sorry but the symbol '~a' is not valid as a context specifier" context-symb)

Write a macro that addresses: Macro call that should be transformed by define-error

(define-error invalid-context-symbol () (context-symb) "Sorry but the symbol '~a' is not valid as a context specifier" context-symb)

[Assistant]
(defmacro define-error (name (&key (error-type 'varjo-error) (prefix "Varjo"))
                            (&rest args) error-string &body body)
  `(defcondition ,name (:error-type ,error-type :prefix ,prefix) ,args
       ,error-string ,@body))

;; macroexpand:
(defcondition invalid-context-symbol (:error-type varjo-error :prefix "Varjo") (context-symb) "Sorry but the symbol '~a' is not valid as a context specifier" context-symb)


[User]
Generate a defmacro form that transforms code like this:
(cswitch (13 :key 1-) (12 :yay) (13.0 :oops))

Pattern to recognize: Macro call that should be transformed by cswitch

(cswitch (13 :key 1-) (12 :yay) (13.0 :oops))

[Assistant]
(defmacro cswitch (&whole whole (object &key (test 'eql) (key 'identity))
                          &body clauses)
  "Like SWITCH, but signals a continuable error if no key matches."
  (generate-switch-body whole object clauses test key '(cerror "Return NIL from CSWITCH.")))

;; macroexpand:
(let ((#:value135 (1- 13))) (cond ((eql #:value135 12) :yay) ((eql #:value135 13.0) :oops) (t (cerror "Return NIL from CSWITCH." "No keys match in SWITCH. Testing against ~S with ~S." #:value135 (quote eql)))))


[User]
Create a Common Lisp macro for the following transformation. Before code:
(signal-syntax-error* (lexer-pos lexer) "Invalid character in named register group.")

What needs to change: Macro call that should be transformed by signal-syntax-error*

(signal-syntax-error* (lexer-pos lexer) "Invalid character in named register group.")

[Assistant]
(defmacro signal-syntax-error* (pos format-control &rest format-arguments)
  `(error 'ppcre-syntax-error
          :pos ,pos
          :format-control ,format-control
          :format-arguments (list ,@format-arguments)))

;; macroexpand:
(error (quote ppcre-syntax-error) :pos (lexer-pos lexer) :format-control "Invalid character in named register group." :format-arguments (list))


[User]
You are a Common Lisp macro expert. Given this code pattern:
(define-path-instruction-pair curve-to "C" (control-x1 control-y1 control-x2 control-y2 x y))

Write a macro that addresses: Macro call that should be transformed by define-path-instruction-pair

(define-path-instruction-pair curve-to "C" (control-x1 control-y1 control-x2 control-y2 x y))

[Assistant]
(defmacro define-path-instruction-pair (name instruction (&rest args))
  (let ((draw-relative (intern (concatenate 'string (string name) "-R"))))
    `(progn
       (defun ,name (,@args)
         (format-instruction ,instruction ,@args))
       (defun ,draw-relative (,@args)
         (format-instruction ,(string-downcase instruction) ,@args)))))

;; macroexpand:
(progn (defun curve-to (control-x1 control-y1 control-x2 control-y2 x y) (format-instruction "C" control-x1 control-y1 control-x2 control-y2 x y)) (defun curve-to-r (control-x1 control-y1 control-x2 control-y2 x y) (format-instruction "c" control-x1 control-y1 control-x2 control-y2 x y)))


[User]
Create a Common Lisp macro for the following transformation. Before code:
(dlet nil
  :key
  nil)

What needs to change: Macro call that should be transformed by DLET

(dlet nil
  :key
  nil)

[Assistant]
(defmacro DLET ...)

;; macroexpand:
(dynamic-let nil
  :key
  nil)


[User]
Create a Common Lisp macro for the following transformation. Before code:
(mvlet* ((form exp? (expand-in-env-1 self form env)) (exps? (or exps? exp?))) (if (not exp?) (values form exps?) (rec form exps?)))

What needs to change: Macro call that should be transformed by mvlet*

(mvlet* ((form exp? (expand-in-env-1 self form env)) (exps? (or exps? exp?))) (if (not exp?) (values form exps?) (rec form exps?)))

[Assistant]
(defmacro mvlet* ((&rest bindings) &body body &environment env)
  "Expand a series of nested `multiple-value-bind' forms.

`mvlet*' is similar in intent to Scheme’s `let-values', but with a
different and less parenthesis-intensive syntax. Each binding is a
list of

    (var var*... expr)

A simple example should suffice to show both the implementation and
the motivation:

    (defun uptime (seconds)
      (mvlet* ((minutes seconds (truncate seconds 60))
               (hours minutes (truncate minutes 60))
               (days hours (truncate hours 24)))
        (declare ((integer 0 *) days hours minutes seconds))
        (fmt \"~d day~:p, ~d hour~:p, ~d minute~:p, ~d second~:p\"
             days hours minutes seconds)))

Note that declarations work just like `let*'."
  (cond ((null bindings)
         `(locally ,@body))
        ((every #'simple-binding-p bindings)
         `(let* ,bindings ,@body))
        (t (multiple-value-bind (body decls)
               (parse-body body)
             (let* ((bindings (canonicalize-bindings bindings))
                    (mvbinds (member-if-not #'simple-binding-p bindings))
                    (simple-binds (ldiff bindings mvbinds)))
               (if simple-binds
                   (multiple-value-bind (local other)
                       (partition-declarations (mapcar #'car simple-binds) decls env)
                     `(let* ,simple-binds
                        ,@local
                        (mvlet* ,mvbinds
                          ,@other
                          ,@body)))
                   (let* ((vars (butlast (car bindings)))
                          (expr (lastcar (car bindings))))
                     (multiple-value-bind (local other)
                         (partition-declarations vars decls env)
                       `(multiple-value-bind ,vars
                            ,expr
                          ,@local
                          (mvlet* ,(cdr bindings)
                            ,@other
                            ,@body))))))))))

;; macroexpand:
(multiple-value-bind (form exp?) (expand-in-env-1 self form env) (mvlet* ((exps? (or exps? exp?))) (if (not exp?) (values form exps?) (rec form exps?))))


[User]
Create a Common Lisp macro for the following transformation. Before code:
(dict-of nil)

What needs to change: Macro call that should be transformed by DICT-OF

(dict-of nil)

[Assistant]
(defmacro DICT-OF ...)

;; macroexpand:
(let ((#:dict122 (make-hash-table :test 'equal)))
  (do-for nil
    (multiple-value-call
        (lambda (#:k123 #:v124) (setf (gethash #:k123 #:dict122) #:v124))
      nil))
  #:dict122)


[User]
Write a Common Lisp macro to handle this code pattern:
(mapping 'some-name)

Problem: Macro call that should be transformed by MAPPING

(mapping 'some-name)

[Assistant]
(defmacro MAPPING ...)

;; macroexpand:
(mapping-mac 'some-name)


[User]
Write a Common Lisp macro to handle this code pattern:
(dotable (item _ set1) (unless (gethash item set2) (add# item set)))

Problem: Macro call that should be transformed by dotable

(dotable (item _ set1) (unless (gethash item set2) (add# item set)))

[Assistant]
(defmacro dotable ((k v table &optional rez) &body body)
  "Like DOLIST but iterates over key-value pairs (K V) in anything, that can be
   viewed as a table (hash-table, alist, plist, object).
   Autodeclares variables named _ as ignored."
  (with-gensyms (pair)
    (once-only (table)
      (let ((_ (find "_" (list k v)
                     :test 'string=
                     :key 'symbol-name)))
        `(block nil
           (etypecase ,table
             (hash-table (maphash (lambda (,k ,v)
                                    ,(when _ `(declare (ignore rutils.bind:_)))
                                    ,@body)
                                  ,table))

             (list (if (rutils.list:alistp ,table)
                       (dolist (,pair ,table)
                         (destructuring-bind (,k . ,v) ,pair
                           ,@(when _ `((declare (ignore ,_))))
                           ,@body))
                       (error 'simple-type-error
                              :format-control "Can't iterate over proper list ~
                                               in DOTABLE: need an alist"))))
           ,rez)))))

;; macroexpand:
(let ((#:table168 set1)) (block nil (etypecase #:table168 (hash-table (maphash (lambda (item _) (declare (ignore rutils.bind:_)) (unless (gethash item set2) (|ADD#| item set))) #:table168)) (list (if (alistp #:table168) (dolist (#:g167 #:table168) (destructuring-bind (item . _) #:g167 (declare (ignore _)) (unless (gethash item set2) (|ADD#| item set)))) (error (quote simple-type-error) :format-control "Can't iterate over proper list ~
                                               in DOTABLE: need an alist")))) nil))


[User]
Write a Common Lisp macro to handle this code pattern:
(defsynonym :multiply :mult)

Problem: Macro call that should be transformed by defsynonym

(defsynonym :multiply :mult)

[Assistant]
(defmacro defsynonym (symbol synonym)
  "Set SYNONYM for a SYMBOL. "
  `(eval-always
     (setf (get ',symbol 'synonym) ',synonym)))

;; macroexpand:
(eval-always (setf (get (quote :multiply) (quote synonym)) (quote :mult)))


[User]
Define a macro that eliminates this repetitive pattern:
(define-custom-var (:boolean *boolean-handler*))

Issue: Macro call that should be transformed by define-custom-var

(define-custom-var (:boolean *boolean-handler*))

[Assistant]
(defmacro define-custom-var ((key name) &rest other-args)
  `(eval-when (:compile-toplevel :load-toplevel :execute)
     (progn (pushnew '(,name . ,key) *custom-vars* :test #'equal)
            (defvar ,name ,@other-args))))

;; macroexpand:
(eval-when (:compile-toplevel :load-toplevel :execute) (progn (pushnew (quote (*boolean-handler* . :boolean)) *custom-vars* :test (function equal)) (defvar *boolean-handler*)))


[User]
Generate a defmacro form that transforms code like this:
(->> nil :key nil)

Pattern to recognize: Macro call that should be transformed by ->>

(->> nil :key nil)

[Assistant]
(defmacro ->> ...)

;; macroexpand:
((:key nil))


[User]
Create a Common Lisp macro for the following transformation. Before code:
(without-symbol-access
  'some-name)

What needs to change: Macro call that should be transformed by WITHOUT-SYMBOL-ACCESS

(without-symbol-access
  'some-name)

[Assistant]
(defmacro WITHOUT-SYMBOL-ACCESS ...)

;; macroexpand:
(let ((*symbol-access* nil))
  'some-name)


[User]
Create a Common Lisp macro for the following transformation. Before code:
(mvlet 'some-name)

What needs to change: Macro call that should be transformed by MVLET

(mvlet 'some-name)

[Assistant]
(defmacro MVLET ...)

;; macroexpand:
(progn (let ((quote) (some-name))))


[User]
Create a Common Lisp macro for the following transformation. Before code:
(with-preprocessor-state-slots (state) (let ((removed-if-section (pop if-section-stack))) (when (eq if-section-skip-reason removed-if-section) (setf if-section-skip-reason nil))))

What needs to change: Macro call that should be transformed by with-preprocessor-state-slots

(with-preprocessor-state-slots (state) (let ((removed-if-section (pop if-section-stack))) (when (eq if-section-skip-reason removed-if-section) (setf if-section-skip-reason nil))))

[Assistant]
(defmacro with-preprocessor-state-slots ((state) &body body)
  `(with-accessors ((file-pathname pp-state-file-pathname)
                    (token-list pp-state-token-list)
                    (result-list pp-state-result-list)
                    (line-number pp-state-line-number)
                    (tokens-in-line pp-state-tokens-in-line)
                    (macro-alist pp-state-macro-alist)
                    (if-section-stack pp-state-if-section-stack)
                    (if-section-skip-reason pp-state-if-section-skip-reason)
                    (include-stack pp-state-include-stack))
       ,state
     ,@body))

;; macroexpand:
(with-accessors ((file-pathname pp-state-file-pathname) (token-list pp-state-token-list) (result-list pp-state-result-list) (line-number pp-state-line-number) (tokens-in-line pp-state-tokens-in-line) (macro-alist pp-state-macro-alist) (if-section-stack pp-state-if-section-stack) (if-section-skip-reason pp-state-if-section-skip-reason) (include-stack pp-state-include-stack)) state (let ((removed-if-section (pop if-section-stack))) (when (eq if-section-skip-reason removed-if-section) (setf if-section-skip-reason nil))))


[User]
Define a macro that eliminates this repetitive pattern:
(ok nil "This supposed to be failed")

Issue: Macro call that should be transformed by ok

(ok nil "This supposed to be failed")

[Assistant]
(defmacro ok (test &optional desc)
  (with-gensyms (duration result)
    (once-only (test desc)
      `(with-catching-errors (:expected T :description ,desc)
         (with-duration ((,duration ,result) ,test)
           (test ,result t ,desc
                 :duration ,duration
                 :test-fn (lambda (x y)
                            (eq (not (null x)) y))
                 :got-form ,test))))))

;; macroexpand:
(let ((#:test150 nil) (#:desc151 "This supposed to be failed")) (with-catching-errors (:expected t :description #:desc151) (with-duration ((#:duration148 #:result149) #:test150) (test #:result149 t #:desc151 :duration #:duration148 :test-fn (lambda (x y) (eq (not (null x)) y)) :got-form #:test150))))


[User]
Define a macro that eliminates this repetitive pattern:
(vect-of 'some-name)

Issue: Macro call that should be transformed by VECT-OF

(vect-of 'some-name)

[Assistant]
(defmacro VECT-OF ...)

;; macroexpand:
(let ((#:vect141 (make-array 10 :adjustable t :fill-pointer 0)))
  (do-for nil
    (vector-push-extend 'some-name #:vect141))
  #:vect141)


[User]
Define a macro that eliminates this repetitive pattern:
(when nil :key nil)

Issue: Macro call that should be transformed by WHEN

(when nil :key nil)

[Assistant]
(defmacro WHEN ...)

;; macroexpand:
(if nil
    (progn :key nil))


[User]
Create a Common Lisp macro for the following transformation. Before code:
(defun-advisable nil
    :key
  nil)

What needs to change: Macro call that should be transformed by DEFUN-ADVISABLE

(defun-advisable nil
    :key
  nil)

[Assistant]
(defmacro DEFUN-ADVISABLE ...)

;; macroexpand:
(let ((#:oldfn136
       (handler-case (symbol-function 'nil) (undefined-function nil nil))))
  (defun nil :key nil)
  (make-advisable 'nil :arguments ':key)
  (when
      (and #:oldfn136
           (not (eql (advisable-function-arguments #:oldfn136) :not-provided))
           (equal (advisable-function-arguments #:oldfn136) ':key))
    (copy-advice #:oldfn136 (symbol-function 'nil))))


[User]
Generate a defmacro form that transforms code like this:
(is (every (curry #'char= #\Null) s))

Pattern to recognize: Macro call that should be transformed by is

(is (every (curry #'char= #\Null) s))

[Assistant]
(defmacro is (test &rest reason-args)
  "The DWIM checking operator.

If TEST returns a true value a test-passed result is generated,
otherwise a test-failure result is generated. The reason, unless
REASON-ARGS is provided, is generated based on the form of TEST:

 (predicate expected actual) - Means that we want to check
 whether, according to PREDICATE, the ACTUAL value is
 in fact what we EXPECTED.

 (predicate value) - Means that we want to ensure that VALUE
 satisfies PREDICATE.

 Wrapping the TEST form in a NOT simply produces a negated reason
 string."
  (assert (listp test)
          (test)
          "Argument to IS must be a list, not ~S" test)
  (let (bindings effective-test default-reason-args)
    (with-gensyms (e a v)
      (flet ((process-entry (predicate expected actual &optional negatedp)
               ;; make sure EXPECTED is holding the entry that starts with 'values
               (when (and (consp actual)
                          (eq (car actual) 'values))
                 (assert (not (and (consp expected)
                                   (eq (car expected) 'values))) ()
                                   "Both the expected and actual part is a values expression.")
                 (rotatef expected actual))
               (let ((setf-forms))
                 (if (and (consp expected)
                          (eq (car expected) 'values))
                     (progn
                       (setf expected (copy-list expected))
                       (setf setf-forms (loop for cell = (rest expected) then (cdr cell)
                                              for i from 0
                                              while cell
                                              when (eq (car cell) '*)
                                              collect `(setf (elt ,a ,i) nil)
                                              and do (setf (car cell) nil)))
                       (setf bindings (list (list e `(list ,@(rest expected)))
                                            (list a `(multiple-value-list ,actual)))))
                     (setf bindings (list (list e expected)
                                          (list a actual))))
                 (setf effective-test `(progn
                                         ,@setf-forms
                                         ,(if negatedp
                                              `(not (,predicate ,e ,a))
                                              `(,predicate ,e ,a)))))))
        (list-match-case test
          ((not (?predicate ?expected ?actual))
           (process-entry ?predicate ?expected ?actual t)
           (setf default-reason-args
                 (list "~2&~S~2% evaluated to ~2&~S~2% which is ~2&~S~2%to ~2&~S~2% (it should not be)"
                       `',?actual a `',?predicate e)))
          ((not (?satisfies ?value))
           (setf bindings (list (list v ?value))
                 effective-test `(not (,?satisfies ,v))
                 default-reason-args
                 (list "~2&~S~2% evaluated to ~2&~S~2% which satisfies ~2&~S~2% (it should not)"
                       `',?value v `',?satisfies)))
          ((?predicate ?expected ?actual)
           (process-entry ?predicate ?expected ?actual)
           (setf default-reason-args
                 (list "~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%"
                       `',?actual a `',?predicate e)))
          ((?satisfies ?value)
           (setf bindings (list (list v ?value))
                 effective-test `(,?satisfies ,v)
                 default-reason-args
                 (list "~2&~S~2% evaluated to ~2&~S~2% which does not satisfy ~2&~S~2%"
                       `',?value v `',?satisfies)))
          (?_
           (setf bindings '()
                 effective-test test
                 default-reason-args (list "~2&~S~2% was NIL." `',test)))))
      `(let ,bindings
         (if ,effective-test
             (add-result 'test-passed :test-expr ',test)
             (process-failure ',test
                              ,@(or reason-args default-reason-args)))))))

;; macroexpand:
(let ((#:e262 (curry (function char=) #\Nul)) (#:a263 s)) (if (progn (every #:e262 #:a263)) (add-result (quote test-passed) :test-expr (quote (every (curry (function char=) #\Nul) s))) (process-failure (quote (every (curry (function char=) #\Nul) s)) "~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%" (quote s) #:a263 (quote every) #:e262)))


[User]
Create a Common Lisp macro for the following transformation. Before code:
(defun-compile-time walk-progn (map-function reduce-function screamer? partial? nested? form environment) (unless (null (rest (last form))) (error "Improper PROGN: ~S" form)) (if reduce-function (funcall reduce-function (funcall map-function form 'progn) (reduce reduce-function (mapcar #'(lambda (subform) (walk map-function reduce-function screamer? partial? nested? subform environment)) (rest form)))) (funcall map-function form 'progn)))

What needs to change: Macro call that should be transformed by defun-compile-time

(defun-compile-time walk-progn (map-function reduce-function screamer? partial? nested? form environment) (unless (null (rest (last form))) (error "Improper PROGN: ~S" form)) (if reduce-function (funcall reduce-function (funcall map-function form 'progn) (reduce reduce-function (mapcar #'(lambda (subform) (walk map-function reduce-function screamer? partial? nested? subform environment)) (rest form)))) (funcall map-function form 'progn)))

[Assistant]
(defmacro defun-compile-time (function-name lambda-list &body body)
  `(eval-when (:compile-toplevel :load-toplevel :execute)
     (cl:defun ,function-name ,lambda-list ,@body)
     (eval-when (:compile-toplevel) (compile ',function-name))))

;; macroexpand:
(eval-when (:compile-toplevel :load-toplevel :execute) (common-lisp:defun walk-progn (map-function reduce-function screamer? partial? nested? form environment) (unless (null (rest (last form))) (error "Improper PROGN: ~S" form)) (if reduce-function (funcall reduce-function (funcall map-function form (quote progn)) (reduce reduce-function (mapcar (function (lambda (subform) (walk map-function reduce-function screamer? partial? nested? subform environment))) (rest form)))) (funcall map-function form (quote progn)))) (eval-when (:compile-toplevel) (compile (quote walk-progn))))


[User]
Generate a defmacro form that transforms code like this:
(count-of nil
  nil)

Pattern to recognize: Macro call that should be transformed by COUNT-OF

(count-of nil
  nil)

[Assistant]
(defmacro COUNT-OF ...)

;; macroexpand:
(lc (nil nil) count)


[User]
Define a macro that eliminates this repetitive pattern:
(defclause accumulating-to-and-returning (vars &rest args &key initially by finally) "Same as accumulating-into, but also returns the value of each <vars> at the end of the loop." (declare (ignore initially by finally)) `((accumulating-to ,vars ,@args) ,@(mapcar (lambda (var) `(returning ,var)) (ensure-list vars))))

Issue: Macro call that should be transformed by defclause

(defclause accumulating-to-and-returning (vars &rest args &key initially by finally) "Same as accumulating-into, but also returns the value of each <vars> at the end of the loop." (declare (ignore initially by finally)) `((accumulating-to ,vars ,@args) ,@(mapcar (lambda (var) `(returning ,var)) (ensure-list vars))))

[Assistant]
(defmacro defclause (name arglist &body body)
  "Same as cl:defmacro, but additionally records <name> in *clauses* as a known clause macro."
  `(progn
     (defmacro ,name ,arglist ,@body)
     (pushnew ',name *clauses*)))

;; macroexpand:
(progn (defmacro accumulating-to-and-returning (vars &rest args &key initially by finally) "Same as accumulating-into, but also returns the value of each <vars> at the end of the loop." (declare (ignore initially by finally)) (sb-int:quasiquote ((accumulating-to #S(sb-impl::comma :expr vars :kind 0) #S(sb-impl::comma :expr args :kind 2)) #S(sb-impl::comma :expr (mapcar (lambda (var) (sb-int:quasiquote (returning #S(sb-impl::comma :expr var :kind 0)))) (ensure-list vars)) :kind 2)))) (pushnew (quote accumulating-to-and-returning) *clauses*))


[User]
You are a Common Lisp macro expert. Given this code pattern:
(defstruct*)

Write a macro that addresses: Macro call that should be transformed by DEFSTRUCT*

(defstruct*)

[Assistant]
(defmacro DEFSTRUCT* ...)

;; macroexpand:
(progn
 (defclass nil nil nil)
 (defun make-nil (&rest structure-ext.as-class::args)
   (apply #'make-instance 'nil structure-ext.as-class::args))
 (defgeneric copy-nil
     (structure-ext.as-class::arg))
 (defmethod copy-nil ((structure-ext.as-class::arg nil))
   (let ((structure-ext.as-class::obj
          (make-instance (class-of structure-ext.as-class::arg))))
     (dolist
         (structure-ext.as-class::slot
          (structure-ext.as-class::slots<=obj structure-ext.as-class::arg))
       (if (slot-boundp structure-ext.as-class::arg
                        structure-ext.as-class::slot)
           (setf (slot-value structure-ext.as-class::obj
                             structure-ext.as-class::slot)
                   (slot-value structure-ext.as-class::arg
                               structure-ext.as-class::slot))
           (slot-makunbound structure-ext.as-class::obj
                            structure-ext.as-class::slot)))
     structure-ext.as-class::obj))
 (defun nil-p (structure-ext.as-class::arg)
   (typep structure-ext.as-class::arg 'nil))
 'nil)


[User]
Write a Common Lisp macro to handle this code pattern:
(with-hamt dict (:test test :hash hash :table table) (%hamt-lookup table key (funcall hash key) 0 test))

Problem: Macro call that should be transformed by with-hamt

(with-hamt dict (:test test :hash hash :table table) (%hamt-lookup table key (funcall hash key) 0 test))

[Assistant]
(defmacro with-hamt (hamt (&key test hash table) &body body)
  "Accessing HAMT slots"
  `(with-accessors ((,test hamt-test)
                    (,hash hamt-hash)
                    (,table hamt-table))
       ,hamt
     ,@body))

;; macroexpand:
(with-accessors ((test hamt-test) (hash hamt-hash) (table hamt-table)) dict (%hamt-lookup table key (funcall hash key) 0 test))


[User]
Write a Common Lisp macro to handle this code pattern:
(match 'some-name)

Problem: Macro call that should be transformed by MATCH

(match 'some-name)

[Assistant]
(defmacro MATCH ...)

;; macroexpand:
(block #:match131
  (let ((#:var130 'some-name))
    (declare (ignorable #:var130))))


[User]
Generate a defmacro form that transforms code like this:
(next)

Pattern to recognize: Macro call that should be transformed by next

(next)

[Assistant]
(defmacro next () `(return-from clause nil))

;; macroexpand:
(common-lisp:return-from trivia.level1.impl::clause common-lisp:nil)


[User]
Define a macro that eliminates this repetitive pattern:
(make-name-transformer name)

Issue: Macro call that should be transformed by make-name-transformer

(make-name-transformer name)

[Assistant]
(defmacro make-name-transformer (&rest elements)
  "Return an accessor name transformer.
The unquoted `name' symbol argument is substituted for the slot name.
Class option examples:

  :accessor-name-transformer (make-name-transformer \"FOO-\" name \"-BAR\")

Use the slot name directly:

  :accessor-name-transformer (make-name-transformer name)"
  `(lambda (name definition)
    (declare (ignorable definition))
    (concatenate-symbol ,@(mapcar (lambda (el)
                                    (if (and (symbolp el)
                                             (string= (symbol-name el) "NAME"))
                                        'name
                                        el))
                                  elements))))

;; macroexpand:
(lambda (name definition) (declare (ignorable definition)) (concatenate-symbol name))


[User]
Write a Common Lisp macro to handle this code pattern:
(define-path-instruction-pair quadratic-curve-to "Q" (control-x1 control-y1 x y))

Problem: Macro call that should be transformed by define-path-instruction-pair

(define-path-instruction-pair quadratic-curve-to "Q" (control-x1 control-y1 x y))

[Assistant]
(defmacro define-path-instruction-pair (name instruction (&rest args))
  (let ((draw-relative (intern (concatenate 'string (string name) "-R"))))
    `(progn
       (defun ,name (,@args)
         (format-instruction ,instruction ,@args))
       (defun ,draw-relative (,@args)
         (format-instruction ,(string-downcase instruction) ,@args)))))

;; macroexpand:
(progn (defun quadratic-curve-to (control-x1 control-y1 x y) (format-instruction "Q" control-x1 control-y1 x y)) (defun quadratic-curve-to-r (control-x1 control-y1 x y) (format-instruction "q" control-x1 control-y1 x y)))


[User]
Write a Common Lisp macro to handle this code pattern:
(some->>
  nil
  (progn))

Problem: Macro call that should be transformed by SOME->>

(some->>
  nil
  (progn))

[Assistant]
(defmacro SOME->> ...)

;; macroexpand:
(let* ((#:var199 nil)
       (#:var200
        (if #:var199
            (progn #:var199)
            nil)))
  #:var200)


[User]
Define a macro that eliminates this repetitive pattern:
(define-simple-documentation-lookup setf-expander cl:setf)

Issue: Macro call that should be transformed by define-simple-documentation-lookup

(define-simple-documentation-lookup setf-expander cl:setf)

[Assistant]
(defmacro define-simple-documentation-lookup (class documentation-type)
  `(defmethod documentation ((,class ,class))
     ,(if (eql documentation-type T)
          `(cl:documentation (object ,class) 'T)
          `(cl:documentation (designator ,class) ',documentation-type))))

;; macroexpand:
(defmethod documentation ((setf-expander setf-expander)) (common-lisp:documentation (designator setf-expander) (quote setf)))


[User]
Generate a defmacro form that transforms code like this:
(collect-append nil nil)

Pattern to recognize: Macro call that should be transformed by COLLECT-APPEND

(collect-append nil nil)

[Assistant]
(defmacro COLLECT-APPEND ...)

;; macroexpand:
(common-lisp:let* ((#:generator-215 (generator nil))
                   #:items-210
                   (#:seq-211 nil))
  (declare (type generator #:generator-215))
  (tagbody
   #:ll-216
    (setq #:items-210 (next-in #:generator-215 (go end)))
    (setq #:seq-211 (cons #:items-210 #:seq-211))
    (go #:ll-216)
   end)
  (apply #'concatenate nil (nreverse #:seq-211)))


[User]
Generate a defmacro form that transforms code like this:
(with-preprocessor-state-slots (state) (when if-section-skip-reason (begin-if-section state '(:skipped :ifdef) nil) (return-from process-preprocessing-directive nil)) (let* ((identifier (pop-last-preprocessor-directive-token directive-token-list directive-symbol)) (condition `(:ifdef ,identifier)) (result (preprocessor-macro-exists-p macro-alist identifier))) (begin-if-section state condition result)))

Pattern to recognize: Macro call that should be transformed by with-preprocessor-state-slots

(with-preprocessor-state-slots (state) (when if-section-skip-reason (begin-if-section state '(:skipped :ifdef) nil) (return-from process-preprocessing-directive nil)) (let* ((identifier (pop-last-preprocessor-directive-token directive-token-list directive-symbol)) (condition `(:ifdef ,identifier)) (result (preprocessor-macro-exists-p macro-alist identifier))) (begin-if-section state condition result)))

[Assistant]
(defmacro with-preprocessor-state-slots ((state) &body body)
  `(with-accessors ((file-pathname pp-state-file-pathname)
                    (token-list pp-state-token-list)
                    (result-list pp-state-result-list)
                    (line-number pp-state-line-number)
                    (tokens-in-line pp-state-tokens-in-line)
                    (macro-alist pp-state-macro-alist)
                    (if-section-stack pp-state-if-section-stack)
                    (if-section-skip-reason pp-state-if-section-skip-reason)
                    (include-stack pp-state-include-stack))
       ,state
     ,@body))

;; macroexpand:
(with-accessors ((file-pathname pp-state-file-pathname) (token-list pp-state-token-list) (result-list pp-state-result-list) (line-number pp-state-line-number) (tokens-in-line pp-state-tokens-in-line) (macro-alist pp-state-macro-alist) (if-section-stack pp-state-if-section-stack) (if-section-skip-reason pp-state-if-section-skip-reason) (include-stack pp-state-include-stack)) state (when if-section-skip-reason (begin-if-section state (quote (:skipped :ifdef)) nil) (return-from process-preprocessing-directive nil)) (let* ((identifier (pop-last-preprocessor-directive-token directive-token-list directive-symbol)) (condition (sb-int:quasiquote (:ifdef #S(sb-impl::comma :expr identifier :kind 0)))) (result (preprocessor-macro-exists-p macro-alist identifier))) (begin-if-section state condition result)))


[User]
You are a Common Lisp macro expert. Given this code pattern:
(define-simple-type-map method cl:method)

Write a macro that addresses: Macro call that should be transformed by define-simple-type-map

(define-simple-type-map method cl:method)

[Assistant]
(defmacro define-simple-type-map (class type)
  `(defmethod type ((,class ,class))
     ',type))

;; macroexpand:
(defmethod type ((method method)) (quote common-lisp:method))


[User]
Write a Common Lisp macro to handle this code pattern:
(defun-compile-time quotify (thing) (if (self-evaluating? thing) thing `',thing))

Problem: Macro call that should be transformed by defun-compile-time

(defun-compile-time quotify (thing) (if (self-evaluating? thing) thing `',thing))

[Assistant]
(defmacro defun-compile-time (function-name lambda-list &body body)
  `(eval-when (:compile-toplevel :load-toplevel :execute)
     (cl:defun ,function-name ,lambda-list ,@body)
     (eval-when (:compile-toplevel) (compile ',function-name))))

;; macroexpand:
(eval-when (:compile-toplevel :load-toplevel :execute) (common-lisp:defun quotify (thing) (if (self-evaluating? thing) thing (sb-int:quasiquote (quote #S(sb-impl::comma :expr thing :kind 0))))) (eval-when (:compile-toplevel) (compile (quote quotify))))