Instruction:
Generate a defmacro form that transforms code like this:
(c-assert (typep fm-parent 'family))

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

Input: (c-assert (typep fm-parent 'family))

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

(unless *stop* (unless (typep fm-parent (quote family)) (c-break "failed assertion: ~a" (quote (typep fm-parent (quote family))))))


Instruction:
Define a macro that eliminates this repetitive pattern:
(define-error no-valid-function () (name types form) "There is no applicable method for the glsl function '~s' when called with ~a ~@[Form: ~a~]" name (if types (format nil "argument types:~%~s" (mapcar #'type->type-spec types)) "no arguments.") form)

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

Input: (define-error no-valid-function () (name types form) "There is no applicable method for the glsl function '~s' when called with ~a ~@[Form: ~a~]" name (if types (format nil "argument types:~%~s" (mapcar #'type->type-spec types)) "no arguments.") form)

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 no-valid-function (:error-type varjo-error :prefix "Varjo") (name types form) "There is no applicable method for the glsl function '~s' when called with ~a ~@[Form: ~a~]" name (if types (format nil "argument types:~%~s" (mapcar (function type->type-spec) types)) "no arguments.") form)


Instruction:
Define a macro that eliminates this repetitive pattern:
(when-let (name (messenger-name self)) (format stream "~a" name))

Issue: Macro call that should be transformed by when-let

Input: (when-let (name (messenger-name self)) (format stream "~a" name))

Output:
(defmacro when-let (binding &body body)
  (destructuring-bind (var val) binding
    `(let ((,var ,val))
       (when ,var
	 ,@body))))

(let ((name (messenger-name self))) (when name (format stream "~a" name)))


Instruction:
Define a macro that eliminates this repetitive pattern:
(collect-product nil)

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

Input: (collect-product nil)

Output: (defmacro COLLECT-PRODUCT ...)

(common-lisp:let* ((#:generator-125 (generator nil))
                   #:numbers-121
                   (#:mul-122 1))
  (declare (type generator #:generator-125)
           (type number #:mul-122))
  (tagbody
   #:ll-126
    (setq #:numbers-121 (next-in #:generator-125 (go end)))
    (setq #:mul-122 (* #:mul-122 #:numbers-121))
    (go #:ll-126)
   end)
  #:mul-122)


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

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

Input:
(resolving
  nil
  :key
  nil)

Output: (defmacro RESOLVING ...)


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

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

Input: (->> nil :key nil)

Output: (defmacro ->> ...)


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

What needs to change: Macro call that should be transformed by CONTINUE-WHOPPER

Input: (continue-whopper nil)

Output: (defmacro CONTINUE-WHOPPER ...)

(call-next-method-fn self class-env inst-env mcs%caller mcs%next-methods
                     (list nil))


Instruction:
Define a macro that eliminates this repetitive pattern:
(define-condition/a dbi-programming-error (dbi-database-error) () (:documentation "Exception raised for programming errors, e.g. table not found or already exists, syntax error in SQL statement, wrong number of parameters specified, etc."))

Issue: Macro call that should be transformed by define-condition/a

Input: (define-condition/a dbi-programming-error (dbi-database-error) () (:documentation "Exception raised for programming errors, e.g. table not found or already exists, syntax error in SQL statement, wrong number of parameters specified, etc."))

Output:
(defmacro define-condition/a (name parent-types slots &body options)
  `(progn
     (define-condition ,name ,parent-types ,slots ,@options)
     (deftype ,(intern (format nil "<~A>" (symbol-name name))) () ',name)
     (setf (find-class ',(intern (format nil "<~A>" (symbol-name name))))
           (find-class ',name))))

(progn (define-condition dbi-programming-error (dbi-database-error) nil (:documentation "Exception raised for programming errors, e.g. table not found or already exists, syntax error in SQL statement, wrong number of parameters specified, etc.")) (deftype <dbi-programming-error> nil (quote dbi-programming-error)) (setf (find-class (quote <dbi-programming-error>)) (find-class (quote dbi-programming-error))))


Instruction:
Define a macro that eliminates this repetitive pattern:
(when item `(make-node ,item))

Issue: Macro call that should be transformed by when

Input: (when item `(make-node ,item))

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

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


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(define-accumulation-binding appending (var form &aux (head (cons NIL NIL)) (tail head)) (declare (type list var) (type cons head tail)) (let ((result (gensym "RESULT")) (new-tail (gensym "NEW-TAIL"))) `(let ((,result ,form)) (when ,result (multiple-value-bind (,head ,new-tail) (copy-list* ,result) (setf (cdr ,tail) ,head ,tail ,new-tail)) (setf ,var (cdr ,head))))))

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

Input: (define-accumulation-binding appending (var form &aux (head (cons NIL NIL)) (tail head)) (declare (type list var) (type cons head tail)) (let ((result (gensym "RESULT")) (new-tail (gensym "NEW-TAIL"))) `(let ((,result ,form)) (when ,result (multiple-value-bind (,head ,new-tail) (copy-list* ,result) (setf (cdr ,tail) ,head ,tail ,new-tail)) (setf ,var (cdr ,head))))))

Output:
(defmacro define-accumulation-binding (name (var &rest args) &body body)
  `(define-form-binding ,name (,var ,@args)
     ,@(form-fiddle:lambda-declarations `(lambda () ,@body))
     (values
      (progn ,@(form-fiddle:lambda-forms `(lambda () ,@body)))
      (delist var))))

(define-form-binding appending (var form &aux (head (cons nil nil)) (tail head)) (declare (type list var) (type cons head tail)) (values (progn (let ((result (gensym "RESULT")) (new-tail (gensym "NEW-TAIL"))) (sb-int:quasiquote (let ((#S(sb-impl::comma :expr result :kind 0) #S(sb-impl::comma :expr form :kind 0))) (when #S(sb-impl::comma :expr result :kind 0) (multiple-value-bind (#S(sb-impl::comma :expr head :kind 0) #S(sb-impl::comma :expr new-tail :kind 0)) (copy-list* #S(sb-impl::comma :expr result :kind 0)) (setf (cdr #S(sb-impl::comma :expr tail :kind 0)) #S(sb-impl::comma :expr head :kind 0) #S(sb-impl::comma :expr tail :kind 0) #S(sb-impl::comma :expr new-tail :kind 0))) (setf #S(sb-impl::comma :expr var :kind 0) (cdr #S(sb-impl::comma :expr head :kind 0)))))))) (delist var)))


Instruction:
Define a macro that eliminates this repetitive pattern:
(when (find (first x) (list 'stropt)) (let ((s (short x)) (l (long x))) (if s (push s opts-short)) (if l (push l opts-long))))

Issue: Macro call that should be transformed by when

Input: (when (find (first x) (list 'stropt)) (let ((s (short x)) (l (long x))) (if s (push s opts-short)) (if l (push l opts-long))))

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

(if (find (first x) (list (quote stropt))) (let ((s (short x)) (l (long x))) (if s (push s opts-short)) (if l (push l opts-long))))


Instruction:
Define a macro that eliminates this repetitive pattern:
(-> :g (v) (put v))

Issue: Macro call that should be transformed by ->

Input: (-> :g (v) (put v))

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


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(-> (from :users) (where (:= :active 1)) (order-by :name))

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

Input: (-> (from :users) (where (:= :active 1)) (order-by :name))

Output:
(defmacro -> (value &rest forms)
  "Smart threading macro that dispatches based on clause types returned by forms.

   This macro enables immutable query composition by threading clauses through
   query-state objects. Creates a single copy at the beginning, then destructively
   adds clauses for efficiency. Supports both v1 select-statements and composer query-states.

   Forms that evaluate to NIL are skipped, enabling conditional composition:
     (-> (from :users)
         (when active-only (where (:= :active 1)))
         (when sort-by-name (order-by :name)))

   Examples:
     ;; With composer clause
     (-> (from :users)
         (where (:= :active 1))
         (order-by :name))

     ;; With v1 select-statement (backward compatible)
     (-> (select (:id :name) (from :users))
         (where (:= :active 1))
         (order-by :name))

     ;; Conditional composition
     (-> (from :users)
         (when include-inactive (where (:= :active 0)))
         (when sort-by-date (order-by :created_at)))"
  (a:with-gensyms (threaded-var clause-var)
    `(let* ((,threaded-var ,value)
            ;; Convert to query-state and copy once at the beginning
            (,threaded-var
              (typecase ,threaded-var
                (query-state-base (copy-query-state-immutable ,threaded-var))
                (stmt:select-statement (select-statement-to-query-state ,threaded-var))
                (stmt:insert-into-statement (insert-statement-to-query-state ,threaded-var))
                (stmt:update-statement (update-statement-to-query-state ,threaded-var))
                (stmt:delete-from-statement (delete-statement-to-query-state ,threaded-var))
                (otherwise (add-clause (make-select-query-state) ,threaded-var)))))
       ;; Now destructively add clauses (no more copying), skipping NILs
       ,@(loop for form in forms
               collect `(let ((,clause-var ,(if (listp form)
                                                ;; For list forms, call the function with its arguments (no threading)
                                                `(,(car form) ,@(cdr form))
                                                ;; For symbol forms, call the function with no arguments
                                                `(,form))))
                          (when ,clause-var
                            (add-clause ,threaded-var ,clause-var))))
       ,threaded-var)))

(let* ((#:threaded-var143 (from :users)) (#:threaded-var143 (typecase #:threaded-var143 (query-state-base (copy-query-state-immutable #:threaded-var143)) (stmt:select-statement (select-statement-to-query-state #:threaded-var143)) (stmt:insert-into-statement (insert-statement-to-query-state #:threaded-var143)) (stmt:update-statement (update-statement-to-query-state #:threaded-var143)) (stmt:delete-from-statement (delete-statement-to-query-state #:threaded-var143)) (otherwise (add-clause (make-select-query-state) #:threaded-var143))))) (let ((#:clause-var144 (where (:= :active 1)))) (when #:clause-var144 (add-clause #:threaded-var143 #:clause-var144))) (let ((#:clause-var144 (order-by :name))) (when #:clause-var144 (add-clause #:threaded-var143 #:clause-var144))) #:threaded-var143)


Instruction:
Write a Common Lisp macro to handle this code pattern:
(implies (slot-boundp object (slot-definition-name slot)) (typep (slot-value object (slot-definition-name slot)) (slot-definition-type slot)))

Problem: Macro call that should be transformed by implies

Input: (implies (slot-boundp object (slot-definition-name slot)) (typep (slot-value object (slot-definition-name slot)) (slot-definition-type slot)))

Output:
(defmacro implies (condition consequent)
  "A boolean operator that evaluates to the value of CONSEQUENT if CONDITION is
   true, and otherwise evaluates to T. This isn't particularly specific to Quid
   Pro Quo, but it is a useful logical operator for contracts."
  `(if ,condition ,consequent t))

(if (slot-boundp object (slot-definition-name slot)) (typep (slot-value object (slot-definition-name slot)) (slot-definition-type slot)) t)


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

Problem: Macro call that should be transformed by DLET*

Input:
(dlet* nil
  (progn))

Output: (defmacro DLET* ...)


Instruction:
Write a Common Lisp macro to handle this code pattern:
(deferror "22" data-exception)

Problem: Macro call that should be transformed by deferror

Input: (deferror "22" 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 data-exception (database-error) nil) (setf (gethash "22" *error-table*) (quote data-exception)))


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

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

Input: (newq 'some-name)

Output: (defmacro NEWQ ...)


Instruction:
Generate a defmacro form that transforms code like this:
(if-generator (tmp gen) (mapcar #'list tmp))

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

Input: (if-generator (tmp gen) (mapcar #'list tmp))

Output:
(defmacro if-generator ((var gen) true-clause &optional false-clause)
  "Pulls a single iteration out of gen. If a single var is specified, it places all the values from the iteration in a list under var. If var is a list, destructures values into the vars in the list. If the generator has stopped, evaluates false-clause, otherwise evaluates true-clause."
  `(,@(if (listp var)
	 `(multiple-value-bind ,var
	      (funcall ,gen))
	 `(let ((,var (multiple-value-list (funcall ,gen))))))
      (if (eq 'generator-stop
	      ,(if (listp var)
		   (car var)
		   `(car ,var)))
	  ,false-clause
	  ,true-clause)))

(let ((tmp (multiple-value-list (funcall gen)))) (if (eq (quote generator-stop) (car tmp)) nil (mapcar (function list) tmp)))


Instruction:
Write a Common Lisp macro to handle this code pattern:
(with-yield-binds (format nil "CREATE~:[~; OR REPLACE~] VIEW ~A AS ~A" (create-view-statement-or-replace statement) (yield (create-view-statement-view-name statement)) (let ((as (create-view-statement-as statement))) (typecase as (string as) (otherwise (yield as))))))

Problem: Macro call that should be transformed by with-yield-binds

Input: (with-yield-binds (format nil "CREATE~:[~; OR REPLACE~] VIEW ~A AS ~A" (create-view-statement-or-replace statement) (yield (create-view-statement-view-name statement)) (let ((as (create-view-statement-as statement))) (typecase as (string as) (otherwise (yield as))))))

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 "CREATE~:[~; OR REPLACE~] VIEW ~A AS ~A" (create-view-statement-or-replace statement) (yield (create-view-statement-view-name statement)) (let ((as (create-view-statement-as statement))) (typecase as (string as) (otherwise (yield as)))))) (loop for bind in (reverse *bind-values*) append bind)))


Instruction:
Write a Common Lisp macro to handle this code pattern:
(action (:after node-variable node bound-variables) (when (and (eq name (node-variable-value node)) (not (member name bound-variables :test #'eq))) (incf count) (unless (identifiers-disjoint-p value-vars bound-variables) (setf unsafe? t))) (values))

Problem: Macro call that should be transformed by action

Input: (action (:after node-variable node bound-variables) (when (and (eq name (node-variable-value node)) (not (member name bound-variables :test #'eq))) (incf count) (unless (identifiers-disjoint-p value-vars bound-variables) (setf unsafe? t))) (values))

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-variable) (lambda (node bound-variables) (declare (type node-variable node)) (when (and (eq name (node-variable-value node)) (not (member name bound-variables :test (function eq)))) (incf count) (unless (identifiers-disjoint-p value-vars bound-variables) (setf unsafe? t))) (values)))


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
($ "value-1" 600)

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

Input: ($ "value-1" 600)

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


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

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

Input:
(dlet* nil
  nil)

Output: (defmacro DLET* ...)


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(define-case-aware-find-symbol find-preprocessor-directive #:with-c-syntax.preprocessor-directive)

What needs to change: Macro call that should be transformed by define-case-aware-find-symbol

Input: (define-case-aware-find-symbol find-preprocessor-directive #:with-c-syntax.preprocessor-directive)

Output:
(defmacro define-case-aware-find-symbol
    (finder-function-name package-name
     &key (upcased-package-name (format nil "~A.~A" (string package-name) '#:UPCASED))
       (docstring
        (format nil "Find a symbol in `~A' package having a same NAME. If not found, returns `nil'."
                package-name)))
  `(eval-when (:compile-toplevel :load-toplevel :execute)
     (defpackage ,upcased-package-name
       (:use)
       (:intern
        ,@(loop for sym being the external-symbol of package-name
                collect (string-upcase (symbol-name sym)))))
     ,@(loop for sym being the external-symbol of package-name
             for upcased = (string-upcase (symbol-name sym))
             collect `(setf (symbol-value (find-symbol ,upcased ',upcased-package-name))
                            ',sym))
     (defun ,finder-function-name (string &optional (readtable-case (readtable-case *readtable*)))
       ,@(if docstring `(,docstring))
       (ecase readtable-case
         ((:upcase :invert)
          (if-let ((up-sym (find-symbol string ',upcased-package-name)))
            (symbol-value up-sym)))
         ((:downcase :preserve)
          (find-symbol string ',package-name))))))

(eval-when (:compile-toplevel :load-toplevel :execute) (defpackage #A((44) base-char . "WITH-C-SYNTAX.PREPROCESSOR-DIRECTIVE.UPCASED") (:use) (:intern #A((4) base-char . "ELIF") #A((6) base-char . "IFNDEF") #A((5) base-char . "UNDEF") #A((5) base-char . "ERROR") #A((5) base-char . "ENDIF") #A((6) base-char . "PRAGMA") #A((6) base-char . "DEFINE") #A((4) base-char . "ELSE") #A((2) base-char . "IF") #A((7) base-char . "INCLUDE") #A((5) base-char . "IFDEF") #A((4) base-char . "LINE"))) (setf (symbol-value (find-symbol #A((4) base-char . "ELIF") (quote #A((44) base-char . "WITH-C-SYNTAX.PREPROCESSOR-DIRECTIVE.UPCASED")))) (quote with-c-syntax.preprocessor-directive:|elif|)) (setf (symbol-value (find-symbol #A((6) base-char . "IFNDEF") (quote #A((44) base-char . "WITH-C-SYNTAX.PREPROCESSOR-DIRECTIVE.UPCASED")))) (quote with-c-syntax.preprocessor-directive:|ifndef|)) (setf (symbol-value (find-symbol #A((5) base-char . "UNDEF") (quote #A((44) base-char . "WITH-C-SYNTAX.PREPROCESSOR-DIRECTIVE.UPCASED")))) (quote with-c-syntax.preprocessor-directive:|undef|)) (setf (symbol-value (find-symbol #A((5) base-char . "ERROR") (quote #A((44) base-char . "WITH-C-SYNTAX.PREPROCESSOR-DIRECTIVE.UPCASED")))) (quote with-c-syntax.preprocessor-directive:|error|)) (setf (symbol-value (find-symbol #A((5) base-char . "ENDIF") (quote #A((44) base-char . "WITH-C-SYNTAX.PREPROCESSOR-DIRECTIVE.UPCASED")))) (quote with-c-syntax.preprocessor-directive:|endif|)) (setf (symbol-value (find-symbol #A((6) base-char . "PRAGMA") (quote #A((44) base-char . "WITH-C-SYNTAX.PREPROCESSOR-DIRECTIVE.UPCASED")))) (quote with-c-syntax.preprocessor-directive:|pragma|)) (setf (symbol-value (find-symbol #A((6) base-char . "DEFINE") (quote #A((44) base-char . "WITH-C-SYNTAX.PREPROCESSOR-DIRECTIVE.UPCASED")))) (quote with-c-syntax.preprocessor-directive:|define|)) (setf (symbol-value (find-symbol #A((4) base-char . "ELSE") (quote #A((44) base-char . "WITH-C-SYNTAX.PREPROCESSOR-DIRECTIVE.UPCASED")))) (quote with-c-syntax.preprocessor-directive:|else|)) (setf (symbol-value (find-symbol #A((2) base-char . "IF") (quote #A((44) base-char . "WITH-C-SYNTAX.PREPROCESSOR-DIRECTIVE.UPCASED")))) (quote with-c-syntax.preprocessor-directive:|if|)) (setf (symbol-value (find-symbol #A((7) base-char . "INCLUDE") (quote #A((44) base-char . "WITH-C-SYNTAX.PREPROCESSOR-DIRECTIVE.UPCASED")))) (quote with-c-syntax.preprocessor-directive:|include|)) (setf (symbol-value (find-symbol #A((5) base-char . "IFDEF") (quote #A((44) base-char . "WITH-C-SYNTAX.PREPROCESSOR-DIRECTIVE.UPCASED")))) (quote with-c-syntax.preprocessor-directive:|ifdef|)) (setf (symbol-value (find-symbol #A((4) base-char . "LINE") (quote #A((44) base-char . "WITH-C-SYNTAX.PREPROCESSOR-DIRECTIVE.UPCASED")))) (quote with-c-syntax.preprocessor-directive:|line|)) (defun find-preprocessor-directive (string &optional (readtable-case (readtable-case *readtable*))) #A((112) base-char . "Find a symbol in `WITH-C-SYNTAX.PREPROCESSOR-DIRECTIVE' package having a same NAME. If not found, returns `nil'.") (ecase readtable-case ((:upcase :invert) (if-let ((up-sym (find-symbol string (quote #A((44) base-char . "WITH-C-SYNTAX.PREPROCESSOR-DIRECTIVE.UPCASED"))))) (symbol-value up-sym))) ((:downcase :preserve) (find-symbol string (quote #:with-c-syntax.preprocessor-directive))))))


Instruction:
Generate a defmacro form that transforms code like this:
(do-files (file (repo-dir *config*) file-type) (let ((obj (construct (class-name doc-type) (read-content file)))) (add-document obj)))

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

Input: (do-files (file (repo-dir *config*) file-type) (let ((obj (construct (class-name doc-type) (read-content file)))) (add-document obj)))

Output:
(defmacro do-files ((var path &optional extension) &body body)
  "For each file under PATH, run BODY. If EXTENSION is provided, only run
BODY on files that match the given extension."
  (alexandria:with-gensyms (extension-p)
    `(flet ((,extension-p (file)
              (string= (pathname-type file) ,extension)))
       (cl-fad:walk-directory ,path (lambda (,var) ,@body)
                              :follow-symlinks nil
                              :test (if ,extension
                                        #',extension-p
                                        (constantly t))))))

(flet ((#:extension-p287 (file) (string= (pathname-type file) file-type))) (cl-fad:walk-directory (repo-dir *config*) (lambda (file) (let ((obj (construct (class-name doc-type) (read-content file)))) (add-document obj))) :follow-symlinks nil :test (if file-type (function #:extension-p287) (constantly t))))


Instruction:
Generate a defmacro form that transforms code like this:
(bind (((:plist- a (b _) (c _ 2) (dd d)) '(b "B" a "A" d "D"))) (list a b c dd))

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

Input: (bind (((:plist- a (b _) (c _ 2) (dd d)) '(b "B" a "A" d "D"))) (list a b c dd))

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

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

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

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

(let* ((#:|values-165| (quote (b "B" a "A" d "D"))) (a (getf #:|values-165| (quote a))) (b (getf #:|values-165| (quote b))) (c (getf #:|values-165| (quote c) 2)) (dd (getf #:|values-165| (quote d)))) (declare (ignorable #:|values-165|)) (progn (list a b c dd)))


Instruction:
Write a Common Lisp macro to handle this code pattern:
(define-simple-object-lookup package find-package)

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

Input: (define-simple-object-lookup package find-package)

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

(defmethod object ((package package)) (find-package (designator package)))


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

Pattern to recognize: Macro call that should be transformed by WITHOUT-DEPENDENCY-CAPTURE

Input:
(without-dependency-capture
  'some-name)

Output: (defmacro WITHOUT-DEPENDENCY-CAPTURE ...)


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(dotable (k v ht2) (setf (gethash k rez) (funcall fn v (gethash k rez))))

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

Input: (dotable (k v ht2) (setf (gethash k rez) (funcall fn v (gethash k rez))))

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

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

(let ((#:table170 ht2)) (block nil (etypecase #:table170 (hash-table (maphash (lambda (k v) nil (setf (gethash k rez) (funcall fn v (gethash k rez)))) #:table170)) (list (if (alistp #:table170) (dolist (#:g169 #:table170) (destructuring-bind (k . v) #:g169 (setf (gethash k rez) (funcall fn v (gethash k rez))))) (error (quote simple-type-error) :format-control "Can't iterate over proper list ~
                                               in DOTABLE: need an alist")))) nil))


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(%define-hash-table-entries-pattern hash-table-entries hash-table-entry)

Write a macro that addresses: Macro call that should be transformed by %define-hash-table-entries-pattern

Input: (%define-hash-table-entries-pattern hash-table-entries hash-table-entry)

Output:
(defmacro %define-hash-table-entries-pattern (name entry-pattern)
  `(defpattern ,name (key pattern &rest keys-and-patterns)
    ,(format nil "Matches hash table which has KEY set to value matching PATTERN.~
                  Multiple KEY PATTERN pairs can be provided, e.g. `(~A :key1 _ :key2 value :key3 1)`.~
                  Expands into list of ~A patterns combined with AND."
             name entry-pattern)
    (when (oddp (length keys-and-patterns))
      (warn 'hash-table-odd-number-of-entries-warning
            :format-control ,(format nil "Odd number of arguments given to ~A pattern. NIL will be used as ~~S pattern." name)
            :format-arguments (last keys-and-patterns)))
    `(and ,(list ',entry-pattern key pattern)
          ,@(loop :for (key pattern) :on keys-and-patterns :by #'cddr
                  :collect (list ',entry-pattern key pattern)))))

(defpattern hash-table-entries (key pattern &rest keys-and-patterns) #A((228) base-char . "Matches hash table which has KEY set to value matching PATTERN.Multiple KEY PATTERN pairs can be provided, e.g. `(HASH-TABLE-ENTRIES :key1 _ :key2 value :key3 1)`.Expands into list of HASH-TABLE-ENTRY patterns combined with AND.") (when (oddp (length keys-and-patterns)) (warn (quote hash-table-odd-number-of-entries-warning) :format-control #A((92) base-char . "Odd number of arguments given to HASH-TABLE-ENTRIES pattern. NIL will be used as ~S pattern.") :format-arguments (last keys-and-patterns))) (sb-int:quasiquote (and #S(sb-impl::comma :expr (list (quote hash-table-entry) key pattern) :kind 0) #S(sb-impl::comma :expr (loop :for (key pattern) :on keys-and-patterns :by (function cddr) :collect (list (quote hash-table-entry) key pattern)) :kind 2))))


Instruction:
Write a Common Lisp macro to handle this code pattern:
(define-error conditional-return-type-mismatch () (sets) "Due to a conditional the function could return any of the following:~{~%~a~} This stopped us working out the correct return types for this function" (mapcar (lambda (x) (or (map 'list #'type->type-spec x) :void)) sets))

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

Input: (define-error conditional-return-type-mismatch () (sets) "Due to a conditional the function could return any of the following:~{~%~a~} This stopped us working out the correct return types for this function" (mapcar (lambda (x) (or (map 'list #'type->type-spec x) :void)) sets))

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 conditional-return-type-mismatch (:error-type varjo-error :prefix "Varjo") (sets) "Due to a conditional the function could return any of the following:~{~%~a~} This stopped us working out the correct return types for this function" (mapcar (lambda (x) (or (map (quote list) (function type->type-spec) x) :void)) sets))


Instruction:
Write a Common Lisp macro to handle this code pattern:
(cond-<>
  nil
  (progn))

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

Input:
(cond-<>
  nil
  (progn))

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


Instruction:
Define a macro that eliminates this repetitive pattern:
(alist-bind (name type) form (let ((sym (foreign-type-symbol name :ctype *package*))) (if (pointer*-to-record-form-p type) (pushnew sym *foreign-record-list* :test #'equal) (if (pointer-alias-form-p type) (pushnew sym *foreign-alias-list* :test #'equal) (pushnew sym *foreign-other-exports-list*))) `(define-foreign-alias ',sym ',@(parse-type type (aval :tag type)))))

Issue: Macro call that should be transformed by alist-bind

Input: (alist-bind (name type) form (let ((sym (foreign-type-symbol name :ctype *package*))) (if (pointer*-to-record-form-p type) (pushnew sym *foreign-record-list* :test #'equal) (if (pointer-alias-form-p type) (pushnew sym *foreign-alias-list* :test #'equal) (pushnew sym *foreign-other-exports-list*))) `(define-foreign-alias ',sym ',@(parse-type type (aval :tag type)))))

Output:
(defmacro alist-bind ((&rest vars) alist &body body)
  "Inefficient but doesn't really matter here"
  (once-only (alist)
    `(let (,@(mapcar (lambda (x)
                       (if (consp x)
                           `(,(car x) (aval ,(cadr x) ,alist))
                           `(,x (aval ,(make-keyword x) ,alist))))
                     vars))
       ,@body)))

(let ((#:alist239 form)) (let ((name (aval :name #:alist239)) (type (aval :type #:alist239))) (let ((sym (foreign-type-symbol name :ctype *package*))) (if (pointer*-to-record-form-p type) (pushnew sym *foreign-record-list* :test (function equal)) (if (pointer-alias-form-p type) (pushnew sym *foreign-alias-list* :test (function equal)) (pushnew sym *foreign-other-exports-list*))) (sb-int:quasiquote (define-foreign-alias (quote #S(sb-impl::comma :expr sym :kind 0)) (quote #S(sb-impl::comma :expr (parse-type type (aval :tag type)) :kind 2)))))))


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

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

Input: (some-> nil)

Output: (defmacro SOME-> ...)


Instruction:
Write a Common Lisp macro to handle this code pattern:
(with-env (setp 2 [assoc-list 'a]))

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

Input: (with-env (setp 2 [assoc-list 'a]))

Output:
(defmacro with-env (&body body)
  (let ((body-value (gensym)))
    `(let (,body-value)
       (defclass foo () ((a :initform 3)))
       (defmethod get-val ((object foo) &rest slot/s) (slot-value object (car slot/s)))
       (defmethod (setf get-val) (new-value (object foo) &rest slot/s)
         (setf (slot-value object (car slot/s)) new-value))
       (defstruct bar a)
       (setq ,body-value
             (let ((str (alexandria:copy-array "abcde"))
                   (vec (alexandria:copy-array #(a b c d e)))
                   (arr (alexandria:copy-array #2A((1 2 3)
                                                   (4 5 6))))
                   (list      (copy-list '(a b c d e)))
                   (ht        (eval (read-from-string "{'a 'b 'c 'd}")))
                   (ht-eq     (eval (read-from-string "{eq \"a\" 1
                                                    \"b\" 2}")))
                   (ht-equalp (eval (read-from-string "{equalp '(1 2 3) \"a\"
                                                               '(4 5 6) \"b\"}")))
                   (assoc-list (copy-tree '((a . 1) (b . 2))))
                   (plist      (copy-list '(:a 4 :c 5)))
                   (clos-object (make-instance 'foo))
                   (struct      (make-bar :a 3)))
               (declare (ignorable str vec arr list ht ht-eq ht-equalp
                                   assoc-list plist clos-object struct))
               ,@body))
       (setf (find-class 'foo nil) nil)
       (setf (find-class 'bar nil) nil)
       ,body-value))

(let (#:g134) (defclass foo nil ((a :initform 3))) (defmethod get-val ((object foo) &rest slot/s) (slot-value object (car slot/s))) (defmethod (setf get-val) (new-value (object foo) &rest slot/s) (setf (slot-value object (car slot/s)) new-value)) (defstruct bar a) (setq #:g134 (let ((str (alexandria:copy-array "abcde")) (vec (alexandria:copy-array #(a b c d e))) (arr (alexandria:copy-array #2A((1 2 3) (4 5 6)))) (list (copy-list (quote (a b c d e)))) (ht (eval (read-from-string "{'a 'b 'c 'd}"))) (ht-eq (eval (read-from-string "{eq \"a\" 1
                                                    \"b\" 2}"))) (ht-equalp (eval (read-from-string "{equalp '(1 2 3) \"a\"
                                                               '(4 5 6) \"b\"}"))) (assoc-list (copy-tree (quote ((a . 1) (b . 2))))) (plist (copy-list (quote (:a 4 :c 5)))) (clos-object (make-instance (quote foo))) (struct (make-bar :a 3))) (declare (ignorable str vec arr list ht ht-eq ht-equalp assoc-list plist clos-object struct)) (setp 2 [assoc-list (quote a])))) (setf (find-class (quote foo) nil) nil) (setf (find-class (quote bar) nil) nil) #:g134)


Instruction:
Write a Common Lisp macro to handle this code pattern:
(define-cfun __error)

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

Input: (define-cfun __error)

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

(progn (defun __error nil (cffi-sys:%foreign-funcall "__error" (:pointer) :convention :cdecl)))


Instruction:
Write a Common Lisp macro to handle this code pattern:
(with-color (:green :stream stream) (format/indent reporter stream "✓ ~D test~:*~P completed" count))

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

Input: (with-color (:green :stream stream) (format/indent reporter stream "✓ ~D test~:*~P completed" count))

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 :green :gray) (eq :green :grey) (eq :green +gray+) (eq :green +grey+)) (with-gray stream (format/indent reporter stream "✓ ~D test~:*~P completed" count)) (cl-ansi-text:with-color (:green :stream stream) (format/indent reporter stream "✓ ~D test~:*~P completed" count))) (progn (format/indent reporter stream "✓ ~D test~:*~P completed" count)))


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(collect-append nil (progn))

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

Input: (collect-append nil (progn))

Output: (defmacro COLLECT-APPEND ...)

(common-lisp:let* ((#:generator-223 (generator (progn)))
                   #:items-218
                   (#:seq-219 nil))
  (declare (type generator #:generator-223))
  (tagbody
   #:ll-224
    (setq #:items-218 (next-in #:generator-223 (go end)))
    (setq #:seq-219 (cons #:items-218 #:seq-219))
    (go #:ll-224)
   end)
  (apply #'concatenate nil (nreverse #:seq-219)))


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(with-temp (input-file :tmpdir d :template "XXXXXX.prolog" :debug (<= 1 *debug-prolog*)) (with-open-file (s input-file :direction :output :if-does-not-exist :error) (dolist (r rules) (print-rule s r))) (run-command-with-debug-print `("swipl" "--quiet" "-l" ,input-file ,@args) :input input :output output :error error))

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

Input: (with-temp (input-file :tmpdir d :template "XXXXXX.prolog" :debug (<= 1 *debug-prolog*)) (with-open-file (s input-file :direction :output :if-does-not-exist :error) (dolist (r rules) (print-rule s r))) (run-command-with-debug-print `("swipl" "--quiet" "-l" ,input-file ,@args) :input input :output output :error error))

Output:
(defmacro with-temp ((var &key directory template (tmpdir "/tmp/") debug) &body body)
  "Create a temporary file, then remove the file by unwind-protect.
Most arguments are analogous to mktemp.
When DIRECTORY is non-nil, creates a directory instead.
DEBUG is a form.
When evaluated to non-nil, it does not remove the directory so that you can investigate what happened inside the directory.
It may be evaluated multiple times."
  (with-gensyms (command)
    `(let ((,var (uiop:run-program
                  (let ((,command (format nil "mktemp --tmpdir='~a' ~@[-d~*~] ~@[~a~]"
                                          ,tmpdir ,directory ,template)))
                    (when ,debug
                      (format *error-output* "~&; ~a~%" ,command))
                    ,command)
                  :output '(:string :stripped t))))
       (unwind-protect
            (progn ,@body)
         (if ,debug
             (format *error-output* "~&; not removing ~a for debugging~%" ,var)
             (uiop:run-program (format nil "rm -rf ~a" (namestring ,var)) :ignore-error-status t))))))

(let ((input-file (uiop/run-program:run-program (let ((#:command176 (format nil "mktemp --tmpdir='~a' ~@[-d~*~] ~@[~a~]" d nil "XXXXXX.prolog"))) (when (<= 1 *debug-prolog*) (format *error-output* "~&; ~a~%" #:command176)) #:command176) :output (quote (:string :stripped t))))) (unwind-protect (progn (with-open-file (s input-file :direction :output :if-does-not-exist :error) (dolist (r rules) (print-rule s r))) (run-command-with-debug-print (sb-int:quasiquote ("swipl" "--quiet" "-l" #S(sb-impl::comma :expr input-file :kind 0) #S(sb-impl::comma :expr args :kind 2))) :input input :output output :error error)) (if (<= 1 *debug-prolog*) (format *error-output* "~&; not removing ~a for debugging~%" input-file) (uiop/run-program:run-program (format nil "rm -rf ~a" (namestring input-file)) :ignore-error-status t))))


Instruction:
Define a macro that eliminates this repetitive pattern:
(define-test timeout :time-limit 0.5 (sleep 0.75))

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

Input: (define-test timeout :time-limit 0.5 (sleep 0.75))

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 timeout) (find-package #A((9) base-char . "PARACHUTE"))) (ensure-test (quote test) :name (quote timeout) :home (find-package #A((9) base-char . "PARACHUTE")) :tests (list (lambda nil (sleep 0.75))) :parent (quote nil) (quote :time-limit) (quote 0.5))) (quote timeout))


Instruction:
Write a Common Lisp macro to handle this code pattern:
(enable-reader-syntax nil)

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

Input: (enable-reader-syntax nil)

Output: (defmacro ENABLE-READER-SYNTAX ...)

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


Instruction:
Generate a defmacro form that transforms code like this:
(when (node-slot type) (del-proxy type))

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

Input: (when (node-slot type) (del-proxy type))

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


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(do+ (for x (across #(3 2 1) :start 2 :end 0)) (collect x))

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

Input: (do+ (for x (across #(3 2 1) :start 2 :end 0)) (collect x))

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 (across #(3 2 1) :start 2 :end 0)) (collect x))


Instruction:
Write a Common Lisp macro to handle this code pattern:
(defhandler load-time-value (load-time-value form &optional (read-only-p nil rop-p)) `(list ',load-time-value ,(e form) ,@(when rop-p `(',read-only-p))))

Problem: Macro call that should be transformed by defhandler

Input: (defhandler load-time-value (load-time-value form &optional (read-only-p nil rop-p)) `(list ',load-time-value ,(e form) ,@(when rop-p `(',read-only-p))))

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

(progn (defun hander-load-time-value (load-time-value form &optional (read-only-p nil rop-p)) (sb-int:quasiquote (list (quote #S(sb-impl::comma :expr load-time-value :kind 0)) #S(sb-impl::comma :expr (e form) :kind 0) #S(sb-impl::comma :expr (when rop-p (sb-int:quasiquote ((quote #S(sb-impl::comma :expr read-only-p :kind 0))))) :kind 2)))) (setf (gethash (quote load-time-value) *form-handler*) (quote hander-load-time-value)))


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(when (or body initializer) `(make-block ,body))

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

Input: (when (or body initializer) `(make-block ,body))

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

(if (or body initializer) (sb-int:quasiquote (make-block #S(sb-impl::comma :expr body :kind 0))))


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(deferror "42P07" duplicate-table syntax-error-or-access-violation)

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

Input: (deferror "42P07" duplicate-table syntax-error-or-access-violation)

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

(progn (define-condition duplicate-table (syntax-error-or-access-violation) nil) (setf (gethash "42P07" *error-table*) (quote duplicate-table)))


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

Pattern to recognize: Macro call that should be transformed by AUTO-PERMUTE-TYPECASE

Input: (auto-permute-typecase 'some-name)

Output: (defmacro AUTO-PERMUTE-TYPECASE ...)


Instruction:
Define a macro that eliminates this repetitive pattern:
(dynamic-relet nil
  :key
  nil)

Issue: Macro call that should be transformed by DYNAMIC-RELET

Input:
(dynamic-relet nil
  :key
  nil)

Output: (defmacro DYNAMIC-RELET ...)

(dynamic-wind
  :proceed
  #:proceed191
  (let ()
    (declare (special))
    (#:proceed191 :key nil)))


Instruction:
Define a macro that eliminates this repetitive pattern:
(rem-bops)

Issue: Macro call that should be transformed by REM-BOPS

Input: (rem-bops)

Output: (defmacro REM-BOPS ...)

(eval-when (:load-toplevel :compile-toplevel :execute)
  (progn (save-binfix) (mapc 'rmbop 'nil) (assign-properties)))


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

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

Input: (mvlet* 'some-name)

Output: (defmacro MVLET* ...)


Instruction:
Generate a defmacro form that transforms code like this:
(define-bug user-func-invalid-x () (kind name args) "Invalid types found in internal user-function construction. Our apologies for this mistake. If you have the time please raise an issue at https://github.com/cbaggers/varjo/issues including the code that triggered this issue. Problematic Definition: NAME: ~s ~a: ~s" name kind args)

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

Input: (define-bug user-func-invalid-x () (kind name args) "Invalid types found in internal user-function construction. Our apologies for this mistake. If you have the time please raise an issue at https://github.com/cbaggers/varjo/issues including the code that triggered this issue. Problematic Definition: NAME: ~s ~a: ~s" name kind args)

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

(defcondition user-func-invalid-x (:error-type varjo-error :prefix "Varjo Bug") (kind name args) "Invalid types found in internal user-function construction. Our apologies for this mistake. If you have the time please raise an issue at https://github.com/cbaggers/varjo/issues including the code that triggered this issue. Problematic Definition: NAME: ~s ~a: ~s" name kind args)


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(define-op (:not unary-op))

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

Input: (define-op (:not unary-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 (not-op (:include unary-op (name "NOT")) (:constructor make-not-op (var))))


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

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

Input: (collect-or nil)

Output: (defmacro COLLECT-OR ...)

(common-lisp:let* ((#:generator-326 (generator nil))
                   #:bools-322
                   (#:bool-323 nil))
  (declare (type generator #:generator-326))
  (tagbody
   #:ll-327
    (setq #:bools-322 (next-in #:generator-326 (go end)))
    (if (setq #:bool-323 #:bools-322)
        (go end))
    (go #:ll-327)
   end)
  #:bool-323)


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(action (:after node-field) #'handle-static-superclass)

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

Input: (action (:after node-field) #'handle-static-superclass)

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-field) (function handle-static-superclass))


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

What needs to change: Macro call that should be transformed by INEXT-NOEXIT

Input: (inext-noexit 'some-name)

Output: (defmacro INEXT-NOEXIT ...)

(let ((vals (multiple-value-list (funcall (i-coro 'some-name) nil))))
  (if (not vals)
      (values nil nil)
      (values (car vals) t)))


Instruction:
Generate a defmacro form that transforms code like this:
(bind (((:flet doit (x)) "whatever" (declare (type fixnum x)) (setf x (* 2 x)) (setf x (+ x 3)) x)) (ensure-same (doit 1) 5) (ensure-same (doit 2) 7))

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

Input: (bind (((:flet doit (x)) "whatever" (declare (type fixnum x)) (setf x (* 2 x)) (setf x (+ x 3)) x)) (ensure-same (doit 1) 5) (ensure-same (doit 2) 7))

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

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

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

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

(flet ((doit (x) "whatever" (declare (type fixnum x)) (progn (setf x (* 2 x)) (setf x (+ x 3)) x))) (progn (ensure-same (doit 1) 5) (ensure-same (doit 2) 7)))


Instruction:
Generate a defmacro form that transforms code like this:
(without-dependency-capture
  nil
  (progn))

Pattern to recognize: Macro call that should be transformed by WITHOUT-DEPENDENCY-CAPTURE

Input:
(without-dependency-capture
  nil
  (progn))

Output: (defmacro WITHOUT-DEPENDENCY-CAPTURE ...)

(let ((%dependent% nil))
  nil
  (progn))


Instruction:
Generate a defmacro form that transforms code like this:
(with-constant-values (start end) env ((start end) (let* ((counted? (or (> start 0) end)) (test (if counted? `(and ,more? (cl:< ,index ,size)) more?)) (inc (when counted? `((cl:incf ,index))))) (values `((,table ,form) ,@(when counted? `((,index ,start) (,size ,(or end `(hash-table-count ,table)))))) `((with-custom-hash-table (with-hash-table-iterator (,next ,table) ,@body))) (make-iter-value test inc) (make-iter-place test inc)))) (nil (values `((,table ,form) (,index ,start) (,size (or ,end (hash-table-count ,table)))) `((with-custom-hash-table (with-hash-table-iterator (,next ,table) ,@body))) (make-iter-value `(and ,more? (cl:< ,index ,size)) `((cl:incf ,index))) (make-iter-place `(and ,more? (cl:< ,index ,size)) `((cl:incf ,index))))))

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

Input: (with-constant-values (start end) env ((start end) (let* ((counted? (or (> start 0) end)) (test (if counted? `(and ,more? (cl:< ,index ,size)) more?)) (inc (when counted? `((cl:incf ,index))))) (values `((,table ,form) ,@(when counted? `((,index ,start) (,size ,(or end `(hash-table-count ,table)))))) `((with-custom-hash-table (with-hash-table-iterator (,next ,table) ,@body))) (make-iter-value test inc) (make-iter-place test inc)))) (nil (values `((,table ,form) (,index ,start) (,size (or ,end (hash-table-count ,table)))) `((with-custom-hash-table (with-hash-table-iterator (,next ,table) ,@body))) (make-iter-value `(and ,more? (cl:< ,index ,size)) `((cl:incf ,index))) (make-iter-place `(and ,more? (cl:< ,index ,size)) `((cl:incf ,index))))))

Output:
(defmacro with-constant-values ((&rest things) env &body clauses)
  "Check whether one or more forms are constant and retrieve their values.

   THINGS:

     A list of bindings each of the form (VAR INITFORM).

     Each INITFORM is evaluated and the result is checked whether it
     is a constant form in the environment ENV. If so the constant
     value is stored in VAR otherwise the resulting form (to which
     INITFORM evaluates) itself is stored in VAR.

     Alternatively each element of THINGS can be a symbol in which
     case it is a shorthand for (VAR VAR).

   ENV:

     The environment in which to check whether the forms are
     constants.

   CLAUSES:

     A list of clauses each of the form (VARS . FORMS), where
     VARS is a list of variables, listed in THINGS, which should be
     constant in order for the corresponding FORMS to be evaluated.

     If all variables in VARS are constants FORMS are evaluated in an
     implicit PROGN, with the result of the last form returned.

     If not all of VARS are constant, FORMS are not evaluated and the
     next clause is tried. If no clause succeeds NIL is returned."

  (let ((const-vars (pairlis (mapcar #'ensure-car things)
                             (make-gensym-list (length things) "CONST?"))))

    (labels ((make-get-value (thing body)
               (destructuring-bind (var &optional (form var))
                   (ensure-list thing)

                 (let ((const-var (cdr (assoc var const-vars))))
                   (assert const-var)

                   `(multiple-value-bind (,var ,const-var)
                        (constant-form-value ,form ,env)

                      ,body))))

             (const-var (var)
               (let ((cvar (cdr (assoc var const-vars))))
                 (unless cvar
                   (error "Variable ~s in clause not one of ~s."
                          var (mapcar #'ensure-car things)))

                 cvar))

             (make-clause (clause)
               (destructuring-bind (vars &rest body) clause
                 `((and ,@(mapcar #'const-var vars))
                   ,@body))))

      (cl:reduce
       #'make-get-value
       things
       :from-end t
       :initial-value
       `(cond ,@(mapcar #'make-clause clauses))))))

(multiple-value-bind (start #:const?144) (constant-form-value start env) (multiple-value-bind (end #:const?145) (constant-form-value end env) (cond ((and #:const?144 #:const?145) (let* ((counted? (or (> start 0) end)) (test (if counted? (sb-int:quasiquote (and #S(sb-impl::comma :expr more? :kind 0) (< #S(sb-impl::comma :expr index :kind 0) #S(sb-impl::comma :expr size :kind 0)))) more?)) (inc (when counted? (sb-int:quasiquote ((incf #S(sb-impl::comma :expr index :kind 0))))))) (values (sb-int:quasiquote ((#S(sb-impl::comma :expr table :kind 0) #S(sb-impl::comma :expr form :kind 0)) #S(sb-impl::comma :expr (when counted? (sb-int:quasiquote ((#S(sb-impl::comma :expr index :kind 0) #S(sb-impl::comma :expr start :kind 0)) (#S(sb-impl::comma :expr size :kind 0) #S(sb-impl::comma :expr (or end (sb-int:quasiquote (hash-table-count #S(sb-impl::comma :expr table :kind 0)))) :kind 0))))) :kind 2))) (sb-int:quasiquote ((with-custom-hash-table (with-hash-table-iterator (#S(sb-impl::comma :expr next :kind 0) #S(sb-impl::comma :expr table :kind 0)) #S(sb-impl::comma :expr body :kind 2))))) (make-iter-value test inc) (make-iter-place test inc)))) ((and) (values (sb-int:quasiquote ((#S(sb-impl::comma :expr table :kind 0) #S(sb-impl::comma :expr form :kind 0)) (#S(sb-impl::comma :expr index :kind 0) #S(sb-impl::comma :expr start :kind 0)) (#S(sb-impl::comma :expr size :kind 0) (or #S(sb-impl::comma :expr end :kind 0) (hash-table-count #S(sb-impl::comma :expr table :kind 0)))))) (sb-int:quasiquote ((with-custom-hash-table (with-hash-table-iterator (#S(sb-impl::comma :expr next :kind 0) #S(sb-impl::comma :expr table :kind 0)) #S(sb-impl::comma :expr body :kind 2))))) (make-iter-value (sb-int:quasiquote (and #S(sb-impl::comma :expr more? :kind 0) (< #S(sb-impl::comma :expr index :kind 0) #S(sb-impl::comma :expr size :kind 0)))) (sb-int:quasiquote ((incf #S(sb-impl::comma :expr index :kind 0))))) (make-iter-place (sb-int:quasiquote (and #S(sb-impl::comma :expr more? :kind 0) (< #S(sb-impl::comma :expr index :kind 0) #S(sb-impl::comma :expr size :kind 0)))) (sb-int:quasiquote ((incf #S(sb-impl::comma :expr index :kind 0))))))))))


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(define-condition missing-partial (serious-condition) ())

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

Input: (define-condition missing-partial (serious-condition) ())

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

(progn (sb-kernel::%define-condition (quote missing-partial) (quote (serious-condition)) (sb-kernel::find-condition-layout (quote missing-partial) (quote (serious-condition))) (list) (list) (quote nil) (quote nil) (sb-c:source-location)) (sb-kernel::%set-condition-report (quote missing-partial) nil) (quote missing-partial))


Instruction:
Define a macro that eliminates this repetitive pattern:
(do+ (terminate outer-loop 3))

Issue: Macro call that should be transformed by do+

Input: (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 (terminate outer-loop 3))


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

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

Input:
(->>
  nil
  :key
  nil)

Output: (defmacro ->> ...)


Instruction:
Write a Common Lisp macro to handle this code pattern:
(receive (new-k new-v) (funcall fn k v) (dict* new new-k new-v))

Problem: Macro call that should be transformed by receive

Input: (receive (new-k new-v) (funcall fn k v) (dict* new new-k new-v))

Output:
(defmacro receive (formals expr &body body)
  "Stricter version of `multiple-value-bind'.

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

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

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

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

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

(multiple-value-call (lambda (new-k new-v) (dict* new new-k new-v)) (funcall fn k v))


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

Issue: Macro call that should be transformed by GATHERLET

Input:
(gatherlet nil
  (progn))

Output: (defmacro GATHERLET ...)


Instruction:
Write a Common Lisp macro to handle this code pattern:
(with-cache ("foo" :store storage) 1)

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

Input: (with-cache ("foo" :store storage) 1)

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

Example:

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

(let ((#:key232 "foo") (#:store233 storage) (#:expire234 nil)) (multiple-value-bind (#:value235 #:exists-p236) (getcache #:key232 #:store233) (if #:exists-p236 #:value235 (let ((#:value235 (progn 1))) (setcache #:key232 #:value235 #:store233 :expire #:expire234) #:value235))))


Instruction:
Write a Common Lisp macro to handle this code pattern:
(deferror "58" system-error)

Problem: Macro call that should be transformed by deferror

Input: (deferror "58" system-error)

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

(progn (define-condition system-error (database-error) nil) (setf (gethash "58" *error-table*) (quote system-error)))


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

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

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

Output: (defmacro SOME-<>> ...)


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

Problem: Macro call that should be transformed by F_%

Input:
(f_%
  nil)

Output: (defmacro F_% ...)

(lambda (&rest #:|ignore126|) (declare (ignore #:|ignore126|)) nil)


Instruction:
Generate a defmacro form that transforms code like this:
(finish T)

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

Input: (finish T)

Output:
(defmacro finish (form &optional description &rest format-args)
  `(eval-in-context
    *context*
    (make-instance 'finishing-result
                   :expression '(finish ,form)
                   :body (lambda () ,form)
                   ,@(when description
                       `(:description (format NIL ,description ,@format-args))))))

(eval-in-context *context* (make-instance (quote finishing-result) :expression (quote (finish t)) :body (lambda nil t)))


Instruction:
Write a Common Lisp macro to handle this code pattern:
(aprog1 :yes (unless (eql it :yes) (error "Broken.")) :no)

Problem: Macro call that should be transformed by aprog1

Input: (aprog1 :yes (unless (eql it :yes) (error "Broken.")) :no)

Output:
(defmacro aprog1 (first &body rest)
  "Binds IT to the first form so that it can be used in the rest of the
forms. The whole thing returns IT."
  `(anaphoric prog1 ,first ,@rest))

(anaphoric prog1 :yes (unless (eql it :yes) (error "Broken.")) :no)


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(destructuring-bind* nil
    :key
  nil)

What needs to change: Macro call that should be transformed by DESTRUCTURING-BIND*

Input:
(destructuring-bind* nil
    :key
  nil)

Output: (defmacro DESTRUCTURING-BIND* ...)

(let (#:in-body134)
  (flet ((#:handle135 (#:condition136)
           (unless #:in-body134
             (error
              (make-condition 'destructuring-error :lambda-list 'nil
                              :expression ':key :reason #:condition136)))))
    (declare (ignorable (function #:handle135)))
    (let ((#:value137 :key))
      (handler-bind ((error #'#:handle135))
        (destructuring-bind
            ()
            #:value137
          (setf #:in-body134 t)
          (locally nil))))))


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(any-of nil
  :key
  nil)

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

Input:
(any-of nil
  :key
  nil)

Output: (defmacro ANY-OF ...)


Instruction:
Define a macro that eliminates this repetitive pattern:
(when-let (previous (find-messenger name :manager manager)) (stop-messenger previous))

Issue: Macro call that should be transformed by when-let

Input: (when-let (previous (find-messenger name :manager manager)) (stop-messenger previous))

Output:
(defmacro when-let (binding &body body)
  (destructuring-bind (var val) binding
    `(let ((,var ,val))
       (when ,var
	 ,@body))))

(let ((previous (find-messenger name :manager manager))) (when previous (stop-messenger previous)))


Instruction:
Define a macro that eliminates this repetitive pattern:
(with-mocks () (register-mock 'foo/simple) (foo/simple) (pass))

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

Input: (with-mocks () (register-mock 'foo/simple) (foo/simple) (pass))

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

(call-with-mocks (lambda nil (register-mock (quote foo/simple)) (foo/simple) (pass)) :recordp t)


Instruction:
Write a Common Lisp macro to handle this code pattern:
(macroexpand-convention (form) (if (consp form) (expand-export-class-using-head (first form) form) form))

Problem: Macro call that should be transformed by macroexpand-convention

Input: (macroexpand-convention (form) (if (consp form) (expand-export-class-using-head (first form) form) form))

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

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


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(define-alias-binding range ranging)

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

Input: (define-alias-binding range ranging)

Output:
(defmacro define-alias-binding (name referenced-binding-name)
  `(progn (setf (binding ',name) ',referenced-binding-name)
          ',name))

(progn (setf (binding (quote range)) (quote ranging)) (quote range))


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

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

Input: (with-changing-vertex (vertex) (call-next-method))

Output:
(defmacro with-changing-vertex ((vertex) &body body)
  "This is used to maintain consistency when changing the value of vertex elements while iterating over the vertexes..."
  (with-variables (v g)
    `(let* ((,v ,vertex)
            (,g (graph ,v)))
       (delete-item-at (graph-vertexes ,g)
                       (funcall (vertex-key ,g) (element ,v)))
       ,@body
       (setf (item-at (graph-vertexes ,g)
                      (funcall (vertex-key ,g) (element ,v))) ,v))))

(let* ((#:v0003 vertex) (#:g0004 (graph #:v0003))) (delete-item-at (graph-vertexes #:g0004) (funcall (vertex-key #:g0004) (element #:v0003))) (call-next-method) (setf (item-at (graph-vertexes #:g0004) (funcall (vertex-key #:g0004) (element #:v0003))) #:v0003))


Instruction:
Define a macro that eliminates this repetitive pattern:
(match 'some-name)

Issue: Macro call that should be transformed by MATCH

Input: (match 'some-name)

Output: (defmacro MATCH ...)


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(defjs map4() (emit this.name 1) (emit "hello" this.k))

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

Input: (defjs map4() (emit this.name 1) (emit "hello" this.k))

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 nil (emit this.name 1) (emit "hello" this.k))))) (setf (gethash (quote map4) *js-definitions*) js-body) (defun map4 nil (get-element "retval" (car (docs (db.eval js-body))))))


Instruction:
Generate a defmacro form that transforms code like this:
(c?-with-stored (v :foo store 'nothing) (bwhen (val (value v)) val))

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

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

Output:
(defmacro c?-with-stored ((var key store &optional default) &body body)
  `(c? (bwhen-c-stored (,var ,key ,store ,default)
	 ,@body)))

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


Instruction:
Generate a defmacro form that transforms code like this:
(ematch0 list ((cons it nil) (cons (funcall fn it t) nil)) ((cons it rest) (cons (funcall fn it nil) (mapcar1-with-last fn rest))))

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

Input: (ematch0 list ((cons it nil) (cons (funcall fn it t) nil)) ((cons it rest) (cons (funcall fn it nil) (mapcar1-with-last fn rest))))

Output:
(defmacro ematch0 (what &body clauses)
  `(match0 ,what
     ,@clauses
     (_ (error "level0 match error!"))))

(match0 list ((cons it nil) (cons (funcall fn it t) nil)) ((cons it rest) (cons (funcall fn it nil) (mapcar1-with-last fn rest))) (_ (error "level0 match error!")))


Instruction:
Define a macro that eliminates this repetitive pattern:
(skip () :report (lambda (s) (format s "Skip the test ~S and all its dependencies." (name test))) (with-run-state (result-list) (push (make-instance 'test-skipped :reason "Circular dependencies" :test-case test) result-list)) (setf (status test) :circular))

Issue: Macro call that should be transformed by skip

Input: (skip () :report (lambda (s) (format s "Skip the test ~S and all its dependencies." (name test))) (with-run-state (result-list) (push (make-instance 'test-skipped :reason "Circular dependencies" :test-case test) result-list)) (setf (status test) :circular))

Output:
(defmacro skip (&rest reason)
  "Generates a TEST-SKIPPED result."
  `(add-result 'test-skipped :reason (format nil ,@reason)))

(add-result (quote test-skipped) :reason (format nil nil :report (lambda (s) (format s "Skip the test ~S and all its dependencies." (name test))) (with-run-state (result-list) (push (make-instance (quote test-skipped) :reason "Circular dependencies" :test-case test) result-list)) (setf (status test) :circular)))


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(define-custom-var (:beginning-of-array *beginning-of-array-handler*))

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

Input: (define-custom-var (:beginning-of-array *beginning-of-array-handler*))

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 (*beginning-of-array-handler* . :beginning-of-array)) *custom-vars* :test (function equal)) (defvar *beginning-of-array-handler*)))


Instruction:
Define a macro that eliminates this repetitive pattern:
(define-error args-incompatible () (previous-args current-args) "Sorry but the output arguments from one stage are not compatible with the input arguments of the next.~%Out vars from previous stage: ~a~%In args from this stage: ~a" previous-args current-args)

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

Input: (define-error args-incompatible () (previous-args current-args) "Sorry but the output arguments from one stage are not compatible with the input arguments of the next.~%Out vars from previous stage: ~a~%In args from this stage: ~a" previous-args current-args)

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 args-incompatible (:error-type varjo-error :prefix "Varjo") (previous-args current-args) "Sorry but the output arguments from one stage are not compatible with the input arguments of the next.~%Out vars from previous stage: ~a~%In args from this stage: ~a" previous-args current-args)


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(define-mustache-character #\! (make-instance 'comment-tag :text ""))

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

Input: (define-mustache-character #\! (make-instance 'comment-tag :text ""))

Output:
(defmacro define-mustache-character (char &body body)
  `(set-mustache-character
    ,char (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))
            ,@body)))

(set-mustache-character #\EXCLAMATION_MARK (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 comment-tag) :text "")))


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(when (node-slot type) (make-proxy type type))

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

Input: (when (node-slot type) (make-proxy type type))

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

(if (node-slot type) (make-proxy type type))


Instruction:
Define a macro that eliminates this repetitive pattern:
(macroexpand-convention (form) (if (consp form) (expand-export-accessors-using-head (first form) form) form))

Issue: Macro call that should be transformed by macroexpand-convention

Input: (macroexpand-convention (form) (if (consp form) (expand-export-accessors-using-head (first form) form) form))

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

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


Instruction:
Define a macro that eliminates this repetitive pattern:
(define-simple-definition-resolver special-variable (designator) (eq :special (sb-cltl2:variable-information designator)))

Issue: Macro call that should be transformed by define-simple-definition-resolver

Input: (define-simple-definition-resolver special-variable (designator) (eq :special (sb-cltl2:variable-information designator)))

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

(define-definition-resolver special-variable (special-variable #:package145) (when (ignore-errors (let ((designator special-variable)) (eq :special (sb-cltl2:variable-information designator)))) (list (make-instance (quote special-variable) :designator special-variable :package #:package145))))


Instruction:
Generate a defmacro form that transforms code like this:
($slot nil)

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

Input: ($slot nil)

Output: (defmacro $SLOT ...)


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

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

Input: (some-> 'some-name)

Output: (defmacro SOME-> ...)


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(define-api readtable-name (named-readtable) (named-readtable-designator => symbol) "Returns the name of the readtable designated by NAMED-READTABLE, or NIL." (let ((readtable (ensure-readtable named-readtable))) (cond ((%readtable-name readtable)) ((eq readtable *readtable*) :current) ((eq readtable *standard-readtable*) :common-lisp) ((eq readtable *case-preserving-standard-readtable*) :modern) (t nil))))

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

Input: (define-api readtable-name (named-readtable) (named-readtable-designator => symbol) "Returns the name of the readtable designated by NAMED-READTABLE, or NIL." (let ((readtable (ensure-readtable named-readtable))) (cond ((%readtable-name readtable)) ((eq readtable *readtable*) :current) ((eq readtable *standard-readtable*) :common-lisp) ((eq readtable *case-preserving-standard-readtable*) :modern) (t nil))))

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

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

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

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

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

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

(progn (declaim (ftype (function (named-readtable-designator) (values symbol &optional)) readtable-name)) (locally (declare (sb-ext:muffle-conditions style-warning)) (defun readtable-name (named-readtable) "Returns the name of the readtable designated by NAMED-READTABLE, or NIL." (locally (declare (sb-ext:unmuffle-conditions style-warning)) (let ((readtable (ensure-readtable named-readtable))) (cond ((%readtable-name readtable)) ((eq readtable *readtable*) :current) ((eq readtable *standard-readtable*) :common-lisp) ((eq readtable *case-preserving-standard-readtable*) :modern) (t nil)))))))


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(setypecase 'foo (string :nono))

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

Input: (setypecase 'foo (string :nono))

Output:
(defmacro setypecase (keyform &body cases)
  "Like ETYPECASE, except binds the keyform to IT (via SYMBOL-MACROLET) for
the scope of the cases. IT can be set with SETF."
  `(symbolic etypecase ,keyform ,@cases))

(symbolic etypecase (quote foo) (string :nono))


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(make-window-or-instance nil nil)

Write a macro that addresses: Macro call that should be transformed by MAKE-WINDOW-OR-INSTANCE

Input: (make-window-or-instance nil nil)

Output: (defmacro MAKE-WINDOW-OR-INSTANCE ...)