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

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

(some-> nil (progn))

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

;; macroexpand:
(let* ((#:g143 nil))
  (if (null #:g143)
      nil
      (-> #:g143 (progn))))


[User]
Define a macro that eliminates this repetitive pattern:
(when export `(export '(,name ,@slot-list)))

Issue: Macro call that should be transformed by when

(when export `(export '(,name ,@slot-list)))

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

;; macroexpand:
(if export (sb-int:quasiquote (export (quote (#S(sb-impl::comma :expr name :kind 0) #S(sb-impl::comma :expr slot-list :kind 2))))))


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

Issue: Macro call that should be transformed by LAMBDA*

(lambda* nil
  :key
  nil)

[Assistant]
(defmacro LAMBDA* ...)

;; macroexpand:
(lambda () (the t (block nil :key nil)))


[User]
Create a Common Lisp macro for the following transformation. Before code:
(do+ (for x (from 0)) (generating y (across #(0 1))) (collect (list x y)) (when (oddp x) (is (= (update y) y))))

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

(do+ (for x (from 0)) (generating y (across #(0 1))) (collect (list x y)) (when (oddp x) (is (= (update y) y))))

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

;; macroexpand:
(do+/internal nil (for x (from 0)) (generating y (across #(0 1))) (collect (list x y)) (when (oddp x) (is (= (update y) y))))


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

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

(define-template nil nil)

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

;; macroexpand:
(defmacro define-nil (&optional (#:name126))
  (flet ((template-unfulfillable ()
           (error 'template-unfulfillable :template 'nil :arguments (list))))
    (declare (ignorable (function template-unfulfillable)))
    (let ((body (progn)) (name (or #:name126 (compose-name #\SOLIDUS 'nil))))
      `(progn
        (declaim
         (ftype
          (function
           ,(loop with types = (declared-variable-types body)
                  for arg in (quote nil)
                  collect (or (second (assoc arg types)) (quote t)))
           ,(declared-return-type body))
          ,name)
         ,@(when (find (quote inline) (declarations body)) `((inline ,name))))
        (defun ,name ,'nil
          (declare (optimize speed (safety 0) (debug 0) (compilation-speed 0))
                   ,@(remove (quote inline) (declarations body)))
          ,@(remove-if #'declaration-p body))))))


[User]
Generate a defmacro form that transforms code like this:
(with-mocks () (register-mock 'foo) (let ((sym (gensym))) (foo sym) (is (equal `((foo ,sym)) (invocations)))))

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

(with-mocks () (register-mock 'foo) (let ((sym (gensym))) (foo sym) (is (equal `((foo ,sym)) (invocations)))))

[Assistant]
(defmacro with-mocks ((&key (recordp T)) &body body)
  "Execute BODY in a new mocking context.  Invocations will be recorded
if RECORDP is set (default true)."
  `(call-with-mocks
    (lambda () ,@body)
    :recordp ,recordp))

;; macroexpand:
(call-with-mocks (lambda nil (register-mock (quote foo)) (let ((sym (gensym))) (foo sym) (is (equal (sb-int:quasiquote ((foo #S(sb-impl::comma :expr sym :kind 0)))) (invocations))))) :recordp t)


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

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

(lambda () (progn))

[Assistant]
(defmacro LAMBDA ...)

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


[User]
Create a Common Lisp macro for the following transformation. Before code:
(define-error switch-type-error () (form) "Currently the clause forms of a switch must all be either ints, uints, floats or doubles:~%Code:~%~a" form)

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

(define-error switch-type-error () (form) "Currently the clause forms of a switch must all be either ints, uints, floats or doubles:~%Code:~%~a" form)

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

;; macroexpand:
(defcondition switch-type-error (:error-type varjo-error :prefix "Varjo") (form) "Currently the clause forms of a switch must all be either ints, uints, floats or doubles:~%Code:~%~a" form)


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

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

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

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

Example:

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

;; macroexpand:
(let ((#:key237 "foo") (#:store238 storage) (#:expire239 nil)) (multiple-value-bind (#:value240 #:exists-p241) (getcache #:key237 #:store238) (if #:exists-p241 #:value240 (let ((#:value240 (progn (error "MUST NOT BE ERROR")))) (setcache #:key237 #:value240 #:store238 :expire #:expire239) #:value240))))


[User]
Define a macro that eliminates this repetitive pattern:
(action (:after node-bind node) (multiple-value-bind (new-node new-changed?) (maybe-collapse-bind node) (when new-changed? (setf changed? t) new-node)))

Issue: Macro call that should be transformed by action

(action (:after node-bind node) (multiple-value-bind (new-node new-changed?) (maybe-collapse-bind node) (when new-changed? (setf changed? t) new-node)))

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

;; macroexpand:
(make-action (quote :after) (quote node-bind) (lambda (node) (declare (type node-bind node)) (multiple-value-bind (new-node new-changed?) (maybe-collapse-bind node) (when new-changed? (setf changed? t) new-node))))


[User]
You are a Common Lisp macro expert. Given this code pattern:
(with-yield-binds (format nil "~{~A~^, ~}" (mapcar (lambda (element) (if (sql-statement-p element) (format nil "(~A)" (yield element)) (yield element))) (sql-list-elements list))))

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

(with-yield-binds (format nil "~{~A~^, ~}" (mapcar (lambda (element) (if (sql-statement-p element) (format nil "(~A)" (yield element)) (yield element))) (sql-list-elements list))))

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

;; macroexpand:
(let ((*bind-values* nil) (*use-global-bind-values* t)) (values (progn (format nil "~{~A~^, ~}" (mapcar (lambda (element) (if (sql-statement-p element) (format nil "(~A)" (yield element)) (yield element))) (sql-list-elements list)))) (loop for bind in (reverse *bind-values*) append bind)))


[User]
Write a Common Lisp macro to handle this code pattern:
(like "truth" "^true")

Problem: Macro call that should be transformed by like

(like "truth" "^true")

[Assistant]
(defmacro like (got regex &optional desc)
  (with-gensyms (duration result)
    (once-only (regex desc)
      `(with-catching-errors (:description ,desc :expected ,regex)
         (with-duration ((,duration ,result) ,got)
           (test ,result ,regex ,desc
                 :duration ,duration
                 :test-fn (lambda (x y) (not (null (ppcre:scan y x))))
                 :report-expected-label "be like"))))))

;; macroexpand:
(let ((#:regex211 "^true") (#:desc212 nil)) (with-catching-errors (:description #:desc212 :expected #:regex211) (with-duration ((#:duration209 #:result210) "truth") (test #:result210 #:regex211 #:desc212 :duration #:duration209 :test-fn (lambda (x y) (not (null (cl-ppcre:scan y x)))) :report-expected-label "be like"))))


[User]
You are a Common Lisp macro expert. Given this code pattern:
(defclause (until expr) "Exit loop if test is non-nil" (setq *loop-end-used?* t) (return-code :body `((if ,(walk-expr expr) (go ,*loop-end*)))))

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

(defclause (until expr) "Exit loop if test is non-nil" (setq *loop-end-used?* t) (return-code :body `((if ,(walk-expr expr) (go ,*loop-end*)))))

[Assistant]
(defmacro defclause (clause-template &body body)
  (define-clause 'defun clause-template body nil))

;; macroexpand:
(eval-when (:compile-toplevel :load-toplevel :execute) (defun clause-until-15 (&key ((:until expr))) "Exit loop if test is non-nil" (setq *loop-end-used?* t) (return-code :body (sb-int:quasiquote ((if #S(sb-impl::comma :expr (walk-expr expr) :kind 0) (go #S(sb-impl::comma :expr *loop-end* :kind 0))))))) (install-clause-info (quote (until)) (quote (until)) (quote clause-until-15) "Exit loop if test is non-nil" nil) (quote (until expr)))


[User]
Generate a defmacro form that transforms code like this:
(receive (one two three four) (values 1 2 3) (list one two three four))

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

(receive (one two three four) (values 1 2 3) (list one two three four))

[Assistant]
(defmacro receive (formals expr &body body)
  "Stricter version of `multiple-value-bind'.

Use `receive' when you want to enforce that EXPR should return a
certain number of values, or a minimum number of values.

If FORMALS is a proper list, then EXPR must return exactly as many
values -- no more and no less -- as there are variables in FORMALS.

If FORMALS is an improper list (VARS . REST), then EXPR must return at
least as many values as there are VARS, and any further values are
bound, as a list, to REST.

Lastly, if FORMALS is a symbol, bind that symbol to all the values
returned by EXPR, as if by `multiple-value-list'.

From Scheme (SRFI-8)."
  ;; It's probably not worth stack-allocating the thunk.
  (cond ((null formals)
         `(multiple-value-call
              (lambda ()
                ,@body)
            ,expr))
        ((atom formals)
         ;; This could also be written:
         #+(or) `(let ((,formals (multiple-value-list ,expr)))
                   ,@body)
         ;; But I want it to be possible to declare FORMALS to have
         ;; dynamic extent, and most Lisps support that for &rest
         ;; lists.
         `(multiple-value-call
              (lambda (&rest ,formals)
                ,@body)
            ,expr))
        ((proper-list-p formals)
         (when (intersection formals lambda-list-keywords)
           (error "Lambda list keywords in formals: ~a" formals))
         `(multiple-value-call
              (lambda ,formals
                ,@body)
            ,expr))
        (t (let* ((last (last formals))
                  (vars (append (butlast formals)
                                (list (car last))))
                  (rest (cdr last)))
             (when (intersection (cons rest vars) lambda-list-keywords)
               (error "Lambda list keywords in formals: ~a" formals))
             `(multiple-value-call
                  (lambda (,@vars &rest ,rest)
                    ,@body)
                ,expr)))))

;; macroexpand:
(multiple-value-call (lambda (one two three four) (list one two three four)) (values 1 2 3))


[User]
Generate a defmacro form that transforms code like this:
(rem-plist-val! nil nil)

Pattern to recognize: Macro call that should be transformed by REM-PLIST-VAL!

(rem-plist-val! nil nil)

[Assistant]
(defmacro rem-plist-val! (id place &key (test '(default-test)) (key '(default-key)))
  `(setf ,place
    (rem-plist-val ,id ,place :test ,test :key ,key)))

;; macroexpand:
(setf nil (rem-plist-val nil nil :test (default-test) :key (default-key)))


[User]
Define a macro that eliminates this repetitive pattern:
(~> (-> :g (a) (+ 1 a)) (list nil) (-> :g (a) (+ a 2)) (>> (-> :g (b) (+ b 6)) (-> :g (b) (+ b 7))) (list (-> :g (a) (+ a 3)) (-> :g (a) (+ a 4)) (-> :g (a) (values (+ a 5) -1))))

Issue: Macro call that should be transformed by ~>

(~> (-> :g (a) (+ 1 a)) (list nil) (-> :g (a) (+ a 2)) (>> (-> :g (b) (+ b 6)) (-> :g (b) (+ b 7))) (list (-> :g (a) (+ a 3)) (-> :g (a) (+ a 4)) (-> :g (a) (values (+ a 5) -1))))

[Assistant]
(defmacro ~> (&rest body)
  "See flow:concurrently"
  `(concurrently ,@body))

;; macroexpand:
(concurrently (-> :g (a) (+ 1 a)) (list nil) (-> :g (a) (+ a 2)) (>> (-> :g (b) (+ b 6)) (-> :g (b) (+ b 7))) (list (-> :g (a) (+ a 3)) (-> :g (a) (+ a 4)) (-> :g (a) (values (+ a 5) -1))))


[User]
Define a macro that eliminates this repetitive pattern:
(is (= 3 (length results)))

Issue: Macro call that should be transformed by is

(is (= 3 (length 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 ((#:e223 3) (#:a224 (length results))) (if (progn (= #:e223 #:a224)) (add-result (quote test-passed) :test-expr (quote (= 3 (length results)))) (process-failure (quote (= 3 (length results))) "~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%" (quote (length results)) #:a224 (quote =) #:e223)))


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

Problem: Macro call that should be transformed by WITH-ACCESS-VALUES

(with-access-values nil
    :key
  nil)

[Assistant]
(defmacro with-access-values ((&rest bindings) obj &body body)
  "A macro which binds local variables from accessed values on object
   according to bindings

   bindings: (local-symbol-and-access-key
              or (local-symbol access-key)
               ...)
   obj: the thing we are accessing data from
  "
  (flet ((key-for (it)
           (etypecase it
             (symbol `(quote ,it))
             ((or string keyword list) it))))
    (let* ((o (gensym "OBJ"))
           (expanded-bindings
             (iter (for b in (ensure-list bindings))
               (when (first-iteration-p)
                 (collect `(,o ,obj)))
               (typecase b
                 (null)
                 (list (collect `(,(first b) (access ,o ,(key-for (second b))))))
                 (symbol (collect `(,b (access ,o ,(key-for b)))))))))
      `(let* ,expanded-bindings
        ,@body))))

;; macroexpand:
(let* ()
  nil)


[User]
Generate a defmacro form that transforms code like this:
(builder (:auth/basic :authenticator (lambda (user pass) (and (string= user "hoge") (string= pass "fuga")))) (lambda (env) `(200 () (,(format nil "Hello, ~A" (getf env :remote-user))))))

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

(builder (:auth/basic :authenticator (lambda (user pass) (and (string= user "hoge") (string= pass "fuga")))) (lambda (env) `(200 () (,(format nil "Hello, ~A" (getf env :remote-user))))))

[Assistant]
(defmacro builder (&rest app-or-middlewares)
  (let ((middlewares (butlast app-or-middlewares)))
    `(reduce #'funcall
             (remove-if
              #'null
              (list
               ,@(loop for mw in middlewares
                       when mw
                         collect (convert-to-middleware-form mw))))
             :initial-value (to-app ,(car (last app-or-middlewares)))
             :from-end t)))

;; macroexpand:
(reduce (function funcall) (remove-if (function null) (list (lambda (#:app186) (funcall (find-middleware :auth/basic) #:app186 :authenticator (lambda (user pass) (and (string= user "hoge") (string= pass "fuga"))))))) :initial-value (to-app (lambda (env) (sb-int:quasiquote (200 nil (#S(sb-impl::comma :expr (format nil "Hello, ~A" (getf env :remote-user)) :kind 0)))))) :from-end t)


[User]
Define a macro that eliminates this repetitive pattern:
(builder (:static :path "/public/" :root (asdf:system-relative-pathname :lack #P"data/")) (lambda (env) (declare (ignore env)) `(200 (:content-type "text/plain") ("Happy Valentine!"))))

Issue: Macro call that should be transformed by builder

(builder (:static :path "/public/" :root (asdf:system-relative-pathname :lack #P"data/")) (lambda (env) (declare (ignore env)) `(200 (:content-type "text/plain") ("Happy Valentine!"))))

[Assistant]
(defmacro builder (&rest app-or-middlewares)
  (let ((middlewares (butlast app-or-middlewares)))
    `(reduce #'funcall
             (remove-if
              #'null
              (list
               ,@(loop for mw in middlewares
                       when mw
                         collect (convert-to-middleware-form mw))))
             :initial-value (to-app ,(car (last app-or-middlewares)))
             :from-end t)))

;; macroexpand:
(reduce (function funcall) (remove-if (function null) (list (lambda (#:app226) (funcall (find-middleware :static) #:app226 :path "/public/" :root (asdf/system:system-relative-pathname :lack #P"data/"))))) :initial-value (to-app (lambda (env) (declare (ignore env)) (sb-int:quasiquote (200 (:content-type "text/plain") ("Happy Valentine!"))))) :from-end t)


[User]
You are a Common Lisp macro expert. Given this code pattern:
(ematch0 missing ((list) pattern) ((list* var rest) (bind-missing-vars-with-nil (with-gensyms (it) `(guard1 ,it t nil (guard1 ,var t) ,it ,pattern)) rest)))

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

(ematch0 missing ((list) pattern) ((list* var rest) (bind-missing-vars-with-nil (with-gensyms (it) `(guard1 ,it t nil (guard1 ,var t) ,it ,pattern)) rest)))

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

;; macroexpand:
(match0 missing ((list) pattern) ((list* var rest) (bind-missing-vars-with-nil (with-gensyms (it) (sb-int:quasiquote (guard1 #S(sb-impl::comma :expr it :kind 0) t nil (guard1 #S(sb-impl::comma :expr var :kind 0) t) #S(sb-impl::comma :expr it :kind 0) #S(sb-impl::comma :expr pattern :kind 0)))) rest)) (_ (error "level0 match error!")))


[User]
Write a Common Lisp macro to handle this code pattern:
(builder :accesslog (lambda (env) (declare (ignore env)) '(200 () ("ok"))))

Problem: Macro call that should be transformed by builder

(builder :accesslog (lambda (env) (declare (ignore env)) '(200 () ("ok"))))

[Assistant]
(defmacro builder (&rest app-or-middlewares)
  (let ((middlewares (butlast app-or-middlewares)))
    `(reduce #'funcall
             (remove-if
              #'null
              (list
               ,@(loop for mw in middlewares
                       when mw
                         collect (convert-to-middleware-form mw))))
             :initial-value (to-app ,(car (last app-or-middlewares)))
             :from-end t)))

;; macroexpand:
(reduce (function funcall) (remove-if (function null) (list (find-middleware :accesslog))) :initial-value (to-app (lambda (env) (declare (ignore env)) (quote (200 nil ("ok"))))) :from-end t)


[User]
Write a Common Lisp macro to handle this code pattern:
(define-op (:/ conjunctive-op))

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

(define-op (:/ conjunctive-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 (/-op (:include conjunctive-op (name "/")) (:constructor make-/-op (&rest expressions))))


[User]
Generate a defmacro form that transforms code like this:
(when (node-slot initializer) (del-proxy initializer))

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

(when (node-slot initializer) (del-proxy initializer))

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

;; macroexpand:
(if (node-slot initializer) (del-proxy initializer))


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

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

(letrec nil)

[Assistant]
(defmacro LETREC ...)

;; macroexpand:
(let ()
  (flet ()
    nil
    (setf)))


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

Issue: Macro call that should be transformed by NEXT-IN

(next-in nil nil)

[Assistant]
(defmacro NEXT-IN ...)

;; macroexpand:
(do-next-in nil #'(lambda () nil))


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

Problem: Macro call that should be transformed by DEFJSMACRO

(defjsmacro 'some-name)

[Assistant]
(defmacro DEFJSMACRO ...)

;; macroexpand:
(defpsmacro 'some-name)


[User]
You are a Common Lisp macro expert. Given this code pattern:
(defclause (repeat n) "Repeat the loop some number of times" (top-level-check) (let* ((c-type (or (expression-type n) 'fixnum)) (count-var (make-var-and-binding 'count n :type c-type))) (setq *loop-end-used?* t) (return-code :body `((if (<= ,count-var 0) (go ,*loop-end*))) :step `((setq ,count-var (1- ,count-var))))))

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

(defclause (repeat n) "Repeat the loop some number of times" (top-level-check) (let* ((c-type (or (expression-type n) 'fixnum)) (count-var (make-var-and-binding 'count n :type c-type))) (setq *loop-end-used?* t) (return-code :body `((if (<= ,count-var 0) (go ,*loop-end*))) :step `((setq ,count-var (1- ,count-var))))))

[Assistant]
(defmacro defclause (clause-template &body body)
  (define-clause 'defun clause-template body nil))

;; macroexpand:
(eval-when (:compile-toplevel :load-toplevel :execute) (defun clause-repeat-2 (&key ((:repeat n))) "Repeat the loop some number of times" (top-level-check) (let* ((c-type (or (expression-type n) (quote fixnum))) (count-var (make-var-and-binding (quote count) n :type c-type))) (setq *loop-end-used?* t) (return-code :body (sb-int:quasiquote ((if (<= #S(sb-impl::comma :expr count-var :kind 0) 0) (go #S(sb-impl::comma :expr *loop-end* :kind 0))))) :step (sb-int:quasiquote ((setq #S(sb-impl::comma :expr count-var :kind 0) (1- #S(sb-impl::comma :expr count-var :kind 0)))))))) (install-clause-info (quote (repeat)) (quote (repeat)) (quote clause-repeat-2) "Repeat the loop some number of times" nil) (quote (repeat n)))


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

Problem: Macro call that should be transformed by INEXT

(inext nil (progn))

[Assistant]
(defmacro INEXT ...)

;; macroexpand:
(let ((vals (multiple-value-list (funcall (i-coro nil) (progn)))))
  (if (not vals)
      (coexit!)
      (car vals)))


[User]
You are a Common Lisp macro expert. Given this code pattern:
(with-preprocessor-state-slots (state) (when if-section-skip-reason (return-from process-preprocessing-directive nil)) (let ((token-list-for-print (remove-whitespace-marker directive-token-list))) (error 'preprocess-error :format-control "[File ~A: Line ~D] #error: ~{~A~^ ~}" :format-arguments (list (if file-pathname (enough-namestring file-pathname)) line-number token-list-for-print))))

Write a macro that addresses: Macro call that should be transformed by with-preprocessor-state-slots

(with-preprocessor-state-slots (state) (when if-section-skip-reason (return-from process-preprocessing-directive nil)) (let ((token-list-for-print (remove-whitespace-marker directive-token-list))) (error 'preprocess-error :format-control "[File ~A: Line ~D] #error: ~{~A~^ ~}" :format-arguments (list (if file-pathname (enough-namestring file-pathname)) line-number token-list-for-print))))

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

;; macroexpand:
(with-accessors ((file-pathname pp-state-file-pathname) (token-list pp-state-token-list) (result-list pp-state-result-list) (line-number pp-state-line-number) (tokens-in-line pp-state-tokens-in-line) (macro-alist pp-state-macro-alist) (if-section-stack pp-state-if-section-stack) (if-section-skip-reason pp-state-if-section-skip-reason) (include-stack pp-state-include-stack)) state (when if-section-skip-reason (return-from process-preprocessing-directive nil)) (let ((token-list-for-print (remove-whitespace-marker directive-token-list))) (error (quote preprocess-error) :format-control "[File ~A: Line ~D] #error: ~{~A~^ ~}" :format-arguments (list (if file-pathname (enough-namestring file-pathname)) line-number token-list-for-print))))


[User]
Create a Common Lisp macro for the following transformation. Before code:
(defvar-compile-time *function-record-table* (make-hash-table :test #'equal) "The function record table.")

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

(defvar-compile-time *function-record-table* (make-hash-table :test #'equal) "The function record table.")

[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 *function-record-table* (make-hash-table :test (function equal)) "The function record table."))


[User]
Generate a defmacro form that transforms code like this:
(defun/1 ldexp (x n) (* x (expt 2 n)))

Pattern to recognize: Macro call that should be transformed by defun/1

(defun/1 ldexp (x n) (* x (expt 2 n)))

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

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

;; macroexpand:
(progn (defun ldexp (x n) (declare (optimize (speed 0) (debug 3) (sb-ext:inhibit-warnings 3))) (* x (expt 2 n))) (defparameter ldexp (vacietis.c:mkptr& (symbol-function (quote ldexp)))))


[User]
Create a Common Lisp macro for the following transformation. Before code:
(do+ (for x (in '(1 3 5 7 9))) (for k (from 10 :to 0)) (initially (format t "initially k = ~S~%" k)) (for m (to 100 :by 5)) (initially (format t "another init form~%")) (with (y 42) z) (stop-when (eql x 7)) (counting loops) (finally (format t "finally k = ~S~%" k)) (accumulating-to w) (accumulating-to p :initially 0 :by #'+ :finally #'-) (returning (list 'x x 'y y 'z z 'k k 'm m 'w w 'p p 'loops loops 'max-length max-length 'longest-list longest-list)) (finally (format t "another final form~%")) (finding max-x (maximizing x)) (for list (in '((1 2) (3) (4 5 6) (7 8) (9)))) (finding max-length (maximizing (length list) :saving list :in longest-list)) (let ((foo "look ma, body is nested!")) (declare (ignore foo)) (format t "~%loop no. ~A~%" loops) (format t "before collect, x ~A y ~A z ~A k ~A m ~A w ~A ~% list ~A max-length ~A longest-list ~A ~%" x y z k m w list max-length longest-list) (collect x :into w) (collect x :into p) (format t "after collect, x ~A y ~A z ~A k ~A m ~A w ~A ~% list ~A max-length ~A longest-list ~A ~%" x y z k m w list max-length longest-list)))

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

(do+ (for x (in '(1 3 5 7 9))) (for k (from 10 :to 0)) (initially (format t "initially k = ~S~%" k)) (for m (to 100 :by 5)) (initially (format t "another init form~%")) (with (y 42) z) (stop-when (eql x 7)) (counting loops) (finally (format t "finally k = ~S~%" k)) (accumulating-to w) (accumulating-to p :initially 0 :by #'+ :finally #'-) (returning (list 'x x 'y y 'z z 'k k 'm m 'w w 'p p 'loops loops 'max-length max-length 'longest-list longest-list)) (finally (format t "another final form~%")) (finding max-x (maximizing x)) (for list (in '((1 2) (3) (4 5 6) (7 8) (9)))) (finding max-length (maximizing (length list) :saving list :in longest-list)) (let ((foo "look ma, body is nested!")) (declare (ignore foo)) (format t "~%loop no. ~A~%" loops) (format t "before collect, x ~A y ~A z ~A k ~A m ~A w ~A ~% list ~A max-length ~A longest-list ~A ~%" x y z k m w list max-length longest-list) (collect x :into w) (collect x :into p) (format t "after collect, x ~A y ~A z ~A k ~A m ~A w ~A ~% list ~A max-length ~A longest-list ~A ~%" x y z k m w list max-length longest-list)))

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

;; macroexpand:
(do+/internal nil (for x (in (quote (1 3 5 7 9)))) (for k (from 10 :to 0)) (initially (format t "initially k = ~S~%" k)) (for m (to 100 :by 5)) (initially (format t "another init form~%")) (with (y 42) z) (stop-when (eql x 7)) (counting loops) (finally (format t "finally k = ~S~%" k)) (accumulating-to w) (accumulating-to p :initially 0 :by (function +) :finally (function -)) (returning (list (quote x) x (quote y) y (quote z) z (quote k) k (quote m) m (quote w) w (quote p) p (quote loops) loops (quote max-length) max-length (quote longest-list) longest-list)) (finally (format t "another final form~%")) (finding max-x (maximizing x)) (for list (in (quote ((1 2) (3) (4 5 6) (7 8) (9))))) (finding max-length (maximizing (length list) :saving list :in longest-list)) (let ((foo "look ma, body is nested!")) (declare (ignore foo)) (format t "~%loop no. ~A~%" loops) (format t "before collect, x ~A y ~A z ~A k ~A m ~A w ~A ~% list ~A max-length ~A longest-list ~A ~%" x y z k m w list max-length longest-list) (collect x :into w) (collect x :into p) (format t "after collect, x ~A y ~A z ~A k ~A m ~A w ~A ~% list ~A max-length ~A longest-list ~A ~%" x y z k m w list max-length longest-list)))


[User]
Generate a defmacro form that transforms code like this:
(do+ (options :name outer-loop) (do+ (options :name inner-loop) (do+ (terminate outer-loop 3))))

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

(do+ (options :name outer-loop) (do+ (options :name inner-loop) (do+ (terminate outer-loop 3))))

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

;; macroexpand:
(do+/internal nil (options :name outer-loop) (do+ (options :name inner-loop) (do+ (terminate outer-loop 3))))


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

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

(-<>
  nil
  :key
  nil)

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

;; macroexpand:
(let* ((#:var208 nil) (#:var209 (:key #:var208)) (#:var210 (nil #:var209)))
  #:var210)


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

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

(defvar* nil :key nil)

[Assistant]
(defmacro DEFVAR* ...)

;; macroexpand:
(defvar/param defvar nil :key nil)


[User]
Define a macro that eliminates this repetitive pattern:
(enable-punch-syntax)

Issue: Macro call that should be transformed by enable-punch-syntax

(enable-punch-syntax)

[Assistant]
(defmacro enable-punch-syntax ()
  '(eval-when (:compile-toplevel :load-toplevel :execute)
    (cl-syntax:use-syntax punch-syntax)))

;; macroexpand:
(eval-when (:compile-toplevel :load-toplevel :execute) (cl-syntax:use-syntax punch-syntax))


[User]
Create a Common Lisp macro for the following transformation. Before code:
(define-error invalid-for-loop-type () (decl-obj) "Invalid type ~a used as counter for for-loop" (primary-type decl-obj))

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

(define-error invalid-for-loop-type () (decl-obj) "Invalid type ~a used as counter for for-loop" (primary-type decl-obj))

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

;; macroexpand:
(defcondition invalid-for-loop-type (:error-type varjo-error :prefix "Varjo") (decl-obj) "Invalid type ~a used as counter for for-loop" (primary-type decl-obj))


[User]
Create a Common Lisp macro for the following transformation. Before code:
(defun-compile-time cps-convert-multiple-value-call (nondeterministic? function forms continuation types value? environment) (let ((dummy-argument (gensym "DUMMY-")) (other-arguments (gensym "OTHER-"))) (cps-convert function `#'(lambda (&optional ,dummy-argument &rest ,other-arguments) (declare (magic) (ignore ,other-arguments)) ,(cps-convert-multiple-value-call-internal nondeterministic? dummy-argument forms continuation types value? environment)) nil t environment)))

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

(defun-compile-time cps-convert-multiple-value-call (nondeterministic? function forms continuation types value? environment) (let ((dummy-argument (gensym "DUMMY-")) (other-arguments (gensym "OTHER-"))) (cps-convert function `#'(lambda (&optional ,dummy-argument &rest ,other-arguments) (declare (magic) (ignore ,other-arguments)) ,(cps-convert-multiple-value-call-internal nondeterministic? dummy-argument forms continuation types value? environment)) nil t environment)))

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

;; macroexpand:
(eval-when (:compile-toplevel :load-toplevel :execute) (common-lisp:defun cps-convert-multiple-value-call (nondeterministic? function forms continuation types value? environment) (let ((dummy-argument (gensym "DUMMY-")) (other-arguments (gensym "OTHER-"))) (cps-convert function (sb-int:quasiquote (function (lambda (&optional #S(sb-impl::comma :expr dummy-argument :kind 0) &rest #S(sb-impl::comma :expr other-arguments :kind 0)) (declare (magic) (ignore #S(sb-impl::comma :expr other-arguments :kind 0))) #S(sb-impl::comma :expr (cps-convert-multiple-value-call-internal nondeterministic? dummy-argument forms continuation types value? environment) :kind 0)))) nil t environment))) (eval-when (:compile-toplevel) (compile (quote cps-convert-multiple-value-call))))


[User]
Write a Common Lisp macro to handle this code pattern:
(defvar-unbound *stream* "Bound to the stream which is read from while parsing a string.")

Problem: Macro call that should be transformed by defvar-unbound

(defvar-unbound *stream* "Bound to the stream which is read from while parsing a string.")

[Assistant]
(defmacro defvar-unbound (variable-name documentation)
  "Like DEFVAR, but the variable will be unbound rather than getting
an initial value.  This is useful for variables which should have no
global value but might have a dynamically bound value."
  ;; stolen from comp.lang.lisp article <k7727i3s.fsf@comcast.net> by
  ;; "prunesquallor@comcast.net"
  `(eval-when (:load-toplevel :compile-toplevel :execute)
    (defvar ,variable-name)
    (setf (documentation ',variable-name 'variable)
            ,documentation)))

;; macroexpand:
(eval-when (:load-toplevel :compile-toplevel :execute) (defvar *stream*) (setf (documentation (quote *stream*) (quote variable)) "Bound to the stream which is read from while parsing a string."))


[User]
Write a Common Lisp macro to handle this code pattern:
(define-generic generic (a b &key c &allow-other-keys) (+ a b))

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

(define-generic generic (a b &key c &allow-other-keys) (+ a b))

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

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

Example:

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

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

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

;; macroexpand:
(prog1 (defgeneric generic (a b &key &allow-other-keys) (:method (a b &key c &allow-other-keys) (+ a b))))


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

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

(lambda-coro)

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

;; macroexpand:
(progn
 (defcoroutine #:name123
     (#:arg124)
   (macrolet ((yield (form)
                (let ((g!-it (gensym "IT")))
                  `(progn
                    (let ((,g!-it ,form))
                      (cl-coroutine:yield ,g!-it))
                    ,'#:arg124)))
              (last-yield-value ()
                '#:arg124))
     (coexit!)))
 (make-coroutine '#:name123))


[User]
You are a Common Lisp macro expert. Given this code pattern:
(deferror "23505" unique-violation integrity-violation)

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

(deferror "23505" unique-violation integrity-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 unique-violation (integrity-violation) nil) (setf (gethash "23505" *error-table*) (quote unique-violation)))


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

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

(make-simple-appender-to-place nil)

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

;; macroexpand:
(progn
 (setf nil (alexandria:ensure-list nil))
 (let ((#:tail131 (last nil)))
   (lambda (&rest values) (append-at-end nil #:tail131 values) nil)))


[User]
You are a Common Lisp macro expert. Given this code pattern:
(action (:after node-direct-application node) (when (eq name (node-rator-name node)) (incf count)) (values))

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

(action (:after node-direct-application node) (when (eq name (node-rator-name node)) (incf count)) (values))

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

;; macroexpand:
(make-action (quote :after) (quote node-direct-application) (lambda (node) (declare (type node-direct-application node)) (when (eq name (node-rator-name node)) (incf count)) (values)))


[User]
Create a Common Lisp macro for the following transformation. Before code:
(define-cfun c-memcpy)

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

(define-cfun c-memcpy)

[Assistant]
(defmacro define-cfun (name-or-function &optional (package *package*))
  (when-let ((fun (find-function name-or-function)))
    (with-wrap-attempt ("function ~S" name-or-function) name-or-function
      (with-slots (name type c-symbol fields) fun
        (let* ((fun-name (intern (symbol-name name) package))
               (param-names (mapcar #'foreign-type-name fields))
               (param-syms (mapcar (lambda (x) (gensym (symbol-name x))) param-names))
               (make-function-p (not (foreign-function-variadic-p fun)))
               (maybe-cbv-return
                 (when (cbv-return-p fun)
                   (list 'return-value))))
          (with-gensyms (!fun !fields rest)
            (let ((form
                    (if make-function-p
                        `(defun ,fun-name (,@maybe-cbv-return
                                           ,@param-names ,@(when (foreign-function-variadic-p fun) `(&rest ,rest)))
                           ,@(when maybe-cbv-return `((declare (ignorable ,@maybe-cbv-return))))
                           ,(let ((!fun (find-function name-or-function)))
                              (with-slots ((!fields fields)) !fun
                                (foreign-to-ffi
                                 (and (car !fields) (foreign-type (car !fields)))
                                 param-syms
                                 param-names
                                 !fields
                                 (make-foreign-funcall !fun (and maybe-cbv-return 'return-value)
                                                       param-syms (when (foreign-function-variadic-p fun) rest))))))
                        `(defmacro ,fun-name (,@maybe-cbv-return
                                              ,@param-names ,@(when (foreign-function-variadic-p fun) `(&rest ,rest)))
                           ,@(when maybe-cbv-return `((declare (ignorable ,@maybe-cbv-return))))
                           (let ((,!fun (find-function ',name-or-function)))
                             (with-slots ((,!fields fields)) ,!fun
                               (foreign-to-ffi
                                (and (car ,!fields) (foreign-type (car ,!fields)))
                                ',param-syms
                                (list ,@param-names)
                                ,!fields
                                (make-foreign-funcall ,!fun ,(and maybe-cbv-return 'return-value)
                                                      ',param-syms ,(when (foreign-function-variadic-p fun) rest)))))))))
              `(progn
                 ,@(when (foreign-function-cbv-p fun)
                     (list (funcall *build-libffi-definition* fun)))
                 ,form))))))))

;; macroexpand:
(progn (defun c-memcpy (dest src n) (let ((#:dest224 dest)) (declare (ignorable #:dest224)) (let ((#:src225 src)) (declare (ignorable #:src225)) (let ((#:n226 n)) (declare (ignorable #:n226)) (cffi-sys:%foreign-funcall "memcpy" (:pointer #:dest224 :pointer #:src225 :unsigned-long-long #:n226 :pointer) :convention :cdecl))))))


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

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

(as->* nil (progn))

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

;; macroexpand:
(as-> (progn) nil)


[User]
Generate a defmacro form that transforms code like this:
(enable-reader-syntax nil (progn))

Pattern to recognize: Macro call that should be transformed by ENABLE-READER-SYNTAX

(enable-reader-syntax nil (progn))

[Assistant]
(defmacro ENABLE-READER-SYNTAX ...)

;; macroexpand:
(eval-when (:compile-toplevel :load-toplevel :execute)
  (push *readtable* *previous-readtables*)
  (setq *readtable* (copy-readtable))
  (%enable-reader-syntax *readtable* nil (progn)))


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

Problem: Macro call that should be transformed by F_N

(f_n
  nil)

[Assistant]
(defmacro F_N ...)

;; macroexpand:
(lambda (&rest _) nil)


[User]
Define a macro that eliminates this repetitive pattern:
(with-mocks () T)

Issue: Macro call that should be transformed by with-mocks

(with-mocks () T)

[Assistant]
(defmacro with-mocks ((&key (recordp T)) &body body)
  "Execute BODY in a new mocking context.  Invocations will be recorded
if RECORDP is set (default true)."
  `(call-with-mocks
    (lambda () ,@body)
    :recordp ,recordp))

;; macroexpand:
(call-with-mocks (lambda nil t) :recordp t)


[User]
You are a Common Lisp macro expert. Given this code pattern:
(assoc-cdr :last-name uinfo)

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

(assoc-cdr :last-name uinfo)

[Assistant]
(defmacro assoc-cdr (key alist &optional (test '#'eql))
  `(cdr (assoc ,key ,alist :test ,test)))

;; macroexpand:
(cdr (assoc :last-name uinfo :test (function eql)))


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

Problem: Macro call that should be transformed by false

(false T)

[Assistant]
(defmacro false (form &optional description &rest format-args)
  `(eval-in-context
    *context*
    (make-instance 'comparison-result
                   :expression '(false ,form)
                   :value-form ',form
                   :body (lambda () ,form)
                   :expected 'NIL
                   :comparison 'geq
                   ,@(when description
                       `(:description (format NIL ,description ,@format-args))))))

;; macroexpand:
(eval-in-context *context* (make-instance (quote comparison-result) :expression (quote (false t)) :value-form (quote t) :body (lambda nil t) :expected (quote nil) :comparison (quote geq)))


[User]
Create a Common Lisp macro for the following transformation. Before code:
(insert-char-class-tester (regex (schar *string* curr-pos)) (non-greedy-constant-length-closure (char-class-test)))

What needs to change: Macro call that should be transformed by insert-char-class-tester

(insert-char-class-tester (regex (schar *string* curr-pos)) (non-greedy-constant-length-closure (char-class-test)))

[Assistant]
(defmacro insert-char-class-tester ((char-class chr-expr) &body body)
  "Utility macro to replace each occurence of '\(CHAR-CLASS-TEST)
within BODY with the correct test (corresponding to CHAR-CLASS)
against CHR-EXPR."
  (with-rebinding (char-class)
    (with-unique-names (test-function)
      (flet ((substitute-char-class-tester (new)
               (subst new '(char-class-test) body
                      :test #'equalp)))
        `(let ((,test-function (test-function ,char-class)))
           ,@(substitute-char-class-tester
              `(funcall ,test-function ,chr-expr)))))))

;; macroexpand:
(let ((#:char-class159 regex)) (let ((#:test-function160 (test-function #:char-class159))) (non-greedy-constant-length-closure (funcall #:test-function160 (schar *string* curr-pos)))))


[User]
Create a Common Lisp macro for the following transformation. Before code:
(when (first in-decl-item) (if (gethash identifier (first names)) (setf (first make-block) t) (progn (push identifier (first delta-names)) (setf (gethash identifier (first names)) t))))

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

(when (first in-decl-item) (if (gethash identifier (first names)) (setf (first make-block) t) (progn (push identifier (first delta-names)) (setf (gethash identifier (first names)) t))))

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

;; macroexpand:
(if (first in-decl-item) (if (gethash identifier (first names)) (setf (first make-block) t) (progn (push identifier (first delta-names)) (setf (gethash identifier (first names)) t))))


[User]
You are a Common Lisp macro expert. Given this code pattern:
(set-plist-val! nil :key nil)

Write a macro that addresses: Macro call that should be transformed by SET-PLIST-VAL!

(set-plist-val! nil :key nil)

[Assistant]
(defmacro set-plist-val! (new id place
                          &key (test '(default-test)) (key '(default-key)))
  `(setf ,place
    (set-plist-val ,new ,id ,place :test ,test :key ,key)))

;; macroexpand:
(setf nil (set-plist-val nil :key nil :test (default-test) :key (default-key)))


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

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

(iterate:declare-variables)

[Assistant]
(defmacro iterate (&body body)
  "Jonathan Amsterdam's powerful iteration facility"
  `(iter .,body))

;; macroexpand:
(declare-variables)


[User]
Define a macro that eliminates this repetitive pattern:
(with-packages-unlocked nil
  nil)

Issue: Macro call that should be transformed by WITH-PACKAGES-UNLOCKED

(with-packages-unlocked nil
  nil)

[Assistant]
(defmacro WITH-PACKAGES-UNLOCKED ...)

;; macroexpand:
(let ((#:|packages121| (locked-packages 'nil)))
  (unlock-packages #:|packages121|)
  (unwind-protect nil (lock-packages #:|packages121|)))


[User]
Generate a defmacro form that transforms code like this:
(defhandler quote (quote object) `(list ',quote ',object))

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

(defhandler quote (quote object) `(list ',quote ',object))

[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-quote (quote object) (sb-int:quasiquote (list (quote #S(sb-impl::comma :expr quote :kind 0)) (quote #S(sb-impl::comma :expr object :kind 0))))) (setf (gethash (quote quote) *form-handler*) (quote hander-quote)))


[User]
You are a Common Lisp macro expert. Given this code pattern:
(ematch0 more-patterns ((list _ pattern) (analyze-pattern pattern)) ((list* _ pattern more-patterns) (analyze-pattern pattern) (analyze-more-patterns more-patterns)))

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

(ematch0 more-patterns ((list _ pattern) (analyze-pattern pattern)) ((list* _ pattern more-patterns) (analyze-pattern pattern) (analyze-more-patterns more-patterns)))

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

;; macroexpand:
(match0 more-patterns ((list _ pattern) (analyze-pattern pattern)) ((list* _ pattern more-patterns) (analyze-pattern pattern) (analyze-more-patterns more-patterns)) (_ (error "level0 match error!")))


[User]
Create a Common Lisp macro for the following transformation. Before code:
(draw group (:circle :cx x :cy y :r (/ w 4)))

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

(draw group (:circle :cx x :cy y :r (/ w 4)))

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

;; macroexpand:
(let ((#:g159 (funcall (function make-svg-element) :circle (append (list :cx x :cy y :r (/ w 4)) (list))))) (add-element group #:g159) #:g159)


[User]
Define a macro that eliminates this repetitive pattern:
(signal-syntax-error "There is no property named ~S." property-name)

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

(signal-syntax-error "There is no property named ~S." property-name)

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

;; macroexpand:
(signal-syntax-error* nil "There is no property named ~S." property-name)


[User]
Define a macro that eliminates this repetitive pattern:
(define-simple-object-lookup compiler-macro compiler-macro-function)

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

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

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

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


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

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

(defsynonym collect :collect)

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

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


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

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

(*> +comma+ +skip-space-and-comments+)

[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 (#:*>-offset239) (multiple-value-bind (#:*>-res240 #:*>-next241) (funcall +comma+ #:*>-offset239) (if (ok? #:*>-res240) (funcall +skip-space-and-comments+ #:*>-next241) (fail #:*>-next241))))


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

Problem: Macro call that should be transformed by DO-FOR

(do-for nil
  (progn))

[Assistant]
(defmacro DO-FOR ...)

;; macroexpand:
(block nil (lc ((block nil (tagbody (return (progn (progn)))))) progn))


[User]
You are a Common Lisp macro expert. Given this code pattern:
(define-condition partial-cant-be-found () ((partial-name :initarg :partial-name :type string :reader partial-name)) (:report (lambda (condition stream) (format stream "Unable to find dynamic partial \"~A\" in a context." (partial-name condition)))))

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

(define-condition partial-cant-be-found () ((partial-name :initarg :partial-name :type string :reader partial-name)) (:report (lambda (condition stream) (format stream "Unable to find dynamic partial \"~A\" in a context." (partial-name condition)))))

[Assistant]
(defmacro define (name template)
  "Define a named renderer of string TEMPLATE."
  `(setf (symbol-function ',name)
         (compile-template ,template)))

;; macroexpand:
(progn (sb-kernel::%define-condition (quote partial-cant-be-found) (quote (condition)) (sb-kernel::find-condition-layout (quote partial-cant-be-found) (quote (condition))) (list (sb-kernel::make-condition-slot :name (quote partial-name) :initargs (quote (:partial-name)) :readers (quote (partial-name)) :writers (quote nil) :initform-p (quote nil) :documentation (quote nil) :initform nil :initfunction nil :allocation (quote :instance))) (list) (quote (partial-name)) (quote nil) (sb-c:source-location)) (sb-kernel::%set-condition-report (quote partial-cant-be-found) (function (sb-int:named-lambda (sb-kernel::condition-report partial-cant-be-found) (condition stream) (declare (type condition condition) (type stream stream)) (funcall (function (lambda (condition stream) (format stream "Unable to find dynamic partial \"~A\" in a context." (partial-name condition)))) condition stream)))) (quote partial-cant-be-found))


[User]
Define a macro that eliminates this repetitive pattern:
(define-custom-var (:string-char *string-char-handler*) (constantly t) "Designator for a function of 1 character argument (String char).")

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

(define-custom-var (:string-char *string-char-handler*) (constantly t) "Designator for a function of 1 character argument (String char).")

[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 (*string-char-handler* . :string-char)) *custom-vars* :test (function equal)) (defvar *string-char-handler* (constantly t) "Designator for a function of 1 character argument (String char).")))


[User]
You are a Common Lisp macro expert. Given this code pattern:
(flow-lambda-macro (flow-context) (with-flow-function-macro (body-fu lambda-list body) `(dispatch-atomically ,flow-context #',body-fu ,invariant ,@opts)))

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

(flow-lambda-macro (flow-context) (with-flow-function-macro (body-fu lambda-list body) `(dispatch-atomically ,flow-context #',body-fu ,invariant ,@opts)))

[Assistant]
(defmacro flow-lambda-macro ((flow-context) &body body)
  `(with-gensyms (,flow-context)
     `(%flow-lambda (,,flow-context)
        ,,@body)))

;; macroexpand:
(with-gensyms (flow-context) (sb-int:quasiquote (%flow-lambda (#S(sb-impl::comma :expr flow-context :kind 0)) #S(sb-impl::comma :expr (with-flow-function-macro (body-fu lambda-list body) (sb-int:quasiquote (dispatch-atomically #S(sb-impl::comma :expr flow-context :kind 0) (function #S(sb-impl::comma :expr body-fu :kind 0)) #S(sb-impl::comma :expr invariant :kind 0) #S(sb-impl::comma :expr opts :kind 2)))) :kind 0))))


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

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

(enable-reader-syntax 'some-name)

[Assistant]
(defmacro ENABLE-READER-SYNTAX ...)

;; macroexpand:
(eval-when (:compile-toplevel :load-toplevel :execute)
  (push *readtable* *previous-readtables*)
  (setq *readtable* (copy-readtable))
  (%enable-reader-syntax *readtable* 'some-name))


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

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

(some-<>>
  nil
  (progn))

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

;; macroexpand:
(let* ((#:var143 nil)
       (#:var144
        (if #:var143
            (progn #:var143)
            nil)))
  #:var144)


[User]
Define a macro that eliminates this repetitive pattern:
(defvar-compile-time *nondeterministic-context?* nil "This must be globally NIL.")

Issue: Macro call that should be transformed by defvar-compile-time

(defvar-compile-time *nondeterministic-context?* 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 *nondeterministic-context?* nil "This must be globally NIL."))


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

Problem: Macro call that should be transformed by DEFPACKAGE

(defpackage nil :key nil)

[Assistant]
(defmacro DEFPACKAGE ...)

;; macroexpand:
(common-lisp:defpackage nil
  (:use :adhoc :closer-mop :cl)
  (:shadowing-import-from :closer-mop
                          #:defmethod
                          #:standard-generic-function
                          #:defgeneric
                          #:standard-method
                          #:standard-class)
  (:shadowing-import-from :adhoc #:defpackage #:variable #:the)
  :key
  ())


[User]
Generate a defmacro form that transforms code like this:
(define-generic generic (a b &key c) (declare (optimize speed (space 2))) (+ a b c))

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

(define-generic generic (a b &key c) (declare (optimize speed (space 2))) (+ a b c))

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

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

Example:

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

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

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

;; macroexpand:
(prog1 (defgeneric generic (a b &key c) (declare (optimize speed (space 2))) (:method (a b &key c) (declare (optimize speed (space 2))) (+ a b c))))


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

Issue: Macro call that should be transformed by $

($ nil (progn))

[Assistant]
(defmacro $ ...)

;; macroexpand:
(progn)


[User]
Write a Common Lisp macro to handle this code pattern:
(without-c-dependency (c-propagate c prior-value t))

Problem: Macro call that should be transformed by without-c-dependency

(without-c-dependency (c-propagate c prior-value t))

[Assistant]
(defmacro without-c-dependency (&body body)
  ` (let (*depender*)
      ,@body))

;; macroexpand:
(let (*depender*) (c-propagate c prior-value t))


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

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

(collect-stream nil :key nil)

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

;; macroexpand:
(common-lisp:let* ((#:generator-489 (generator :key)) #:items-484)
  (declare (type generator #:generator-489))
  (tagbody
   #:ll-490
    (setq #:items-484 (next-in #:generator-489 (go end)))
    (common-lisp:funcall nil #:items-484 nil)
    (go #:ll-490)
   end)
  nil)


[User]
Write a Common Lisp macro to handle this code pattern:
(defclass/a dbd-sqlite3-connection (dbi-connection) ())

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

(defclass/a dbd-sqlite3-connection (dbi-connection) ())

[Assistant]
(defmacro defclass/a (name superclasses slots &rest class-options)
  `(progn
     (defclass ,name ,superclasses ,slots ,@class-options)
     (deftype ,(intern (format nil "<~A>" (symbol-name name))) () ',name)
     (setf (find-class ',(intern (format nil "<~A>" (symbol-name name))))
           (find-class ',name))))

;; macroexpand:
(progn (defclass dbd-sqlite3-connection (dbi-connection) nil) (deftype <dbd-sqlite3-connection> nil (quote dbd-sqlite3-connection)) (setf (find-class (quote <dbd-sqlite3-connection>)) (find-class (quote dbd-sqlite3-connection))))


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

What needs to change: Macro call that should be transformed by WITH-COLLECTORS

(with-collectors nil
  :key
  nil)

[Assistant]
(defmacro WITH-COLLECTORS ...)

;; macroexpand:
(progn :key nil)


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

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

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

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

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


[User]
Generate a defmacro form that transforms code like this:
(%proper-list-p object)

Pattern to recognize: Macro call that should be transformed by %proper-list-p

(%proper-list-p object)

[Assistant]
(defmacro %proper-list-p (var &optional (element-type '*))
  `(loop
     (typecase ,var
       (null (return t))
       (cons (if (or ,(eq element-type '*)
                     (typep (car ,var) ,element-type))
                 (setq ,var (cdr ,var))
                 (return)))
       (t    (return)))))

;; macroexpand:
(loop (typecase object (null (return t)) (cons (if (or t (typep (car object) *)) (setq object (cdr object)) (return))) (t (return))))


[User]
Define a macro that eliminates this repetitive pattern:
(defun/1 putc (c fd) (fputc c fd))

Issue: Macro call that should be transformed by defun/1

(defun/1 putc (c fd) (fputc c fd))

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

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

;; macroexpand:
(progn (defun putc (c fd) (declare (optimize (speed 0) (debug 3) (sb-ext:inhibit-warnings 3))) (fputc c fd)) (defparameter putc (vacietis.c:mkptr& (symbol-function (quote putc)))))


[User]
You are a Common Lisp macro expert. Given this code pattern:
(assoc-cdr "code" parameters #'equal)

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

(assoc-cdr "code" parameters #'equal)

[Assistant]
(defmacro assoc-cdr (key alist &optional (test '#'eql))
  `(cdr (assoc ,key ,alist :test ,test)))

;; macroexpand:
(cdr (assoc "code" parameters :test (function equal)))


[User]
Write a Common Lisp macro to handle this code pattern:
(match list ((list x) unless (evenp x) x))

Problem: Macro call that should be transformed by match

(match list ((list x) unless (evenp x) x))

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

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

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

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

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

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

will be translated to

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

Examples:

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

;; macroexpand:
(%or (%if (consp list) (let ((#:g142 (car list)) (#:g143 (cdr list))) (declare (ignorable #:g142 #:g143)) (%if (%equals #:g143 nil) (%or (let ((x #:g142)) (if (not (evenp x)) x (fail))) (fail)) (fail))) (fail)) nil)


[User]
Generate a defmacro form that transforms code like this:
(builder (if t (lambda (app) (lambda (env) (funcall app env))) nil) *app*)

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

(builder (if t (lambda (app) (lambda (env) (funcall app env))) nil) *app*)

[Assistant]
(defmacro builder (&rest app-or-middlewares)
  (let ((middlewares (butlast app-or-middlewares)))
    `(reduce #'funcall
             (remove-if
              #'null
              (list
               ,@(loop for mw in middlewares
                       when mw
                         collect (convert-to-middleware-form mw))))
             :initial-value (to-app ,(car (last app-or-middlewares)))
             :from-end t)))

;; macroexpand:
(reduce (function funcall) (remove-if (function null) (list (let ((#:res168 (if t (lambda (app) (lambda (env) (funcall app env))) nil))) (typecase #:res168 (keyword (find-middleware #:res168)) (cons (if (keywordp (car #:res168)) (let ((#:res-mw167 (find-middleware (car #:res168)))) (lambda (#:app166) (apply #:res-mw167 #:app166 (cdr #:res168)))) #:res168)) (standard-object (lambda (#:app166) (funcall (intern (string :wrap) :clack.middleware) #:res168 #:app166))) (otherwise #:res168))))) :initial-value (to-app *app*) :from-end t)


[User]
You are a Common Lisp macro expert. Given this code pattern:
(define-simple-definition-resolver declaration (designator) (sb-int:info :source-location :declaration designator))

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

(define-simple-definition-resolver declaration (designator) (sb-int:info :source-location :declaration designator))

[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 declaration (declaration #:package152) (when (ignore-errors (let ((designator declaration)) (sb-int:info :source-location :declaration designator))) (list (make-instance (quote declaration) :designator declaration :package #:package152))))


[User]
You are a Common Lisp macro expert. Given this code pattern:
(draw scene (:ellipse :cx (random 500) :cy (random 500) :rx (+ 10 (random 65)) :ry (+ 10 (random 65))) :stroke "rgb(232, 229, 148)" :fill (one-of *groovy-test-colors*))

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

(draw scene (:ellipse :cx (random 500) :cy (random 500) :rx (+ 10 (random 65)) :ry (+ 10 (random 65))) :stroke "rgb(232, 229, 148)" :fill (one-of *groovy-test-colors*))

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

;; macroexpand:
(let ((#:g146 (funcall (function make-svg-element) :ellipse (append (list :cx (random 500) :cy (random 500) :rx (+ 10 (random 65)) :ry (+ 10 (random 65))) (list :stroke "rgb(232, 229, 148)" :fill (one-of *groovy-test-colors*)))))) (add-element scene #:g146) #:g146)


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

Problem: Macro call that should be transformed by accase

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

[Assistant]
(defmacro accase (keyform &body cases)
  "Like CCASE, except binds the result of the keyform to IT (via LET) for the
scope of the cases. Unlike CCASE, the keyform/place doesn't receive new values
possibly stored with STORE-VALUE restart; the new value is received by IT."
  `(anaphoric ccase ,keyform ,@cases))

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


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

What needs to change: Macro call that should be transformed by MAKE-NAME-TRANSFORMER

(make-name-transformer 'some-name)

[Assistant]
(defmacro MAKE-NAME-TRANSFORMER ...)

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


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

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

(emit 'some-name)

[Assistant]
(defmacro EMIT ...)

;; macroexpand:
(let ((#:ast182 'some-name))
  (progn
   (assert (typep #:ast182 'delayed-emitting) nil
           "Something went awry around the quasi quoted stuff, EMIT got a ~S."
           #:ast182)
   (funcall #:ast182)))


[User]
You are a Common Lisp macro expert. Given this code pattern:
(when (eql (top-sign) 'first-initializer) (pop-sign))

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

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

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

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


[User]
Define a macro that eliminates this repetitive pattern:
(letrec ((f (constantly t)) (a (funcall f))) a)

Issue: Macro call that should be transformed by letrec

(letrec ((f (constantly t)) (a (funcall f))) a)

[Assistant]
(defmacro letrec ((&rest bindings) &body body)
  "Recursive LET.
The idea is that functions created in BINDINGS can close over one
another, and themselves.

Note that `letrec' only binds variables: it can define recursive
functions, but can't bind them as functions. (But see `fbindrec'.)"
  `(letrec-with psetq ,bindings
     ,@body))

;; macroexpand:
(letrec-with psetq ((f (constantly t)) (a (funcall f))) a)


[User]
You are a Common Lisp macro expert. Given this code pattern:
(define-class child2 (parent2) ((name "foo" :type string) (age 17) (bio "Dummy biography")) (:automatic-types-p t))

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

(define-class child2 (parent2) ((name "foo" :type string) (age 17) (bio "Dummy biography")) (:automatic-types-p t))

[Assistant]
(defmacro define-class (name supers slots &rest options)
  "Convenience wrapper of `defclass'.

It automates a lot of boilerplate (like exporting all the accessors of a class)
plus adds some new features.

Slot options:

- The initform can be specified as the second value.

- `:accessor', `:reader' and `:writer' can be set to either a name, NIL or T.
  If NIL, the method is not generated.
  If T, the method is generated using the `:accessor-name-transformer' class option value.

- The `:export' option allows to control the slot-name export on a per-slot basis.

New class options (defaults are NIL unless specified):

- `:slot-definition-transformer' (default: `default-slot-definition-transformer').
  A function that takes a SLOT-DEFINITION and returns a new one.

- `:accessor-name-package': The package of the generated accessors.  See
  `:accessor-name-transformer'.  Some special values are accepted:
  - `:slot-name': The package of the slot-name.
  - `:default': The current package.

- `:accessor-name-transformer' (default `default-accessor-name-transformer').

  A function of (SLOT-NAME SLOT-DEFINITION) arguments that returns the accessor
  name (a symbol).  Other transformer: `dwim-accessor-name-transformer'.

- `:automatic-accessors-p': Whether to generate accessor names automatically for
  all slots.

  As a special case, the accessor is not generated if all following conditions are met:
  - `:accessor-name-package' is `:slot-name',
  - slot name package is different from current package,
  - if the `:accessor' slot option is not provided,

- `:initarg-name-transformer' (default: `default-initarg-name-transformer'.)

  A function of (SLOT-NAME SLOT-DEFINITION) arguments that returns the accessor
  name (a symbol.

- `:automatic-initargs-p' (default: T): Whether to generate accessor names
  automatically for all slots.

- `:predicate-name-transformer' (default: `default-predicate-name-transformer').

  A function of (SLOT-NAME SLOT-DEFINITION) arguments that returns the predicate
  name (a symbol).

- `:automatic-predicates-p' (default: T): Whether to generate a predicate
  for the class.

- `:type-inference' (default: `default-type-inference').

  Function that returns the type of a slot definition (with an initform).  It
  takes 3 arguments:

  - The initform.
  - The slot name.
  - The rest of the slot definition.

- `:automatic-types-p': Whether to generate the type automatically for all
  slots.  The type can still be specified manually with the `:type' slot option.

- Self-explanatory export options (all NIL by default):
  - `:export-class-name-p'
  - `:export-accessor-names-p'
  - `:export-slot-names-p'
  - `:export-predicate-name'"
  (build-defclass-like-expansion
   name supers slots options
   (lambda (processed-slots clean-options)
     `(defclass ,name ,supers
        ,processed-slots
        ,@clean-options))))

;; macroexpand:
(progn (defclass child2 (parent2) ((name :initform "foo" :accessor name :initarg :name :type string) (age :initform 17 :accessor age :initarg :age) (bio :initform "Dummy biography" :accessor bio :initarg :bio))) (unless (fboundp (quote child2p)) (define-generic child2p (object) #A((71) base-char . "Auto-generated predicate for whether OBJECT is an instance of `child2'.") (declare (sb-ext:muffle-conditions style-warning)) (typep object (quote child2)))) (setf (documentation (quote bio) (quote function)) #A((46) base-char . "Auto-generated accessor function for slot BIO.")) (ignore-errors (setf (documentation (fdefinition (quote bio)) (quote function)) #A((46) base-char . "Auto-generated accessor function for slot BIO."))) (ignore-errors (setf (documentation (fdefinition (quote (setf bio))) (quote function)) #A((46) base-char . "Auto-generated accessor function for slot BIO."))) (setf (documentation (quote age) (quote function)) #A((46) base-char . "Auto-generated accessor function for slot AGE.")) (ignore-errors (setf (documentation (fdefinition (quote age)) (quote function)) #A((46) base-char . "Auto-generated accessor function for slot AGE."))) (ignore-errors (setf (documentation (fdefinition (quote (setf age))) (quote function)) #A((46) base-char . "Auto-generated accessor function for slot AGE."))) (setf (documentation (quote name) (quote function)) #A((47) base-char . "Auto-generated accessor function for slot NAME.")) (ignore-errors (setf (documentation (fdefinition (quote name)) (quote function)) #A((47) base-char . "Auto-generated accessor function for slot NAME."))) (ignore-errors (setf (documentation (fdefinition (quote (setf name))) (quote function)) #A((47) base-char . "Auto-generated accessor function for slot NAME."))) (find-class (quote child2) nil))


[User]
Write a Common Lisp macro to handle this code pattern:
(enable-infix-syntax)

Problem: Macro call that should be transformed by ENABLE-INFIX-SYNTAX

(enable-infix-syntax)

[Assistant]
(defmacro ENABLE-INFIX-SYNTAX ...)

;; macroexpand:
(use-syntax :mexpr)


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

Problem: Macro call that should be transformed by VAR

(var nil)

[Assistant]
(defmacro VAR ...)

;; macroexpand:
(defparameter nil nil)


[User]
Generate a defmacro form that transforms code like this:
(define-option-expander import-from (package import-package &rest symbols) (import (collect-symbols-from import-package symbols) package))

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

(define-option-expander import-from (package import-package &rest symbols) (import (collect-symbols-from import-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 ((#:type132 (eql :import-from)) package #:args131) (destructuring-bind (import-package &rest symbols) #:args131 (import (collect-symbols-from import-package symbols) package)))


[User]
Write a Common Lisp macro to handle this code pattern:
(defclause accumulating-to (vars &key initially by finally) "Specifies an accumulation clause. Refer to the manual for details." (labels ((make-finally-form (var function) `(setf ,var (funcall ,function ,var))) (make-one-accumulation (var) (cons (make-simple-iteration :var var :init initially) (if by (list* (make-accumulator :var var :function by) (when finally (list (make-finalization :form (make-finally-form var finally))))) (list (make-accumulator :var var :function '(function cons)) (make-finalization :form (make-finally-form var (or finally '(function nreverse))))))))) (mapcan #'make-one-accumulation (ensure-list vars))))

Problem: Macro call that should be transformed by defclause

(defclause accumulating-to (vars &key initially by finally) "Specifies an accumulation clause. Refer to the manual for details." (labels ((make-finally-form (var function) `(setf ,var (funcall ,function ,var))) (make-one-accumulation (var) (cons (make-simple-iteration :var var :init initially) (if by (list* (make-accumulator :var var :function by) (when finally (list (make-finalization :form (make-finally-form var finally))))) (list (make-accumulator :var var :function '(function cons)) (make-finalization :form (make-finally-form var (or finally '(function nreverse))))))))) (mapcan #'make-one-accumulation (ensure-list vars))))

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

;; macroexpand:
(progn (defmacro accumulating-to (vars &key initially by finally) "Specifies an accumulation clause. Refer to the manual for details." (labels ((make-finally-form (var function) (sb-int:quasiquote (setf #S(sb-impl::comma :expr var :kind 0) (funcall #S(sb-impl::comma :expr function :kind 0) #S(sb-impl::comma :expr var :kind 0))))) (make-one-accumulation (var) (cons (make-simple-iteration :var var :init initially) (if by (list* (make-accumulator :var var :function by) (when finally (list (make-finalization :form (make-finally-form var finally))))) (list (make-accumulator :var var :function (quote (function cons))) (make-finalization :form (make-finally-form var (or finally (quote (function nreverse)))))))))) (mapcan (function make-one-accumulation) (ensure-list vars)))) (pushnew (quote accumulating-to) *clauses*))