[User]
You are a Common Lisp macro expert. Given this code pattern:
(answer foo 23)

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

(answer foo 23)

[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 ((#:g159 (fdefinition (quote foo)))) (declare (ignorable #:g159)) (let ((times 0)) (lambda (&rest args) (declare (ignorable args)) (case (prog1 times (incf times)) (t 23))))))


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

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

(dreletf nil
  nil)

[Assistant]
(defmacro DRELETF ...)

;; macroexpand:
(let ((#:symbol-store232
       (with-symbol-access
         (list))))
  (special-symbol-reprogv #:symbol-store232
      (list)
    (locally (declare (special)) nil)))


[User]
Generate a defmacro form that transforms code like this:
(define-op (:like infix-op))

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

(define-op (:like infix-op))

[Assistant]
(defmacro define-op ((op-name struct-type &key sql-op-name include-slots (package (find-package '#:sxql/operator))) &body body)
  (check-type op-name symbol)
  (let ((struct-name (intern (concatenate 'string (symbol-name op-name) #.(string :-op)) package)))
    `(defstruct (,struct-name (:include ,struct-type
                               (name ,(or sql-op-name
                                          (with-output-to-string (s)
                                            (loop for c across (symbol-name op-name)
                                                  if (char= c #\-)
                                                    do (write-char #\Space s)
                                                  else
                                                    do (write-char c s)))))
                               ,@include-slots)
                              (:constructor ,(intern (concatenate 'string
                                                                  #.(string :make-)
                                                                  (symbol-name op-name)
                                                                  #.(string :-op))
                                                     package)
                                  ,(ecase struct-type
                                     ((unary-op
                                       unary-splicing-op
                                       unary-postfix-op) '(var))
                                     ((infix-op
                                       infix-splicing-op
                                       infix-list-op) '(left right))
                                     (conjunctive-op '(&rest expressions)))))
       ,@body)))

;; macroexpand:
(defstruct (like-op (:include infix-op (name "LIKE")) (:constructor make-like-op (left right))))


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

Problem: Macro call that should be transformed by MAKE-SIMPLE-COLLECTOR-TO-PLACE

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

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

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


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

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

(any-of nil
  (progn))

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

;; macroexpand:
(lc (nil (progn)) thereis)


[User]
Create a Common Lisp macro for the following transformation. Before code:
(set-custom-vars :integer #'parse-number :real #'parse-number :boolean #'json-boolean-to-lisp :beginning-of-array #'init-accumulator :array-member #'accumulator-add :end-of-array #'accumulator-get-sequence :array-type 'list :beginning-of-object #'init-accumulator :object-key #'accumulator-add-key :object-value #'accumulator-add-value :end-of-object #'accumulator-get :beginning-of-string #'init-string-stream-accumulator :string-char #'string-stream-accumulator-add :end-of-string #'string-stream-accumulator-get :aggregate-scope (union *aggregate-scope-variables* '(*accumulator* *accumulator-last*)) :internal-decoder #'decode-json)

What needs to change: Macro call that should be transformed by set-custom-vars

(set-custom-vars :integer #'parse-number :real #'parse-number :boolean #'json-boolean-to-lisp :beginning-of-array #'init-accumulator :array-member #'accumulator-add :end-of-array #'accumulator-get-sequence :array-type 'list :beginning-of-object #'init-accumulator :object-key #'accumulator-add-key :object-value #'accumulator-add-value :end-of-object #'accumulator-get :beginning-of-string #'init-string-stream-accumulator :string-char #'string-stream-accumulator-add :end-of-string #'string-stream-accumulator-get :aggregate-scope (union *aggregate-scope-variables* '(*accumulator* *accumulator-last*)) :internal-decoder #'decode-json)

[Assistant]
(defmacro set-custom-vars (&rest key-args)
  `(setq
    ,@(loop for (supplied-key value) on key-args by #'cddr
         append (loop for (var . var-key) in *custom-vars*
                   thereis (if (eql var-key supplied-key)
                               (list var value))))))

;; macroexpand:
(setq *integer-handler* (function parse-number) *real-handler* (function parse-number) *boolean-handler* (function json-boolean-to-lisp) *beginning-of-array-handler* (function init-accumulator) *array-member-handler* (function accumulator-add) *end-of-array-handler* (function accumulator-get-sequence) *json-array-type* (quote list) *beginning-of-object-handler* (function init-accumulator) *object-key-handler* (function accumulator-add-key) *object-value-handler* (function accumulator-add-value) *end-of-object-handler* (function accumulator-get) *beginning-of-string-handler* (function init-string-stream-accumulator) *string-char-handler* (function string-stream-accumulator-add) *end-of-string-handler* (function string-stream-accumulator-get) *aggregate-scope-variables* (union *aggregate-scope-variables* (quote (*accumulator* *accumulator-last*))) *internal-decoder* (function decode-json))


[User]
Define a macro that eliminates this repetitive pattern:
(dynamic-let* nil)

Issue: Macro call that should be transformed by DYNAMIC-LET*

(dynamic-let* nil)

[Assistant]
(defmacro DYNAMIC-LET* ...)

;; macroexpand:
(progn)


[User]
Write a Common Lisp macro to handle this code pattern:
(parse-conjunctive-clauses client instance t :var (parse-d-spec client :type-spec *placeholder-result*))

Problem: Macro call that should be transformed by parse-conjunctive-clauses

(parse-conjunctive-clauses client instance t :var (parse-d-spec client :type-spec *placeholder-result*))

[Assistant]
(defmacro parse-conjunctive-clauses (client region read-name-p &rest args)
  (with-unique-names (clauses next)
    `(prog (,clauses)
      ,next
        (push (do-parse-clause ,client ,region *index* ,read-name-p ,@args)
              ,clauses)
        (when (maybe-parse-token :keywords '(:and))
          (go ,next))
        (return (nreverse ,clauses)))))

;; macroexpand:
(prog (#:clauses124) #:next125 (push (do-parse-clause client instance *index* t :var (parse-d-spec client :type-spec *placeholder-result*)) #:clauses124) (when (maybe-parse-token :keywords (quote (:and))) (go #:next125)) (return (nreverse #:clauses124)))


[User]
Write a Common Lisp macro to handle this code pattern:
(define-type-dispatch nil
    (progn))

Problem: Macro call that should be transformed by DEFINE-TYPE-DISPATCH

(define-type-dispatch nil
    (progn))

[Assistant]
(defmacro DEFINE-TYPE-DISPATCH ...)

;; macroexpand:
(progn
 (defun nil (progn)
   (declare (optimize speed (debug 1) (safety 1) (compilation-speed 0)))
   (etypecase progn))
 (sb-c:defknown nil
     ((or))
     (or)
     (sb-c:any)
   :overwrite-fndb-silently
   t))


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

Problem: Macro call that should be transformed by quasiquote

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

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

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


[User]
Write a Common Lisp macro to handle this code pattern:
(aecase (car x) (:y :no) (:x (list it :yes)))

Problem: Macro call that should be transformed by aecase

(aecase (car x) (:y :no) (:x (list it :yes)))

[Assistant]
(defmacro aecase (keyform &body cases)
  "Like ECASE, except binds the result of the keyform to IT (via LET) for the
scope of the cases."
  `(anaphoric ecase ,keyform ,@cases))

;; macroexpand:
(anaphoric ecase (car x) (:y :no) (:x (list it :yes)))


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

Issue: Macro call that should be transformed by COLLECT-AND

(collect-and 'some-name)

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

;; macroexpand:
(common-lisp:let* ((#:generator-501 (generator 'some-name))
                   #:bools-497
                   (#:bool-498 t))
  (declare (type generator #:generator-501))
  (tagbody
   #:ll-502
    (setq #:bools-497 (next-in #:generator-501 (go end)))
    (if (null (setq #:bool-498 #:bools-497))
        (go end))
    (go #:ll-502)
   end)
  #:bool-498)


[User]
Create a Common Lisp macro for the following transformation. Before code:
(cache-dir #p"/tmp/clache-test/")

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

(cache-dir #p"/tmp/clache-test/")

[Assistant]
(defmacro cache ((keyargs &key store expire) function-definition-form)
  "Annotation for caching functions with their arguments. This should
be used with CL-ANNOT. KEYARGS is a form or a list of form for making
a cache key.  To make cache keys distinct as to the function, you may
add a keyword or a symbol into KEYARGS. See also WITH-CACHE.

Example:

    @cache ((:f x y z))
    (defun f (x y z)
      ...)

    ;; Remove a cache of F
    (remcache '(:f 1 2 3))"
  (replace-function-body
   (lambda (name lambda-list body)
     @ignore name
     @ignore lambda-list
     (let ((key (if (listp keyargs)
                    `(list ,@keyargs)
                    keyargs)))
       `(with-cache (,key :store ,store :expire ,expire)
          ,@body)))
   function-definition-form))

;; macroexpand:
(cache-dir #P"/tmp/clache-test/")


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

Problem: Macro call that should be transformed by PS-HTML

(ps-html nil nil)

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

;; macroexpand:
(stringify nil nil)


[User]
Define a macro that eliminates this repetitive pattern:
(signal-syntax-error* error-pos "Comment group not closed.")

Issue: Macro call that should be transformed by signal-syntax-error*

(signal-syntax-error* error-pos "Comment group not closed.")

[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 error-pos :format-control "Comment group not closed." :format-arguments (list))


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

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

(dynamic-wind
  nil
  :key
  nil)

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

;; macroexpand:
(flet ((#:dynamic-wind-thunk225 (#:proceed-thunk226)
         (macrolet ((proceed (&body #:proceed-body227)
                      `(if ,'#:proceed-thunk226
                           (funcall (the function ,'#:proceed-thunk226))
                           (progn ,@#:proceed-body227))))
           nil
           :key
           nil)))
  (declare (inline #:dynamic-wind-thunk225))
  (let ((*dynamic-wind-stack*
         (cons #'#:dynamic-wind-thunk225 *dynamic-wind-stack*)))
    (#:dynamic-wind-thunk225 nil)))


[User]
Generate a defmacro form that transforms code like this:
(define-path-instruction-pair move-to "M" (x y))

Pattern to recognize: Macro call that should be transformed by define-path-instruction-pair

(define-path-instruction-pair move-to "M" (x y))

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

;; macroexpand:
(progn (defun move-to (x y) (format-instruction "M" x y)) (defun move-to-r (x y) (format-instruction "m" x y)))


[User]
Write a Common Lisp macro to handle this code pattern:
(define-port-value-slot nil nil)

Problem: Macro call that should be transformed by DEFINE-PORT-VALUE-SLOT

(define-port-value-slot nil nil)

[Assistant]
(defmacro DEFINE-PORT-VALUE-SLOT ...)

;; macroexpand:
(progn
 (defmethod port-value ((nil nil)) (slot-value nil nil))
 (defmethod (setf port-value) (value (nil nil))
   (setf (slot-value nil nil) value))
 (defmethod port-value-boundp ((nil nil)) (slot-boundp nil 'nil))
 (defmethod port-value-makunbound ((nil nil)) (slot-makunbound nil 'nil)))


[User]
Generate a defmacro form that transforms code like this:
(defcategory-fn (my-category-keyword) '(or :debug :info))

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

(defcategory-fn (my-category-keyword) '(or :debug :info))

[Assistant]
(defmacro defcategory (category &optional expands-as set)
  `(defcategory-fn ',category ',expands-as ,set))

;; macroexpand:
(defcategory-fn (my-category-keyword) (quote (or :debug :info)))


[User]
Write a Common Lisp macro to handle this code pattern:
(when (and (not (equal identifier name-string)) (find :hyphen *enabled-warnings*)) (warn "Possible ambiguity through hyphen override of ~s" check-name))

Problem: Macro call that should be transformed by when

(when (and (not (equal identifier name-string)) (find :hyphen *enabled-warnings*)) (warn "Possible ambiguity through hyphen override of ~s" check-name))

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

;; macroexpand:
(if (and (not (equal identifier name-string)) (find :hyphen *enabled-warnings*)) (warn "Possible ambiguity through hyphen override of ~s" check-name))


[User]
Generate a defmacro form that transforms code like this:
(define-error no-function-returns () (name return-set) "Function '~a' did not specify any return types" name)

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

(define-error no-function-returns () (name return-set) "Function '~a' did not specify any return types" name)

[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 no-function-returns (:error-type varjo-error :prefix "Varjo") (name return-set) "Function '~a' did not specify any return types" name)


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

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

(defexpander nil)

[Assistant]
(defmacro DEFEXPANDER ...)

;; macroexpand:
(eval-when (:compile-toplevel :load-toplevel :execute)
  (setf (get 'nil +expander-prop+) (gensym #A((3) base-char . "NIL")))
  (defmethod (setf documentation)
             (#:docstring122 #:sym-obj123 (#:doc-type124 (eql 'nil)))
    (declare (ignore #:doc-type124))
    (setf (expander-info-docstring
           (get #:sym-obj123 (get 'nil +expander-prop+)))
            #:docstring122))
  (defmethod documentation (#:sym-obj123 (#:doc-type124 (eql 'nil)))
    (declare (ignore #:doc-type124))
    (expander-info-docstring (get #:sym-obj123 (get 'nil +expander-prop+))))
  'nil)


[User]
You are a Common Lisp macro expert. Given this code pattern:
(defvar-compile-time *local?* nil "This must be globally NIL.")

Write a macro that addresses: Macro call that should be transformed by defvar-compile-time

(defvar-compile-time *local?* nil "This must be globally NIL.")

[Assistant]
(defmacro defvar-compile-time (name &optional initial-value documentation)
  `(eval-when (:compile-toplevel :load-toplevel :execute)
     (defvar ,name ,initial-value ,documentation)))

;; macroexpand:
(eval-when (:compile-toplevel :load-toplevel :execute) (defvar *local?* nil "This must be globally NIL."))


[User]
Generate a defmacro form that transforms code like this:
(make-obsolete mustache-compile compile-template "0.10.0")

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

(make-obsolete mustache-compile compile-template "0.10.0")

[Assistant]
(defmacro make-obsolete (obsolete-name current-name when)
  `(defun ,obsolete-name (&rest args)
     ,(documentation current-name 'function)
     (warn 'deprecation-warning
           :name ',obsolete-name :replacement ',current-name :since ,when)
     (apply ',current-name args)))

;; macroexpand:
(defun mustache-compile (&rest args) "Return a compiled rendering function." (warn (quote deprecation-warning) :name (quote mustache-compile) :replacement (quote compile-template) :since "0.10.0") (apply (quote compile-template) args))


[User]
Create a Common Lisp macro for the following transformation. Before code:
(defguarantee add (&rest addends) "result < 20" (declare (ignore addends)) (< (results) 20))

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

(defguarantee add (&rest addends) "result < 20" (declare (ignore addends)) (< (results) 20))

[Assistant]
(defmacro defguarantee (name (&rest lambda-list) &body body)
  "Adds a postcondition to the NAMEd function. It can be either a generic or
   non-generic function. If it's the former, then use a specialized lambda list,
   otherwise use an ordinary lambda list. The docstring, if any, will be used in
   failure reports."
  #+qpq-postcondition-checks-disabled
  (declare (ignore name lambda-list body))
  #+qpq-postcondition-checks-disabled
  (values)
  #-qpq-postcondition-checks-disabled
  (multiple-value-bind (remaining-forms declarations doc-string)
      (parse-body body :documentation t)
    (declare (ignore declarations))
    (let* ((stripped-ll (strip-lambda-list lambda-list))
           (lambda-vars (remove-if (rcurry #'member
                                           '(&optional &rest
                                             &key &allow-other-keys &aux))
                                   stripped-ll))
           (method `(progn
                      (ensure-contracted-function ',name ',stripped-ll)
                      (defmethod ,name
                          :guarantee
                          ,(or doc-string
                            (format nil "~A"
                             (description<-remaining-forms
                              remaining-forms)))
                        ,lambda-list
                        (declare (ignorable ,@lambda-vars))
                        ,@body))))
      (if (every #'symbolp lambda-list)
          `(if (and (fboundp ',name)
                    (not (typep (fdefinition ',name) 'generic-function)))
               (defcontract ,name :guarantee ,lambda-list
                 (declare (ignorable ,@lambda-vars))
                 ,@body)
               ,method)
          method))))

;; macroexpand:
(if (and (fboundp (quote add)) (not (typep (fdefinition (quote add)) (quote generic-function)))) (defcontract add :guarantee (&rest addends) (declare (ignorable addends)) "result < 20" (declare (ignore addends)) (< (results) 20)) (progn (ensure-contracted-function (quote add) (quote (&rest addends))) (defmethod add :guarantee "result < 20" (&rest addends) (declare (ignorable addends)) "result < 20" (declare (ignore addends)) (< (results) 20))))


[User]
Create a Common Lisp macro for the following transformation. Before code:
(with-html-string (:tag :name "x-y" "Hello"))

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

(with-html-string (:tag :name "x-y" "Hello"))

[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 (:tag :name "x-y" "Hello")))


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

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

(lexpr-$send nil nil)

[Assistant]
(defmacro LEXPR-$SEND ...)

;; macroexpand:
(apply #'send-message nil nil)


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

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

(fgatherlet nil
  :key
  nil)

[Assistant]
(defmacro FGATHERLET ...)

;; macroexpand:
(flet ()
  :key
  nil)


[User]
Write a Common Lisp macro to handle this code pattern:
(defjs reduce4(k vals) (return (ps:create :vals vals)))

Problem: Macro call that should be transformed by defjs

(defjs reduce4(k vals) (return (ps:create :vals vals)))

[Assistant]
(defmacro defjs (name args &body body)
  "Define client side javascript. Works like defun; body is in lisp, with parenscript
   additions, like return. So (defjs hello (x y) (return (+ x y))) defines an adder.
   macro creates a lisp function which sends the javascript function over to the mongo
   server to be evaluated. Result is processed and returned to the reader.
   This will execute 10 times on the server :
   (mapcar (lambda (x) (hello 10 x)) (list 1 2 3 4 5 6 7 8 9 10))"
  `(let* ((js-body (parenscript:ps (lambda ,args ,@body))))
     (setf (gethash ',name *js-definitions*) js-body)
     (defun ,name ,args
       (get-element "retval" (car (docs (db.eval js-body ,@args)))))))

;; macroexpand:
(let* ((js-body (parenscript:ps (lambda (k vals) (return (parenscript:create :vals vals)))))) (setf (gethash (quote reduce4) *js-definitions*) js-body) (defun reduce4 (k vals) (get-element "retval" (car (docs (db.eval js-body k vals))))))


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

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

(is (plusp a))

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

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

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

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

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

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


[User]
Generate a defmacro form that transforms code like this:
(def-neo4j-fun delete-relationship (relationship-id) :delete (:uri-spec (format nil "relationship/~A" relationship-id)) (:status-handlers (204 (values t body)) (404 (error 'relationship-not-found-error :uri uri))))

Pattern to recognize: Macro call that should be transformed by def-neo4j-fun

(def-neo4j-fun delete-relationship (relationship-id) :delete (:uri-spec (format nil "relationship/~A" relationship-id)) (:status-handlers (204 (values t body)) (404 (error 'relationship-not-found-error :uri uri))))

[Assistant]
(defmacro def-neo4j-fun (name lambda-list method &rest args)
  `(progn
     (defun ,name (&key ,@lambda-list)
       (let ((uri ,(cadr (assoc :uri-spec args)))
             (json (encode-neo4j-json-payload ,@(aif (assoc :encode args)
                                                     (cdr it)
                                                     (list '() :string)))))
         (make-neo4j-request ,method uri json
                             (list ,@(mapcar (lambda (handler)
                                               `(list ,(car handler) (lambda (body uri json)
                                                                  ,(cadr handler))))
                                             (cdr (assoc :status-handlers args)))))))))

;; macroexpand:
(progn (defun delete-relationship (&key relationship-id) (let ((uri (format nil "relationship/~A" relationship-id)) (json (encode-neo4j-json-payload nil :string))) (make-neo4j-request :delete uri json (list (list 204 (lambda (body uri json) (values t body))) (list 404 (lambda (body uri json) (error (quote relationship-not-found-error) :uri uri))))))))


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

Problem: Macro call that should be transformed by DEFUN

(defun nil :key nil)

[Assistant]
(defmacro DEFUN ...)

;; macroexpand:
(progn
 (eval-when (:compile-toplevel) (sb-c:%compiler-defun 'nil t nil nil))
 (sb-impl::%defun 'nil
                  (sb-int:named-lambda nil
                      :key
                    (block nil nil))))


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

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

(dynamic-let nil
  nil)

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

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


[User]
Write a Common Lisp macro to handle this code pattern:
(destructure-specialized-lambda-list descriptive-lambda-list vanilla-lambda-list type-list specialized-lambda-list `(funcall (dispatch-function (dispatch-for-qualifier ',qualifier)) (list ,@vanilla-lambda-list) (mapcar #'hook-name (specific-hooks-for-generic ',type-list ',generic-function ',qualifier))))

Problem: Macro call that should be transformed by destructure-specialized-lambda-list

(destructure-specialized-lambda-list descriptive-lambda-list vanilla-lambda-list type-list specialized-lambda-list `(funcall (dispatch-function (dispatch-for-qualifier ',qualifier)) (list ,@vanilla-lambda-list) (mapcar #'hook-name (specific-hooks-for-generic ',type-list ',generic-function ',qualifier))))

[Assistant]
(defmacro destructure-specialized-lambda-list (descriptive-lambda-list-sym vanilla-lambda-list-sym type-list-sym specialized-lambda-list &body body)
  "if specialized-lambda-list is ((a integer) b):
descriptive-lambda-list will be ((x integer) (x t))
type-list will be (integer t) and vanilla-lambda-list is (a b)"
  (let ((item (gensym)))
    `(let* ((,descriptive-lambda-list-sym
             (loop :for ,item :in ,specialized-lambda-list
                :if (listp ,item)
                :collect ,item
                :else :collect (list ,item t)))
            (,vanilla-lambda-list-sym (mapcar #'first ,descriptive-lambda-list-sym))
            (,type-list-sym (mapcar #'second ,descriptive-lambda-list-sym)))
       (declare (ignorable ,descriptive-lambda-list-sym ,vanilla-lambda-list-sym ,type-list-sym))
       ,@body)))

;; macroexpand:
(let* ((descriptive-lambda-list (loop :for #:g124 :in specialized-lambda-list :if (listp #:g124) :collect #:g124 :else :collect (list #:g124 t))) (vanilla-lambda-list (mapcar (function first) descriptive-lambda-list)) (type-list (mapcar (function second) descriptive-lambda-list))) (declare (ignorable descriptive-lambda-list vanilla-lambda-list type-list)) (sb-int:quasiquote (funcall (dispatch-function (dispatch-for-qualifier (quote #S(sb-impl::comma :expr qualifier :kind 0)))) (list #S(sb-impl::comma :expr vanilla-lambda-list :kind 2)) (mapcar (function hook-name) (specific-hooks-for-generic (quote #S(sb-impl::comma :expr type-list :kind 0)) (quote #S(sb-impl::comma :expr generic-function :kind 0)) (quote #S(sb-impl::comma :expr qualifier :kind 0)))))))


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

What needs to change: Macro call that should be transformed by WITH-CACHED-READER-CONDITIONALS

(with-cached-reader-conditionals
  'some-name)

[Assistant]
(defmacro WITH-CACHED-READER-CONDITIONALS ...)

;; macroexpand:
(call-with-cached-reader-conditionals (lambda () 'some-name))


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

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

(matrix-typecase 'some-name)

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

;; macroexpand:
(let ((#:g245 quote))
  (typecase #:g245))


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

Problem: Macro call that should be transformed by INEXT-OR-ERROR

(inext-or-error 'some-name)

[Assistant]
(defmacro INEXT-OR-ERROR ...)

;; macroexpand:
(let ((vals (multiple-value-list (funcall (i-coro 'some-name) nil))))
  (if (not vals)
      (error 'stop-iteration)
      (values (car vals) t)))


[User]
Define a macro that eliminates this repetitive pattern:
(define-direct-binding = (var form &key then) (let* ((undef '#.(gensym "UNDEF")) (vars (loop for var in (lambda-fiddle:extract-lambda-vars (enlist var)) collect `(,var ',undef)))) (if then (values `(let ,vars) `(if (eq ,(caar vars) ,undef) (update ,var ,form) (update ,var ,then))) (values `(let ,vars) `(update ,var ,form)))))

Issue: Macro call that should be transformed by define-direct-binding

(define-direct-binding = (var form &key then) (let* ((undef '#.(gensym "UNDEF")) (vars (loop for var in (lambda-fiddle:extract-lambda-vars (enlist var)) collect `(,var ',undef)))) (if then (values `(let ,vars) `(if (eq ,(caar vars) ,undef) (update ,var ,form) (update ,var ,then))) (values `(let ,vars) `(update ,var ,form)))))

[Assistant]
(defmacro define-direct-binding (name args &body body)
  (let ((env (or (lambda-fiddle:environment-lambda-var args) (gensym "ENVIRONMENT"))))
    `(progn (setf (binding ',name)
                  (lambda ,(lambda-fiddle:remove-environment-part args)
                    (let ((,env *environment*))
                      (declare (ignorable ,env))
                      ,@body)))
            ',name)))

;; macroexpand:
(progn (setf (binding (quote =)) (lambda (var form &key then) (let ((#:environment130 *environment*)) (declare (ignorable #:environment130)) (let* ((undef (quote #:undef129)) (vars (loop for var in (lambda-fiddle:extract-lambda-vars (enlist var)) collect (sb-int:quasiquote (#S(sb-impl::comma :expr var :kind 0) (quote #S(sb-impl::comma :expr undef :kind 0))))))) (if then (values (sb-int:quasiquote (let #S(sb-impl::comma :expr vars :kind 0))) (sb-int:quasiquote (if (eq #S(sb-impl::comma :expr (caar vars) :kind 0) #S(sb-impl::comma :expr undef :kind 0)) (update #S(sb-impl::comma :expr var :kind 0) #S(sb-impl::comma :expr form :kind 0)) (update #S(sb-impl::comma :expr var :kind 0) #S(sb-impl::comma :expr then :kind 0))))) (values (sb-int:quasiquote (let #S(sb-impl::comma :expr vars :kind 0))) (sb-int:quasiquote (update #S(sb-impl::comma :expr var :kind 0) #S(sb-impl::comma :expr form :kind 0))))))))) (quote =))


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

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

(defreply nil
    (progn))

[Assistant]
(defmacro DEFREPLY ...)

;; macroexpand:
(progn
 (eval-when (:compile-toplevel)
   (unless (fboundp 'nil)
     (warn 'automatic-message-creation :message-name 'nil)
     (ensure-message 'nil :lambda-list '(progn))))
 (ensure-reply 'nil :qualifiers 'nil :lambda-list '(progn) :participants
               (list =t=) :documentation nil :function
               (lambda (#:args140 #:next-replies141 &rest #:more-args143)
                 (declare
                  (ignorable #:args140 #:next-replies141 #:more-args143))
                 (flet ((next-reply-p ()
                          (not (null #:next-replies141)))
                        (call-next-reply (&rest args)
                          (if (null #:next-replies141)
                              (apply 'no-next-reply
                                     (getf #:more-args143 :message)
                                     (getf #:more-args143 :reply)
                                     (or args #:args140))
                              (apply (reply-function (car #:next-replies141))
                                     (or args #:args140)
                                     (cdr #:next-replies141) #:more-args143))))
                   (declare
                    (ignorable (function next-reply-p)
                     (function call-next-reply)))
                   (flet ((#:reply-function142 (progn)
                            (declare (ignorable))
                            (block nil)))
                     (declare (inline #:reply-function142))
                     (apply #'#:reply-function142 #:args140))))))


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

Problem: Macro call that should be transformed by defsynonym

(defsynonym mult :mult)

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

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


[User]
Create a Common Lisp macro for the following transformation. Before code:
(answer (foo 2) 3)

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

(answer (foo 2) 3)

[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 ((#:g161 (fdefinition (quote foo)))) (declare (ignorable #:g161)) (let ((times 0)) (lambda (&rest args) (declare (ignorable args)) (trivia.level2:match args ((list 2) (case (prog1 times (incf times)) (t 3))) (_ (unhandled)))))))


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

Problem: Macro call that should be transformed by deferror

(deferror "40" 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 transaction-rollback (database-error) nil) (setf (gethash "40" *error-table*) (quote transaction-rollback)))


[User]
Write a Common Lisp macro to handle this code pattern:
(with-html-string (:p :class :foo))

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

(with-html-string (:p :class :foo))

[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 (:p :class :foo)))


[User]
Define a macro that eliminates this repetitive pattern:
(lambda (quote some-name))

Issue: Macro call that should be transformed by LAMBDA

(lambda (quote some-name))

[Assistant]
(defmacro LAMBDA ...)

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


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

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

(the-part nil (progn))

[Assistant]
(defmacro THE-PART ...)

;; macroexpand:
(send part nil (progn))


[User]
Generate a defmacro form that transforms code like this:
(with-connection (let ((user (retrieve-one :user :by :name := "nitro_idiot" :as 'user))) (is-type (user-created-at user) 'local-time:timestamp) (is (user-updated-at user) nil) (is (user-status user) :normal) (is (length (user-tweets user)) 2) (is (tweet-id (car (user-tweets user :limit 1))) 2) (is (tweet-id (car (user-tweets user :limit 1 :offset 1))) 1) (is (length (user-tweets user :limit 2)) 2) (ok (every (lambda (tweet) (typep tweet 'tweet)) (user-tweets user))) (execute (insert-into :tweet (set= :id 3 :user_id 1 :body "Looks good." :created_at (princ-to-string *now*)))) (is (length (user-tweets user)) 2 "Result cached") (let ((test-val '#:test-val)) (setf (user-tweets user) test-val) (is (user-tweets user) test-val :test #'eq "Set cache value")) (datafly.cache:clear-object-caches user) (is (length (user-tweets user)) 3)))

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

(with-connection (let ((user (retrieve-one :user :by :name := "nitro_idiot" :as 'user))) (is-type (user-created-at user) 'local-time:timestamp) (is (user-updated-at user) nil) (is (user-status user) :normal) (is (length (user-tweets user)) 2) (is (tweet-id (car (user-tweets user :limit 1))) 2) (is (tweet-id (car (user-tweets user :limit 1 :offset 1))) 1) (is (length (user-tweets user :limit 2)) 2) (ok (every (lambda (tweet) (typep tweet 'tweet)) (user-tweets user))) (execute (insert-into :tweet (set= :id 3 :user_id 1 :body "Looks good." :created_at (princ-to-string *now*)))) (is (length (user-tweets user)) 2 "Result cached") (let ((test-val '#:test-val)) (setf (user-tweets user) test-val) (is (user-tweets user) test-val :test #'eq "Set cache value")) (datafly.cache:clear-object-caches user) (is (length (user-tweets user)) 3)))

[Assistant]
(defmacro with-connection (&body body)
  `(let ((*connection* (connect-cached :sqlite3 :database-name *db-path*)))
     ,@body))

;; macroexpand:
(let ((let (connect ((user (retrieve-one :user :by :name := "nitro_idiot" :as (quote user)))) (is-type (user-created-at user) (quote local-time:timestamp)) (is (user-updated-at user) nil) (is (user-status user) :normal) (is (length (user-tweets user)) 2) (is (tweet-id (car (user-tweets user :limit 1))) 2) (is (tweet-id (car (user-tweets user :limit 1 :offset 1))) 1) (is (length (user-tweets user :limit 2)) 2) (ok (every (lambda (tweet) (typep tweet (quote tweet))) (user-tweets user))) (execute (insert-into :tweet (set= :id 3 :user_id 1 :body "Looks good." :created_at (princ-to-string *now*)))) (is (length (user-tweets user)) 2 "Result cached") (let ((test-val (quote #:test-val))) (setf (user-tweets user) test-val) (is (user-tweets user) test-val :test (function eq) "Set cache value")) (datafly.cache:clear-object-caches user) (is (length (user-tweets user)) 3)))) (unwind-protect (progn) (disconnect let)))


[User]
You are a Common Lisp macro expert. Given this code pattern:
(when (symbolp x) (equal (symbol-name x) (string-upcase symbol)))

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

(when (symbolp x) (equal (symbol-name x) (string-upcase symbol)))

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

;; macroexpand:
(if (symbolp x) (equal (symbol-name x) (string-upcase symbol)))


[User]
Define a macro that eliminates this repetitive pattern:
(when name `(make-node ,name))

Issue: Macro call that should be transformed by when

(when name `(make-node ,name))

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

;; macroexpand:
(if name (sb-int:quasiquote (make-node #S(sb-impl::comma :expr name :kind 0))))


[User]
Create a Common Lisp macro for the following transformation. Before code:
(letrec-syntax common-lisp:nil :key common-lisp:nil)

What needs to change: Macro call that should be transformed by LETREC-SYNTAX

(letrec-syntax common-lisp:nil :key common-lisp:nil)

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

;; macroexpand:
(common-lisp:macrolet ()
  :key
  common-lisp:nil)


[User]
Define a macro that eliminates this repetitive pattern:
(define-bug with-fresh-env-scope-missing-env () () "with-fresh-env-scope expects a code object & an environment to be returned from it's body. However there was no environment returned.")

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

(define-bug with-fresh-env-scope-missing-env () () "with-fresh-env-scope expects a code object & an environment to be returned from it's body. However there was no environment returned.")

[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 with-fresh-env-scope-missing-env (:error-type varjo-error :prefix "Varjo Bug") nil "with-fresh-env-scope expects a code object & an environment to be returned from it's body. However there was no environment returned.")


[User]
Generate a defmacro form that transforms code like this:
(defsynonym generating :generate)

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

(defsynonym generating :generate)

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

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


[User]
You are a Common Lisp macro expert. Given this code pattern:
(ematch0 args (nil nil) ((list* '&aux rest) args) ((list* (list name) rest) (list* (list name ''_) (process-keyword-args rest))) ((list* (list name default) rest) (list* (list name default) (process-keyword-args rest))) ((list* (list name default pred) rest) (list* (list name default pred) (process-keyword-args rest))) ((list* name rest) (list* (list name ''_) (process-keyword-args rest))))

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

(ematch0 args (nil nil) ((list* '&aux rest) args) ((list* (list name) rest) (list* (list name ''_) (process-keyword-args rest))) ((list* (list name default) rest) (list* (list name default) (process-keyword-args rest))) ((list* (list name default pred) rest) (list* (list name default pred) (process-keyword-args rest))) ((list* name rest) (list* (list name ''_) (process-keyword-args rest))))

[Assistant]
(defmacro ematch0 (what &body clauses)
  `(match0 ,what
     ,@clauses
     (_ (error "level0 match error!"))))

;; macroexpand:
(match0 args (nil nil) ((list* (quote &aux) rest) args) ((list* (list name) rest) (list* (list name (quote (quote _))) (process-keyword-args rest))) ((list* (list name default) rest) (list* (list name default) (process-keyword-args rest))) ((list* (list name default pred) rest) (list* (list name default pred) (process-keyword-args rest))) ((list* name rest) (list* (list name (quote (quote _))) (process-keyword-args rest))) (_ (error "level0 match error!")))


[User]
Generate a defmacro form that transforms code like this:
(with-wcs-math-error-handling (ret (cos 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 (cos 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* ((#:g209 x) (#:g210 nil) (#:g211 (list #:g209))) (declare (ignorable #:g210) (type list #:g211) (dynamic-extent #:g211)) (catch (quote return-from-with-wcs-math-error-handling) (multiple-value-bind (ret) (call-with-wcs-math-error-handler (quote cos) #:g211) (flet ((check-wcs-math-result (&optional (ret ret) (arg-list #:g211)) (check-wcs-math-result ret arg-list))) (check-wcs-math-result)))))


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

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

(dlet nil)

[Assistant]
(defmacro DLET ...)

;; macroexpand:
(dynamic-let nil)


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

Issue: Macro call that should be transformed by DEFMETHOD

(defmethod nil
  :key
  nil)

[Assistant]
(defmacro DEFMETHOD ...)

;; macroexpand:
(common-lisp:defmethod nil :key ())


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

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

(xor nil nil 1 nil)

[Assistant]
(defmacro xor (&rest datums)
  "Evaluates its arguments one at a time, from left to right. If more than one
argument evaluates to a true value no further DATUMS are evaluated, and NIL is
returned as both primary and secondary value. If exactly one argument
evaluates to true, its value is returned as the primary value after all the
arguments have been evaluated, and T is returned as the secondary value. If no
arguments evaluate to true NIL is returned as primary, and T as secondary
value."
  (with-gensyms (xor tmp true)
    `(let (,tmp ,true)
       (declare (ignorable ,tmp))
       (block ,xor
         ,@(mapcar (lambda (datum)
                     `(if (setf ,tmp ,datum)
                          (if ,true
                              (return-from ,xor (values nil nil))
                              (setf ,true ,tmp))))
                   datums)
         (return-from ,xor (values ,true t))))))

;; macroexpand:
(let (#:tmp141 #:true142) (declare (ignorable #:tmp141)) (block #:xor140 (if (setf #:tmp141 nil) (if #:true142 (return-from #:xor140 (values nil nil)) (setf #:true142 #:tmp141))) (if (setf #:tmp141 nil) (if #:true142 (return-from #:xor140 (values nil nil)) (setf #:true142 #:tmp141))) (if (setf #:tmp141 1) (if #:true142 (return-from #:xor140 (values nil nil)) (setf #:true142 #:tmp141))) (if (setf #:tmp141 nil) (if #:true142 (return-from #:xor140 (values nil nil)) (setf #:true142 #:tmp141))) (return-from #:xor140 (values #:true142 t))))


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

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

(defstruct*
  'some-name)

[Assistant]
(defmacro DEFSTRUCT* ...)

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


[User]
Write a Common Lisp macro to handle this code pattern:
(defclause summing-to (vars &optional result-processor) "Specifies an accumulation strategy with 0 as the default value and + as the accumulator function." `(accumulating-to ,vars :initially 0 :by #'+ :finally ,result-processor))

Problem: Macro call that should be transformed by defclause

(defclause summing-to (vars &optional result-processor) "Specifies an accumulation strategy with 0 as the default value and + as the accumulator function." `(accumulating-to ,vars :initially 0 :by #'+ :finally ,result-processor))

[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 summing-to (vars &optional result-processor) "Specifies an accumulation strategy with 0 as the default value and + as the accumulator function." (sb-int:quasiquote (accumulating-to #S(sb-impl::comma :expr vars :kind 0) :initially 0 :by (function +) :finally #S(sb-impl::comma :expr result-processor :kind 0)))) (pushnew (quote summing-to) *clauses*))


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

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

(fgathering nil
  (progn))

[Assistant]
(defmacro FGATHERING ...)

;; macroexpand:
(flet ()
  (progn)
  (values))


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

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

(defcell a 0)

[Assistant]
(defmacro defcell (name value-form &environment env)
  "Define a global cell identified by NAME.

This macro defines a cell identified by NAME with its value computed
by VALUE-FORM. The value of the cell can be referenced by the symbol
NAME following the DEFCELL form.

If VALUE-FORM is a constant, by CONSTANTP, a mutable cell is defined
which can have its value set directly using SETF or SETQ on the symbol
NAME.

If VALUE-FORM is not a constant a computed cell is created. A computed
cell may reference one or more argument cells in VALUE-FORM or a
function called during the evaluation of VALUE-FORM.  When the values
of any of the argument cells change, the value of the computed cell is
recomputed by evaluating VALUE-FORM again. The referenced argument
cells are determined automatically when the VALUE-FORM is evaluated.

This macro creates a cell definition that is visible globally to all
forms unless it is lexically shadowed by a definition with the same
NAME using CELL-LET. Note that despite being visible globally, the
cell definition is still lexically scoped and not dynamically scoped
like global variables defined with DEFVAR or DEFPARAMETER."

  (if (constantp value-form env)
      `(define-mutable-cell% ,name ,value-form)
      `(define-computed-cell% ,name ,value-form)))

;; macroexpand:
(define-mutable-cell% a 0)


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

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

(or 'some-name)

[Assistant]
(defmacro OR ...)

;; macroexpand:
(the t 'some-name)


[User]
Create a Common Lisp macro for the following transformation. Before code:
(with-package (package) (let ((nicks (package-nicknames package))) (unless (member nickname nicks :test #'string=) (rename-package package (package-name package) (cons nickname nicks)))))

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

(with-package (package) (let ((nicks (package-nicknames package))) (unless (member nickname nicks :test #'string=) (rename-package package (package-name package) (cons nickname nicks)))))

[Assistant]
(defmacro with-package ((var &optional (package var)) &body body)
  `(let ((,var (ensure-package ,package)))
     ,@body))

;; macroexpand:
(let ((package (ensure-package package))) (let ((nicks (package-nicknames package))) (unless (member nickname nicks :test (function string=)) (rename-package package (package-name package) (cons nickname nicks)))))


[User]
Write a Common Lisp macro to handle this code pattern:
(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))

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

(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))

[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 name (arg1 arg2) (:method (arg1 arg2) |"DOCSTRING"| (quote body-form))))


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

Problem: Macro call that should be transformed by COLLECT-AND

(collect-and nil)

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

;; macroexpand:
(common-lisp:let* ((#:generator-495 (generator nil)) #:bools-491 (#:bool-492 t))
  (declare (type generator #:generator-495))
  (tagbody
   #:ll-496
    (setq #:bools-491 (next-in #:generator-495 (go end)))
    (if (null (setq #:bool-492 #:bools-491))
        (go end))
    (go #:ll-496)
   end)
  #:bool-492)


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

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

(fgather-result 'some-name)

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

;; macroexpand:
('some-name nil t)


[User]
Generate a defmacro form that transforms code like this:
(define-method-combination% list)

Pattern to recognize: Macro call that should be transformed by define-method-combination%

(define-method-combination% list)

[Assistant]
(defmacro define-method-combination% (name &rest args)
  "Define a method-combination for the static-dispatch system only.

   Arguments are of the same form as to CL:DEFINE-METHOD-COMBINATION."

  `(eval-when (:compile-toplevel :load-toplevel :execute)
     (setf
      (combination-function ',name)
      ,(match args
         ((or nil
              (list* (and (type symbol) (not nil)) _))

          (destructuring-bind (&key (operator name) (identity-with-one-argument nil))
              args

            `(method-combination-function-short ,name ,operator ,identity-with-one-argument)))

         (_
          `(method-combination-function ,name ,@args))))))

;; macroexpand:
(eval-when (:compile-toplevel :load-toplevel :execute) (setf (combination-function (quote list)) (method-combination-function-short list list nil)))


[User]
Create a Common Lisp macro for the following transformation. Before code:
(define-option-expander export (package &rest symbols) (export (mapcar #'(lambda (s) (intern (string s) package)) symbols) package))

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

(define-option-expander export (package &rest symbols) (export (mapcar #'(lambda (s) (intern (string s) package)) symbols) package))

[Assistant]
(defmacro define-option-expander (name (package &rest arguments) &body body)
  (let ((args (gensym "ARGS")))
    `(defmethod expand-option ((,(gensym "TYPE") (eql ,(intern (string name) "KEYWORD"))) ,package ,args)
       (destructuring-bind ,arguments ,args
         ,@body))))

;; macroexpand:
(defmethod expand-option ((#:type134 (eql :export)) package #:args133) (destructuring-bind (&rest symbols) #:args133 (export (mapcar (function (lambda (s) (intern (string s) package))) symbols) package)))


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

Pattern to recognize: Macro call that should be transformed by define-simple-definition-resolver

(define-simple-definition-resolver compiler-macro compiler-macro-function)

[Assistant]
(defmacro define-simple-definition-resolver (class lookup-function &body body)
  (let ((package (gensym "PACKAGE")))
    `(define-definition-resolver ,class (,class ,package)
       (when (ignore-errors ,(if body
                                 `(let ((,(first lookup-function) ,class))
                                    ,@body)
                                 `(,lookup-function ,class)))
         (list (make-instance ',class :designator ,class :package ,package))))))

;; macroexpand:
(define-definition-resolver compiler-macro (compiler-macro #:package135) (when (ignore-errors (compiler-macro-function compiler-macro)) (list (make-instance (quote compiler-macro) :designator compiler-macro :package #:package135))))


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

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

(iterate nil :key nil)

[Assistant]
(defmacro ITERATE ...)

;; macroexpand:
(progn (tagbody #:ll-255 ((lambda () :key nil)) (go #:ll-255)) nil)


[User]
You are a Common Lisp macro expert. Given this code pattern:
(defalias path:relative-p (pathname) cl-fad:pathname-relative-p)

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

(defalias path:relative-p (pathname) cl-fad:pathname-relative-p)

[Assistant]
(defmacro defalias (name args realname)
  `(progn
     (defun ,name ,args
       ,(if (eql '&rest (first args))
            `(apply #',realname ,(second args))
            `(,realname ,@args)))
     (define-compiler-macro ,name (&rest args)
       (list* ',realname args))))

;; macroexpand:
(progn (defun path:relative-p (pathname) (pathname-relative-p pathname)) (define-compiler-macro path:relative-p (&rest args) (list* (quote pathname-relative-p) args)))


[User]
You are a Common Lisp macro expert. Given this code pattern:
(*> +any-crlf+ +skipws1+)

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

(*> +any-crlf+ +skipws1+)

[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 (#:*>-offset134) (multiple-value-bind (#:*>-res135 #:*>-next136) (funcall +any-crlf+ #:*>-offset134) (if (ok? #:*>-res135) (funcall +skipws1+ #:*>-next136) (fail #:*>-next136))))


[User]
Write a Common Lisp macro to handle this code pattern:
(with-decoder-simple-list-semantics (is (equalp '((:hello . "hej") (:hi . "tjena")) (decode-json-from-string input))) (is-false (decode-json-from-string " { } ")) (is-false (decode-json-from-string "{}")))

Problem: Macro call that should be transformed by with-decoder-simple-list-semantics

(with-decoder-simple-list-semantics (is (equalp '((:hello . "hej") (:hi . "tjena")) (decode-json-from-string input))) (is-false (decode-json-from-string " { } ")) (is-false (decode-json-from-string "{}")))

[Assistant]
(defmacro with-decoder-simple-list-semantics (&body body)
  "Execute BODY in a dynamic environement where the decoder semantics
is such as set by SET-DECODER-SIMPLE-LIST-SEMANTICS."
  `(with-shadowed-custom-vars
     (set-decoder-simple-list-semantics)
     ,@body))

;; macroexpand:
(with-shadowed-custom-vars (set-decoder-simple-list-semantics) (is (equalp (quote ((:hello . "hej") (:hi . "tjena"))) (decode-json-from-string input))) (is-false (decode-json-from-string " { } ")) (is-false (decode-json-from-string "{}")))


[User]
Write a Common Lisp macro to handle this code pattern:
(define-method-combination% append :operator append :identity-with-one-argument t)

Problem: Macro call that should be transformed by define-method-combination%

(define-method-combination% append :operator append :identity-with-one-argument t)

[Assistant]
(defmacro define-method-combination% (name &rest args)
  "Define a method-combination for the static-dispatch system only.

   Arguments are of the same form as to CL:DEFINE-METHOD-COMBINATION."

  `(eval-when (:compile-toplevel :load-toplevel :execute)
     (setf
      (combination-function ',name)
      ,(match args
         ((or nil
              (list* (and (type symbol) (not nil)) _))

          (destructuring-bind (&key (operator name) (identity-with-one-argument nil))
              args

            `(method-combination-function-short ,name ,operator ,identity-with-one-argument)))

         (_
          `(method-combination-function ,name ,@args))))))

;; macroexpand:
(eval-when (:compile-toplevel :load-toplevel :execute) (setf (combination-function (quote append)) (method-combination-function-short append append t)))


[User]
Define a macro that eliminates this repetitive pattern:
(define-test bad-var (is eql a 'c))

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

(define-test bad-var (is eql a 'c))

[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 bad-var) (find-package #A((9) base-char . "PARACHUTE"))) (ensure-test (quote test) :name (quote bad-var) :home (find-package #A((9) base-char . "PARACHUTE")) :tests (list (lambda nil (is eql a (quote c)))) :parent (quote nil))) (quote bad-var))


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

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

(rte-case nil)

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

;; macroexpand:
(let ((#:rte169 nil))
  (typecase #:rte169
    ((not sequence) nil)
    (t
     (funcall
      (lambda (#:rte169)
        (declare (optimize (speed 3) (debug 0) (safety 0)))
        (block check
          (typecase #:rte169
            (list nil)
            (simple-vector
             (let ((i 0) (len (length #:rte169)))
               (declare (type (and unsigned-byte fixnum) i len)
                        (ignorable len))
               nil))
            (vector
             (let ((i 0) (len (length #:rte169)))
               (declare (type (and fixnum unsigned-byte) i len)
                        (ignorable len))
               nil))
            (sequence
             (let ((i 0) (len (sb-sequence:length #:rte169)))
               (declare (type (and fixnum unsigned-byte) i len)
                        (ignorable len))
               nil))
            (t nil))))
      #:rte169))))


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

What needs to change: Macro call that should be transformed by DYNAMIC-PROGV

(dynamic-progv nil
    nil)

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

;; macroexpand:
(let* ((#:fixed-symbols235 nil)
       (#:fixed-bindings236 (compute-bindings #:fixed-symbols235 nil)))
  (dynamic-wind
    :proceed
    #:proceed237
    (progv #:fixed-symbols235 #:fixed-bindings236 (#:proceed237))))


[User]
Generate a defmacro form that transforms code like this:
(if-let ((x 2) (y x)) (+ x y) :oops)

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

(if-let ((x 2) (y x)) (+ x y) :oops)

[Assistant]
(defmacro if-let (bindings &body (then-form &optional else-form))
    "Creates new variable bindings, and conditionally executes either
THEN-FORM or ELSE-FORM. ELSE-FORM defaults to NIL.

BINDINGS must be either single binding of the form:

 (variable initial-form)

or a list of bindings of the form:

 ((variable-1 initial-form-1)
  (variable-2 initial-form-2)
  ...
  (variable-n initial-form-n))

All initial-forms are executed sequentially in the specified order. Then all
the variables are bound to the corresponding values.

If all variables were bound to true values, the THEN-FORM is executed with the
bindings in effect, otherwise the ELSE-FORM is executed with the bindings in
effect."
    (let* ((binding-list (if (and (consp bindings) (symbolp (car bindings)))
                             (list bindings)
                             bindings))
         (variables (mapcar #'car binding-list)))
    `(let ,binding-list
       (if (and ,@variables)
           ,then-form
           ,else-form))))

;; macroexpand:
(let ((x 2) (y x)) (if (and x y) (+ x y) :oops))


[User]
Write a Common Lisp macro to handle this code pattern:
(with-special-initargs nil
  :key
  nil)

Problem: Macro call that should be transformed by WITH-SPECIAL-INITARGS

(with-special-initargs nil
  :key
  nil)

[Assistant]
(defmacro WITH-SPECIAL-INITARGS ...)

;; macroexpand:
(funcall-with-special-initargs (list) (lambda () :key nil))


[User]
Create a Common Lisp macro for the following transformation. Before code:
(assert-values ("added foo = nil") (foo nil) (foo+1 nil) (bar 'nothing) (bar-1 'nothing))

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

(assert-values ("added foo = nil") (foo nil) (foo+1 nil) (bar 'nothing) (bar-1 '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 "added foo = nil") (assert (eql (value foo) nil)) (assert (eql (value foo+1) nil)) (assert (eql (value bar) (quote nothing))) (assert (eql (value bar-1) (quote nothing))))


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

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

(->> 'some-name)

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

;; macroexpand:
'some-name


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

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

(define-simple-object-lookup function fdefinition)

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

;; macroexpand:
(defmethod object ((function function)) (fdefinition (designator function)))


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

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

(defun+ nil
    (progn))

[Assistant]
(defmacro DEFUN+ ...)

;; macroexpand:
(defun nil (#:g128) (let+ ((progn #:g128))))


[User]
Create a Common Lisp macro for the following transformation. Before code:
(defhandler declare (declare &rest body) `(list ',declare ,@(mapcar (lambda (f) `',f) body)))

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

(defhandler declare (declare &rest body) `(list ',declare ,@(mapcar (lambda (f) `',f) 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-declare (declare &rest body) (sb-int:quasiquote (list (quote #S(sb-impl::comma :expr declare :kind 0)) #S(sb-impl::comma :expr (mapcar (lambda (f) (sb-int:quasiquote (quote #S(sb-impl::comma :expr f :kind 0)))) body) :kind 2)))) (setf (gethash (quote declare) *form-handler*) (quote hander-declare)))


[User]
Create a Common Lisp macro for the following transformation. Before code:
(defalias path:-e (pathname) cl-fad:file-exists-p)

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

(defalias path:-e (pathname) cl-fad:file-exists-p)

[Assistant]
(defmacro defalias (name args realname)
  `(progn
     (defun ,name ,args
       ,(if (eql '&rest (first args))
            `(apply #',realname ,(second args))
            `(,realname ,@args)))
     (define-compiler-macro ,name (&rest args)
       (list* ',realname args))))

;; macroexpand:
(progn (defun path:-e (pathname) (file-exists-p pathname)) (define-compiler-macro path:-e (&rest args) (list* (quote file-exists-p) args)))


[User]
You are a Common Lisp macro expert. Given this code pattern:
(define-custom-var (:end-of-string *end-of-string-handler*))

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

(define-custom-var (:end-of-string *end-of-string-handler*))

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

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


[User]
You are a Common Lisp macro expert. Given this code pattern:
(defhandler progv (progv symbols values &rest body) `(list ',progv (list ,@(e-list symbols)) (list ,@(e-list values)) ,@(e-list body)))

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

(defhandler progv (progv symbols values &rest body) `(list ',progv (list ,@(e-list symbols)) (list ,@(e-list values)) ,@(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-progv (progv symbols values &rest body) (sb-int:quasiquote (list (quote #S(sb-impl::comma :expr progv :kind 0)) (list #S(sb-impl::comma :expr (e-list symbols) :kind 2)) (list #S(sb-impl::comma :expr (e-list values) :kind 2)) #S(sb-impl::comma :expr (e-list body) :kind 2)))) (setf (gethash (quote progv) *form-handler*) (quote hander-progv)))


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

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

(advisable-lambda 'some-name)

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

;; macroexpand:
(make-instance 'advisable-function :main #'(lambda (quote some-name))
               :arguments ''some-name :dispatcher-generator
               #'(lambda (#:fobj130)
                   #'(lambda (quote some-name)
                       #A((29) base-char . "Advisable function dispatcher")
                       (let ((#:fixed131
                              (append (list quote) (list some-name))))
                         (apply-before #:fobj130 #:fixed131)
                         (multiple-value-prog1
                             (apply-around #:fobj130 #:fixed131)
                           (apply-after #:fobj130 #:fixed131))))))


[User]
You are a Common Lisp macro expert. Given this code pattern:
(deferror "42P04" duplicate-database syntax-error-or-access-violation)

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

(deferror "42P04" duplicate-database syntax-error-or-access-violation)

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

;; macroexpand:
(progn (define-condition duplicate-database (syntax-error-or-access-violation) nil) (setf (gethash "42P04" *error-table*) (quote duplicate-database)))


[User]
Define a macro that eliminates this repetitive pattern:
(when (eql (top-sign) 'skip-first) (pop-sign))

Issue: Macro call that should be transformed by when

(when (eql (top-sign) 'skip-first) (pop-sign))

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

;; macroexpand:
(if (eql (top-sign) (quote skip-first)) (pop-sign))


[User]
Create a Common Lisp macro for the following transformation. Before code:
(with-html-string (:div :class "status col-xs-2 col-md-1" (:span :class "text-success" (:a :href "https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#200" 200))))

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

(with-html-string (:div :class "status col-xs-2 col-md-1" (:span :class "text-success" (:a :href "https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#200" 200))))

[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 (:div :class "status col-xs-2 col-md-1" (:span :class "text-success" (:a :href "https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#200" 200)))))


[User]
Generate a defmacro form that transforms code like this:
(c? (incf plus-ct) (trc nil "m-plus rule firing!!!!!!!!!!!!!!" plus-ct) (f-plusp :syna-2 (- 2 (^m-syn-a))))

Pattern to recognize: Macro call that should be transformed by c?

(c? (incf plus-ct) (trc nil "m-plus rule firing!!!!!!!!!!!!!!" plus-ct) (f-plusp :syna-2 (- 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 plus-ct) (trc nil "m-plus rule firing!!!!!!!!!!!!!!" plus-ct) (f-plusp :syna-2 (- 2 (^m-syn-a))))) :value-state :unevaluated :rule (c-lambda (incf plus-ct) (trc nil "m-plus rule firing!!!!!!!!!!!!!!" plus-ct) (f-plusp :syna-2 (- 2 (^m-syn-a)))))


[User]
Generate a defmacro form that transforms code like this:
(alet (1+ 1) it (1+ it))

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

(alet (1+ 1) it (1+ it))

[Assistant]
(defmacro alet (form &body body)
  "Binds the FORM to IT (via LET) in the scope of the BODY."
  `(anaphoric ignore-first ,form (progn ,@body)))

;; macroexpand:
(anaphoric ignore-first (1+ 1) (progn it (1+ it)))


[User]
You are a Common Lisp macro expert. Given this code pattern:
(when (slot-value parent 'tail-qualifiers) (format stream " "))

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

(when (slot-value parent 'tail-qualifiers) (format stream " "))

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

;; macroexpand:
(if (slot-value parent (quote tail-qualifiers)) (format stream " "))


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

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

(do () (progn))

[Assistant]
(defmacro DO ...)

;; macroexpand:
(block nil
  (let ()
    (declare (ignorable))
    (tagbody
      (go #:g193)
     #:g192
      (tagbody)
      (psetq)
     #:g193
      (unless progn (go #:g192))
      (return-from nil (progn)))))


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

Issue: Macro call that should be transformed by COLLECT-FIRST

(collect-first nil)

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

;; macroexpand:
(common-lisp:let* ((#:generator-616 (generator nil))
                   #:items-610
                   (#:item-612 nil))
  (declare (type generator #:generator-616)
           (type (null-or t) #:item-612))
  (tagbody
   #:ll-617
    (setq #:items-610 (next-in #:generator-616 (go end)))
    (setq #:item-612 #:items-610)
   end)
  #:item-612)


[User]
You are a Common Lisp macro expert. Given this code pattern:
(with-html-string (:p "foo" "bar" (values "baz")))

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

(with-html-string (:p "foo" "bar" (values "baz")))

[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 (:p "foo" "bar" (values "baz"))))


[User]
Define a macro that eliminates this repetitive pattern:
(define-path-instruction-pair smooth-quadratic-curve-to "T" (x y))

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

(define-path-instruction-pair smooth-quadratic-curve-to "T" (x y))

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

;; macroexpand:
(progn (defun smooth-quadratic-curve-to (x y) (format-instruction "T" x y)) (defun smooth-quadratic-curve-to-r (x y) (format-instruction "t" x y)))


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

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

(list-of nil
  nil)

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

;; macroexpand:
(lc (nil nil) collect)


[User]
You are a Common Lisp macro expert. Given this code pattern:
(with-html-string (:p "foo" "bar" "baz"))

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

(with-html-string (:p "foo" "bar" "baz"))

[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 (:p "foo" "bar" "baz")))


[User]
Define a macro that eliminates this repetitive pattern:
(is (not (some #'test-failure-p results)))

Issue: Macro call that should be transformed by is

(is (not (some #'test-failure-p results)))

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

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

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

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

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

;; macroexpand:
(let ((#:e244 (function test-failure-p)) (#:a245 results)) (if (progn (not (some #:e244 #:a245))) (add-result (quote test-passed) :test-expr (quote (not (some (function test-failure-p) results)))) (process-failure (quote (not (some (function test-failure-p) results))) "~2&~S~2% evaluated to ~2&~S~2% which is ~2&~S~2%to ~2&~S~2% (it should not be)" (quote results) #:a245 (quote some) #:e244)))


[User]
Define a macro that eliminates this repetitive pattern:
(defun-speedy ascii-string-to-octets (string) (%ascii-string-to-octets string))

Issue: Macro call that should be transformed by defun-speedy

(defun-speedy ascii-string-to-octets (string) (%ascii-string-to-octets string))

[Assistant]
(defmacro defun-speedy (name lambda-list &body body)
  `(progn
     (declaim (notinline ,name))
     (defun ,name ,lambda-list
       ,*speedy-declaration*
       ,@body)))

;; macroexpand:
(progn (declaim (notinline ascii-string-to-octets)) (defun ascii-string-to-octets (string) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0))) (%ascii-string-to-octets string)))