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

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

(defsynonym leave :leave)

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

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


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

Write a macro that addresses: Macro call that should be transformed by MAYBE-ONCE-ONLY

(maybe-once-only 'some-name)

[Assistant]
(defmacro MAYBE-ONCE-ONLY ...)

;; macroexpand:
(let* ((#:g185 nil)
       (quote
        (let ((form (ps-macroexpand quote)))
          (if (atom form)
              form
              (let ((var1 (ps-gensym 'quote)))
                (push (list var1 form) #:g185)
                var1))))
       (some-name
        (let ((form (ps-macroexpand some-name)))
          (if (atom form)
              form
              (let ((var1 (ps-gensym 'some-name)))
                (push (list var1 form) #:g185)
                var1)))))
  `(let* ,(nreverse #:g185)))


[User]
Generate a defmacro form that transforms code like this:
(with-path curvy (smooth-quadratic-curve-to (random 500) (random 500)))

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

(with-path curvy (smooth-quadratic-curve-to (random 500) (random 500)))

[Assistant]
(defmacro with-path (path &body cmds)
  (let ((s (gensym "stream"))
        (n (gensym)))
    `(flet ((assert-string (s)
              (error-unless-string s)))
       (with-output-to-string (,s ,path)
         ;; Do trivial breaking up of the path data - SVG does not have
         ;; to accept indefinitely long lines of data.
         (let ((,n 0))
           (dolist (inst (mapcar #'assert-string (list ,@cmds)) (format ,s "~&"))
             (format ,s "~@{~A~}" inst)
             (incf ,n)
             (when (= (mod ,n 10) 0)
               (format ,s "~&"))))))))

;; macroexpand:
(flet ((assert-string (s) (error-unless-string s))) (with-output-to-string (#:|stream138| curvy) (let ((#:g139 0)) (dolist (inst (mapcar (function assert-string) (list (smooth-quadratic-curve-to (random 500) (random 500)))) (format #:|stream138| "~&")) (format #:|stream138| "~@{~A~}" inst) (incf #:g139) (when (= (mod #:g139 10) 0) (format #:|stream138| "~&"))))))


[User]
You are a Common Lisp macro expert. Given this code pattern:
(define-error keyword-in-function-position () (form) "Keyword cannot appear in function name position : ~s" form)

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

(define-error keyword-in-function-position () (form) "Keyword cannot appear in function name position : ~s" form)

[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 keyword-in-function-position (:error-type varjo-error :prefix "Varjo") (form) "Keyword cannot appear in function name position : ~s" form)


[User]
Create a Common Lisp macro for the following transformation. Before code:
(define-element-maker :polyline "polyline" '(:points))

What needs to change: Macro call that should be transformed by define-element-maker

(define-element-maker :polyline "polyline" '(:points))

[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 :polyline)) attributes) (declare (ignore element)) (unless (evenp (length attributes)) (warn "attribute list may be missing data: ~A" attributes)) (let ((missing (set-difference (quote (:points)) attributes))) (when missing (error (quote missing-attributes) :message (format nil "~A missing attributes: ~{~A~^ ~}" :polyline missing))))) (defmethod make-svg-element ((element (eql :polyline)) attributes) (when *check-required-attributes* (assert-required-attributes element attributes)) (make-instance (quote svg-element) :name "polyline" :attributes attributes)))


[User]
Write a Common Lisp macro to handle this code pattern:
(answer (foo 1) 42)

Problem: Macro call that should be transformed by answer

(answer (foo 1) 42)

[Assistant]
(defmacro answer (call &body forms)
  (let ((name (if (listp call) (car call) call))
        (sym (gensym)))
    `(if-called
      ',name
      (let ((,sym (fdefinition ',name)))
        (declare (ignorable ,sym))
        (let ((times 0))
          (lambda (&rest args)
            (declare (ignorable args))
            ,(let ((cases
                     `(case (prog1 times (incf times))
                        ,.(loop
                            for i from 0
                            for (form . rest) on forms
                            collect `(,(if rest i T) ,form)))))
               (if (listp call)
                   `(trivia:match args
                     ((list . ,(cdr call)) ,cases)
                     (_ (unhandled)))
                   cases))))))))

;; macroexpand:
(if-called (quote foo) (let ((#:g158 (fdefinition (quote foo)))) (declare (ignorable #:g158)) (let ((times 0)) (lambda (&rest args) (declare (ignorable args)) (trivia.level2:match args ((list 1) (case (prog1 times (incf times)) (t 42))) (_ (unhandled)))))))


[User]
Create a Common Lisp macro for the following transformation. Before code:
(c? (incf delta-ct) (trc nil "syn-b rule firing!!!!!!!!!!!!!!" delta-ct) (eko (nil "syn-b rule returning") (f-delta :syna-1 (:sensitivity 2) (^m-syn-a))))

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

(c? (incf delta-ct) (trc nil "syn-b rule firing!!!!!!!!!!!!!!" delta-ct) (eko (nil "syn-b rule returning") (f-delta :syna-1 (:sensitivity 2) (^m-syn-a))))

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

;; macroexpand:
(make-c-dependent :code (quote ((incf delta-ct) (trc nil "syn-b rule firing!!!!!!!!!!!!!!" delta-ct) (eko (nil "syn-b rule returning") (f-delta :syna-1 (:sensitivity 2) (^m-syn-a))))) :value-state :unevaluated :rule (c-lambda (incf delta-ct) (trc nil "syn-b rule firing!!!!!!!!!!!!!!" delta-ct) (eko (nil "syn-b rule returning") (f-delta :syna-1 (:sensitivity 2) (^m-syn-a)))))


[User]
Create a Common Lisp macro for the following transformation. Before code:
(with-yield-binds (format nil "~A ~A ~A" (slot-value clause 'name) (yield (distinct-on-clause-columns clause)) (yield (statement-clause-statement clause))))

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

(with-yield-binds (format nil "~A ~A ~A" (slot-value clause 'name) (yield (distinct-on-clause-columns clause)) (yield (statement-clause-statement clause))))

[Assistant]
(defmacro with-yield-binds (&body body)
  `(let ((*bind-values* nil)
         (*use-global-bind-values* t))
     (values
      (progn ,@body)
      (loop for bind in (reverse *bind-values*)
            append bind))))

;; macroexpand:
(let ((*bind-values* nil) (*use-global-bind-values* t)) (values (progn (format nil "~A ~A ~A" (slot-value clause (quote name)) (yield (distinct-on-clause-columns clause)) (yield (statement-clause-statement clause)))) (loop for bind in (reverse *bind-values*) append bind)))


[User]
Define a macro that eliminates this repetitive pattern:
(define-global-parameter* nil nil)

Issue: Macro call that should be transformed by DEFINE-GLOBAL-PARAMETER*

(define-global-parameter* nil nil)

[Assistant]
(defmacro DEFINE-GLOBAL-PARAMETER* ...)

;; macroexpand:
(progn
 (setf (get 'nil +value-key+) nil)
 (sb-ext:define-load-time-global nil (get 'nil +value-key+))
 (setf nil (get 'nil +value-key+))
 (remprop 'nil +value-key+)
 'nil)


[User]
You are a Common Lisp macro expert. Given this code pattern:
(with-store-entry (key store) (trc "looked up dead item -- resetting to nil" key store) (setf (item key store) nil))

Write a macro that addresses: Macro call that should be transformed by with-store-entry

(with-store-entry (key store) (trc "looked up dead item -- resetting to nil" key store) (setf (item key store) nil))

[Assistant]
(defmacro with-store-entry ((key store &key quiet) &body body)
  `(prog1
       (progn
	 ,@body)
     (unless ,quiet
       (kick-c-link ,key ,store))))

;; macroexpand:
(prog1 (progn (trc "looked up dead item -- resetting to nil" key store) (setf (item key store) nil)) (unless nil (kick-c-link key store)))


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

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

(js-inline nil :key nil)

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

;; macroexpand:
(js-inline* '(progn nil :key nil))


[User]
You are a Common Lisp macro expert. Given this code pattern:
(do-generator-value-list (vars (apply #'multi-gen generators)) (apply #'yield (mapcar #'car vars)))

Write a macro that addresses: Macro call that should be transformed by do-generator-value-list

(do-generator-value-list (vars (apply #'multi-gen generators)) (apply #'yield (mapcar #'car vars)))

[Assistant]
(defmacro do-generator-value-list ((var generator) &body body)
  "Like do-generator, except all values emitted by the generator are placed in a list under the user defined variable."
  (let ((g (gensym)))
    `(let ((,g ,generator))
       (loop
	  do (if-generator (,var ,g)
			   (progn ,@body)
			   (return))))))

;; macroexpand:
(let ((#:g179 (apply (function multi-gen) generators))) (loop do (if-generator (vars #:g179) (progn (apply (function yield) (mapcar (function car) vars))) (return))))


[User]
Write a Common Lisp macro to handle this code pattern:
(define-case-aware-token-p-function pp-with-c-syntax-pragma-p find-pragma-name with-c-syntax.pragma-name:|WITH_C_SYNTAX|)

Problem: Macro call that should be transformed by define-case-aware-token-p-function

(define-case-aware-token-p-function pp-with-c-syntax-pragma-p find-pragma-name with-c-syntax.pragma-name:|WITH_C_SYNTAX|)

[Assistant]
(defmacro define-case-aware-token-p-function (function-name find-symbol-function symbol)
  `(defun ,function-name (token &optional (readtable-case (readtable-case *readtable*)))
     (and (symbolp token)
          (eq (,find-symbol-function (string token) readtable-case)
              ',symbol))))

;; macroexpand:
(defun pp-with-c-syntax-pragma-p (token &optional (readtable-case (readtable-case *readtable*))) (and (symbolp token) (eq (find-pragma-name (string token) readtable-case) (quote with-c-syntax.pragma-name:with_c_syntax))))


[User]
Create a Common Lisp macro for the following transformation. Before code:
(make-stream-method pp-xml-attr (s (kw symbol) &optional colon-p at-p) (declare (ignore colon-p at-p)) (format s "~A" (xmlify-keyword kw)))

What needs to change: Macro call that should be transformed by make-stream-method

(make-stream-method pp-xml-attr (s (kw symbol) &optional colon-p at-p) (declare (ignore colon-p at-p)) (format s "~A" (xmlify-keyword kw)))

[Assistant]
(defmacro make-stream-method (name (s &rest args) &body body)
  `(progn
     (defmethod ,name ((,s stream) ,@args)
       ,@body)
     #+abcl
     (defmethod ,name ((,s xp::xp-structure) ,@args)
       ,@body)))

;; macroexpand:
(progn (defmethod pp-xml-attr ((s stream) (kw symbol) &optional colon-p at-p) (declare (ignore colon-p at-p)) (format s "~A" (xmlify-keyword kw))))


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

Write a macro that addresses: Macro call that should be transformed by DEFINE-GLOBAL-VAR

(define-global-var nil :key nil)

[Assistant]
(defmacro DEFINE-GLOBAL-VAR ...)

;; macroexpand:
(sb-ext:defglobal nil :key nil)


[User]
Write a Common Lisp macro to handle this code pattern:
(defclass/std prefix () ((without-prefix)))

Problem: Macro call that should be transformed by defclass/std

(defclass/std prefix () ((without-prefix)))

[Assistant]
(defmacro defclass/std (name direct-superclasses direct-slots &rest options
                        &environment env)
  "Shortcut macro to the DEFCLASS macro.

  (defclass/std example ()
    ((slot1 slot2 slot3)))

  expands to:

  (DEFCLASS EXAMPLE ()
    ((SLOT1 :ACCESSOR SLOT1 :INITARG :SLOT1 :INITFORM NIL)
    (SLOT2 :ACCESSOR SLOT2 :INITARG :SLOT2 :INITFORM NIL)
    (SLOT3 :ACCESSOR SLOT3 :INITARG :SLOT3 :INITFORM NIL)))

  Each slot definition accepts options:

    :std 1 => changes the :initform to 1. It can be :unbound.
    :with or :with-prefix => creates accessors with the class name as prefix.

  See the README for more.

  See also `class/std' and `print-object/std'.
  "
  `(defclass ,name ,direct-superclasses
     ,(process-slots env direct-slots name)
     ,@options))

;; macroexpand:
(defclass prefix nil ((without-prefix :accessor without-prefix :initarg :without-prefix :initform nil)))


[User]
Define a macro that eliminates this repetitive pattern:
(defsynonym :as :for)

Issue: Macro call that should be transformed by defsynonym

(defsynonym :as :for)

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

;; macroexpand:
(eval-always (setf (get (quote :as) (quote synonym)) (quote :for)))


[User]
Generate a defmacro form that transforms code like this:
(-> :g (a) (+ 1 a))

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

(-> :g (a) (+ 1 a))

[Assistant]
(defmacro -> (invariant &body args)
  "See flow:atomically"
  `(atomically ,invariant ,@args))

;; macroexpand:
(atomically :g (a) (+ 1 a))


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

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

(collect-length nil)

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

;; macroexpand:
(common-lisp:let* ((#:generator-462 (generator nil)) (#:number-459 0))
  (declare (type generator #:generator-462)
           (type fixnum #:number-459))
  (tagbody
   #:ll-463
    (next-in #:generator-462 (go end))
    (incf #:number-459)
    (go #:ll-463)
   end)
  #:number-459)


[User]
Generate a defmacro form that transforms code like this:
(check-cursor-attached cluffer:erase-item (cursor))

Pattern to recognize: Macro call that should be transformed by check-cursor-attached

(check-cursor-attached cluffer:erase-item (cursor))

[Assistant]
(defmacro check-cursor-attached (name arguments)
  (let ((args (substitute '(cursor cluffer:cursor) 'cursor arguments)))
    `(defmethod ,name :before ,args
       (declare (ignore ,@(set-difference (remove 'cursor arguments)
                                          lambda-list-keywords)))
       (unless (cluffer:cursor-attached-p cursor)
         (error 'cluffer:cursor-detached)))))

;; macroexpand:
(defmethod cluffer:erase-item :before ((cursor cluffer:cursor)) (declare (ignore)) (unless (cluffer:cursor-attached-p cursor) (error (quote cluffer:cursor-detached))))


[User]
Generate a defmacro form that transforms code like this:
(define-hook (:boot uiop) () (unless uiop/image::*image-restored-p* (setf uiop/image::*image-restored-p* :in-progress) (uiop/image:call-image-restore-hook) (setf uiop/image::*image-restored-p* T)))

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

(define-hook (:boot uiop) () (unless uiop/image::*image-restored-p* (setf uiop/image::*image-restored-p* :in-progress) (uiop/image:call-image-restore-hook) (setf uiop/image::*image-restored-p* T)))

[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 ((uiop (or (hook :boot (quote uiop)) (make-instance (quote hook) :name (quote uiop) :type :boot)))) (setf (hook-priority uiop) 0) (setf (hook-function uiop) (flet ((uiop (&key &allow-other-keys) (unless uiop/image::*image-restored-p* (setf uiop/image::*image-restored-p* :in-progress) (uiop/image:call-image-restore-hook) (setf uiop/image::*image-restored-p* t)))) (function uiop))) (setf (hook :boot (quote uiop)) uiop) (setf (docstring uiop) nil) (quote uiop))


[User]
Create a Common Lisp macro for the following transformation. Before code:
(define-fixture-restore macro (symbol value) (setf (macro-function symbol) value))

What needs to change: Macro call that should be transformed by define-fixture-restore

(define-fixture-restore macro (symbol value) (setf (macro-function symbol) value))

[Assistant]
(defmacro define-fixture-restore (name args &body body)
  `(progn (setf (gethash ',name *fixture-restores*)
                (lambda ,args ,@body))
          ',name))

;; macroexpand:
(progn (setf (gethash (quote macro) *fixture-restores*) (lambda (symbol value) (setf (macro-function symbol) value))) (quote macro))


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

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

(some->
  nil
  :key
  nil)

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

;; macroexpand:
(let* ((#:var173 nil)
       (#:var174
        (if #:var173
            (:key #:var173)
            nil))
       (#:var175
        (if #:var174
            (nil #:var174)
            nil)))
  #:var175)


[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:
(defjsmacro nil (progn))

Issue: Macro call that should be transformed by DEFJSMACRO

(defjsmacro nil (progn))

[Assistant]
(defmacro DEFJSMACRO ...)

;; macroexpand:
(defpsmacro nil
    (progn))


[User]
You are a Common Lisp macro expert. Given this code pattern:
(assert-values ("deleted bar") (foo 'nothing) (foo+1 'nothing) (bar 'nothing) (bar-1 'nothing) (baz 'nothing))

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

(assert-values ("deleted bar") (foo 'nothing) (foo+1 'nothing) (bar 'nothing) (bar-1 'nothing) (baz 'nothing))

[Assistant]
(defmacro assert-values ((desc) &body objects-and-values)
  `(progn
     (trc ,desc)
     ,@(loop for (obj val) in objects-and-values
	    collect `(assert (eql (value ,obj) ,val)))))

;; macroexpand:
(progn (trc "deleted bar") (assert (eql (value foo) (quote nothing))) (assert (eql (value foo+1) (quote nothing))) (assert (eql (value bar) (quote nothing))) (assert (eql (value bar-1) (quote nothing))) (assert (eql (value baz) (quote nothing))))


[User]
Write a Common Lisp macro to handle this code pattern:
(enable-quasi-quoted-string-to-binary-emitting-form-syntax nil)

Problem: Macro call that should be transformed by ENABLE-QUASI-QUOTED-STRING-TO-BINARY-EMITTING-FORM-SYNTAX

(enable-quasi-quoted-string-to-binary-emitting-form-syntax nil)

[Assistant]
(defmacro ENABLE-QUASI-QUOTED-STRING-TO-BINARY-EMITTING-FORM-SYNTAX ...)

;; macroexpand:
(eval-when (:compile-toplevel :execute)
  (setf *readtable* (copy-readtable *readtable*))
  (set-quasi-quoted-string-to-binary-emitting-form-syntax-in-readtable nil
                                                                       :with-inline-emitting
                                                                       nil
                                                                       :declarations
                                                                       'nil
                                                                       :start-character
                                                                       nil
                                                                       :end-character
                                                                       nil
                                                                       :unquote-character
                                                                       #\COMMA
                                                                       :splice-character
                                                                       #\COMMERCIAL_AT
                                                                       :destructive-splice-character
                                                                       #\FULL_STOP
                                                                       :dispatched-quasi-quote-name
                                                                       "str"
                                                                       :encoding
                                                                       *default-character-encoding*)
  (values))


[User]
Create a Common Lisp macro for the following transformation. Before code:
(defun/1 fgetc (fd) (handler-case (char-code (read-char (fd-stream fd))) (end-of-file () (setf (feof fd) 1) EOF) (error () (setf (ferror fd) EIO) EOF)))

What needs to change: Macro call that should be transformed by defun/1

(defun/1 fgetc (fd) (handler-case (char-code (read-char (fd-stream fd))) (end-of-file () (setf (feof fd) 1) EOF) (error () (setf (ferror fd) EIO) EOF)))

[Assistant]
(defmacro defun/1 (name arglist &body body)
  "Lisp-1 defun; makes function pointers work."
  `(progn
     (defun ,name ,arglist
       (declare (optimize (speed 0) (debug 3)
                          ;; FIXME: Why do minor warnings result in load errors?
                          #+sbcl (sb-ext:inhibit-warnings 3)))

       ,@body)
     (defparameter ,name (vacietis.c:mkptr& (symbol-function ',name)))))

;; macroexpand:
(progn (defun fgetc (fd) (declare (optimize (speed 0) (debug 3) (sb-ext:inhibit-warnings 3))) (handler-case (char-code (read-char (fd-stream fd))) (end-of-file nil (setf (feof fd) 1) eof) (error nil (setf (ferror fd) eio) eof))) (defparameter fgetc (vacietis.c:mkptr& (symbol-function (quote fgetc)))))


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

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

(max-of 'some-name)

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

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


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

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

(rte-ecase nil)

[Assistant]
(defmacro RTE-ECASE ...)

;; macroexpand:
(let ((#:rte171 nil))
  (rte-ecase #:rte171
    ((:* t) (error "The sequence ~A fell through the RTE-ECASE" #:rte171))))


[User]
Generate a defmacro form that transforms code like this:
(class/std new-stub var1 var2 var3 var4 :with :std :unbound)

Pattern to recognize: Macro call that should be transformed by class/std

(class/std new-stub var1 var2 var3 var4 :with :std :unbound)

[Assistant]
(defmacro class/std (name &body defaulted-slots)
  "The most concise shortcut macro to DEFCLASS.

  (class/std example slot1 slot2 slot3)

  expands to:

  (DEFCLASS/STD EXAMPLE ()
    ((SLOT1 SLOT2 SLOT3)))

  which expands to:

  (DEFCLASS EXAMPLE ()
    ((SLOT1 :ACCESSOR SLOT1 :INITARG :SLOT1 :INITFORM NIL)
    (SLOT2 :ACCESSOR SLOT2 :INITARG :SLOT2 :INITFORM NIL)
    (SLOT3 :ACCESSOR SLOT3 :INITARG :SLOT3 :INITFORM NIL)))
"
  `(defclass/std ,name ()
     ((,@defaulted-slots))))

;; macroexpand:
(defclass/std new-stub nil ((var1 var2 var3 var4 :with :std :unbound)))


[User]
Write a Common Lisp macro to handle this code pattern:
(deferror "40P01" deadlock-detected transaction-rollback)

Problem: Macro call that should be transformed by deferror

(deferror "40P01" deadlock-detected transaction-rollback)

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

;; macroexpand:
(progn (define-condition deadlock-detected (transaction-rollback) nil) (setf (gethash "40P01" *error-table*) (quote deadlock-detected)))


[User]
Generate a defmacro form that transforms code like this:
(signal-syntax-error* (1- (lexer-pos lexer)) "Character '~A' may not follow '(?<' (because ~a = NIL)" next-char '*allow-named-registers*)

Pattern to recognize: Macro call that should be transformed by signal-syntax-error*

(signal-syntax-error* (1- (lexer-pos lexer)) "Character '~A' may not follow '(?<' (because ~a = NIL)" next-char '*allow-named-registers*)

[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 (1- (lexer-pos lexer)) :format-control "Character '~A' may not follow '(?<' (because ~a = NIL)" :format-arguments (list next-char (quote *allow-named-registers*)))


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

Problem: Macro call that should be transformed by FN

(fn 'some-name)

[Assistant]
(defmacro FN ...)

;; macroexpand:
(lambda () 'some-name)


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

Write a macro that addresses: Macro call that should be transformed by WITH-SYMBOL-ACCESS

(with-symbol-access
  nil
  nil)

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

;; macroexpand:
(let ((*symbol-access* t))
  nil
  nil)


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

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

(def$flavor nil :key nil)

[Assistant]
(defmacro DEF$FLAVOR ...)

;; macroexpand:
(progn
 (eval-when (:compile-toplevel)
   (defvar nil)
   (setq nil
           (funcall (mcs-slot-value flavor-class (index-of-basicnew-fn))
                    flavor-class :name 'nil :supers
                    (if 'nil
                        (list)
                        (list standard-object))
                    :own-slots ':key :req-inst-vars 'nil)))
 (eval-when (:load-toplevel)
   (defvar nil)
   (setq nil
           (send-fast
            (funcall (mcs-slot-value flavor-class (index-of-basicnew-fn))
                     flavor-class :name 'nil :supers
                     (if 'nil
                         (list)
                         (list standard-object))
                     :own-slots ':key :req-inst-vars 'nil)
            :init)))
 (eval-when (:execute)
   (defvar nil)
   (let ((new-class
          (funcall (mcs-slot-value flavor-class (index-of-basicnew-fn))
                   flavor-class :name 'nil :supers
                   (if 'nil
                       (list)
                       (list standard-object))
                   :own-slots ':key :req-inst-vars 'nil)))
     (if (flavorp 'nil)
         (redefine-class nil new-class)
         (setq nil (send-fast new-class :init))))))


[User]
Create a Common Lisp macro for the following transformation. Before code:
(with-wrap-attempt ("accessors for structure ~S" foreign-record) foreign-record (let ((*package* (find-package package)) (foreign-record (etypecase foreign-record (foreign-record foreign-record) ((or symbol cons) (require-type-no-context foreign-record))))) (unless (and (typep foreign-record 'foreign-alias) (struct-or-union-p (foreign-type-name foreign-record))) (let* ((*accessor-forms*) (*accessor-seen-types*) (*accessor-params* (list (foreign-type-name foreign-record))) (*accessor-record-name* (foreign-type-name foreign-record)) (actual-foreign-record (basic-foreign-type foreign-record))) (when (typep actual-foreign-record 'foreign-record) (%make-accessors actual-foreign-record :prefix *accessor-record-name*) `(progn ,@(nreverse *accessor-forms*)))))))

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

(with-wrap-attempt ("accessors for structure ~S" foreign-record) foreign-record (let ((*package* (find-package package)) (foreign-record (etypecase foreign-record (foreign-record foreign-record) ((or symbol cons) (require-type-no-context foreign-record))))) (unless (and (typep foreign-record 'foreign-alias) (struct-or-union-p (foreign-type-name foreign-record))) (let* ((*accessor-forms*) (*accessor-seen-types*) (*accessor-params* (list (foreign-type-name foreign-record))) (*accessor-record-name* (foreign-type-name foreign-record)) (actual-foreign-record (basic-foreign-type foreign-record))) (when (typep actual-foreign-record 'foreign-record) (%make-accessors actual-foreign-record :prefix *accessor-record-name*) `(progn ,@(nreverse *accessor-forms*)))))))

[Assistant]
(defmacro with-wrap-attempt ((&optional format-control &rest format-args) wrappable-name &body body)
  `(call-with-wrap-attempt ,wrappable-name (lambda () ,@body) ,format-control (list ,@format-args)))

;; macroexpand:
(call-with-wrap-attempt foreign-record (lambda nil (let ((*package* (find-package package)) (foreign-record (etypecase foreign-record (foreign-record foreign-record) ((or symbol cons) (require-type-no-context foreign-record))))) (unless (and (typep foreign-record (quote foreign-alias)) (struct-or-union-p (foreign-type-name foreign-record))) (let* ((*accessor-forms*) (*accessor-seen-types*) (*accessor-params* (list (foreign-type-name foreign-record))) (*accessor-record-name* (foreign-type-name foreign-record)) (actual-foreign-record (basic-foreign-type foreign-record))) (when (typep actual-foreign-record (quote foreign-record)) (%make-accessors actual-foreign-record :prefix *accessor-record-name*) (sb-int:quasiquote (progn #S(sb-impl::comma :expr (nreverse *accessor-forms*) :kind 2)))))))) "accessors for structure ~S" (list foreign-record))


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

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

(define 'some-name)

[Assistant]
(defmacro DEFINE ...)

;; macroexpand:
(eval-when (:load-toplevel :execute)
  (check-if-bound ''some-name)
  (setf (get ''some-name 'read-macro)
          (lambda (#:stream149) (let ((*standard-input* #:stream149)))))
  ''some-name)


[User]
Write a Common Lisp macro to handle this code pattern:
(mvlet* ((fn (caar bindings)) (body decls (parse-body body)) (local others (partition-declarations `((function ,fn)) decls env))) `(fbind (,(first bindings)) ,@local (fbind* ,(rest bindings) ,@others ,@body)))

Problem: Macro call that should be transformed by mvlet*

(mvlet* ((fn (caar bindings)) (body decls (parse-body body)) (local others (partition-declarations `((function ,fn)) decls env))) `(fbind (,(first bindings)) ,@local (fbind* ,(rest bindings) ,@others ,@body)))

[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:
(let* ((fn (caar bindings))) (mvlet* ((body decls (parse-body body)) (local others (partition-declarations (sb-int:quasiquote ((function #S(sb-impl::comma :expr fn :kind 0)))) decls env))) (sb-int:quasiquote (fbind (#S(sb-impl::comma :expr (first bindings) :kind 0)) #S(sb-impl::comma :expr local :kind 2) (fbind* #S(sb-impl::comma :expr (rest bindings) :kind 0) #S(sb-impl::comma :expr others :kind 2) #S(sb-impl::comma :expr body :kind 2))))))


[User]
Generate a defmacro form that transforms code like this:
(with-disable-handler-restart ((first handler-entry)) (with-hook-restart (list (apply (first handler-entry) args))))

Pattern to recognize: Macro call that should be transformed by with-disable-handler-restart

(with-disable-handler-restart ((first handler-entry)) (with-hook-restart (list (apply (first handler-entry) args))))

[Assistant]
(defmacro with-disable-handler-restart ((handler) &body body)
  "This is intended to wrap all handler executions."
  `(restart-case
       (progn ,@body)
     (disable-handler ()
       :report
       (lambda (stream)
         (format stream "Disable handler ~a which causes the error." ,handler))
       (disable-hook *hook* ,handler))))

;; macroexpand:
(restart-case (progn (with-hook-restart (list (apply (first handler-entry) args)))) (disable-handler nil :report (lambda (stream) (format stream "Disable handler ~a which causes the error." (first handler-entry))) (disable-hook *hook* (first handler-entry))))


[User]
Write a Common Lisp macro to handle this code pattern:
(with-html-string (:body (:h* "This is a top level heading") (:p "...") (let ((*html-path* (append *html-path* '(:section)))) (:h* "This is a second-level tricked by *HTML-PATH*") (:p "..."))))

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

(with-html-string (:body (:h* "This is a top level heading") (:p "...") (let ((*html-path* (append *html-path* '(:section)))) (:h* "This is a second-level tricked by *HTML-PATH*") (:p "..."))))

[Assistant]
(defmacro with-html (&body body &environment env)
  "Interpret BODY as HTML. Consult README.txt for the syntax."
  `(let ((*html* (ensure-html-stream *html*)))
     ,(if (and (null (cdr body)) (atom (car body)))
          (car body)
          `(progn ,@(parse-html body env)))))

;; macroexpand:
(with-output-to-string (*html*) (with-html (:body (:h* "This is a top level heading") (:p "...") (let ((*html-path* (append *html-path* (quote (:section))))) (:h* "This is a second-level tricked by *HTML-PATH*") (:p "...")))))


[User]
Create a Common Lisp macro for the following transformation. Before code:
(gen-lambda-with-sticky-stop () (let ((res (funcall source-func))) (if (funcall predicate res) res (sticky-stop))))

What needs to change: Macro call that should be transformed by gen-lambda-with-sticky-stop

(gen-lambda-with-sticky-stop () (let ((res (funcall source-func))) (if (funcall predicate res) res (sticky-stop))))

[Assistant]
(defmacro gen-lambda-with-sticky-stop (&rest rest)
  `(make-instance
    'basic-generator
    :function (sticky-stop-lambda ,@rest)))

;; macroexpand:
(make-instance (quote basic-generator) :function (sticky-stop-lambda nil (let ((res (funcall source-func))) (if (funcall predicate res) res (sticky-stop)))))


[User]
You are a Common Lisp macro expert. Given this code pattern:
(macroexpand-convention (form) (if (consp form) (expand-export-constructors-using-head (first form) form) form))

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

(macroexpand-convention (form) (if (consp form) (expand-export-constructors-using-head (first form) form) form))

[Assistant]
(defmacro macroexpand-convention ((original-form) &body body)
  "Executes BODY as like `progn' and return the result as the first
value.  As the second value, returns a boolean whether the result is
not same with ORIGINAL-FORM or not.
This macro is designed to follow the `macroexpand' convention."
  `(multiple-value-bind (result expanded-p)
       (progn ,@body)
     (values result
             (or expanded-p
                 (not (eq result ,original-form))))))

;; macroexpand:
(multiple-value-bind (result expanded-p) (progn (if (consp form) (expand-export-constructors-using-head (first form) form) form)) (values result (or expanded-p (not (eq result form)))))


[User]
Write a Common Lisp macro to handle this code pattern:
(define-bug loop-flow-analysis-failure (:error-type varjo-critical-error) () "Varjo's flow analyzer has been unable to resolve the variable flow in this loop within a reasonable ammount of time. This counts as a compiler bug so please report it on github")

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

(define-bug loop-flow-analysis-failure (:error-type varjo-critical-error) () "Varjo's flow analyzer has been unable to resolve the variable flow in this loop within a reasonable ammount of time. This counts as a compiler bug so please report it on github")

[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 loop-flow-analysis-failure (:error-type varjo-critical-error :prefix "Varjo Bug") nil "Varjo's flow analyzer has been unable to resolve the variable flow in this loop within a reasonable ammount of time. This counts as a compiler bug so please report it on github")


[User]
Create a Common Lisp macro for the following transformation. Before code:
(*> +skip-space+ +slash+)

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

(*> +skip-space+ +slash+)

[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 (#:*>-offset259) (multiple-value-bind (#:*>-res260 #:*>-next261) (funcall +skip-space+ #:*>-offset259) (if (ok? #:*>-res260) (funcall +slash+ #:*>-next261) (fail #:*>-next261))))


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

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

(none-of nil)

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

;; macroexpand:
(lc (nil) never)


[User]
You are a Common Lisp macro expert. Given this code pattern:
(with-csv-input-stream (in-stream stream-or-string) (read-with-dispatch-table csv-reader in-stream) (coerce (rows csv-reader) 'list))

Write a macro that addresses: Macro call that should be transformed by with-csv-input-stream

(with-csv-input-stream (in-stream stream-or-string) (read-with-dispatch-table csv-reader in-stream) (coerce (rows csv-reader) 'list))

[Assistant]
(defmacro with-csv-input-stream ((name inp) &body body)
  (alexandria:with-unique-names (opened?)
    `(multiple-value-bind (,name ,opened?) (%in-stream ,inp)
      (flet ((body () ,@body))
        (unwind-protect (body)
          (when (and ,name ,opened?)
            (close ,name)))))))

;; macroexpand:
(multiple-value-bind (in-stream #:opened?199) (%in-stream stream-or-string) (flet ((body nil (read-with-dispatch-table csv-reader in-stream) (coerce (rows csv-reader) (quote list)))) (unwind-protect (body) (when (and in-stream #:opened?199) (close in-stream)))))


[User]
Define a macro that eliminates this repetitive pattern:
(with-input-from-file (stream pathname :element-type '(unsigned-byte 8)) (read-stream-content-into-byte-vector stream :initial-size (file-length stream)))

Issue: Macro call that should be transformed by with-input-from-file

(with-input-from-file (stream pathname :element-type '(unsigned-byte 8)) (read-stream-content-into-byte-vector stream :initial-size (file-length stream)))

[Assistant]
(defmacro with-input-from-file ((stream-name file-name &rest args
                                             &key (direction nil direction-p)
                                             &allow-other-keys)
                                &body body)
  "Evaluate BODY with STREAM-NAME to an input stream on the file
FILE-NAME. ARGS is sent as is to the call to OPEN except EXTERNAL-FORMAT,
which is only sent to WITH-OPEN-FILE when it's not NIL."
  (declare (ignore direction))
  (when direction-p
    (error "Can't specify :DIRECTION for WITH-INPUT-FROM-FILE."))
  `(with-open-file* (,stream-name ,file-name :direction :input ,@args)
     ,@body))

;; macroexpand:
(with-open-file* (stream pathname :direction :input :element-type (quote (unsigned-byte 8))) (read-stream-content-into-byte-vector stream :initial-size (file-length stream)))


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

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

(-> nil (value) (1+ value))

[Assistant]
(defmacro -> (invariant &body args)
  "See flow:atomically"
  `(atomically ,invariant ,@args))

;; macroexpand:
(atomically nil (value) (1+ value))


[User]
Create a Common Lisp macro for the following transformation. Before code:
(deferror "08000" connection-exception)

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

(deferror "08000" connection-exception)

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

;; macroexpand:
(progn (define-condition connection-exception (database-error) nil) (setf (gethash "08000" *error-table*) (quote connection-exception)))


[User]
Generate a defmacro form that transforms code like this:
(do-readtable ((char reader-fn non-terminating-p disp? table) from) (check-reader-macro-conflict from to char) (cond ((not disp?) (set-macro-character char reader-fn non-terminating-p to)) (t (ensure-dispatch-macro-character char non-terminating-p to) (loop for (subchar . subfn) in table do (check-reader-macro-conflict from to char subchar) (set-dispatch-macro-character char subchar subfn to)))))

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

(do-readtable ((char reader-fn non-terminating-p disp? table) from) (check-reader-macro-conflict from to char) (cond ((not disp?) (set-macro-character char reader-fn non-terminating-p to)) (t (ensure-dispatch-macro-character char non-terminating-p to) (loop for (subchar . subfn) in table do (check-reader-macro-conflict from to char subchar) (set-dispatch-macro-character char subchar subfn to)))))

[Assistant]
(defmacro do-readtable ((entry-designator readtable &optional result)
                        &body body)
  "Iterate through a readtable's macro characters, and dispatch macro characters."
  (destructuring-bind (char &optional reader-fn non-terminating-p disp? table)
      (if (symbolp entry-designator)
          (list entry-designator)
          entry-designator)
    (let ((iter (gensym "ITER+"))
          (more? (gensym "MORE?+"))
          (rt (gensym "READTABLE+")))
      `(let ((,rt ,readtable))
         (with-readtable-iterator (,iter ,rt)
           (loop
             (multiple-value-bind (,more?
                                   ,char
                                   ,@(when reader-fn (list reader-fn))
                                   ,@(when disp? (list disp?))
                                   ,@(when table (list table)))
                 (,iter)
               (unless ,more? (return ,result))
               (let ,(when non-terminating-p
                       ;; FIXME: N-T-P should be incorporated in iterators.
                       `((,non-terminating-p
                          (nth-value 1 (get-macro-character ,char ,rt)))))
                 ,@body))))))))

;; macroexpand:
(let ((#:readtable+149 from)) (with-readtable-iterator (#:iter+147 #:readtable+149) (loop (multiple-value-bind (#:more?+148 char reader-fn disp? table) (#:iter+147) (unless #:more?+148 (return nil)) (let ((non-terminating-p (nth-value 1 (get-macro-character char #:readtable+149)))) (check-reader-macro-conflict from to char) (cond ((not disp?) (set-macro-character char reader-fn non-terminating-p to)) (t (ensure-dispatch-macro-character char non-terminating-p to) (loop for (subchar . subfn) in table do (check-reader-macro-conflict from to char subchar) (set-dispatch-macro-character char subchar subfn to)))))))))


[User]
Write a Common Lisp macro to handle this code pattern:
(-> :g (r) (put r))

Problem: Macro call that should be transformed by ->

(-> :g (r) (put r))

[Assistant]
(defmacro -> (invariant &body args)
  "See flow:atomically"
  `(atomically ,invariant ,@args))

;; macroexpand:
(atomically :g (r) (put r))


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

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

(-<>> nil nil)

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

;; macroexpand:
(nil)


[User]
You are a Common Lisp macro expert. Given this code pattern:
(lambda-ignoring-_ (kwd id _l decl _r) (make-struct-or-union-spec :type kwd :id id :struct-decl-list decl))

Write a macro that addresses: Macro call that should be transformed by lambda-ignoring-_

(lambda-ignoring-_ (kwd id _l decl _r) (make-struct-or-union-spec :type kwd :id id :struct-decl-list decl))

[Assistant]
(defmacro lambda-ignoring-_ (lambda-list &body body)
  "Works like `cl:lambda' macro except automatically `declare's
 `ignore' for parameters beginning with '_' character."
  (let ((ignored-parameters
          (collect-_-symbol-in-lambda-list lambda-list)))
    (unless ignored-parameters
      (warn "No ignored parameters in: ~A" lambda-list))
    (multiple-value-bind (body decls doc)
        (parse-body body :documentation t)
      `(lambda ,lambda-list
         ,@ (if doc `(,doc))
         (declare (ignore ,@ignored-parameters))
         ,@decls
         ,@body))))

;; macroexpand:
(lambda (kwd id _l decl _r) (declare (ignore _l _r)) (make-struct-or-union-spec :type kwd :id id :struct-decl-list decl))


[User]
Create a Common Lisp macro for the following transformation. Before code:
(define-test override (true T) (skip "Not ready yet" (false T) (is = 5 6)) (with-forced-status (:failed) (false NIL)))

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

(define-test override (true T) (skip "Not ready yet" (false T) (is = 5 6)) (with-forced-status (:failed) (false NIL)))

[Assistant]
(defmacro define-test (name &body arguments-and-body)
  (destructuring-bind (nparent name) (if (listp name) name (list NIL name))
    (form-fiddle:with-body-options (body options parent home (test-class 'test) (compile-at :compile-time) defun) arguments-and-body
      (let ((body (remove 'define-test body :key (lambda (a) (when (listp a) (car a))) :test #'eql))
            (defs (remove 'define-test body :key (lambda (a) (when (listp a) (car a))) :test-not #'eql))
            (home-form (or home `(find-package ,(package-name *package*)))))
        (when (and parent nparent)
          (error "Cannot specify parent through name and through a keyword argument at the same time!"))
        `(let ((*package* (find-package ,(package-name *package*)))) ; Make sure package stays consistent throughout initialisation.
           (setf (find-test ',name ,home-form)
                 (ensure-test ',test-class
                              :name ',name
                              :home ,home-form
                              :tests (list ,@(loop for form in body
                                                   collect (ecase compile-at
                                                             (:compile-time `(lambda () ,form))
                                                             (:execute `(lambda () (call-compile ',form))))))
                              :parent ',(or parent nparent)
                              ,@(loop for option in options
                                      collect `',option)))
           ,@(loop for (def subname . body) in defs
                   collect `(,def (,name ,subname)
                              :home ,home
                              ,@body))
           ,@(when defun
               `((defun ,(if (stringp name) (read-symbol name) name) (&rest test-args)
                   (apply #'test (find-test ',name ,home-form) test-args))))
           ',name)))))

;; macroexpand:
(let ((*package* (find-package #A((9) base-char . "PARACHUTE")))) (setf (find-test (quote override) (find-package #A((9) base-char . "PARACHUTE"))) (ensure-test (quote test) :name (quote override) :home (find-package #A((9) base-char . "PARACHUTE")) :tests (list (lambda nil (true t)) (lambda nil (skip "Not ready yet" (false t) (is = 5 6))) (lambda nil (with-forced-status (:failed) (false nil)))) :parent (quote nil))) (quote override))


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

What needs to change: Macro call that should be transformed by DEFINE-DECLARATION

(define-declaration nil
    :key
  nil)

[Assistant]
(defmacro DEFINE-DECLARATION ...)

;; macroexpand:
(eval-when (:compile-toplevel :load-toplevel :execute)
  (proclaim '(declaration nil))
  (flet ((sb-cltl2::func :key
           nil))
    (setf (sb-int:info :declaration :known 'nil)
            (lambda
                (sb-kernel:lexenv sb-cltl2::spec sb-cltl2::pd-vars
                 sb-cltl2::pd-fvars)
              (multiple-value-bind (sb-cltl2::kind sb-cltl2::data)
                  (sb-cltl2::func sb-cltl2::spec sb-kernel:lexenv)
                (sb-cltl2::update-lexenv-user-data sb-kernel:lexenv
                                                   sb-cltl2::kind
                                                   sb-cltl2::data
                                                   sb-cltl2::pd-vars
                                                   sb-cltl2::pd-fvars))))))


[User]
Generate a defmacro form that transforms code like this:
(make-stream-method pp-xml-attr (s (kw string) &optional colon-p at-p) (declare (ignore colon-p at-p)) (format s "~A" kw))

Pattern to recognize: Macro call that should be transformed by make-stream-method

(make-stream-method pp-xml-attr (s (kw string) &optional colon-p at-p) (declare (ignore colon-p at-p)) (format s "~A" kw))

[Assistant]
(defmacro make-stream-method (name (s &rest args) &body body)
  `(progn
     (defmethod ,name ((,s stream) ,@args)
       ,@body)
     #+abcl
     (defmethod ,name ((,s xp::xp-structure) ,@args)
       ,@body)))

;; macroexpand:
(progn (defmethod pp-xml-attr ((s stream) (kw string) &optional colon-p at-p) (declare (ignore colon-p at-p)) (format s "~A" kw)))


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

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

(->> nil nil)

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

;; macroexpand:
(nil)


[User]
Create a Common Lisp macro for the following transformation. Before code:
(action (:after node-lisp node new-subs) (multiple-value-bind (let-bindings lisp-var-bindings) (loop :for (lisp-var . coalton-var) :in (node-lisp-vars node) :for new-var := (gensym (symbol-name coalton-var)) :for res := (or (find coalton-var subs :key #'ast-substitution-from) (find coalton-var new-subs :key #'ast-substitution-from)) :if (and res (node-variable-p (ast-substitution-to res))) :collect (cons lisp-var (node-variable-value (ast-substitution-to res))) :into lisp-var-bindings :else :if res :collect (cons lisp-var new-var) :into lisp-var-bindings :and :collect (cons new-var (ast-substitution-to res)) :into let-bindings :else :collect (cons lisp-var coalton-var) :into lisp-var-bindings :finally (return (values let-bindings lisp-var-bindings))) (let ((new-lisp-node (make-node-lisp :type (node-type node) :vars lisp-var-bindings :form (node-lisp-form node)))) (if (endp let-bindings) new-lisp-node (make-node-let :type (node-type node) :bindings let-bindings :subexpr new-lisp-node)))))

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

(action (:after node-lisp node new-subs) (multiple-value-bind (let-bindings lisp-var-bindings) (loop :for (lisp-var . coalton-var) :in (node-lisp-vars node) :for new-var := (gensym (symbol-name coalton-var)) :for res := (or (find coalton-var subs :key #'ast-substitution-from) (find coalton-var new-subs :key #'ast-substitution-from)) :if (and res (node-variable-p (ast-substitution-to res))) :collect (cons lisp-var (node-variable-value (ast-substitution-to res))) :into lisp-var-bindings :else :if res :collect (cons lisp-var new-var) :into lisp-var-bindings :and :collect (cons new-var (ast-substitution-to res)) :into let-bindings :else :collect (cons lisp-var coalton-var) :into lisp-var-bindings :finally (return (values let-bindings lisp-var-bindings))) (let ((new-lisp-node (make-node-lisp :type (node-type node) :vars lisp-var-bindings :form (node-lisp-form node)))) (if (endp let-bindings) new-lisp-node (make-node-let :type (node-type node) :bindings let-bindings :subexpr new-lisp-node)))))

[Assistant]
(defmacro action ((when type &rest args) &body body)
  "Construct an action block, turning `body` into a lambda function
accepting `args` if `args` are provided. If there are no `args`, then
`body` is assumed to be a function object and is used directly with
`when` and `type` to create an `action` instance. Otherwise, the first
argument in `args` is declared to be a node of type `type`, and the
`args` and `body` are used to generate a lambda function."
  (check-type when keyword)
  (check-type type symbol)
  (assert (subtypep type 'node))
  (assert (or (not (endp args)) (= 1 (length body))))
  (if (endp args)
      `(make-action ',when ',type ,@body)
      `(make-action ',when ',type
                    (lambda (,@args)
                      (declare (type ,type ,(first args)))
                      ,@body))))

;; macroexpand:
(make-action (quote :after) (quote node-lisp) (lambda (node new-subs) (declare (type node-lisp node)) (multiple-value-bind (let-bindings lisp-var-bindings) (loop :for (lisp-var . coalton-var) :in (node-lisp-vars node) :for new-var := (gensym (symbol-name coalton-var)) :for res := (or (find coalton-var subs :key (function ast-substitution-from)) (find coalton-var new-subs :key (function ast-substitution-from))) :if (and res (node-variable-p (ast-substitution-to res))) :collect (cons lisp-var (node-variable-value (ast-substitution-to res))) :into lisp-var-bindings :else :if res :collect (cons lisp-var new-var) :into lisp-var-bindings :and :collect (cons new-var (ast-substitution-to res)) :into let-bindings :else :collect (cons lisp-var coalton-var) :into lisp-var-bindings :finally (return (values let-bindings lisp-var-bindings))) (let ((new-lisp-node (make-node-lisp :type (node-type node) :vars lisp-var-bindings :form (node-lisp-form node)))) (if (endp let-bindings) new-lisp-node (make-node-let :type (node-type node) :bindings let-bindings :subexpr new-lisp-node))))))


[User]
You are a Common Lisp macro expert. Given this code pattern:
(with-html-string (:a :href "#" :data-instant t))

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

(with-html-string (:a :href "#" :data-instant t))

[Assistant]
(defmacro with-html (&body body &environment env)
  "Interpret BODY as HTML. Consult README.txt for the syntax."
  `(let ((*html* (ensure-html-stream *html*)))
     ,(if (and (null (cdr body)) (atom (car body)))
          (car body)
          `(progn ,@(parse-html body env)))))

;; macroexpand:
(with-output-to-string (*html*) (with-html (:a :href "#" :data-instant t)))


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

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

(collect 'some-name)

[Assistant]
(defmacro COLLECT ...)

;; macroexpand:
(common-lisp:let* ((#:generator-608 (generator 'some-name))
                   #:items-603
                   (#:lastcons-604 (list nil))
                   (#:lst-605 #:lastcons-604))
  (declare (type generator #:generator-608)
           (type cons #:lastcons-604)
           (type list #:lst-605))
  (tagbody
   #:ll-609
    (setq #:items-603 (next-in #:generator-608 (go end)))
    (setq #:lastcons-604 (setf (cdr #:lastcons-604) (cons #:items-603 nil)))
    (go #:ll-609)
   end)
  (cdr #:lst-605))


[User]
You are a Common Lisp macro expert. Given this code pattern:
(define-simple-clause never (form &aux (result T)) (values `(when ,form (setf ,result NIL) (end-for)) result))

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

(define-simple-clause never (form &aux (result T)) (values `(when ,form (setf ,result NIL) (end-for)) result))

[Assistant]
(defmacro define-simple-clause (name args &body body)
  (multiple-value-bind (args outer-let inner-let result-let) (compute-binding-parts NIL NIL args)
    `(define-direct-clause ,name ,(rest args)
       (let ,outer-let
         (values* `(let* ,(list
                           ,@result-let)
                     (declare (ignorable ,,@(mapcar #'delist outer-let))))
                  (let ,inner-let
                    (declare (ignorable ,@(mapcar #'delist inner-let)))
                    ,@body))))))

;; macroexpand:
(define-direct-clause never (form) (let ((#:result187 (gensym #A((6) base-char . "RESULT")))) (values* (sb-int:quasiquote (let* #S(sb-impl::comma :expr (list (list #:result187 (quote t))) :kind 0) (declare (ignorable #S(sb-impl::comma :expr #:result187 :kind 0))))) (let ((result #:result187)) (declare (ignorable result)) (values (sb-int:quasiquote (when #S(sb-impl::comma :expr form :kind 0) (setf #S(sb-impl::comma :expr result :kind 0) nil) (end-for))) result)))))


[User]
Define a macro that eliminates this repetitive pattern:
(with-c-compilation-unit () (parse-with-lexer lexer *c-parser*))

Issue: Macro call that should be transformed by with-c-compilation-unit

(with-c-compilation-unit () (parse-with-lexer lexer *c-parser*))

[Assistant]
(defmacro with-c-compilation-unit ((&key return-last-statement)
				   &body body)
  "Establishes variable bindings for a new compilation."
  `(let ((*struct-specs* (copy-hash-table *struct-specs*))
         (*typedef-names* (copy-hash-table *typedef-names*))
	 (*return-last-statement* ,return-last-statement)
         (*function-pointer-ids* nil))
     ,@body))

;; macroexpand:
(let ((*struct-specs* (copy-hash-table *struct-specs*)) (*typedef-names* (copy-hash-table *typedef-names*)) (*return-last-statement* nil) (*function-pointer-ids* nil)) (parse-with-lexer lexer *c-parser*))


[User]
Generate a defmacro form that transforms code like this:
($send nil nil)

Pattern to recognize: Macro call that should be transformed by $SEND

($send nil nil)

[Assistant]
(defmacro $SEND ...)

;; macroexpand:
(send-message nil nil)


[User]
You are a Common Lisp macro expert. Given this code pattern:
(with-component-testers (a b #'pathname-directory) (and (null a) (null b)) (and (= (length a) (length b)) (every (lambda (a b) (or (and (stringp a) (stringp b) (string= a b)) (and (null a) (null b)) (and (keywordp a) (keywordp b) (eql a b)))) a b)))

Write a macro that addresses: Macro call that should be transformed by with-component-testers

(with-component-testers (a b #'pathname-directory) (and (null a) (null b)) (and (= (length a) (length b)) (every (lambda (a b) (or (and (stringp a) (stringp b) (string= a b)) (and (null a) (null b)) (and (keywordp a) (keywordp b) (eql a 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* ((#:g145 (function pathname-directory)) (a (funcall #:g145 a)) (b (funcall #:g145 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)) (and (= (length a) (length b)) (every (lambda (a b) (or (and (stringp a) (stringp b) (string= a b)) (and (null a) (null b)) (and (keywordp a) (keywordp b) (eql a b)))) a b))) (values t a b) nil)))


[User]
Create a Common Lisp macro for the following transformation. Before code:
(c-assert (c-model c) () "c-awaken sees uninstalled cell" c)

What needs to change: Macro call that should be transformed by c-assert

(c-assert (c-model c) () "c-awaken sees uninstalled cell" c)

[Assistant]
(defmacro c-assert (assertion &optional places fmt$ &rest fmt-args)
  (declare (ignorable assertion places fmt$ fmt-args))
   #+(or)`(progn)
  `(unless *stop*
     (unless ,assertion
       ,(if fmt$
            `(c-break ,fmt$ ,@fmt-args)
          `(c-break "failed assertion: ~a" ',assertion)))))

;; macroexpand:
(unless *stop* (unless (c-model c) (c-break "c-awaken sees uninstalled cell" c)))


[User]
Define a macro that eliminates this repetitive pattern:
(defsynonym generate :generate)

Issue: Macro call that should be transformed by defsynonym

(defsynonym generate :generate)

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

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


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

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

(cond->> nil :key nil)

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

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


[User]
Write a Common Lisp macro to handle this code pattern:
(dflet ((foo () 23)) (is (eql 23 (foo))))

Problem: Macro call that should be transformed by dflet

(dflet ((foo () 23)) (is (eql 23 (foo))))

[Assistant]
(defmacro dflet ((&rest definitions) &body body)
  "Like FLET, but dynamically sets the FDEFINITIONS during the duration of
the BODY."
  `(progf
       ',(mapcar #'car definitions)
       (list
        ,.(mapcar (lambda (definition)
                    `(lambda ,(cadr definition)
                       ,@(cddr definition)))
                  definitions))
     ,@body))

;; macroexpand:
(progf (quote (foo)) (list (lambda nil 23)) (is (eql 23 (foo))))


[User]
Define a macro that eliminates this repetitive pattern:
(return)

Issue: Macro call that should be transformed by RETURN

(return)

[Assistant]
(defmacro RETURN ...)

;; macroexpand:
(return-from nil nil)


[User]
Define a macro that eliminates this repetitive pattern:
(some->> nil nil)

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

(some->> nil nil)

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

;; macroexpand:
(let* ((#:|some121| nil) (#:|some121| (when #:|some121| (#:|some121|))))
  #:|some121|)


[User]
Generate a defmacro form that transforms code like this:
(lret* ((offset (- length (length vec))) (element-type (array-element-type vec)) (out (make-array length :element-type element-type))) (replace out vec :start1 offset) (fill out pad :end offset) out)

Pattern to recognize: Macro call that should be transformed by lret*

(lret* ((offset (- length (length vec))) (element-type (array-element-type vec)) (out (make-array length :element-type element-type))) (replace out vec :start1 offset) (fill out pad :end offset) out)

[Assistant]
(defmacro lret* ((&rest bindings) &body body)
  "Cf. `lret'."
  `(lret-aux let* ,bindings
     ,@body))

;; macroexpand:
(lret-aux let* ((offset (- length (length vec))) (element-type (array-element-type vec)) (out (make-array length :element-type element-type))) (replace out vec :start1 offset) (fill out pad :end offset) out)


[User]
Write a Common Lisp macro to handle this code pattern:
(-> :p () 1)

Problem: Macro call that should be transformed by ->

(-> :p () 1)

[Assistant]
(defmacro -> (invariant &body args)
  "See flow:atomically"
  `(atomically ,invariant ,@args))

;; macroexpand:
(atomically :p nil 1)


[User]
Define a macro that eliminates this repetitive pattern:
(match 1 (1 1))

Issue: Macro call that should be transformed by match

(match 1 (1 1))

[Assistant]
(defmacro match (arg &body clauses)
  "Matches ARG with CLAUSES. CLAUSES is a list of the form of (PATTERN
. BODY) where PATTERN is a pattern specifier and BODY is an implicit
progn. If ARG matches some PATTERN, `match` then evaluates
the corresponding BODY and returns the evaluated value.  If no pattern matches,
then returns NIL.

Evaluating a form (FAIL) in the clause body causes the latest pattern
matching to fail. For example,

    (match 1
      (x (if (eql x 1)
             (fail)
             x))
      (_ 'ok))

returns OK, because the form (FAIL) in the first clause is
evaluated.

If BODY starts with the symbols WHEN or UNLESS, then the next form
will be used to introduce (FAIL). That is,

    (match list ((list x) when (oddp x) x))
    (match list ((list x) unless (evenp x) x))

will be translated to

    (match list ((list x) (if (oddp x) x (fail))))
    (match list ((list x) (if (evenp x) (fail) x)))

Examples:

    (match 1 (1 1))
    => 1
    (match 1 (2 2))
    => 2
    (match 1 (x x))
    => 1
    (match (list 1 2 3)
      (list x y z) (+ x y z))
    => 6"
  (compile-match-1 arg clauses nil))

;; macroexpand:
(let ((#:var148 1)) (declare (ignorable #:var148)) (%or (%if (%equals #:var148 1) (%or 1 (fail)) (fail)) nil))


[User]
Define a macro that eliminates this repetitive pattern:
(defhandler eval-when (eval-when situation &rest body) `(list ',eval-when ',situation ,@(e-list body)))

Issue: Macro call that should be transformed by defhandler

(defhandler eval-when (eval-when situation &rest body) `(list ',eval-when ',situation ,@(e-list body)))

[Assistant]
(defmacro defhandler (symbol lambda-list &body body)
  (let ((syms (force-list symbol)))
    (let ((func (intern (format nil "~A~A" 'hander- (first syms)))))
      `(progn
         (defun ,func ,lambda-list
           ,@body)
         (setf
          ,@(loop for sym in syms
               collect `(gethash ',sym *form-handler*)
               collect `',func))))))

;; macroexpand:
(progn (defun hander-eval-when (eval-when situation &rest body) (sb-int:quasiquote (list (quote #S(sb-impl::comma :expr eval-when :kind 0)) (quote #S(sb-impl::comma :expr situation :kind 0)) #S(sb-impl::comma :expr (e-list body) :kind 2)))) (setf (gethash (quote eval-when) *form-handler*) (quote hander-eval-when)))


[User]
Generate a defmacro form that transforms code like this:
(with-component-testers (a b #'pathname-host) (eq a b) (components-are-member '(nil :unspecific)) (components-are-string=) (components-are-every #'string=))

Pattern to recognize: Macro call that should be transformed by with-component-testers

(with-component-testers (a b #'pathname-host) (eq a b) (components-are-member '(nil :unspecific)) (components-are-string=) (components-are-every #'string=))

[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* ((#:g143 (function pathname-host)) (a (funcall #:g143 a)) (b (funcall #:g143 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 (eq a b) (components-are-member (quote (nil :unspecific))) (components-are-string=) (components-are-every (function string=))) (values t a b) nil)))


[User]
Create a Common Lisp macro for the following transformation. Before code:
(define-class-method nil
    (progn))

What needs to change: Macro call that should be transformed by DEFINE-CLASS-METHOD

(define-class-method nil
    (progn))

[Assistant]
(defmacro DEFINE-CLASS-METHOD ...)

;; macroexpand:
(progn
 (define-incongruent-method nil
     (progn))
 (eval-when (:compile-toplevel :load-toplevel :execute)
   (add-class-principal-method 'nil '(progn))))


[User]
Create a Common Lisp macro for the following transformation. Before code:
(defclause counting (var) "Counts the number of iterations, starting from 0." (make-simple-iteration :var var :init 0 :step `(1+ ,var)))

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

(defclause counting (var) "Counts the number of iterations, starting from 0." (make-simple-iteration :var var :init 0 :step `(1+ ,var)))

[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 counting (var) "Counts the number of iterations, starting from 0." (make-simple-iteration :var var :init 0 :step (sb-int:quasiquote (1+ #S(sb-impl::comma :expr var :kind 0))))) (pushnew (quote counting) *clauses*))


[User]
Write a Common Lisp macro to handle this code pattern:
(rem-arg-list-key-value! nil nil)

Problem: Macro call that should be transformed by REM-ARG-LIST-KEY-VALUE!

(rem-arg-list-key-value! nil nil)

[Assistant]
(defmacro rem-arg-list-key-value! (ids place &key (test '#'equalper) (key '#'identity))
  `(progn
    (iter (for id in (ensure-list ,ids))
      (setf ,place (rem-arg-list-key-value id ,place :test ,test :key ,key)))
    ,place))

;; macroexpand:
(progn
 (iter
   (for id in (ensure-list nil))
   (setf nil (rem-arg-list-key-value id nil :test #'equalper :key #'identity)))
 nil)


[User]
Generate a defmacro form that transforms code like this:
(define-filtered-function nil
    nil)

Pattern to recognize: Macro call that should be transformed by DEFINE-FILTERED-FUNCTION

(define-filtered-function nil
    nil)

[Assistant]
(defmacro DEFINE-FILTERED-FUNCTION ...)

;; macroexpand:
(progn
 (defgeneric nil
     nil
   (:generic-function-class filtered-function)
   (:method-class filtered-method)
   (:method-combination filtered))
 (setf (generic-function-filters (fdefinition 'nil)) (list))
 'nil)


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

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

(iterate
  nil)

[Assistant]
(defmacro ITERATE ...)

;; macroexpand:
(iter
  nil)


[User]
Generate a defmacro form that transforms code like this:
(ltbdd-with-new-hash 'some-name)

Pattern to recognize: Macro call that should be transformed by LTBDD-WITH-NEW-HASH

(ltbdd-with-new-hash 'some-name)

[Assistant]
(defmacro LTBDD-WITH-NEW-HASH ...)

;; macroexpand:
(bdd-call-with-new-hash (lambda (quote some-name)) :bdd-node-type
                        '(or lisp-type-bdd-node bdd-leaf))


[User]
You are a Common Lisp macro expert. Given this code pattern:
(with-yield (do-generators ((g (some-numbers)) (:list l data :fill-value 0)) (yield (+ l g))))

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

(with-yield (do-generators ((g (some-numbers)) (:list l data :fill-value 0)) (yield (+ l g))))

[Assistant]
(defmacro with-yield (&body body)
  (let ((point (gensym))
        (current (gensym)))
    `(let (,point ,current)
       (with-call/cc
	 (labels ((yield (&rest values)
		    (setf ,current values)
		    (let/cc k
		      (setf ,point k))))
	   ,@body
	   (setf ,point nil)))
       (gen-lambda ()
	 (cond ((null ,point)
		'generator-stop)
	       (t
		(let ((current ,current))
		  (funcall ,point nil)
		  ;values-handler: see gen-lambda
		  (apply #'values (funcall values-handler current)))))))))

;; macroexpand:
(let (#:g147 #:g148) (with-call/cc (labels ((yield (&rest values) (setf #:g148 values) (let/cc k (setf #:g147 k)))) (do-generators ((g (some-numbers)) (:list l data :fill-value 0)) (yield (+ l g))) (setf #:g147 nil))) (gen-lambda nil (cond ((null #:g147) (quote generator-stop)) (t (let ((current #:g148)) (funcall #:g147 nil) (apply (function values) (funcall values-handler current)))))))


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

What needs to change: Macro call that should be transformed by MATRIX-ECASE

(matrix-ecase nil)

[Assistant]
(defmacro MATRIX-ECASE ...)

;; macroexpand:
nil


[User]
Write a Common Lisp macro to handle this code pattern:
(do+ (for (x &optional (y 'y) &rest z &key k1 (k2 'k2) ((:kk k3) 'k3)) (in '((1 a) (2) (3 c :k1 a :kk b :k2 c)))) (collect (list x y z k1 k2 k3)))

Problem: Macro call that should be transformed by do+

(do+ (for (x &optional (y 'y) &rest z &key k1 (k2 'k2) ((:kk k3) 'k3)) (in '((1 a) (2) (3 c :k1 a :kk b :k2 c)))) (collect (list x y z k1 k2 k3)))

[Assistant]
(defmacro do+ (&body body)
  "High-level, extensible iteration construct. Refer to the manual for syntax and semantics."
  `(do+/internal nil ,@body))

;; macroexpand:
(do+/internal nil (for (x &optional (y (quote y)) &rest z &key k1 (k2 (quote k2)) ((:kk k3) (quote k3))) (in (quote ((1 a) (2) (3 c :k1 a :kk b :k2 c))))) (collect (list x y z k1 k2 k3)))


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

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

(rem-bops 'some-name)

[Assistant]
(defmacro REM-BOPS ...)

;; macroexpand:
(eval-when (:load-toplevel :compile-toplevel :execute)
  (progn (save-binfix) (mapc 'rmbop '('some-name)) (assign-properties)))


[User]
Create a Common Lisp macro for the following transformation. Before code:
(define-bug problem-with-the-compiler () (target) "This shouldnt have been possible so this needs a bug report. Sorry about that~%~s" target)

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

(define-bug problem-with-the-compiler () (target) "This shouldnt have been possible so this needs a bug report. Sorry about that~%~s" target)

[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 problem-with-the-compiler (:error-type varjo-error :prefix "Varjo Bug") (target) "This shouldnt have been possible so this needs a bug report. Sorry about that~%~s" target)


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

Issue: Macro call that should be transformed by UNLESS

(unless nil :key nil)

[Assistant]
(defmacro UNLESS ...)

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


[User]
Write a Common Lisp macro to handle this code pattern:
(quasiquote-unexpand-1 'unquote-nsplicing el)

Problem: Macro call that should be transformed by quasiquote

(quasiquote-unexpand-1 'unquote-nsplicing el)

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

;; macroexpand:
(quasiquote-unexpand-1 (quote unquote-nsplicing) el)


[User]
You are a Common Lisp macro expert. Given this code pattern:
(with-yield-binds (format nil "ON DUPLICATE KEY UPDATE ~{~A = ~A~^, ~}" (mapcar #'yield-arg (on-duplicate-key-update-clause-args clause))))

Write a macro that addresses: Macro call that should be transformed by with-yield-binds

(with-yield-binds (format nil "ON DUPLICATE KEY UPDATE ~{~A = ~A~^, ~}" (mapcar #'yield-arg (on-duplicate-key-update-clause-args clause))))

[Assistant]
(defmacro with-yield-binds (&body body)
  `(let ((*bind-values* nil)
         (*use-global-bind-values* t))
     (values
      (progn ,@body)
      (loop for bind in (reverse *bind-values*)
            append bind))))

;; macroexpand:
(let ((*bind-values* nil) (*use-global-bind-values* t)) (values (progn (format nil "ON DUPLICATE KEY UPDATE ~{~A = ~A~^, ~}" (mapcar (function yield-arg) (on-duplicate-key-update-clause-args clause)))) (loop for bind in (reverse *bind-values*) append bind)))


[User]
Generate a defmacro form that transforms code like this:
(defclass/std unknown () ((slot :a :unknown keywords :without-values)))

Pattern to recognize: Macro call that should be transformed by defclass/std

(defclass/std unknown () ((slot :a :unknown keywords :without-values)))

[Assistant]
(defmacro defclass/std (name direct-superclasses direct-slots &rest options
                        &environment env)
  "Shortcut macro to the DEFCLASS macro.

  (defclass/std example ()
    ((slot1 slot2 slot3)))

  expands to:

  (DEFCLASS EXAMPLE ()
    ((SLOT1 :ACCESSOR SLOT1 :INITARG :SLOT1 :INITFORM NIL)
    (SLOT2 :ACCESSOR SLOT2 :INITARG :SLOT2 :INITFORM NIL)
    (SLOT3 :ACCESSOR SLOT3 :INITARG :SLOT3 :INITFORM NIL)))

  Each slot definition accepts options:

    :std 1 => changes the :initform to 1. It can be :unbound.
    :with or :with-prefix => creates accessors with the class name as prefix.

  See the README for more.

  See also `class/std' and `print-object/std'.
  "
  `(defclass ,name ,direct-superclasses
     ,(process-slots env direct-slots name)
     ,@options))

;; macroexpand:
(defclass unknown nil ((slot :accessor slot :initform nil :unknown keywords :without-values)))


[User]
You are a Common Lisp macro expert. Given this code pattern:
(pmap #'1+ #'unsigned)

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

(pmap #'1+ #'unsigned)

[Assistant]
(defmacro pmap (f parser)
  "Similar to `fmap', but this transforms a parser into another one, altering
its inner result if it happened to be successful."
  `(lambda (offset)
     (fmap ,f (funcall ,parser offset))))

;; macroexpand:
(lambda (offset) (fmap (function 1+) (funcall (function unsigned) offset)))


[User]
Define a macro that eliminates this repetitive pattern:
(with-reader-syntax (get-val array hash-table) (with-output-to-string (*error-output*) (is (char= #\f (er "(with-env (setp #\\f [str 0]))"))) (is (eq 'f (er "(with-env (setp 'f [vec 0]))"))) (is (= 4 (er "(with-env (setp 4 [arr 0 2]))"))) (is (eq 'f (er "(with-env (setp 'f [list 3]))"))) (is (eq 'f (er "(with-env (setp 'f [ht 'a]))"))) (is (= 2 (er "(with-env (setp 2 [assoc-list 'a]))"))) (is (eq 3 (er "(with-env (setp 3 [assoc-list 'c]))"))) (is (= 2 (er "(with-env (setp 2 [plist :c]))"))) (is (eq 3 (er "(with-env (setp 3 [plist :e]))"))) (is (eq 5 (er "(with-env (setp 5 [clos-object 'a]))"))) (is (eq 7 (er "(with-env (setp 7 [struct 'a]))")))))

Issue: Macro call that should be transformed by with-reader-syntax

(with-reader-syntax (get-val array hash-table) (with-output-to-string (*error-output*) (is (char= #\f (er "(with-env (setp #\\f [str 0]))"))) (is (eq 'f (er "(with-env (setp 'f [vec 0]))"))) (is (= 4 (er "(with-env (setp 4 [arr 0 2]))"))) (is (eq 'f (er "(with-env (setp 'f [list 3]))"))) (is (eq 'f (er "(with-env (setp 'f [ht 'a]))"))) (is (= 2 (er "(with-env (setp 2 [assoc-list 'a]))"))) (is (eq 3 (er "(with-env (setp 3 [assoc-list 'c]))"))) (is (= 2 (er "(with-env (setp 2 [plist :c]))"))) (is (eq 3 (er "(with-env (setp 3 [plist :e]))"))) (is (eq 5 (er "(with-env (setp 5 [clos-object 'a]))"))) (is (eq 7 (er "(with-env (setp 7 [struct 'a]))")))))

[Assistant]
(defmacro with-reader-syntax (reader-macro-identifiers &body body)
  "This macro is only made for use by read-and-eval functionality,
and rather directed towards tests than users. So, do not export."
  (let ((identifiers (loop :for identifier :in reader-macro-identifiers
                           :collect `(quote ,identifier))))
    `(let ((*array-function*         'make-t-array-from-initial-contents)
           (*hash-table-function*    'alexandria:plist-hash-table)
           (*get-val-function*       'get-val)
           (*get-val-array-function* 'cl:aref)
           (*set-function*           'cl:remove-duplicates)
           (*alists-are-lists*       nil)
           (*plists-are-lists*       nil)
           (*readtable*             (%enable-reader-syntax *readtable* ,@identifiers)))
       ,@body)))

;; macroexpand:
(let ((*array-function* (quote make-t-array-from-initial-contents)) (*hash-table-function* (quote alexandria:plist-hash-table)) (*get-val-function* (quote get-val)) (*get-val-array-function* (quote aref)) (*set-function* (quote remove-duplicates)) (*alists-are-lists* nil) (*plists-are-lists* nil) (*readtable* (%enable-reader-syntax *readtable* (quote get-val) (quote array) (quote hash-table)))) (with-output-to-string (*error-output*) (is (char= #\LATIN_SMALL_LETTER_F (er "(with-env (setp #\\f [str 0]))"))) (is (eq (quote f) (er "(with-env (setp 'f [vec 0]))"))) (is (= 4 (er "(with-env (setp 4 [arr 0 2]))"))) (is (eq (quote f) (er "(with-env (setp 'f [list 3]))"))) (is (eq (quote f) (er "(with-env (setp 'f [ht 'a]))"))) (is (= 2 (er "(with-env (setp 2 [assoc-list 'a]))"))) (is (eq 3 (er "(with-env (setp 3 [assoc-list 'c]))"))) (is (= 2 (er "(with-env (setp 2 [plist :c]))"))) (is (eq 3 (er "(with-env (setp 3 [plist :e]))"))) (is (eq 5 (er "(with-env (setp 5 [clos-object 'a]))"))) (is (eq 7 (er "(with-env (setp 7 [struct 'a]))")))))


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

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

(cond->> 'some-name)

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

;; macroexpand:
(let* ((#:g137 'some-name))
  #:g137)


[User]
Write a Common Lisp macro to handle this code pattern:
(define-generic generic ((a a) (b b) &key (c nil)) (+ a b) "This is not recognized as documentation.")

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

(define-generic generic ((a a) (b b) &key (c nil)) (+ a b) "This is not recognized as documentation.")

[Assistant]
(defmacro define-generic (name (&rest arglist) &body body)
  "Convenience macro to define generics as if they were methods.
ARGLIST can be a method arglist, in which case it's parsed into
generic function arglist by removing method-specific args.

BODY can be a list of `defgeneric' options (processed as-is, even
:method ones) intermixed with other Lisp forms:
- If there's a docstring as the first form, it's processed into
  :documentation option of `defgeneric'.
- If there are non-option forms, they are put together into a separate
  :method option under ARGLIST.
- If there's a `declare' form:
  - If it's generic-friendly (optimize for speed or space), then it's
    put into both generic body and :method body (if any).
  - Otherwise it's only put into :method (creating it if necessary).
- If there's an `:export-generic-name-p' boolean option, export (T) or
  don't export (NIL) the generic symbol.

Example:

\(define-generic add ((a integer) (b integer) &key coerce-to-fixnum &allow-other-keys)
  \"Adds A and B, coercing them to fixnum if the sum is too big.\"
  (if coerce-to-fixnum
      (coerce (+ a b) 'fixnum)
      (+ a b))
  (:method ((a string) (b integer))
   (error \"Cannot use `add' on strings!\")))
=>
\(defgeneric add (a b &key &allow-other-keys)
  (:method ((a integer) (b integer) &key coerce-to-fixnum &allow-other-keys)
   (if coerce-to-fixnum
      (coerce (+ a b) 'fixnum)
      (+ a b)))
  (:method ((a string) (b integer))
   (error \"Cannot use `add' on strings!\"))
  (:documentation \"Adds A and B, coercing them to fixnum if the sum is too big.\"))"
  (multiple-value-bind (body declarations documentation)
      (uiop:parse-body body :documentation t)
    (when (and (= 1 (length body))
               (stringp (first body)))
      (style-warn "Body of DEFINE-GENERIC contains a single string:
~s.
It's interpreted as a method body by default.

If you meant this string to be a generic docstring, and not a method
body, add an explicit NIL or some other body form:
(define-generic name (arg1 arg2)
  \"Docstring\"
  'body-form)

If you meant it as a body form, do nothing, or provide explicit
documentation or any other option:
(define-generic name (arg1 arg2)
  \"Docstring\"
  (:documentation \"Real docstring\"))" (first body)))
    (let* ((generic-declarations (remove-if (lambda (d)
                                              (or (> (length d) 2)
                                                  (not (eq 'optimize (first (second d))))
                                                  (notevery (lambda (o)
                                                              (let ((feature (first (uiop:ensure-list o))))
                                                                (or (eq feature 'speed)
                                                                    (eq feature 'space))))
                                                            (rest (second d)))))
                                            declarations))
           (options (remove-if-not (lambda (form)
                                     (keywordp (first (uiop:ensure-list form))))
                                   body))
           (method-body (remove-if (lambda (f) (member f options :test #'equal)) body))
           (export-generic-name-p (find :export-generic-name-p options :key #'first))
           (options (remove export-generic-name-p options :test #'equal))
           (export-p (if export-generic-name-p
                         (second export-generic-name-p)
                         *export-generic-name-p*))
           (generalized-arglist (generalize-arglist arglist)))
      (when (and (not (equal generalized-arglist arglist))
                 (every #'null (list method-body options)))
        (style-warn "Specialized arglist used without method body in define-generic: ~a" arglist))
      `(prog1
           (defgeneric ,name ,generalized-arglist
             ,@generic-declarations
             ,@(when (or method-body
                         (not (equal generic-declarations
                                     declarations)))
                 `((:method ,arglist
                     ,@declarations
                     ,@method-body)))
             ,@options
             ,@(when documentation
                 `((:documentation ,documentation))))
         ;; FIXME: Maybe only export if package of generic function name
         ;; matches *PACKAGE*?
         ,@(when export-p
             `((eval-when (:compile-toplevel :load-toplevel :execute)
                 (export ',name ,(package-name *package*)))))
         ,@(let ((documentation (or documentation
                                    (second (first (member :documentation options :key #'first))))))
             (when documentation
               `((setf (documentation ',name 'function) ,documentation)
                 (setf (documentation (fdefinition ',name) 'function) ,documentation))))))))

;; macroexpand:
(prog1 (defgeneric generic (a b &key c) (:method ((a a) (b b) &key (c nil)) (+ a b) "This is not recognized as documentation.")))


[User]
Generate a defmacro form that transforms code like this:
(with-standard-definer-options nil
  nil)

Pattern to recognize: Macro call that should be transformed by WITH-STANDARD-DEFINER-OPTIONS

(with-standard-definer-options nil
  nil)

[Assistant]
(defmacro WITH-STANDARD-DEFINER-OPTIONS ...)

;; macroexpand:
`(progn
  ,@(when (getf -options- :export)
      `((eval-when (:compile-toplevel :load-toplevel :execute)
          (export ',nil))))
  ,nil)


[User]
Generate a defmacro form that transforms code like this:
(defstore example (object &key &allow-other-keys))

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

(defstore example (object &key &allow-other-keys))

[Assistant]
(defmacro defstore (store-name store-lambda-list &body body &environment env)
  (let* ((store-class-name (second (find :store-class body :key #'first)))
         (store-class (etypecase store-class-name
                        (null (find-class 'standard-store))
                        (symbol (find-class store-class-name))))
         (form (apply #'defstore-using-class store-class store-name store-lambda-list
                      :environment env
                      (mapcan #'(lambda (item)
                                  (cond ((eql (first item) :store-class)
                                         `(:store-class ',store-class-name))
                                        ((and (member (first item) '(:documentation :specialization-class)))
                                         (if (= 2 (length item))
                                             item
                                             (error "Invalid store definition option: ~W." item)))
                                        (t
                                         (list (first item) (rest item)))))
                              body))))
    `(eval-when (:compile-toplevel :load-toplevel :execute)
       ,form)))

;; macroexpand:
(eval-when (:compile-toplevel :load-toplevel :execute) (progn (ensure-store (quote example) (quote (object &key &allow-other-keys)))))


[User]
You are a Common Lisp macro expert. Given this code pattern:
(is #\a #\a)

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

(is #\a #\a)

[Assistant]
(defmacro is (got expected &rest args)
  (with-gensyms (duration result new-args desc)
    (once-only (expected)
      `(let* ((,new-args (list ,@args))
              (,desc (parse-description-and-test ,new-args)))
         (with-catching-errors (:description ,desc :expected ,expected)
           (with-duration ((,duration ,result) ,got)
             (test ,result ,expected ,new-args
                   :duration ,duration)))))))

;; macroexpand:
(let ((#:expected166 #\LATIN_SMALL_LETTER_A)) (let* ((#:new-args164 (list)) (#:desc165 (parse-description-and-test #:new-args164))) (with-catching-errors (:description #:desc165 :expected #:expected166) (with-duration ((#:duration162 #:result163) #\LATIN_SMALL_LETTER_A) (test #:result163 #:expected166 #:new-args164 :duration #:duration162)))))


[User]
Define a macro that eliminates this repetitive pattern:
(defgenerator dropwhile (predicate generator) "Goes through generator, dropping the items until the predicate fails, then emits the rest of the source generator's items. Eg: (dropwhile (lambda (x) (< x 5)) (list->generator '(1 4 6 4 1))) -> 6 4 1" (do-generator (item generator) (unless (funcall predicate item) (yield item) (return))) (yield-all generator))

Issue: Macro call that should be transformed by defgenerator

(defgenerator dropwhile (predicate generator) "Goes through generator, dropping the items until the predicate fails, then emits the rest of the source generator's items. Eg: (dropwhile (lambda (x) (< x 5)) (list->generator '(1 4 6 4 1))) -> 6 4 1" (do-generator (item generator) (unless (funcall predicate item) (yield item) (return))) (yield-all generator))

[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 dropwhile (predicate generator) "Goes through generator, dropping the items until the predicate fails, then emits the rest of the source generator's items. Eg: (dropwhile (lambda (x) (< x 5)) (list->generator '(1 4 6 4 1))) -> 6 4 1" (with-yield (do-generator (item generator) (unless (funcall predicate item) (yield item) (return))) (yield-all generator)))


[User]
Generate a defmacro form that transforms code like this:
(-> :tag-3 (text) (setf result text) (mt:open-latch latch))

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

(-> :tag-3 (text) (setf result text) (mt:open-latch latch))

[Assistant]
(defmacro -> (invariant &body args)
  "See flow:atomically"
  `(atomically ,invariant ,@args))

;; macroexpand:
(atomically :tag-3 (text) (setf result text) (cl-muth:open-latch latch))


[User]
Define a macro that eliminates this repetitive pattern:
(def-launched-iter nil
    (progn))

Issue: Macro call that should be transformed by DEF-LAUNCHED-ITER

(def-launched-iter nil
    (progn))

[Assistant]
(defmacro DEF-LAUNCHED-ITER ...)

;; macroexpand:
(defun nil (progn)
  (let ((it (make-instance 'iterator :coro (lambda-coro))))
    (inext-or-error it)
    it))


[User]
You are a Common Lisp macro expert. Given this code pattern:
(when (and (>= (length operatorXX) 8) (string-equal "operator" operatorXX :start2 0 :end2 8)) (when (not (gethash operatorXX name-map))) (setf (gethash operatorXX name-map) check-name))

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

(when (and (>= (length operatorXX) 8) (string-equal "operator" operatorXX :start2 0 :end2 8)) (when (not (gethash operatorXX name-map))) (setf (gethash operatorXX name-map) check-name))

[Assistant]
(defmacro when (test &body forms)
  `(if ,test
	   ,(cl:if (cadr forms)
			   `(progn ,@forms)
			   (car forms))))

;; macroexpand:
(if (and (>= (length operatorxx) 8) (string-equal "operator" operatorxx :start2 0 :end2 8)) (progn (when (not (gethash operatorxx name-map))) (setf (gethash operatorxx name-map) check-name)))


[User]
Generate a defmacro form that transforms code like this:
(with-wcs-math-error-handling (ret (log x)) (check-wcs-math-result))

Pattern to recognize: Macro call that should be transformed by with-wcs-math-error-handling

(with-wcs-math-error-handling (ret (log 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* ((#:g221 x) (#:g222 nil) (#:g223 (list #:g221))) (declare (ignorable #:g222) (type list #:g223) (dynamic-extent #:g223)) (catch (quote return-from-with-wcs-math-error-handling) (multiple-value-bind (ret) (call-with-wcs-math-error-handler (quote log) #:g223) (flet ((check-wcs-math-result (&optional (ret ret) (arg-list #:g223)) (check-wcs-math-result ret arg-list))) (check-wcs-math-result)))))