Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(builder (:mount "/admin" (lambda (env) `(200 () ("admin" ,(getf env :path-info))))) *app*)

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

Input: (builder (:mount "/admin" (lambda (env) `(200 () ("admin" ,(getf env :path-info))))) *app*)

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

(reduce (function funcall) (remove-if (function null) (list (lambda (#:app172) (funcall (find-middleware :mount) #:app172 "/admin" (lambda (env) (sb-int:quasiquote (200 nil ("admin" #S(sb-impl::comma :expr (getf env :path-info) :kind 0))))))))) :initial-value (to-app *app*) :from-end t)


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(lambda () nil)

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

Input: (lambda () nil)

Output: (defmacro LAMBDA ...)


Instruction:
Generate a defmacro form that transforms code like this:
(is (not (plusp 1)))

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

Input: (is (not (plusp 1)))

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

(let ((#:v197 1)) (if (not (plusp #:v197)) (add-result (quote test-passed) :test-expr (quote (not (plusp 1)))) (process-failure (quote (not (plusp 1))) "~2&~S~2% evaluated to ~2&~S~2% which satisfies ~2&~S~2% (it should not)" (quote 1) #:v197 (quote plusp))))


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(labels* nil)

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

Input: (labels* nil)

Output: (defmacro LABELS* ...)


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(defclause-driver (for var-spec &sequence) "Numbers" (top-level-check) (if with-index (clause-error "WITH-INDEX should not be specified for this clause")) (check-sequence-keywords from upfrom downfrom to downto above below nil) (let* ((var (extract-var var-spec)) (initial (or from upfrom downfrom 0)) (limit (or to downto above below)) (step-func (if (or downfrom downto above) '- '+)) (test-func (cond (to '>) (downto '<) (below '>=) (above '<=))) (limit-var (if (and limit (not (constant? limit))) (make-var-and-binding 'limit limit :using-type-of (if (expression-type limit) limit var)))) (step-var (if (not (constantp by)) (make-var-and-binding 'step by :using-type-of by))) (step-thing (or step-var by)) (limit-code (or limit-var limit)) (init-val (eval-const-expr (list (if (eq step-func '+) '- '+) initial step-thing))) (test (if limit (progn (setq *loop-end-used?* t) `((if (,test-func ,var ,limit-code) (go ,*loop-end*)))) nil)) (next `((setq ,var (,step-func ,var ,step-thing)) .,test))) (make-binding var-spec init-val :type 'number) (return-driver-code :next next :variable var)))

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

Input: (defclause-driver (for var-spec &sequence) "Numbers" (top-level-check) (if with-index (clause-error "WITH-INDEX should not be specified for this clause")) (check-sequence-keywords from upfrom downfrom to downto above below nil) (let* ((var (extract-var var-spec)) (initial (or from upfrom downfrom 0)) (limit (or to downto above below)) (step-func (if (or downfrom downto above) '- '+)) (test-func (cond (to '>) (downto '<) (below '>=) (above '<=))) (limit-var (if (and limit (not (constant? limit))) (make-var-and-binding 'limit limit :using-type-of (if (expression-type limit) limit var)))) (step-var (if (not (constantp by)) (make-var-and-binding 'step by :using-type-of by))) (step-thing (or step-var by)) (limit-code (or limit-var limit)) (init-val (eval-const-expr (list (if (eq step-func '+) '- '+) initial step-thing))) (test (if limit (progn (setq *loop-end-used?* t) `((if (,test-func ,var ,limit-code) (go ,*loop-end*)))) nil)) (next `((setq ,var (,step-func ,var ,step-thing)) .,test))) (make-binding var-spec init-val :type 'number) (return-driver-code :next next :variable var)))

Output:
(defmacro defclause (clause-template &body body)
  (define-clause 'defun clause-template body nil))

(eval-when (:compile-toplevel :load-toplevel :execute) (defun clause-for-3 (&key ((:for var-spec)) ((:from from)) ((:upfrom upfrom)) ((:downfrom downfrom)) ((:to to)) ((:downto downto)) ((:above above)) ((:below below)) ((:by by) 1) ((:with-index with-index)) generate) "Numbers" (top-level-check) (if with-index (clause-error "WITH-INDEX should not be specified for this clause")) (check-sequence-keywords from upfrom downfrom to downto above below nil) (let* ((var (extract-var var-spec)) (initial (or from upfrom downfrom 0)) (limit (or to downto above below)) (step-func (if (or downfrom downto above) (quote -) (quote +))) (test-func (cond (to (quote >)) (downto (quote <)) (below (quote >=)) (above (quote <=)))) (limit-var (if (and limit (not (constant? limit))) (make-var-and-binding (quote limit) limit :using-type-of (if (expression-type limit) limit var)))) (step-var (if (not (constantp by)) (make-var-and-binding (quote step) by :using-type-of by))) (step-thing (or step-var by)) (limit-code (or limit-var limit)) (init-val (eval-const-expr (list (if (eq step-func (quote +)) (quote -) (quote +)) initial step-thing))) (test (if limit (progn (setq *loop-end-used?* t) (sb-int:quasiquote ((if (#S(sb-impl::comma :expr test-func :kind 0) #S(sb-impl::comma :expr var :kind 0) #S(sb-impl::comma :expr limit-code :kind 0)) (go #S(sb-impl::comma :expr *loop-end* :kind 0)))))) nil)) (next (sb-int:quasiquote ((setq #S(sb-impl::comma :expr var :kind 0) (#S(sb-impl::comma :expr step-func :kind 0) #S(sb-impl::comma :expr var :kind 0) #S(sb-impl::comma :expr step-thing :kind 0))) . #S(sb-impl::comma :expr test :kind 0))))) (make-binding var-spec init-val :type (quote number)) (return-driver-code :next next :variable var))) (install-clause-info (quote (for)) (quote (for &optional :from :upfrom :downfrom :to :downto :above :below :by :with-index)) (quote clause-for-3) "Numbers" t) (quote (for var-spec &optional :from from :upfrom upfrom :downfrom downfrom :to to :downto downto :above above :below below :by (by 1) :with-index with-index)))


Instruction:
Define a macro that eliminates this repetitive pattern:
(enable-quasi-quote-syntax nil nil)

Issue: Macro call that should be transformed by ENABLE-QUASI-QUOTE-SYNTAX

Input: (enable-quasi-quote-syntax nil nil)

Output: (defmacro ENABLE-QUASI-QUOTE-SYNTAX ...)

(eval-when (:compile-toplevel :execute)
  (setf *readtable* (copy-readtable *readtable*))
  (set-quasi-quote-syntax-in-readtable nil nil :nested-quasi-quote-wrapper
                                       quasi-quote-wrapper :start-character nil
                                       :dispatch-character nil :end-character
                                       nil :unquote-character #\COMMA
                                       :splice-character #\COMMERCIAL_AT
                                       :destructive-splice-character
                                       #\FULL_STOP :dispatched-quasi-quote-name
                                       nil :toplevel-reader-wrapper #'identity
                                       :unquote-readtable-case nil :body-reader
                                       nil :readtable-case nil)
  (values))


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(define-modf-rewrite fifth (expr) `(car (cddddr ,(second expr))))

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

Input: (define-modf-rewrite fifth (expr) `(car (cddddr ,(second expr))))

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

(eval-when (:compile-toplevel :load-toplevel :execute) (setf (gethash (quote fifth) *modf-rewrites*) (lambda (expr) (sb-int:quasiquote (car (cddddr #S(sb-impl::comma :expr (second expr) :kind 0)))))))


Instruction:
Generate a defmacro form that transforms code like this:
(defun/1 tolower (c) (char-downcase (code-char c)))

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

Input: (defun/1 tolower (c) (char-downcase (code-char c)))

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

(progn (defun tolower (c) (declare (optimize (speed 0) (debug 3) (sb-ext:inhibit-warnings 3))) (char-downcase (code-char c))) (defparameter tolower (vacietis.c:mkptr& (symbol-function (quote tolower)))))


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

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

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

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

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

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

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

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

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

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


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(doseq! (item seq :start start :end end) (setf item value))

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

Input: (doseq! (item seq :start start :end end) (setf item value))

Output:
(defmacro doseq (name/seq &body body)
  "Iterate over the elements of a single sequence SEQUENCE.

   Same as DO-SEQUENCES but for the special case of iterating over a
   single sequence.

   The macro arguments can be in one of the following two forms:

    1. (NAME (ELEMENT SEQUENCE &REST ARGS) &BODY BODY)

    2. ((ELEMENT SEQUENCE &REST ARGS) &BODY BODY)

   NAME is the block name, NIL if not given.

   ELEMENT is the variable to which each element of the sequence is
   bound.

   SEQUENCE is the sequence, with ARGS being the remaining arguments
   passed to the ITERATOR function.

   BODY is the list of forms evaluated on each iteration."

  (let-if ((name name/seq)
           (seq (first body) name/seq)
           (body (rest body) body))
      (symbolp name/seq)

    (destructuring-bind (element sequence &rest args) seq
      `(do-sequences ,name
         ((,element ,sequence ,@args))
         ,@body))))

(do-sequences! nil ((item seq :start start :end end)) (setf item value))


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(def-neo4j-fun get-path (node-id to-node-id relationships (max-depth 3) (algorithm :shortest-path)) :post (:uri-spec (format nil "node/~A/path" node-id)) (:encode (list (list (cons "to" to-node-id) :node-url) (list (cons "relationships" relationships)) (list (cons "max_depth" max-depth)) (list (cons "algorithm" (case algorithm (:shortest-path "shortestPath") (:all-paths "allPaths") (:all-simple-paths "allSimplePaths") (:dijkstra "dijkstra"))))) :object) (:status-handlers (200 (decode-neo4j-json-output body)) (404 (error 'path-not-found-error :uri uri))))

What needs to change: Macro call that should be transformed by def-neo4j-fun

Input: (def-neo4j-fun get-path (node-id to-node-id relationships (max-depth 3) (algorithm :shortest-path)) :post (:uri-spec (format nil "node/~A/path" node-id)) (:encode (list (list (cons "to" to-node-id) :node-url) (list (cons "relationships" relationships)) (list (cons "max_depth" max-depth)) (list (cons "algorithm" (case algorithm (:shortest-path "shortestPath") (:all-paths "allPaths") (:all-simple-paths "allSimplePaths") (:dijkstra "dijkstra"))))) :object) (:status-handlers (200 (decode-neo4j-json-output body)) (404 (error 'path-not-found-error :uri uri))))

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

(progn (defun get-path (&key node-id to-node-id relationships (max-depth 3) (algorithm :shortest-path)) (let ((uri (format nil "node/~A/path" node-id)) (json (encode-neo4j-json-payload (list (list (cons "to" to-node-id) :node-url) (list (cons "relationships" relationships)) (list (cons "max_depth" max-depth)) (list (cons "algorithm" (case algorithm (:shortest-path "shortestPath") (:all-paths "allPaths") (:all-simple-paths "allSimplePaths") (:dijkstra "dijkstra"))))) :object))) (make-neo4j-request :post uri json (list (list 200 (lambda (body uri json) (decode-neo4j-json-output body))) (list 404 (lambda (body uri json) (error (quote path-not-found-error) :uri uri))))))))


Instruction:
Define a macro that eliminates this repetitive pattern:
(with-decoder-simple-list-semantics (setf x (decode-json-from-string "{\"x\":1}")) (is (equal (symbol-package (caar x)) (find-package :cl-user))))

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

Input: (with-decoder-simple-list-semantics (setf x (decode-json-from-string "{\"x\":1}")) (is (equal (symbol-package (caar x)) (find-package :cl-user))))

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

(with-shadowed-custom-vars (set-decoder-simple-list-semantics) (setf x (decode-json-from-string "{\"x\":1}")) (is (equal (symbol-package (caar x)) (find-package :cl-user))))


Instruction:
Generate a defmacro form that transforms code like this:
(define-error invalid-form-list () (code) "Tried to compile form however the first element of the form was a list: ~s" code)

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

Input: (define-error invalid-form-list () (code) "Tried to compile form however the first element of the form was a list: ~s" code)

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

(defcondition invalid-form-list (:error-type varjo-error :prefix "Varjo") (code) "Tried to compile form however the first element of the form was a list: ~s" code)


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(augment arglist (list 'generate))

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

Input: (augment arglist (list 'generate))

Output:
(defmacro augment (var stuff)
  `(setf ,var (nconc ,var ,stuff)))

(setf arglist (nconc arglist (list (quote generate))))


Instruction:
Write a Common Lisp macro to handle this code pattern:
(lambda* nil)

Problem: Macro call that should be transformed by LAMBDA*

Input: (lambda* nil)

Output: (defmacro LAMBDA* ...)


Instruction:
Define a macro that eliminates this repetitive pattern:
(with-file-name-lock-held () (format nil "~:@(~36,8,'0R~)" (random (expt 36 8) *name-random-state*)))

Issue: Macro call that should be transformed by with-file-name-lock-held

Input: (with-file-name-lock-held () (format nil "~:@(~36,8,'0R~)" (random (expt 36 8) *name-random-state*)))

Output:
(defmacro with-file-name-lock-held (() &body body)
  `(bordeaux-threads:with-lock-held (*create-file-name-lock*)
     ,@body))

(bordeaux-threads:with-lock-held (*create-file-name-lock*) (format nil "~:@(~36,8,'0R~)" (random (expt 36 8) *name-random-state*)))


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(defsynonym finally :finally)

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

Input: (defsynonym finally :finally)

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

(eval-always (setf (get (quote finally) (quote synonym)) (quote :finally)))


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(defclause symbols-in (package-or-packages &rest symbol-types) "Iterates over the symbols in one or more packages. Symbol-types follows the specification of cl:with-package-iterator." (let ((variables (ensure-list *iteration-variable*)) (package-list (ensure-list package-or-packages)) (symbol-types (or symbol-types '(:external))) (iterator (gensym "PACKAGE-ITERATOR")) (test (gensym "TEST"))) (unless (<= 1 (length variables) 3) (error "Invalid variable specification for package entry, expected (symbol &optional accessibility package) but got ~S" *iteration-variable*)) `(,(make-wrapper :function (lambda (body) `(with-package-iterator (,iterator (list ,@package-list) ,@symbol-types) ,body))) ,(make-iteration :bindings `(,test ,@variables) :initializations `((setf (values ,test ,@variables) (,iterator))) :steps `((setf (values ,test ,@variables) (,iterator))) :postconditions `((not (null ,test)))))))

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

Input: (defclause symbols-in (package-or-packages &rest symbol-types) "Iterates over the symbols in one or more packages. Symbol-types follows the specification of cl:with-package-iterator." (let ((variables (ensure-list *iteration-variable*)) (package-list (ensure-list package-or-packages)) (symbol-types (or symbol-types '(:external))) (iterator (gensym "PACKAGE-ITERATOR")) (test (gensym "TEST"))) (unless (<= 1 (length variables) 3) (error "Invalid variable specification for package entry, expected (symbol &optional accessibility package) but got ~S" *iteration-variable*)) `(,(make-wrapper :function (lambda (body) `(with-package-iterator (,iterator (list ,@package-list) ,@symbol-types) ,body))) ,(make-iteration :bindings `(,test ,@variables) :initializations `((setf (values ,test ,@variables) (,iterator))) :steps `((setf (values ,test ,@variables) (,iterator))) :postconditions `((not (null ,test)))))))

Output:
(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*)))

(progn (defmacro symbols-in (package-or-packages &rest symbol-types) "Iterates over the symbols in one or more packages. Symbol-types follows the specification of cl:with-package-iterator." (let ((variables (ensure-list *iteration-variable*)) (package-list (ensure-list package-or-packages)) (symbol-types (or symbol-types (quote (:external)))) (iterator (gensym "PACKAGE-ITERATOR")) (test (gensym "TEST"))) (unless (<= 1 (length variables) 3) (error "Invalid variable specification for package entry, expected (symbol &optional accessibility package) but got ~S" *iteration-variable*)) (sb-int:quasiquote (#S(sb-impl::comma :expr (make-wrapper :function (lambda (body) (sb-int:quasiquote (with-package-iterator (#S(sb-impl::comma :expr iterator :kind 0) (list #S(sb-impl::comma :expr package-list :kind 2)) #S(sb-impl::comma :expr symbol-types :kind 2)) #S(sb-impl::comma :expr body :kind 0))))) :kind 0) #S(sb-impl::comma :expr (make-iteration :bindings (sb-int:quasiquote (#S(sb-impl::comma :expr test :kind 0) #S(sb-impl::comma :expr variables :kind 2))) :initializations (sb-int:quasiquote ((setf (values #S(sb-impl::comma :expr test :kind 0) #S(sb-impl::comma :expr variables :kind 2)) (#S(sb-impl::comma :expr iterator :kind 0))))) :steps (sb-int:quasiquote ((setf (values #S(sb-impl::comma :expr test :kind 0) #S(sb-impl::comma :expr variables :kind 2)) (#S(sb-impl::comma :expr iterator :kind 0))))) :postconditions (sb-int:quasiquote ((not (null #S(sb-impl::comma :expr test :kind 0)))))) :kind 0))))) (pushnew (quote symbols-in) *clauses*))


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(collect-nth nil (progn))

What needs to change: Macro call that should be transformed by COLLECT-NTH

Input: (collect-nth nil (progn))

Output: (defmacro COLLECT-NTH ...)

(common-lisp:let* ((#:generator-409 (generator (progn)))
                   #:items-401
                   (#:counter-403 nil)
                   (#:item-404 nil))
  (declare (type generator #:generator-409)
           (type (null-or fixnum) #:counter-403)
           (type (null-or t) #:item-404))
  (tagbody
   #:ll-410
    (setq #:items-401 (next-in #:generator-409 (go end)))
    (when (zerop #:counter-403) (setq #:item-404 #:items-401) (go end))
    (decf #:counter-403)
    (go #:ll-410)
   end)
  #:item-404)


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(with-yield-binds (format nil "ALTER COLUMN ~A~:[~; TYPE ~:*~A~]~:[~; SET DEFAULT ~:*~A~]~:[~; DROP DEFAULT~]~A" (yield (alter-column-clause-column-name clause)) (and (alter-column-clause-type clause) (let ((*use-placeholder* nil)) (yield (alter-column-clause-type clause)))) (and (alter-column-clause-set-default clause) (yield (alter-column-clause-set-default clause))) (alter-column-clause-drop-default clause) (cond ((eq (alter-column-clause-not-null clause) :unspecified) "") ((alter-column-clause-not-null clause) " SET NOT NULL") (T " DROP NOT NULL"))))

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

Input: (with-yield-binds (format nil "ALTER COLUMN ~A~:[~; TYPE ~:*~A~]~:[~; SET DEFAULT ~:*~A~]~:[~; DROP DEFAULT~]~A" (yield (alter-column-clause-column-name clause)) (and (alter-column-clause-type clause) (let ((*use-placeholder* nil)) (yield (alter-column-clause-type clause)))) (and (alter-column-clause-set-default clause) (yield (alter-column-clause-set-default clause))) (alter-column-clause-drop-default clause) (cond ((eq (alter-column-clause-not-null clause) :unspecified) "") ((alter-column-clause-not-null clause) " SET NOT NULL") (T " DROP NOT NULL"))))

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

(let ((*bind-values* nil) (*use-global-bind-values* t)) (values (progn (format nil "ALTER COLUMN ~A~:[~; TYPE ~:*~A~]~:[~; SET DEFAULT ~:*~A~]~:[~; DROP DEFAULT~]~A" (yield (alter-column-clause-column-name clause)) (and (alter-column-clause-type clause) (let ((*use-placeholder* nil)) (yield (alter-column-clause-type clause)))) (and (alter-column-clause-set-default clause) (yield (alter-column-clause-set-default clause))) (alter-column-clause-drop-default clause) (cond ((eq (alter-column-clause-not-null clause) :unspecified) "") ((alter-column-clause-not-null clause) " SET NOT NULL") (t " DROP NOT NULL")))) (loop for bind in (reverse *bind-values*) append bind)))


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(do+ outer-loop (do+ inner-loop (do+ (terminate outer-loop 3))))

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

Input: (do+ outer-loop (do+ inner-loop (do+ (terminate outer-loop 3))))

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

(do+/internal nil outer-loop (do+ inner-loop (do+ (terminate outer-loop 3))))


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(with-color (:cyan :stream stream) (with-additional-indent (reporter stream "- ") (let ((description (possible-report-description report))) (when description (format/indent reporter stream description)))) (terpri stream))

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

Input: (with-color (:cyan :stream stream) (with-additional-indent (reporter stream "- ") (let ((description (possible-report-description report))) (when description (format/indent reporter stream description)))) (terpri stream))

Output:
(defmacro with-color ((color &rest args) &body body)
  (cond
    ((or (eq color :gray)
         (eq color :grey))
     `(if *enable-colors*
          (with-gray ,(or (getf args :stream) t) ,@body)
          (progn ,@body)))
    (T `(if *enable-colors*
            (if (or (eq ,color :gray)
                    (eq ,color :grey)
                    (eq ,color cl-colors:+gray+)
                    (eq ,color cl-colors:+grey+))
                (with-gray ,(or (getf args :stream) t) ,@body)
                (cl-ansi-text:with-color (,color ,@args) ,@body))
            (progn ,@body)))))

(if *enable-colors* (if (or (eq :cyan :gray) (eq :cyan :grey) (eq :cyan +gray+) (eq :cyan +grey+)) (with-gray stream (with-additional-indent (reporter stream "- ") (let ((description (possible-report-description report))) (when description (format/indent reporter stream description)))) (terpri stream)) (cl-ansi-text:with-color (:cyan :stream stream) (with-additional-indent (reporter stream "- ") (let ((description (possible-report-description report))) (when description (format/indent reporter stream description)))) (terpri stream))) (progn (with-additional-indent (reporter stream "- ") (let ((description (possible-report-description report))) (when description (format/indent reporter stream description)))) (terpri stream)))


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
($send nil (progn))

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

Input: ($send nil (progn))

Output: (defmacro $SEND ...)


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(define-shell-component myth :input-type "myth" :output-type "css" :shell-command "myth")

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

Input: (define-shell-component myth :input-type "myth" :output-type "css" :shell-command "myth")

Output:
(defmacro define-shell-component (name &key input-type output-type shell-command)
  "Define an ASDF component that's compiled by running a shell command."
  `(define-component ,name
     :input-type ,input-type
     :output-type ,output-type
     :compile-function (lambda (input-pathname output-pathname)
                         (inferior-shell:run (list ,@(ensure-list shell-command)
                                                    input-pathname
                                                    output-pathname)
                                             :show t))))

(define-component myth :input-type "myth" :output-type "css" :compile-function (lambda (input-pathname output-pathname) (inferior-shell:run (list "myth" input-pathname output-pathname) :show t)))


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(define-global-var nil nil)

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

Input: (define-global-var nil nil)

Output: (defmacro DEFINE-GLOBAL-VAR ...)


Instruction:
Write a Common Lisp macro to handle this code pattern:
(with-html-string (:x-y "Hello"))

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

Input: (with-html-string (:x-y "Hello"))

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

(with-output-to-string (*html*) (with-html (:x-y "Hello")))


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(reduced-typecase 'some-name)

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

Input: (reduced-typecase 'some-name)

Output: (defmacro REDUCED-TYPECASE ...)


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(c?-with-stored (v :foo store 'nothing) (bwhen (val (value v)) (1+ val)))

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

Input: (c?-with-stored (v :foo store 'nothing) (bwhen (val (value v)) (1+ val)))

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

(c? (bwhen-c-stored (v :foo store (quote nothing)) (bwhen (val (value v)) (1+ val))))


Instruction:
Generate a defmacro form that transforms code like this:
(define-final-class nil :key nil)

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

Input: (define-final-class nil :key nil)

Output: (defmacro DEFINE-FINAL-CLASS ...)

(defclass nil :key nil (:metaclass final-class))


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(assoc-cdr :authorization--endpoint disc)

What needs to change: Macro call that should be transformed by assoc-cdr

Input: (assoc-cdr :authorization--endpoint disc)

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

(cdr (assoc :authorization--endpoint disc :test (function eql)))


Instruction:
Write a Common Lisp macro to handle this code pattern:
(-> :p (a) (declare (type fixnum a)) (the fixnum (1+ a)))

Problem: Macro call that should be transformed by ->

Input: (-> :p (a) (declare (type fixnum a)) (the fixnum (1+ a)))

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

(atomically :p (a) (declare (type fixnum a)) (the fixnum (1+ a)))


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(with-yield)

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

Input: (with-yield)

Output: (defmacro WITH-YIELD ...)


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(defclause initially (&rest forms) "Evaluates <form> before the first iteration." (mapcar (lambda (form) (make-initialization :form form)) forms))

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

Input: (defclause initially (&rest forms) "Evaluates <form> before the first iteration." (mapcar (lambda (form) (make-initialization :form form)) forms))

Output:
(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*)))

(progn (defmacro initially (&rest forms) "Evaluates <form> before the first iteration." (mapcar (lambda (form) (make-initialization :form form)) forms)) (pushnew (quote initially) *clauses*))


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(-<>
  nil
  nil)

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

Input:
(-<>
  nil
  nil)

Output: (defmacro -<> ...)


Instruction:
Generate a defmacro form that transforms code like this:
(cond->> 'some-name)

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

Input: (cond->> 'some-name)

Output: (defmacro COND->> ...)


Instruction:
Define a macro that eliminates this repetitive pattern:
(defvariant nil
  nil)

Issue: Macro call that should be transformed by DEFVARIANT

Input:
(defvariant nil
  nil)

Output: (defmacro DEFVARIANT ...)

(progn
 (defstruct (nil (:constructor nil)))
 (defstruct (nil-nil (:include nil)))
 (defmacro match-nil (expr &body match-cases)
   #A((34) base-char . "Match values of variant type: NIL.")
   (let ((expr-var (gensym "-val")))
     `(let ((,expr-var ,expr))
        ,(build-dispatch `,'nil `,'(nil) match-cases expr-var)))))


Instruction:
Generate a defmacro form that transforms code like this:
(with-indentation (with-xml-group-element (s "tspan" opts) (string->xml s text)))

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

Input: (with-indentation (with-xml-group-element (s "tspan" opts) (string->xml s text)))

Output:
(defmacro with-indentation (&body body)
  `(let ((*indent-level* (+ *indent-level* *indent-spacing*)))
     ,@body))

(let ((*indent-level* (+ *indent-level* *indent-spacing*))) (with-xml-group-element (s "tspan" opts) (string->xml s text)))


Instruction:
Define a macro that eliminates this repetitive pattern:
(builder (:backtrace :output *test-error-output* :result-on-error '(500 (:content-type "text/plain") ("Internal Server Error"))) (lambda (env) (declare (ignore env)) (error "Error occured")))

Issue: Macro call that should be transformed by builder

Input: (builder (:backtrace :output *test-error-output* :result-on-error '(500 (:content-type "text/plain") ("Internal Server Error"))) (lambda (env) (declare (ignore env)) (error "Error occured")))

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

(reduce (function funcall) (remove-if (function null) (list (lambda (#:app196) (funcall (find-middleware :backtrace) #:app196 :output *test-error-output* :result-on-error (quote (500 (:content-type "text/plain") ("Internal Server Error"))))))) :initial-value (to-app (lambda (env) (declare (ignore env)) (error "Error occured"))) :from-end t)


Instruction:
Generate a defmacro form that transforms code like this:
(draw group (:line :x1 x :y1 y :x2 dx :y2 dy))

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

Input: (draw group (:line :x1 x :y1 y :x2 dx :y2 dy))

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

(let ((#:g158 (funcall (function make-svg-element) :line (append (list :x1 x :y1 y :x2 dx :y2 dy) (list))))) (add-element group #:g158) #:g158)


Instruction:
Write a Common Lisp macro to handle this code pattern:
(-> :one () (increment))

Problem: Macro call that should be transformed by ->

Input: (-> :one () (increment))

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


Instruction:
Define a macro that eliminates this repetitive pattern:
(ps-html nil)

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

Input: (ps-html nil)

Output: (defmacro PS-HTML ...)


Instruction:
Define a macro that eliminates this repetitive pattern:
(with-slots nil
    (progn))

Issue: Macro call that should be transformed by WITH-SLOTS

Input:
(with-slots nil
    (progn))

Output: (defmacro WITH-SLOTS ...)

(let ((#:g179 (progn)))
  (declare (ignorable #:g179))
  (symbol-macrolet ()))


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(defsynonym :finding :find)

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

Input: (defsynonym :finding :find)

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

(eval-always (setf (get (quote :finding) (quote synonym)) (quote :find)))


Instruction:
Generate a defmacro form that transforms code like this:
(deferror "22012" db-division-by-zero data-exception)

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

Input: (deferror "22012" db-division-by-zero data-exception)

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

(progn (define-condition db-division-by-zero (data-exception) nil) (setf (gethash "22012" *error-table*) (quote db-division-by-zero)))


Instruction:
Define a macro that eliminates this repetitive pattern:
(define-test subtest :parent example (fail (error "An expected failure.")) (fail (warn "An expected warning.") warning))

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

Input: (define-test subtest :parent example (fail (error "An expected failure.")) (fail (warn "An expected warning.") warning))

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

(let ((*package* (find-package #A((9) base-char . "PARACHUTE")))) (setf (find-test (quote subtest) (find-package #A((9) base-char . "PARACHUTE"))) (ensure-test (quote test) :name (quote subtest) :home (find-package #A((9) base-char . "PARACHUTE")) :tests (list (lambda nil (fail (error "An expected failure."))) (lambda nil (fail (warn "An expected warning.") warning))) :parent (quote example))) (quote subtest))


Instruction:
Define a macro that eliminates this repetitive pattern:
(defclause summing-to-and-returning (vars &optional result-processor) "Same as summing-to, but also returns the value of each <vars> at the end of the loop." `((summing-to ,vars ,result-processor) ,@(mapcar (lambda (var) `(returning ,var)) (ensure-list vars))))

Issue: Macro call that should be transformed by defclause

Input: (defclause summing-to-and-returning (vars &optional result-processor) "Same as summing-to, but also returns the value of each <vars> at the end of the loop." `((summing-to ,vars ,result-processor) ,@(mapcar (lambda (var) `(returning ,var)) (ensure-list vars))))

Output:
(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*)))

(progn (defmacro summing-to-and-returning (vars &optional result-processor) "Same as summing-to, but also returns the value of each <vars> at the end of the loop." (sb-int:quasiquote ((summing-to #S(sb-impl::comma :expr vars :kind 0) #S(sb-impl::comma :expr result-processor :kind 0)) #S(sb-impl::comma :expr (mapcar (lambda (var) (sb-int:quasiquote (returning #S(sb-impl::comma :expr var :kind 0)))) (ensure-list vars)) :kind 2)))) (pushnew (quote summing-to-and-returning) *clauses*))


Instruction:
Write a Common Lisp macro to handle this code pattern:
(action (:after node-match) #'apply-lift)

Problem: Macro call that should be transformed by action

Input: (action (:after node-match) #'apply-lift)

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

(make-action (quote :after) (quote node-match) (function apply-lift))


Instruction:
Write a Common Lisp macro to handle this code pattern:
(with-handle-interrupt (lambda () (format *error-output* "Interrupted")) (prog1 (apply #'clack.handler:run app server :port port :debug debug :use-thread use-thread (delete-from-plist args :server :port :debug :use-thread)) (when (and use-thread (not silent)) (format t "~&~:(~A~) server is started.~%Listening on ~A:~A.~%" server address port))))

Problem: Macro call that should be transformed by with-handle-interrupt

Input: (with-handle-interrupt (lambda () (format *error-output* "Interrupted")) (prog1 (apply #'clack.handler:run app server :port port :debug debug :use-thread use-thread (delete-from-plist args :server :port :debug :use-thread)) (when (and use-thread (not silent)) (format t "~&~:(~A~) server is started.~%Listening on ~A:~A.~%" server address port))))

Output:
(defmacro with-handle-interrupt (int-handler &body body)
  (let ((main (gensym "MAIN")))
    `(flet ((,main () ,@body))
       #+(or sbcl ccl clisp allegro ecl)
       (handler-case
           (let (#+ccl (ccl:*break-hook* (lambda (condition hook)
                                           (declare (ignore hook))
                                           (error condition))))
             (,main))
         (#+sbcl sb-sys:interactive-interrupt
          #+ccl  ccl:interrupt-signal-condition
          #+clisp system::simple-interrupt-condition
          #+ecl ext:interactive-interrupt
          #+allegro excl:interrupt-signal
          ()
           (funcall ,int-handler)))
       #-(or sbcl ccl clisp allegro ecl)
       (,main))))

(flet ((#:main163 nil (prog1 (apply (function run) app server :port port :debug debug :use-thread use-thread (delete-from-plist args :server :port :debug :use-thread)) (when (and use-thread (not silent)) (format t "~&~:(~A~) server is started.~%Listening on ~A:~A.~%" server address port))))) (handler-case (let nil (#:main163)) (sb-sys:interactive-interrupt nil (funcall (lambda nil (format *error-output* "Interrupted"))))))


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(acond (:foo))

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

Input: (acond (:foo))

Output:
(defmacro acond (&body clauses)
  "Like COND, except result of each test-form is bound to IT (via LET) for the
scope of the corresponding clause."
  (labels ((rec (clauses)
	     (if clauses
		 (destructuring-bind ((test &body body) . rest)  clauses
		   (if body
		       `(anaphoric if ,test (progn ,@body) ,(rec rest))
		       `(anaphoric if ,test it ,(rec rest))))
		 nil)))
    (rec clauses)))

(let ((#:it :foo)) (if #:it #:it (acond)))


Instruction:
Write a Common Lisp macro to handle this code pattern:
(when (or (typep (node-slot expression) 'function-call) (typep (node-slot expression) 'infix-expression) (typep (node-slot expression) 'prefix-expression) (typep (node-slot expression) 'postfix-expression)) (format stream "~&~a" indent))

Problem: Macro call that should be transformed by when

Input: (when (or (typep (node-slot expression) 'function-call) (typep (node-slot expression) 'infix-expression) (typep (node-slot expression) 'prefix-expression) (typep (node-slot expression) 'postfix-expression)) (format stream "~&~a" indent))

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

(if (or (typep (node-slot expression) (quote function-call)) (typep (node-slot expression) (quote infix-expression)) (typep (node-slot expression) (quote prefix-expression)) (typep (node-slot expression) (quote postfix-expression))) (format stream "~&~a" indent))


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(defgenerator product (&rest lists) "Iterates through each of the supplied lists with nested dolists, yielding an element from each for every iteration of the innermost loop. The yielded values cycle in an odometer-like fashion, with the first value changing seldom and the last changing on every yield. Eg: (product '(a b c d) '(x y)) -(values)-> (a x) (a y) (b x) (b y) (c x) (c y)... " (labels ((listholder (lists) (if (null lists) (lambda (stack) (apply #'yield (reverse stack))) (let ((nextfunc (listholder (cdr lists)))) (lambda (stack) (dolist (itm (car lists)) (funcall nextfunc (cons itm stack)))))))) (funcall (listholder lists) nil)))

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

Input: (defgenerator product (&rest lists) "Iterates through each of the supplied lists with nested dolists, yielding an element from each for every iteration of the innermost loop. The yielded values cycle in an odometer-like fashion, with the first value changing seldom and the last changing on every yield. Eg: (product '(a b c d) '(x y)) -(values)-> (a x) (a y) (b x) (b y) (c x) (c y)... " (labels ((listholder (lists) (if (null lists) (lambda (stack) (apply #'yield (reverse stack))) (let ((nextfunc (listholder (cdr lists)))) (lambda (stack) (dolist (itm (car lists)) (funcall nextfunc (cons itm stack)))))))) (funcall (listholder lists) nil)))

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

(defun product (&rest lists) "Iterates through each of the supplied lists with nested dolists, yielding an element from each for every iteration of the innermost loop. The yielded values cycle in an odometer-like fashion, with the first value changing seldom and the last changing on every yield. Eg: (product '(a b c d) '(x y)) -(values)-> (a x) (a y) (b x) (b y) (c x) (c y)... " (with-yield (labels ((listholder (lists) (if (null lists) (lambda (stack) (apply (function yield) (reverse stack))) (let ((nextfunc (listholder (cdr lists)))) (lambda (stack) (dolist (itm (car lists)) (funcall nextfunc (cons itm stack)))))))) (funcall (listholder lists) nil))))


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(iterate nil)

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

Input: (iterate nil)

Output: (defmacro ITERATE ...)

(progn (tagbody #:ll-246 ((lambda ())) (go #:ll-246)) nil)


Instruction:
Define a macro that eliminates this repetitive pattern:
(is-true (with-*test-dribble* nil (explain! (run 'is1))))

Issue: Macro call that should be transformed by is-true

Input: (is-true (with-*test-dribble* nil (explain! (run 'is1))))

Output:
(defmacro is-true (condition &rest reason-args)
  "Like IS this check generates a pass if CONDITION returns true
  and a failure if CONDITION returns false. Unlike IS this check
  does not inspect CONDITION to determine how to report the
  failure."
  `(if ,condition
       (add-result 'test-passed :test-expr ',condition)
       (process-failure ',condition
                        ,@(or reason-args
                              `("~S did not return a true value" ',condition)))))

(if (with-*test-dribble* nil (explain! (run (quote is1)))) (add-result (quote test-passed) :test-expr (quote (with-*test-dribble* nil (explain! (run (quote is1)))))) (process-failure (quote (with-*test-dribble* nil (explain! (run (quote is1))))) "~S did not return a true value" (quote (with-*test-dribble* nil (explain! (run (quote is1)))))))


Instruction:
Write a Common Lisp macro to handle this code pattern:
(when (first in-decl) (push nil in-decl-item))

Problem: Macro call that should be transformed by when

Input: (when (first in-decl) (push nil in-decl-item))

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

(if (first in-decl) (push nil in-decl-item))


Instruction:
Write a Common Lisp macro to handle this code pattern:
(the nil nil)

Problem: Macro call that should be transformed by THE

Input: (the nil nil)

Output: (defmacro THE ...)


Instruction:
Define a macro that eliminates this repetitive pattern:
(defjs hello (x y) (return (+ x y)))

Issue: Macro call that should be transformed by defjs

Input: (defjs hello (x y) (return (+ x y)))

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

(let* ((js-body (parenscript:ps (lambda (x y) (return (+ x y)))))) (setf (gethash (quote hello) *js-definitions*) js-body) (defun hello (x y) (get-element "retval" (car (docs (db.eval js-body x y))))))


Instruction:
Generate a defmacro form that transforms code like this:
(do+ (for x (in '(1 2 3))) (do+ (for y (in '(a b))) (collect (list x y) :into foo)))

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

Input: (do+ (for x (in '(1 2 3))) (do+ (for y (in '(a b))) (collect (list x y) :into foo)))

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

(do+/internal nil (for x (in (quote (1 2 3)))) (do+ (for y (in (quote (a b)))) (collect (list x y) :into foo)))


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(lambda+ nil
  :key
  nil)

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

Input:
(lambda+ nil
  :key
  nil)

Output: (defmacro LAMBDA+ ...)

(lambda ()
  (let+ nil
    :key
    nil))


Instruction:
Define a macro that eliminates this repetitive pattern:
(check-cursor-attached cluffer:beginning-of-buffer-p (cursor))

Issue: Macro call that should be transformed by check-cursor-attached

Input: (check-cursor-attached cluffer:beginning-of-buffer-p (cursor))

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

(defmethod cluffer:beginning-of-buffer-p :before ((cursor cluffer:cursor)) (declare (ignore)) (unless (cluffer:cursor-attached-p cursor) (error (quote cluffer:cursor-detached))))


Instruction:
Generate a defmacro form that transforms code like this:
(the 'some-name)

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

Input: (the 'some-name)

Output: (defmacro THE ...)


Instruction:
Generate a defmacro form that transforms code like this:
(fgathering nil
  :key
  nil)

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

Input:
(fgathering nil
  :key
  nil)

Output: (defmacro FGATHERING ...)


Instruction:
Define a macro that eliminates this repetitive pattern:
(with-sql-logging (mapc #'execute-sql (table-definition class)))

Issue: Macro call that should be transformed by with-sql-logging

Input: (with-sql-logging (mapc #'execute-sql (table-definition class)))

Output:
(defmacro with-sql-logging (&body body)
  `(let ((*mito-logger-stream* *mito-migration-logger-stream*))
     (with-trace-sql ,@body)))

(let ((*mito-logger-stream* *mito-migration-logger-stream*)) (with-trace-sql (mapc (function execute-sql) (table-definition class))))


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(destructuring-bind () nil)

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

Input: (destructuring-bind () nil)

Output: (defmacro DESTRUCTURING-BIND ...)

(sb-int:binding* ((nil (sb-c::check-ds-list nil 0 0 'nil))))


Instruction:
Generate a defmacro form that transforms code like this:
(lambda-ignoring-_ (exp1 _ exp2) `(,op ,exp1 ,exp2))

Pattern to recognize: Macro call that should be transformed by lambda-ignoring-_

Input: (lambda-ignoring-_ (exp1 _ exp2) `(,op ,exp1 ,exp2))

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

(lambda (exp1 _ exp2) (declare (ignore _)) (sb-int:quasiquote (#S(sb-impl::comma :expr op :kind 0) #S(sb-impl::comma :expr exp1 :kind 0) #S(sb-impl::comma :expr exp2 :kind 0))))


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(atomically nil () (symbol-name 'this))

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

Input: (atomically nil () (symbol-name 'this))

Output:
(defmacro atomically (invariant &body args)
  "Encloses atomic flow block of code that can be dispatched
concurrently. Non-consing."
  (destructuring-bind (opts lambda-list body) (parse-atomic-block-args args)
    (flow-lambda-macro (flow-context)
      (with-flow-function-macro (body-fu lambda-list body)
        `(dispatch-atomically ,flow-context #',body-fu ,invariant ,@opts)))))

(%flow-lambda (#:flow-context155) (%with-flow-function (#:body-fu156 nil (symbol-name (quote this))) (dispatch-atomically #:flow-context155 (function #:body-fu156) nil)))


Instruction:
Generate a defmacro form that transforms code like this:
(with-context (context) (call-next-method))

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

Input: (with-context (context) (call-next-method))

Output:
(defmacro with-context ((context) &body body)
  `(let* ((*context* ,context)
          (*request* (context :request))
          (*response* (context :response))
          (*session* (context :session)))
     ,@body))

(let* ((*context* context) (*request* (context :request)) (*response* (context :response)) (*session* (context :session))) (call-next-method))


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(do-matches (match-start match-end regex target-string (nreverse result-list) :start start :end end) (push match-start result-list) (push match-end result-list))

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

Input: (do-matches (match-start match-end regex target-string (nreverse result-list) :start start :end end) (push match-start result-list) (push match-end result-list))

Output:
(defmacro do-matches ((match-start match-end regex
                                   target-string
                                   &optional result-form
                                   &key start end)
                      &body body)
  "Iterates over TARGET-STRING and tries to match REGEX as often as
possible evaluating BODY with MATCH-START and MATCH-END bound to the
start/end positions of each match in turn.  After the last match,
returns RESULT-FORM if provided or NIL otherwise.  An implicit block
named NIL surrounds DO-MATCHES; RETURN may be used to terminate the
loop immediately.  If REGEX matches an empty string the scan is
continued one position behind this match.  BODY may start with
declarations."
  ;; this is a simplified form of DO-SCANS - we just provide two dummy
  ;; vars and ignore them
  (with-unique-names (reg-starts reg-ends)
    `(do-scans (,match-start ,match-end
                ,reg-starts ,reg-ends
                ,regex ,target-string
                ,result-form
                :start ,start :end ,end)
      ,@body)))

(do-scans (match-start match-end #:reg-starts139 #:reg-ends140 regex target-string (nreverse result-list) :start start :end end) (push match-start result-list) (push match-end result-list))


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(define-modf-rewrite caaaar (expr) `(car (caaar ,(second expr))))

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

Input: (define-modf-rewrite caaaar (expr) `(car (caaar ,(second expr))))

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

(eval-when (:compile-toplevel :load-toplevel :execute) (setf (gethash (quote caaaar) *modf-rewrites*) (lambda (expr) (sb-int:quasiquote (car (caaar #S(sb-impl::comma :expr (second expr) :kind 0)))))))


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(define-mustache-character #\/ (make-instance 'section-end-tag :text arg-text :start start))

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

Input: (define-mustache-character #\/ (make-instance 'section-end-tag :text arg-text :start start))

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

(set-mustache-character #\SOLIDUS (lambda (raw-text arg-text escapep start end) (declare (ignorable raw-text arg-text escapep start end) (type simple-string raw-text arg-text) (boolean escapep) (offset start end)) (make-instance (quote section-end-tag) :text arg-text :start start)))


Instruction:
Generate a defmacro form that transforms code like this:
(f nil
  :key
  nil)

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

Input:
(f nil
  :key
  nil)

Output: (defmacro F ...)


Instruction:
Define a macro that eliminates this repetitive pattern:
(define-component js-minify :input-type "js" :output-type "min.js" :compile-function (lambda (input-pathname output-pathname) (inferior-shell:run `("yui-compressor" ,input-pathname "-o" ,output-pathname) :show t)))

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

Input: (define-component js-minify :input-type "js" :output-type "min.js" :compile-function (lambda (input-pathname output-pathname) (inferior-shell:run `("yui-compressor" ,input-pathname "-o" ,output-pathname) :show t)))

Output:
(defmacro define-component (name &key input-type output-type compile-function)
  "Define an ASDF component."
  `(progn
     (defclass ,name (source-file)
       ((type :initform ,input-type)
        (output :reader output :initarg :output)))

     (defmethod perform ((o load-op) (component ,name)) t)

     (defmethod output-files ((operation compile-op) (component ,name))
       (list
        (output-pathname component ,output-type)))

     (defmethod perform ((o compile-op) (component ,name))
       (funcall ,compile-function
                (component-pathname component)
                (output-pathname component ,output-type)))

     (import ',name :asdf)))

(progn (defclass js-minify (source-file) ((type :initform "js") (output :reader output :initarg :output))) (defmethod perform ((o load-op) (component js-minify)) t) (defmethod output-files ((operation compile-op) (component js-minify)) (list (output-pathname component "min.js"))) (defmethod perform ((o compile-op) (component js-minify)) (funcall (lambda (input-pathname output-pathname) (inferior-shell:run (sb-int:quasiquote ("yui-compressor" #S(sb-impl::comma :expr input-pathname :kind 0) "-o" #S(sb-impl::comma :expr output-pathname :kind 0))) :show t)) (component-pathname component) (output-pathname component "min.js"))) (import (quote js-minify) :asdf))


Instruction:
Generate a defmacro form that transforms code like this:
(defun-compile-time walk-multiple-value-prog1 (map-function reduce-function screamer? partial? nested? form environment) (unless (null (rest (last form))) (error "Improper MULTIPLE-VALUE-PROG1: ~S" form)) (unless (>= (length form) 2) (error "MULTIPLE-VALUE-PROG1 must have at least one argument, a FORM: ~S" form)) (if reduce-function (funcall reduce-function (funcall map-function form 'multiple-value-prog1) (reduce reduce-function (mapcar #'(lambda (subform) (walk map-function reduce-function screamer? partial? nested? subform environment)) (rest form)))) (funcall map-function form 'multiple-value-prog1)))

Pattern to recognize: Macro call that should be transformed by defun-compile-time

Input: (defun-compile-time walk-multiple-value-prog1 (map-function reduce-function screamer? partial? nested? form environment) (unless (null (rest (last form))) (error "Improper MULTIPLE-VALUE-PROG1: ~S" form)) (unless (>= (length form) 2) (error "MULTIPLE-VALUE-PROG1 must have at least one argument, a FORM: ~S" form)) (if reduce-function (funcall reduce-function (funcall map-function form 'multiple-value-prog1) (reduce reduce-function (mapcar #'(lambda (subform) (walk map-function reduce-function screamer? partial? nested? subform environment)) (rest form)))) (funcall map-function form 'multiple-value-prog1)))

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

(eval-when (:compile-toplevel :load-toplevel :execute) (common-lisp:defun walk-multiple-value-prog1 (map-function reduce-function screamer? partial? nested? form environment) (unless (null (rest (last form))) (error "Improper MULTIPLE-VALUE-PROG1: ~S" form)) (unless (>= (length form) 2) (error "MULTIPLE-VALUE-PROG1 must have at least one argument, a FORM: ~S" form)) (if reduce-function (funcall reduce-function (funcall map-function form (quote multiple-value-prog1)) (reduce reduce-function (mapcar (function (lambda (subform) (walk map-function reduce-function screamer? partial? nested? subform environment))) (rest form)))) (funcall map-function form (quote multiple-value-prog1)))) (eval-when (:compile-toplevel) (compile (quote walk-multiple-value-prog1))))


Instruction:
Write a Common Lisp macro to handle this code pattern:
(with-open-temporary-file (f :keep keep) (pathname f))

Problem: Macro call that should be transformed by with-open-temporary-file

Input: (with-open-temporary-file (f :keep keep) (pathname f))

Output:
(defmacro with-open-temporary-file ((stream &rest args &key keep &allow-other-keys) &body body)
  "Create a temporary file using OPEN-TEMPORARY with ARGS and run BODY
  with STREAM bound to the temporary file stream.  Returns the values
  returned by BODY.  By default, the file is deleted when BODY is
  exited. If a true value is passed in KEEP, the file is not deleted
  when the body is exited.  See OPEN-TEMPORARY for more permitted
  options."
  `(with-open-stream (,stream (open-temporary ,@(alexandria:remove-from-plist args :keep)))
     #+sbcl
     (declare (sb-ext:muffle-conditions sb-ext:code-deletion-note))
     ,(if (and (constantp keep)
               keep)
          `(progn ,@body)
          `(unwind-protect
                (progn ,@body)
             (unless ,keep
               (close ,stream)
               (delete-file (pathname ,stream)))))))

(with-open-stream (f (open-temporary)) (declare (sb-ext:muffle-conditions sb-ext:code-deletion-note)) (unwind-protect (progn (pathname f)) (unless keep (close f) (delete-file (pathname f)))))


Instruction:
Write a Common Lisp macro to handle this code pattern:
(defclause returning (&rest forms) "Returns each form in <forms> as the value of the do+ form when the loop ends. If multiple forms are specified, by one or more RETURNING clauses, multiple values are returned, in the order the corresponding forms appear lexically. If one of the <forms> is (cl:values ...), then each value will be returned as if the values were spelled as direct arguments of the RETURNING form." (let (result-clauses) (dolist (form forms) (if (and (listp form) (eq 'values (car form))) (dolist (form (cdr form)) (push (make-result :form form) result-clauses)) (push (make-result :form form) result-clauses))) (nreverse result-clauses)))

Problem: Macro call that should be transformed by defclause

Input: (defclause returning (&rest forms) "Returns each form in <forms> as the value of the do+ form when the loop ends. If multiple forms are specified, by one or more RETURNING clauses, multiple values are returned, in the order the corresponding forms appear lexically. If one of the <forms> is (cl:values ...), then each value will be returned as if the values were spelled as direct arguments of the RETURNING form." (let (result-clauses) (dolist (form forms) (if (and (listp form) (eq 'values (car form))) (dolist (form (cdr form)) (push (make-result :form form) result-clauses)) (push (make-result :form form) result-clauses))) (nreverse result-clauses)))

Output:
(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*)))

(progn (defmacro returning (&rest forms) "Returns each form in <forms> as the value of the do+ form when the loop ends. If multiple forms are specified, by one or more RETURNING clauses, multiple values are returned, in the order the corresponding forms appear lexically. If one of the <forms> is (cl:values ...), then each value will be returned as if the values were spelled as direct arguments of the RETURNING form." (let (result-clauses) (dolist (form forms) (if (and (listp form) (eq (quote values) (car form))) (dolist (form (cdr form)) (push (make-result :form form) result-clauses)) (push (make-result :form form) result-clauses))) (nreverse result-clauses))) (pushnew (quote returning) *clauses*))


Instruction:
Write a Common Lisp macro to handle this code pattern:
(next-in nil)

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

Input: (next-in nil)

Output: (defmacro NEXT-IN ...)


Instruction:
Define a macro that eliminates this repetitive pattern:
(pop-last-preprocessor-directive-token directive-token-list directive-symbol)

Issue: Macro call that should be transformed by pop-last-preprocessor-directive-token

Input: (pop-last-preprocessor-directive-token directive-token-list directive-symbol)

Output:
(defmacro pop-last-preprocessor-directive-token (token-list directive-name)
  "For #ifdef, #ifndef, and #undef"
  (with-gensyms (dsym_)
    `(let ((,dsym_ ,directive-name))
       (prog1 (pop-preprocessor-directive-token ,token-list ,dsym_)
         (check-no-preprocessor-token ,token-list ,dsym_)))))

(let ((#:dsym_269 directive-symbol)) (prog1 (pop-preprocessor-directive-token directive-token-list #:dsym_269) (check-no-preprocessor-token directive-token-list #:dsym_269)))


Instruction:
Write a Common Lisp macro to handle this code pattern:
(-> :heh () (funcall #'%continue))

Problem: Macro call that should be transformed by ->

Input: (-> :heh () (funcall #'%continue))

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

(atomically :heh nil (funcall (function %continue)))


Instruction:
Define a macro that eliminates this repetitive pattern:
(defstruct*
  nil
  (progn))

Issue: Macro call that should be transformed by DEFSTRUCT*

Input:
(defstruct*
  nil
  (progn))

Output: (defmacro DEFSTRUCT* ...)

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


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(draw scene (:rect :x 30 :y 300 :width 400 :height 150) :fill "rgb(230,230,230)" :stroke "black")

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

Input: (draw scene (:rect :x 30 :y 300 :width 400 :height 150) :fill "rgb(230,230,230)" :stroke "black")

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

(let ((#:g165 (funcall (function make-svg-element) :rect (append (list :x 30 :y 300 :width 400 :height 150) (list :fill "rgb(230,230,230)" :stroke "black"))))) (add-element scene #:g165) #:g165)


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(builder (:session :store (make-dbi-store :connector (lambda () *conn*))) (lambda (env) (unless (gethash :counter (getf env :lack.session)) (setf (gethash :counter (getf env :lack.session)) 0)) `(200 (:content-type "text/plain") (,(format nil "Hello, you've been here for ~Ath times!" (incf (gethash :counter (getf env :lack.session))))))))

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

Input: (builder (:session :store (make-dbi-store :connector (lambda () *conn*))) (lambda (env) (unless (gethash :counter (getf env :lack.session)) (setf (gethash :counter (getf env :lack.session)) 0)) `(200 (:content-type "text/plain") (,(format nil "Hello, you've been here for ~Ath times!" (incf (gethash :counter (getf env :lack.session))))))))

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

(reduce (function funcall) (remove-if (function null) (list (lambda (#:app232) (funcall (find-middleware :session) #:app232 :store (make-dbi-store :connector (lambda nil *conn*)))))) :initial-value (to-app (lambda (env) (unless (gethash :counter (getf env :lack.session)) (setf (gethash :counter (getf env :lack.session)) 0)) (sb-int:quasiquote (200 (:content-type "text/plain") (#S(sb-impl::comma :expr (format nil "Hello, you've been here for ~Ath times!" (incf (gethash :counter (getf env :lack.session)))) :kind 0)))))) :from-end t)


Instruction:
Write a Common Lisp macro to handle this code pattern:
(next-in nil (progn))

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

Input: (next-in nil (progn))

Output: (defmacro NEXT-IN ...)


Instruction:
Generate a defmacro form that transforms code like this:
(define-custom-var (:string-scope *string-scope-variables*) nil "A list of symbols naming dynamic variables which should be re-bound in the scope of every JSON String.")

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

Input: (define-custom-var (:string-scope *string-scope-variables*) nil "A list of symbols naming dynamic variables which should be re-bound in the scope of every JSON String.")

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

(eval-when (:compile-toplevel :load-toplevel :execute) (progn (pushnew (quote (*string-scope-variables* . :string-scope)) *custom-vars* :test (function equal)) (defvar *string-scope-variables* nil "A list of symbols naming dynamic variables which should be re-bound in the scope of every JSON String.")))


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(asif (incf (car x)) it (list :oops it))

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

Input: (asif (incf (car x)) it (list :oops it))

Output:
(defmacro asif (test then &optional else)
  "Like IF, except binds the result of the test to IT (via LET) for
the the scope of the then-expression, and the test form to IT (via
SYMBOL-MACROLET) for the scope of the else-expression. Within scope of
the else-expression, IT can be set with SETF."
    `(let ((it ,test))
       (if it
	   ,then
	   (symbolic ignore-first ,test ,else))))

(let ((it (incf (car x)))) (if it it (symbolic ignore-first (incf (car x)) (list :oops it))))


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(is (= 6 (length results)))

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

Input: (is (= 6 (length results)))

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

(let ((#:e202 6) (#:a203 (length results))) (if (progn (= #:e202 #:a203)) (add-result (quote test-passed) :test-expr (quote (= 6 (length results)))) (process-failure (quote (= 6 (length results))) "~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%" (quote (length results)) #:a203 (quote =) #:e202)))


Instruction:
Write a Common Lisp macro to handle this code pattern:
(defcategory :critical)

Problem: Macro call that should be transformed by defcategory

Input: (defcategory :critical)

Output:
(defmacro defcategory (category &optional expands-as set)
  `(defcategory-fn ',category ',expands-as ,set))

(defcategory-fn (quote :critical) (quote nil) nil)


Instruction:
Generate a defmacro form that transforms code like this:
(deferror "22007" invalid-datetime-format data-exception)

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

Input: (deferror "22007" invalid-datetime-format data-exception)

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

(progn (define-condition invalid-datetime-format (data-exception) nil) (setf (gethash "22007" *error-table*) (quote invalid-datetime-format)))


Instruction:
Generate a defmacro form that transforms code like this:
(when (first in-decl) (setf (first in-decl-item) nil))

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

Input: (when (first in-decl) (setf (first in-decl-item) nil))

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

(if (first in-decl) (setf (first in-decl-item) nil))


Instruction:
Write a Common Lisp macro to handle this code pattern:
(collect-or 'some-name)

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

Input: (collect-or 'some-name)

Output: (defmacro COLLECT-OR ...)

(common-lisp:let* ((#:generator-332 (generator 'some-name))
                   #:bools-328
                   (#:bool-329 nil))
  (declare (type generator #:generator-332))
  (tagbody
   #:ll-333
    (setq #:bools-328 (next-in #:generator-332 (go end)))
    (if (setq #:bool-329 #:bools-328)
        (go end))
    (go #:ll-333)
   end)
  #:bool-329)


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(lambda* nil
  (progn))

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

Input:
(lambda* nil
  (progn))

Output: (defmacro LAMBDA* ...)


Instruction:
Write a Common Lisp macro to handle this code pattern:
(maybe-do-not-silence-errors (handler-case (call-next-method) (error (err) (warn "Unhandled error when evaluating ~a:~% ~a~%" (or (ignore-errors (format-result result :oneline)) result) err) (setf (description result) (format NIL "The test failed to evaluate properly:~% ~a" err)) (setf (status result) :failed))))

Problem: Macro call that should be transformed by maybe-do-not-silence-errors

Input: (maybe-do-not-silence-errors (handler-case (call-next-method) (error (err) (warn "Unhandled error when evaluating ~a:~% ~a~%" (or (ignore-errors (format-result result :oneline)) result) err) (setf (description result) (format NIL "The test failed to evaluate properly:~% ~a" err)) (setf (status result) :failed))))

Output:
(defmacro maybe-do-not-silence-errors (&body body)
  `(if *silence-plain-compilation-errors-p*
       ,@body
       (let ((ok nil))
         (unwind-protect
              (multiple-value-prog1
                  (call-next-method)
                (setf ok t))
           (unless ok (setf (status result) :failed))))))

(if *silence-plain-compilation-errors-p* (handler-case (call-next-method) (error (err) (warn "Unhandled error when evaluating ~a:~% ~a~%" (or (ignore-errors (format-result result :oneline)) result) err) (setf (description result) (format nil "The test failed to evaluate properly:~% ~a" err)) (setf (status result) :failed))) (let ((ok nil)) (unwind-protect (multiple-value-prog1 (call-next-method) (setf ok t)) (unless ok (setf (status result) :failed)))))


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(terminate)

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

Input: (terminate)

Output: (defmacro TERMINATE ...)


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(@ nil nil)

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

Input: (@ nil nil)

Output: (defmacro @ ...)


Instruction:
Generate a defmacro form that transforms code like this:
(in-readtable nil)

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

Input: (in-readtable nil)

Output: (defmacro IN-READTABLE ...)

(eval-when (:compile-toplevel :load-toplevel :execute)
  (setf *readtable* (ensure-readtable 'nil))
  (when (or (find-package :swank) (find-package :slynk))
    (editor-hints.named-readtables::%frob-swank-readtable-alist *package*
                                                                *readtable*))
  *readtable*)


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(define-op (:!= infix-op))

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

Input: (define-op (:!= infix-op))

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

(defstruct (!=-op (:include infix-op (name "!=")) (:constructor make-!=-op (left right))))


Instruction:
Write a Common Lisp macro to handle this code pattern:
(is-true (with-*test-dribble* nil (explain! (run 'is1))))

Problem: Macro call that should be transformed by is

Input: (is-true (with-*test-dribble* nil (explain! (run 'is1))))

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

(if (with-*test-dribble* nil (explain! (run (quote is1)))) (add-result (quote test-passed) :test-expr (quote (with-*test-dribble* nil (explain! (run (quote is1)))))) (process-failure (quote (with-*test-dribble* nil (explain! (run (quote is1))))) "~S did not return a true value" (quote (with-*test-dribble* nil (explain! (run (quote is1)))))))


Instruction:
Write a Common Lisp macro to handle this code pattern:
(make-name-transformer nil)

Problem: Macro call that should be transformed by MAKE-NAME-TRANSFORMER

Input: (make-name-transformer nil)

Output: (defmacro MAKE-NAME-TRANSFORMER ...)

(lambda (name definition)
  (declare (ignorable definition))
  (concatenate-symbol nil))


Instruction:
Write a Common Lisp macro to handle this code pattern:
(defalias path:= (a b) cl-fad:pathname-equal)

Problem: Macro call that should be transformed by defalias

Input: (defalias path:= (a b) cl-fad:pathname-equal)

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

(progn (defun path:= (a b) (pathname-equal a b)) (define-compiler-macro path:= (&rest args) (list* (quote pathname-equal) args)))


Instruction:
Define a macro that eliminates this repetitive pattern:
($ "$max" ($ "value-1" 610))

Issue: Macro call that should be transformed by $

Input: ($ "$max" ($ "value-1" 610))

Output:
(defmacro $ (&rest args)
  `(kv ,@args))