Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(letrec* 'lol-gen::some-name)

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

Input: (letrec* 'lol-gen::some-name)

Output:
(defmacro letrec* ((&rest bindings) &body body)
  "Like LETREC, but the bindings are evaluated in order.
See Waddell et al., *Fixing Letrec* for motivation.

Cf. `fbindrec*'."
  `(letrec-with setq ,bindings
     ,@body))


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

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

Input: (collect-stream nil (progn))

Output: (defmacro COLLECT-STREAM ...)


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

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

Input: (cond->> nil)

Output: (defmacro cond->> (init &body exps) (cond-arrow-macro init exps t))


Instruction:
Write a Common Lisp macro to handle this code pattern:
(defclass/std nil :key nil)

Problem: Macro call that should be transformed by DEFCLASS/STD

Input: (defclass/std nil :key nil)

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

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

  expands to:

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

  Each slot definition accepts options:

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

  See the README for more.

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


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

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

Input: (-<>> nil)

Output: (defmacro -<>> (init &body exps) (diamond-wand init exps t))


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

Problem: Macro call that should be transformed by REMF

Input: (remf nil (progn))

Output: (defmacro REMF ...)


Instruction:
Define a macro that eliminates this repetitive pattern:
(define-reader)

Issue: Macro call that should be transformed by DEFINE-READER

Input: (define-reader)

Output:
(defmacro define-reader (&key file-reader string-reader macro-character)
  `(progn
     (defun ,file-reader (file &key (debug nil))
       "Read c-mera source file and return AST"
       (let ((asts nil)
	     (*readtable* (copy-readtable nil)))
	 ;; Preserve case, and parse convenient stuff
	 (setf (readtable-case *readtable*) :invert)
	 ,@macro-character
	 ;(handler-case
	     (with-open-file (in file)
	       (loop for s-expr = (read in nil nil nil) while s-expr do ;; TODO CHECK call
		    (let* ((s-expr (eval s-expr))
			   (evaluated (if (listp s-expr)
					  s-expr
					  (list s-expr))))
		      (when (typep (car evaluated) 'node)
			(setf asts (append asts evaluated))))))

	   ;; TODO
	   ;; Standard clozure error handling breaks console.
	   ;; This hanlder-case  is only a tentative fix
	   ;#+clozure (error (err) (let ((*print-pretty* t))
	   ;			    (format *error-output* "~a" err))))
	 ;; Return single AST
	 (nodelist asts)))
     (defun ,string-reader (str)
       "Rread c-mera source string and return AST"
       (let ((asts nil)
	     (*readtable* (copy-readtable nil)))
	 ;; Preserve case, and parse convenient stuff
	 (setf (readtable-case *readtable*) :invert)
	 ,@macro-character
	 ;(handler-case
	     (let* ((s-expr (eval (read-from-string str)))
		    (evaluated (if (listp s-expr)
				   s-expr
				   (list s-expr))))
	       (when (typep (car evaluated) 'node)
		 (setf asts evaluated)))

	   ;; TODO
	   ;; Standard clozure error handling breaks console.
	   ;; This hanlder-case  is only a tentative fix
	   ;#+clozure (error (err) (let ((*print-pretty* t))
	   ;			    (format *error-output* "~a" err))))
	 ;; Return single AST
	 (nodelist asts)))))


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

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

Input:
(cll-outer nil
  (progn))

Output:
(defmacro cll-outer (val &body body)
 `(let ((outer-val ,val))
    ,@body))


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

Issue: Macro call that should be transformed by QUERY

Input: (query 'lol-gen::some-name)

Output:
(defmacro query (query &rest args/format)
  "Execute the given query, which can be either a string or an S-SQL form (list
starting with a keyword). If the query contains placeholders ($1, $2, etc)
their values can be given as extra arguments. If one of these arguments is a
keyword occurring in the table below, it will not be used as a query
argument, but will determine the format in which the results are returned
instead. Any of the following formats can be used, with the default being :rows:

| :none	             | Ignore the result values.                                 |
| :lists, :rows      | Return a list of lists, each list containing the values   |
|                    | for a row.                                                |
| :list, :row        | Return a single row as a list.                            |
| :alists	           | Return a list of alists which map column names to values, |
|                    | with the names represented as keywords.                   |
| :alist	           | Return a single row as an alist.                          |
| :array-hash        | Return an array of hashtables which map column names to   |
|                    | hash table keys. NOTE: It will return an empty array      |
|                    | if there is no result.                                    |
| :vectors           | Returns a vector of vectors where each internal vector is |
|                    | a returned row from the query. The field names are not    |
|                    | included. NOTE: It will return an empty vector instead of |
|                    | NIL if there is no result.                                |
| :str-alists        | Like :alists, but use the original column names.          |
| :str-alist	       | Return a single row as an alist, with strings for names.  |
| :plists	           | Return a list of plists which map column names to values, |
|                    | with the names represented as keywords.                   |
| :plist	           | Return a single row as a plist.                           |
| :column	           | Return a single column as a list.                         |
| :single	           | Return a single value.                                    |
| :single!	         | Like :single, but raise an error when the number of       |
|                    | selected rows is not equal to 1.                          |
| (:dao type)	       | Return a list of DAOs of the given type. The names of the |
|                    | fields returned by the query must match slots in the DAO  |
|                    | class the same way as with query-dao.                     |
| (:dao type :single)| Return a single DAO of the given type.                    |
| :json-strs         | Return a list of strings where each row is a json object  |
|                    | expressed as a string                                     |
| :json-str          | Return a single string where the row returned is a json   |
|                    | object expressed as a string.                             |
| :json-array-str    | Return a string containing a json array, each element in  |
|                    | the array is a selected row expressed as a json object.   |
|                    | NOTE: If there is no result, it will return a string with |
|                    | an empty json array.                                      |

If the database returns information about the amount rows that were affected,
such as with updating or deleting queries, this is returned as a second value."
  (let* ((format :rows)
         (args (loop :for arg :in args/format
                     :if (or (dao-spec-for-format arg)
                             (assoc arg *result-styles*)) :do (setf format arg)
                     :else :collect arg)))
    (destructuring-bind (reader result-form) (reader-for-format format)
      (let ((base (if args
		      (let ((vars (loop :for x :in args :collect (gensym))))
			`(let ,(loop :for v :in vars :for a :in args :collect `(,v ,a))
			   (prepare-query *database* "" ,(real-query query) (list ,@vars))
			   (exec-prepared *database* "" (list ,@vars) ,reader)))
		      `(exec-query *database* ,(real-query query) ,reader))))
        `(,result-form ,base)))))


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

Problem: Macro call that should be transformed by NOR

Input: (nor)

Output:
(defmacro nor (&rest forms)
  "Equivalent to (not (or ...)).

From Arc."
  (if (null forms) t
      (if (null (rest forms))
          `(not ,(first forms))
          `(if ,(first forms)
               nil
               (nor ,@(rest forms))))))


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

What needs to change: Macro call that should be transformed by ONCE-ON

Input:
(once-on nil
    :key
  nil)

Output:
(defmacro once-on (hook args &body body)
  "Attach a handler with ARGS and BODY to the HOOK.

Remove the handler after it fires the first time.

See `on'."
  (let ((handler-name (gensym "once-on-hook-handler"))
        (args (alexandria:ensure-list args)))
    (alexandria:once-only (hook)
      `(add-hook
        ,hook (make-instance 'handler
                             :fn (lambda ,args
                                   (declare (ignorable ,@args))
                                   (remove-hook ,hook (quote ,handler-name))
                                   ,@body)
                             :name (quote ,handler-name))))))


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(dynamic-extent 'lol-gen::some-name)

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

Input: (dynamic-extent 'lol-gen::some-name)

Output: (defmacro DYNAMIC-EXTENT ...)


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

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

Input: (when nil :key nil)

Output: (defmacro WHEN ...)


Instruction:
Write a Common Lisp macro to handle this code pattern:
(auto-permute-typecase 'lol-gen::some-name)

Problem: Macro call that should be transformed by AUTO-PERMUTE-TYPECASE

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

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


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

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

Input:
(doquery nil
    nil)

Output:
(defmacro doquery (query (&rest names) &body body)
  "Execute the given query (a string or a list starting with a keyword),
iterating over the rows in the result. The body will be executed with the values
in the row bound to the symbols given in names. To iterate over a
parameterised query, one can specify a list whose car is the query, and whose
cdr contains the arguments. For example:

(doquery (:select 'name 'score :from 'scores) (n s)
  (incf (gethash n *scores*) s))

(doquery ((:select 'name :from 'scores :where (:> 'score '$1)) 100) (name)
  (print name))"
  (let* ((fields (gensym))
         (query-name (gensym))
         args
         (reader-expr
           `(row-reader (,fields)
              (unless (= ,(length names) (length ,fields))
                (error "Number of field names does not match number of selected fields in query ~A."
                       ,query-name))
              (loop :while (next-row)
                    :do (let ,(loop :for i :from 0
                                    :for name :in names
                                    :collect `(,name (next-field (elt ,fields ,i))))
                          ,@body)))))
    (when (and (consp query) (not (keywordp (first query))))
      (setf args (cdr query) query (car query)))
    (if args
        `(let ((,query-name ,(real-query query)))
           (prepare-query *database* "" ,query-name (list ,@args))
           (exec-prepared *database* "" (list ,@args) ,reader-expr))
        `(let ((,query-name ,(real-query query)))
           (exec-query *database* ,query-name ,reader-expr)))))


Instruction:
Write a Common Lisp macro to handle this code pattern:
(f-zerop 'lol-gen::some-name)

Problem: Macro call that should be transformed by F-ZEROP

Input: (f-zerop 'lol-gen::some-name)

Output:
(defmacro f-zerop (key &rest body)
  `(with-synapse ,key (prior-fire-value)
     (let ((new-basis (progn ,@body)))
       (values new-basis (if (xor prior-fire-value (zerop new-basis))
                             (progn
                               (setf prior-fire-value (zerop new-basis))
                               :propagate)
                           :no-propagate)))))


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

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

Input: (defmethod 'lol-gen::some-name)

Output:
(defmacro defmethod (name &rest args)
  (handler-case
      (multiple-value-bind (qualifiers specializers lambda-list body)
          (parse-method args)

        (declare (ignore qualifiers))

        (with-gensyms (method)
          (let ((fn-name (gentemp (symbol-name (block-name name)) *method-function-package*)))
            `(progn
               ,(make-method-function name fn-name lambda-list body)

               (let ((,method
                      (walk-environment
                        (c2mop:defmethod ,name ,@args))))

                 (when (combination-options ',name)
                   ,(make-add-method-info name method fn-name body)
                   ,(make-static-dispatch name lambda-list specializers))

                 ,method)))))

    (error (e)
      (simple-style-warning "Error parsing DEFMETHOD form:~%~2T~a" e)
      `(walk-environment
         (c2mop:defmethod ,name ,@args)))))


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

Issue: Macro call that should be transformed by LRET

Input: (lret nil)

Output:
(defmacro lret ((&rest bindings) &body body)
  "Return the initial value of the last binding in BINDINGS. The idea
is to create something, initialize it, and then return it.

    (lret ((x 1)
           (y (make-array 1)))
      (setf (aref y 0) x))
    => #(1)

Note that the value returned is the value initially bound. Subsequent
assignments are ignored.

    (lret ((x 1))
      (setf x 2))
    => 1

Furthermore, on Lisps that support it, the variable may be made
read-only, making assignment a compiler-time error.

`lret' may seem trivial, but it fufills the highest purpose a macro
can: it eliminates a whole class of bugs (initializing an object, but
forgetting to return it).

Cf. `aprog1' in Anaphora."
  `(lret-aux let ,bindings
     ,@body))


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(lambda-cmatch
  common-lisp:nil
  :key
  common-lisp:nil)

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

Input:
(lambda-cmatch
  common-lisp:nil
  :key
  common-lisp:nil)

Output:
(defmacro lambda-cmatch (&body body)
  "Equivalent to (lambda (arg) (cmatch arg BODY...))."
  (multiple-value-bind (preamble clauses) (parse-matcher-body body)
    (with-gensyms (clause)
      `(lambda (,clause)
         ,@preamble
         (cmatch ,clause
           ,@clauses)))))


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

Problem: Macro call that should be transformed by IGNORING

Input: (ignoring nil)

Output:
(defmacro ignoring (type &body body)
  "DEPRECATED: use `alexandria:ignore-some-conditions' instead."
  (simple-style-warning "~s is deprecated, use ~s instead"
                        'ignoring 'ignore-some-conditions)
  `(ignore-some-conditions (,type)
     ,@body))


Instruction:
Define a macro that eliminates this repetitive pattern:
(cond-bind nil
  (progn))

Issue: Macro call that should be transformed by COND-BIND

Input:
(cond-bind nil
  (progn))

Output: (defmacro COND-BIND ...)


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(with-compilation-unit nil (progn))

Write a macro that addresses: Macro call that should be transformed by WITH-COMPILATION-UNIT

Input: (with-compilation-unit nil (progn))

Output: (defmacro WITH-COMPILATION-UNIT ...)


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

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

Input: (from nil nil)

Output:
(defmacro from (&rest statements)
  `(make-clause :from ,@(mapcar #'expand-op statements)))


Instruction:
Generate a defmacro form that transforms code like this:
(product-of 'lol-gen::some-name)

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

Input: (product-of 'lol-gen::some-name)

Output: (defmacro PRODUCT-OF ...)


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

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

Input: (collecting)

Output:
(defmacro collecting (&body body)
  "Like `with-collector', with the collector bound to the result of
interning `collect' in the current package."
  (with-current-package-symbols (collect)
    `(with-collector (,collect)
       ,@body)))


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

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

Input: (defgeneric nil nil)

Output: (defmacro DEFGENERIC ...)


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(pipe common-lisp:nil (common-lisp:progn))

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

Input: (pipe common-lisp:nil (common-lisp:progn))

Output:
(defmacro pipe (cl:&rest items)
  "A syntactic convenience for function application, sometimes called a \"threading macro\". Transform

    (pipe x h g f)

to

    (f (g (h x)))."
  (cl:assert (cl:<= 2 (cl:list-length items)))
  `(nest ,@(cl:reverse items)))


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

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

Input: (tree-ecase nil)

Output: (defmacro TREE-ECASE ...)


Instruction:
Define a macro that eliminates this repetitive pattern:
(fail-compile nil nil)

Issue: Macro call that should be transformed by FAIL-COMPILE

Input: (fail-compile nil nil)

Output:
(defmacro fail-compile (form &optional (type 'error) description &rest format-args)
  `(eval-in-context
    *context*
    (make-instance 'comparison-result
                   :expression '(fail-expansion ,form)
                   :value-form '(nth-value 3 (try-compile ',form ',type))
                   :body (lambda () (nth-value 3 (try-compile ',form ',type)))
                   :expected ',(maybe-unquote type)
                   :comparison 'typep
                   ,@(when description
                       `(:description (format NIL ,description ,@format-args))))))


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(.< common-lisp:nil (common-lisp:progn))

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

Input: (.< common-lisp:nil (common-lisp:progn))

Output:
(defmacro .< (cl:&rest items)
  "Right associative compose operator. Creates a new functions that will run the
functions right to left when applied. This is the same as the `nest` macro without supplying
the value. The composition is thus the same order as `compose`.

`(.< f g h)` creates the function `(fn (x) (f (g (h x))))`."
  (alexandria:with-gensyms (x)
    `(fn (,x)
       (nest ,@items ,x))))


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

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

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

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


Instruction:
Generate a defmacro form that transforms code like this:
(f_%
  nil)

Pattern to recognize: Macro call that should be transformed by F_%

Input:
(f_%
  nil)

Output: (defmacro F_% ...)


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

Issue: Macro call that should be transformed by RETURNING

Input: (returning nil)

Output: (defmacro RETURNING ...)


Instruction:
Define a macro that eliminates this repetitive pattern:
(with-unique-names nil
  nil)

Issue: Macro call that should be transformed by WITH-UNIQUE-NAMES

Input:
(with-unique-names nil
  nil)

Output:
(defmacro with-unique-names (names &body body)
  `(let ,(mapcar (lambda (sym)
                   `(,sym (gensym ,(symbol-name sym))))
                  names)
     ,@body))


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(ignorable common-lisp:nil
  common-lisp:nil)

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

Input:
(ignorable common-lisp:nil
  common-lisp:nil)

Output: (defmacro IGNORABLE ...)


Instruction:
Generate a defmacro form that transforms code like this:
(destructuring-match nil
  (progn))

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

Input:
(destructuring-match nil
  (progn))

Output: (defmacro DESTRUCTURING-MATCH ...)


Instruction:
Define a macro that eliminates this repetitive pattern:
(yield-all 'lol-gen::some-name)

Issue: Macro call that should be transformed by YIELD-ALL

Input: (yield-all 'lol-gen::some-name)

Output:
(defmacro yield-all (generator)
  "Walks through generator, re-yielding all of the items in it. Only meant for use inside of a defgenerator or with-yield block."
  (let ((x (gensym)))
    `(do-generator (,x ,generator)
       (yield ,x))))


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

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

Input:
(product-of nil
  (progn))

Output: (defmacro PRODUCT-OF ...)


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(lambda-cmatch1 common-lisp:nil
  (common-lisp:progn))

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

Input:
(lambda-cmatch1 common-lisp:nil
  (common-lisp:progn))

Output:
(defmacro lambda-cmatch1 (pattern &body body)
  "Equivalent to (lambda (arg) (cmatch arg (PATTERN BODY...)))."
  `(lambda-cmatch (,pattern ,@body)))


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

Problem: Macro call that should be transformed by WITH-ACCESSORS

Input:
(with-accessors nil
    nil)

Output: (defmacro WITH-ACCESSORS ...)


Instruction:
Define a macro that eliminates this repetitive pattern:
(some-<> nil
  (progn))

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

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

Output: (defmacro some-<> (init &body exps) (diamond-wand init exps nil t))


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

Problem: Macro call that should be transformed by AWHEN

Input:
(awhen nil
  :key
  nil)

Output: (defmacro AWHEN ...)


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

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

Input: (-> nil nil)

Output: (defmacro -> ...)


Instruction:
Define a macro that eliminates this repetitive pattern:
(with-output-to-file 'lol-gen::some-name)

Issue: Macro call that should be transformed by WITH-OUTPUT-TO-FILE

Input: (with-output-to-file 'lol-gen::some-name)

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


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

Problem: Macro call that should be transformed by MAX-OF

Input:
(max-of nil
  (progn))

Output: (defmacro MAX-OF ...)


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

Problem: Macro call that should be transformed by ->

Input: (-> 'lol-gen::some-name)

Output:
(defmacro -> (x &rest forms)
  "Threads the expr through FORMS. Inserts X as the
   second item in the first form, or in place of % if it is present in the form,
   making a list of it if it is not a list already.
   If there are more forms, inserts the first form
   as the second item in second form, etc."
  (if (first forms)
      (let* ((form (first forms))
             (threaded (if (listp form)
                           (if (member '% form)
                               `(funcall (lambda (%) ,form) ,x)
                               `(,(first form) ,x ,@(rest form)))
                           `(,form ,x))))
        `(-> ,threaded ,@(rest forms)))
      x))


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

Issue: Macro call that should be transformed by MAXF

Input: (maxf nil)

Output: (defmacro MAXF ...)


Instruction:
Write a Common Lisp macro to handle this code pattern:
(with-hook-restart
  nil)

Problem: Macro call that should be transformed by WITH-HOOK-RESTART

Input:
(with-hook-restart
  nil)

Output:
(defmacro with-hook-restart (&body body)
  `(with-simple-restart (continue "Call next function in hook ~s" *hook*)
     ,@body))


Instruction:
Define a macro that eliminates this repetitive pattern:
(string-ecase nil
  nil)

Issue: Macro call that should be transformed by STRING-ECASE

Input:
(string-ecase nil
  nil)

Output: (defmacro STRING-ECASE ...)


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

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

Input: (returning nil)

Output:
(defmacro returning (&rest expressions)
  `(apply #'make-clause :returning
          (list ,@(mapcar (lambda (expr)
                            (if (and (listp expr)
                                     (keywordp (car expr)))
                              (expand-op expr)
                              `,expr))
                          expressions))))


Instruction:
Generate a defmacro form that transforms code like this:
(bcond
  nil
  (progn))

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

Input:
(bcond
  nil
  (progn))

Output:
(defmacro bcond (&body clauses)
  "Scheme's extended COND.

This is exactly like COND, except for clauses having the form

     (test :=> recipient)

In that case, if TEST evaluates to a non-nil result, then RECIPIENT, a
function, is called with that result, and the result of RECIPIENT is
return as the value of the `cond`.

As an extension, a clause like this:

     (test :=> var ...)

Can be used as a shorthand for

     (test :=> (lambda (var) ...))

The name `bcond' for a “binding cond” goes back at least to the days
of the Lisp Machines. I do not know who was first to use it, but the
oldest examples I have found are by Michael Parker and Scott L.
Burson."
  (flet ((send-clause? (clause)
           (let ((second (second clause)))
             (and (symbolp second)
                  (string= second :=>))))
         (parse-send-clause (clause)
           (destructuring-bind (test => . body) clause
             (declare (ignore =>))
             (cond ((null body) (error "Missing clause"))
                   ((null (rest body))
                    (values test (car body)))
                   (t (destructuring-bind (var . body) body
                        (let ((fn `(lambda (,var) ,@body)))
                          (values test fn))))))))
    ;; Note that we expand into `cond' rather than `if' so we don't
    ;; have to handle tests without bodies.
    (cond ((null clauses) nil)
          ((member-if #'send-clause? clauses)
           (let* ((tail (member-if #'send-clause? clauses))
                  (preceding (ldiff clauses tail))
                  (clause (car tail))
                  (clauses (cdr tail)))
             (multiple-value-bind (test fn)
                 (parse-send-clause clause)
               (with-gensyms (tmp)
                 `(cond ,@preceding
                        (t (if-let1 ,tmp ,test
                             (funcall ,fn ,tmp)
                             (bcond ,@clauses))))))))
          (t `(cond ,@clauses)))))


Instruction:
Generate a defmacro form that transforms code like this:
(nth-value-or nil
  (progn))

Pattern to recognize: Macro call that should be transformed by NTH-VALUE-OR

Input:
(nth-value-or nil
  (progn))

Output:
(defmacro nth-value-or (nth-value &body forms)
  "Evaluates FORM arguments one at a time, until the NTH-VALUE returned by one
of the forms is true. It then returns all the values returned by evaluating
that form. If none of the forms return a true nth value, this form returns
NIL."
  (once-only (nth-value)
    (with-gensyms (values)
      `(let ((,values (multiple-value-list ,(first forms))))
         (if (nth ,nth-value ,values)
             (values-list ,values)
             ,(if (rest forms)
                  `(nth-value-or ,nth-value ,@(rest forms))
                  nil))))))


Instruction:
Generate a defmacro form that transforms code like this:
(eval-always
  nil)

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

Input:
(eval-always
  nil)

Output:
(defmacro eval-always (&body body)
  "Wrap BODY in eval-when with all keys (compile, load and execute) mentioned."
  `(eval-when (:compile-toplevel :load-toplevel :execute)
     ,@body))


Instruction:
Define a macro that eliminates this repetitive pattern:
(define-templated-dispatch nil
    nil)

Issue: Macro call that should be transformed by DEFINE-TEMPLATED-DISPATCH

Input:
(define-templated-dispatch nil
    nil)

Output: (defmacro DEFINE-TEMPLATED-DISPATCH ...)


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

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

Input: (~>> nil nil)

Output:
(defmacro ~>> (needle &rest holes)
  "Like `~>' but, by default, thread NEEDLE as the last argument
instead of the first."
  (thread-aux '~>> needle holes
              (lambda (needle hole)
                (append hole (list needle)))))


Instruction:
Generate a defmacro form that transforms code like this:
(abbr nil (progn))

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

Input: (abbr nil (progn))

Output:
(defmacro abbr (short long &optional lambda-list)
  "Abbreviate LONG macro or function name as SHORT.
   If LAMBDA-LIST is present, also copy appropriate SETF-expander."
  `(eval-always
     ;; Lispworks signals error while abbreviating to keywords
     ;; SBCL has package locks when accessing built-in functionality
     ;; other similar things are probably possible in other implementations
     (handler-bind ((error (lambda (e)
                             (let ((r (find-restart 'continue e)))
                               (when r
                                 (warn 'rutils-style-warning
                                       :format-control
                                       "Skipped error during abbreviation: ~A"
                                       :format-arguments (list e))
                                 (invoke-restart r))))))
       (cond
         ((macro-function ',long)
          (setf (macro-function ',short) (macro-function ',long))
          #+ccl (setf (ccl:arglist ',short) (ccl:arglist ',long)))
         ((special-operator-p ',long)
          (error "Can't abbreviate a special-operator ~a" ',long))
         ((fboundp ',long)
          (setf (fdefinition ',short) (fdefinition ',long))
          #+ccl (setf (ccl:arglist ',short) (ccl:arglist ',long))
          ,(when lambda-list
            `(define-setf-expander ,short ,lambda-list
               (values ,@(multiple-value-bind
                          (dummies vals store store-form access-form)
                          (get-setf-expansion
                           (cons long (remove-if (lambda (sym)
                                                   (member sym '(&optional &key)))
                                                 lambda-list)))
                          (let ((expansion-vals (mapcar (lambda (x) `(quote ,x))
                                                        (list dummies
                                                              vals
                                                              store
                                                              store-form
                                                              access-form))))
                            (setf (second expansion-vals)
                                  (cons 'list vals))
                            expansion-vals))))))
         (t
          (error "Can't abbreviate ~a" ',long)))
       (setf (documentation ',short 'function) (documentation ',long 'function))
       ',short)))


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

Problem: Macro call that should be transformed by LIVE

Input:
(live
  nil)

Output:
(defmacro live (&body forms)
  "Define a live block consisting of FORMS.

The FORMS are evaluated once when the LIVE form is first evaluated,
after which they are evaluated again whenever the values of the cells
referenced by them change. Cells may be referenced either directly in
FORMS or by a function called during the evaluation of FORMS.

Returns a function which when called, stops the live block. Once
stopped the live block will no longer be called when the values of the
referenced cells change."

  (let ((spec (make-instance 'watch-function-spec :body forms)))
    (generate-watch-function spec)))


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(doc 'lol-gen::some-name)

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

Input: (doc 'lol-gen::some-name)

Output: (defmacro DOC ...)


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

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

Input: (as-> nil nil)

Output: (defmacro AS-> ...)


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

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

Input:
(swhen nil
  (progn))

Output:
(defmacro swhen (test &body body)
  "Like WHEN, except binds the test form to IT (via SYMBOL-MACROLET) for the
scope of the body. IT can be set with SETF."
  `(symbolic when ,test ,@body))


Instruction:
Write a Common Lisp macro to handle this code pattern:
(c?_
  nil
  :key
  nil)

Problem: Macro call that should be transformed by C?_

Input:
(c?_
  nil
  :key
  nil)

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


Instruction:
Write a Common Lisp macro to handle this code pattern:
(without-dependency-capture)

Problem: Macro call that should be transformed by WITHOUT-DEPENDENCY-CAPTURE

Input: (without-dependency-capture)

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


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(enable-quasi-quoted-list-syntax)

Write a macro that addresses: Macro call that should be transformed by ENABLE-QUASI-QUOTED-LIST-SYNTAX

Input: (enable-quasi-quoted-list-syntax)

Output: (defmacro ENABLE-QUASI-QUOTED-LIST-SYNTAX ...)


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

Issue: Macro call that should be transformed by DEFTYPE

Input: (deftype nil ())

Output: (defmacro DEFTYPE ...)


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

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

Input: (defparam nil (progn))

Output: (defmacro DEFPARAM ...)


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

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

Input: (make-method nil)

Output: (defmacro MAKE-METHOD ...)


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

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

Input:
(some->> nil
  nil)

Output: (defmacro some->> (init &body exps) (arrow-macro init exps t t))


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(with-input-from-file 'lol-gen::some-name)

Write a macro that addresses: Macro call that should be transformed by WITH-INPUT-FROM-FILE

Input: (with-input-from-file 'lol-gen::some-name)

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


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

Pattern to recognize: Macro call that should be transformed by WITH-SPECIAL-INITARGS

Input:
(with-special-initargs nil
  :key
  nil)

Output: (defmacro WITH-SPECIAL-INITARGS ...)


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

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

Input:
(with-capped-stack nil
  nil)

Output:
(defmacro with-capped-stack (() &body body)
  `(stack-capper (lambda () ,@body)))


Instruction:
Generate a defmacro form that transforms code like this:
(ensure-functionf 'lol-gen::some-name)

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

Input: (ensure-functionf 'lol-gen::some-name)

Output:
(defmacro ensure-functionf (&rest places)
  "Multiple-place modify macro for ENSURE-FUNCTION: ensures that each of
PLACES contains a function."
  `(progn ,@(mapcar (lambda (x) `(ensure-functionf/1 ,x)) places)))


Instruction:
Write a Common Lisp macro to handle this code pattern:
(define-test+run nil
  nil)

Problem: Macro call that should be transformed by DEFINE-TEST+RUN

Input:
(define-test+run nil
  nil)

Output:
(defmacro define-test+run (name &body args-and-body)
  `(progn
     (define-test ,name ,@args-and-body)
     (eval-when (:execute)
       (let* ((*silence-plain-compilation-errors-p* nil) ; must be let*! the order matters!
              (report (test ',name :report 'plain)))
         (if (member (status report) '(:passed :skipped))
             report
             (values report
                     (loop for result across (results report)
                           when (and (not (typep result 'test-result))
                                     (eql :failed (status result)))
                           collect (expression result))))))))


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(defun-ematch* common-lisp:nil
    :key
  common-lisp:nil)

What needs to change: Macro call that should be transformed by DEFUN-EMATCH*

Input:
(defun-ematch* common-lisp:nil
    :key
  common-lisp:nil)

Output:
(defmacro defun-ematch* (name args &body body)
  "Equivalent to (defun (arg) [decl-and-docstring] (ematch arg (PATTERN BODY...)))."
  (multiple-value-bind (preamble clauses) (parse-matcher-body body)
    `(defun ,name ,args
       ,@preamble
       (ematch* ,args
         ,@clauses))))


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

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

Input:
(define-values nil
  (progn))

Output:
(defmacro define-values (values &body (expr))
  "Like `def', but for multiple values.
Each variable in VALUES is given a global, lexical binding, as with
`def', then set all at once, as with `multiple-value-setq'."
  `(progn
     ,@(loop for v in values collect `(def ,v nil))
     (setf (values ,@values) ,expr)
     (values ,@(loop for v in values collect `(quote ,v)))))


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

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

Input: (sort-values nil :key nil)

Output:
(defmacro sort-values (pred &rest values)
  "Sort VALUES with PRED and return as multiple values.

Equivalent to

    (values-list (sort (list VALUES...) pred))

But with less consing, and potentially faster."
  ;; Remember to evaluate `pred' no matter what.
  (with-gensyms (gpred)
    `(let ((,gpred (ensure-function ,pred)))
       (declare (ignorable ,gpred)
                (function ,gpred)
                (optimize (safety 1) (debug 0) (compilation-speed 0)))
       ,(match values
          ((list) `(values))
          ((list x) `(values ,x))
          ;; The strategy here is to use a sorting network if the
          ;; inputs are few, and a stack-allocated vector if the
          ;; inputs are many.
          (otherwise
           (if (<= (length values) 8)
               `(sort-values/network ,gpred ,@values)
               `(sort-values/temp-vector ,gpred ,@values)))))))


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

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

Input:
(sctypecase nil
  (progn))

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


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

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

Input: (letrec* nil)

Output:
(defmacro letrec* ((&rest bindings) &body body)
  "Like LETREC, but the bindings are evaluated in order.
See Waddell et al., *Fixing Letrec* for motivation.

Cf. `fbindrec*'."
  `(letrec-with setq ,bindings
     ,@body))


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(prependf 'lol-gen::some-name)

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

Input: (prependf 'lol-gen::some-name)

Output: (defmacro PREPENDF ...)


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

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

Input: (collect-alist nil nil)

Output: (defmacro COLLECT-ALIST ...)


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

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

Input: (econd nil nil)

Output:
(defmacro econd (&rest clauses)
  "Like `cond', but signal an error of type `econd-failure' if no
clause succeeds."
  (let ((test-count (length clauses)))
    `(cond ,@clauses
           ;; SBCL will silently eliminate this branch if it is
           ;; unreachable.
           (t (error 'econd-failure :test-count ',test-count)))))


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

What needs to change: Macro call that should be transformed by IF-LET

Input:
(if-let nil
  nil)

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

BINDINGS must be either single binding of the form:

 (variable initial-form)

or a list of bindings of the form:

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

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

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


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

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

Input:
(do+
  nil
  (progn))

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


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

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

Input:
(define-declaration nil
    nil)

Output: (defmacro DEFINE-DECLARATION ...)


Instruction:
Generate a defmacro form that transforms code like this:
(fm^v 'lol-gen::some-name)

Pattern to recognize: Macro call that should be transformed by FM^V

Input: (fm^v 'lol-gen::some-name)

Output:
(defmacro fm^v (id)
  `(value (fm^ ,id)))


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

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

Input:
(c_?
  nil
  (progn))

Output:
(defmacro c_? (&body body)
  "Lazy until asked, then eagerly propagating"
  `(make-c-dependent
    :code ',body
    :value-state :unevaluated
    :lazy :until-asked
    :rule (c-lambda ,@body)))


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

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

Input: (collect-product 'lol-gen::some-name)

Output: (defmacro COLLECT-PRODUCT ...)


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(with-string 'lol-gen::some-name)

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

Input: (with-string 'lol-gen::some-name)

Output:
(defmacro with-string ((var &optional stream
                        &key (element-type nil element-type-supplied?))
                       &body body)
  "Bind VAR to the character stream designated by STREAM.

STREAM is resolved like the DESTINATION argument to `format': it can
be any of t (for `*standard-output*'), nil (for a string stream), a
string with a fill pointer, or a stream to be used directly.

When possible, it is a good idea for functions that build strings to
take a stream to write to, so callers can avoid consing a string just
to write it to a stream. This macro makes it easy to write such
functions.

    (defun format-x (x &key stream)
      (with-string (s stream)
        ...))"
  (declare #+sbcl (sb-ext:muffle-conditions style-warning))
  (when (constantp stream)
    (let ((stream (eval stream)))
      (cond ((eql stream t)
             (return-from with-string
               `(let ((,var *standard-output*))
                  ,@body)))
            ((null stream)
             (return-from with-string
               `(with-output-to-string (,var
                                        ,@(and element-type-supplied?
                                               `(:element-type ,element-type)))
                  ,@body))))))

  (with-thunk ((body :name with-string) var)
    `(call/string #',body ,stream)))


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(with-standard-input-syntax
  nil)

Write a macro that addresses: Macro call that should be transformed by WITH-STANDARD-INPUT-SYNTAX

Input:
(with-standard-input-syntax
  nil)

Output:
(defmacro with-standard-input-syntax (&body body)
  "Like `with-standard-io-syntax', but only bind the variables that
control the reader, not the printer.

This may be preferable to using `with-standard-io-syntax' when loading
data, as it will not effect how errors are printed, thus preserving
debugging information."
  (with-thunk ((body :name with-standard-input-syntax))
    `(call/standard-input-syntax ,body)))


Instruction:
Write a Common Lisp macro to handle this code pattern:
(dynamic-let* 'lol-gen::some-name)

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

Input: (dynamic-let* 'lol-gen::some-name)

Output: (defmacro DYNAMIC-LET* ...)


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

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

Input: (enable-interpol-syntax nil :key nil)

Output:
(defmacro enable-interpol-syntax (&rest %enable-interpol-syntax-args)
  "Enable CL-INTERPOL reader syntax."
  `(eval-when (:compile-toplevel :load-toplevel :execute)
    (%enable-interpol-syntax ,@%enable-interpol-syntax-args)))


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

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

Input:
(with-connection nil
  (progn))

Output:
(defmacro with-connection (spec &body body)
  "Evaluates the body with *database* bound to a connection as specified by spec,
which should be list that connect can be applied to."
  `(let ((*database* (apply #'connect ,spec)))
     (unwind-protect (progn ,@body)
       (disconnect *database*))))


Instruction:
Write a Common Lisp macro to handle this code pattern:
(define-print-object/std nil)

Problem: Macro call that should be transformed by DEFINE-PRINT-OBJECT/STD

Input: (define-print-object/std nil)

Output:
(defmacro define-print-object/std (class)
  "Define a print-object method for objects of class CLASS.

  Print all slots with their values. Prints \"UNBOUND\", as a string, when slots are unbound.

  Usage:

  (defclass/std test () ((a b)))

  (print-object/std test)

  The macro expands to:

  (DEFMETHOD PRINT-OBJECT ((OBJ TEST) STREAM)
    (PRINT-UNREADABLE-OBJECT (OBJ STREAM :TYPE T :IDENTITY T)
        (FORMAT STREAM \"~{~a~^ ~}\" (COLLECT-OBJECT-SLOTS OBJ))))
"
  `(defmethod print-object ((obj ,class) stream)
     (print-unreadable-object (obj stream :type t :identity t)
       (format stream "~{~a~^ ~}"
               (collect-object-slots obj)))))


Instruction:
Define a macro that eliminates this repetitive pattern:
(character-literal 'lol-gen::some-name)

Issue: Macro call that should be transformed by CHARACTER-LITERAL

Input: (character-literal 'lol-gen::some-name)

Output: (defmacro CHARACTER-LITERAL ...)


Instruction:
Write a Common Lisp macro to handle this code pattern:
(bind-custom-vars nil
  :key
  nil)

Problem: Macro call that should be transformed by BIND-CUSTOM-VARS

Input:
(bind-custom-vars nil
  :key
  nil)

Output:
(defmacro bind-custom-vars ((&rest customizations) &body body)
  `(let ,(loop-on-custom (key var value) customizations
            collect (list var value))
     ,@body))


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

Issue: Macro call that should be transformed by HTML

Input: (html nil (progn))

Output:
(defmacro html (&rest tags)
  `(with-doctype :html
     (tag->string (cons :html ',tags))))


Instruction:
Write a Common Lisp macro to handle this code pattern:
(multiple-value-prog2 nil
    nil)

Problem: Macro call that should be transformed by MULTIPLE-VALUE-PROG2

Input:
(multiple-value-prog2 nil
    nil)

Output:
(defmacro multiple-value-prog2 (first-form second-form &body forms)
  "Evaluates FIRST-FORM, then SECOND-FORM, and then FORMS. Yields as its value
   all the value returned by SECOND-FORM."
  `(progn ,first-form (multiple-value-prog1 ,second-form ,@forms)))


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

What needs to change: Macro call that should be transformed by WHEN-IT

Input:
(when-it nil
  (progn))

Output:
(defmacro when-it (test &body body)
  "Like WHEN. IT is bound to TEST."
  `(let ((it ,test))
     (when it
       ,@body)))


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

Problem: Macro call that should be transformed by PRINT-VALUES

Input:
(print-values
  nil
  (progn))

Output: (defmacro PRINT-VALUES ...)


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

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

Input: (bind 'lol-gen::some-name)

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


Instruction:
Write a Common Lisp macro to handle this code pattern:
(with-open-files nil
  :key
  nil)

Problem: Macro call that should be transformed by WITH-OPEN-FILES

Input:
(with-open-files nil
  :key
  nil)

Output:
(defmacro with-open-files ((&rest args) &body body)
  "A simple macro to open one or more files providing the streams for the BODY. The ARGS is a list of `(stream filespec options*)` as supplied to WITH-OPEN-FILE."
  (case (length args)
    ((0)
     `(progn ,@body))
    ((1)
     `(with-open-file ,(first args) ,@body))
    (t `(with-open-file ,(first args)
          (with-open-files
              ,(rest args) ,@body)))))


Instruction:
Define a macro that eliminates this repetitive pattern:
(js-inline)

Issue: Macro call that should be transformed by JS-INLINE

Input: (js-inline)

Output: (defmacro JS-INLINE ...)


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

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

Input:
(as-> nil
    nil)

Output:
(defmacro as-> (init var &body exps)
  `(let ((,var ,init))
     ,var
     ,@(loop for (exp next-exp) on exps
          collect (if next-exp `(setf ,var ,exp) exp))))


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

Problem: Macro call that should be transformed by SETF

Input: (setf nil (progn))

Output: (defmacro SETF ...)


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(cll-outer 'lol-gen::some-name)

What needs to change: Macro call that should be transformed by CLL-OUTER

Input: (cll-outer 'lol-gen::some-name)

Output:
(defmacro cll-outer (val &body body)
 `(let ((outer-val ,val))
    ,@body))


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

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

Input: (nand nil :key nil)

Output:
(defmacro nand (&rest forms)
  "Equivalent to (not (and ...))."
  (if (null forms) nil
      (if (null (rest forms))
          `(not ,(first forms))
          `(if ,(first forms)
               (nand ,@(rest forms))
               t))))


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(list-of 'lol-gen::some-name)

What needs to change: Macro call that should be transformed by LIST-OF

Input: (list-of 'lol-gen::some-name)

Output: (defmacro LIST-OF ...)


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

Problem: Macro call that should be transformed by UPDATE

Input: (update nil)

Output:
(defmacro update (table &body clauses)
  `(make-statement :update
                   ,(expand-expression table) ,@clauses))


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

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

Input: (collect-append nil)

Output: (defmacro COLLECT-APPEND ...)


Instruction:
Define a macro that eliminates this repetitive pattern:
(lambda-match1 common-lisp:nil
  (common-lisp:progn))

Issue: Macro call that should be transformed by LAMBDA-MATCH1

Input:
(lambda-match1 common-lisp:nil
  (common-lisp:progn))

Output:
(defmacro lambda-match1 (pattern &body body)
  "Equivalent to (lambda (arg) (match arg (PATTERN BODY...)))."
  `(lambda-match (,pattern ,@body)))


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

What needs to change: Macro call that should be transformed by IF-LET

Input:
(if-let nil
  :key
  nil)

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

BINDINGS must be either single binding of the form:

 (variable initial-form)

or a list of bindings of the form:

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

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

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


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

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

Input:
(some->
  nil
  :key
  nil)

Output: (defmacro SOME-> ...)


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

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

Input:
(-<>
  nil
  (progn))

Output: (defmacro -<> ...)


Instruction:
Generate a defmacro form that transforms code like this:
(coalton-codegen-ast)

Pattern to recognize: Macro call that should be transformed by COALTON-CODEGEN-AST

Input: (coalton-codegen-ast)

Output: (defmacro COALTON-CODEGEN-AST ...)


Instruction:
Define a macro that eliminates this repetitive pattern:
(pprint-coalton-codegen-types
  'lol-gen::some-name)

Issue: Macro call that should be transformed by PPRINT-COALTON-CODEGEN-TYPES

Input:
(pprint-coalton-codegen-types
  'lol-gen::some-name)

Output: (defmacro PPRINT-COALTON-CODEGEN-TYPES ...)


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

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

Input: (whichever nil nil)

Output:
(defmacro whichever (&rest possibilities &environment env)
  "Evaluates exactly one of POSSIBILITIES, chosen at random."
  (setf possibilities (mapcar (lambda (p) (macroexpand p env)) possibilities))
  (let ((length (length possibilities)))
    (cond
      ((= 1 length)
       (first possibilities))
      ((every #'constantp possibilities)
       `(svref (load-time-value (vector ,@possibilities))
               (random ,length)))
      (T
       (labels ((expand (possibilities position random-number)
                  (if (null (cdr possibilities))
                      (car possibilities)
                      (let* ((length (length possibilities))
                             (half (truncate length 2))
                             (second-half (nthcdr half possibilities))
                             (first-half (butlast possibilities (- length half))))
                        `(if (< ,random-number ,(+ position half))
                             ,(expand first-half position random-number)
                             ,(expand second-half (+ position half) random-number))))))
         (with-gensyms (random-number)
           `(let ((,random-number (random ,length)))
              ,(expand possibilities 0 random-number))))))))


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

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

Input:
(m nil
  nil)

Output: (defmacro M ...)


Instruction:
Define a macro that eliminates this repetitive pattern:
(for-all* nil
  nil)

Issue: Macro call that should be transformed by FOR-ALL*

Input:
(for-all* nil
  nil)

Output:
(defmacro for-all* (bindings &body body)
  "Bind BINDINGS to random variables and test BODY *num-trials* times.

Works like FOR-ALL but variables are defined sequentially - subsequent
generator bindings may use value of a previous generator.

Example:

  (for-all* ((a (gen-integer))
             (b (gen-integer :min a :max (+ a 20)))
    (is (<= a b)))"
  (with-gensyms (test-lambda-args)
    `(perform-random-testing
      nil
      (lambda (,test-lambda-args)
        (declare (ignore ,test-lambda-args))
        (dbind-rec ,bindings
          (if (and ,@(delete-if #'null (mapcar #'third bindings)))
              (progn ,@body)
              (throw 'run-once
                (list :guard-conditions-failed))))))))


Instruction:
Generate a defmacro form that transforms code like this:
(with-savepoint nil
  nil)

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

Input:
(with-savepoint nil
  nil)

Output:
(defmacro with-savepoint (name &body body)
  "Can only be used within a transaction. Establishes a savepoint with the given
name at the start of body, and binds the same name to a handle for that savepoint.
The body is executed and, at the end of body, the savepoint is released, unless a
condition is thrown, in which case it is rolled back. Execute the body within a
savepoint, releasing savepoint when the body exits normally, and rolling back
otherwise. NAME is both the variable that can be used to release or rolled back
before the body unwinds, and the SQL name of the savepoint.

An example might look like this:

(defun test12 (x &optional (y nil))
  (with-logical-transaction (lt1 :read-committed-rw)
    (execute (:insert-into 'test-data :set 'value 0))
    (with-savepoint sp1
      (execute (:insert-into 'test-data :set 'value 1))
      (if (< x 0)
          (rollback-savepoint sp1)
          (release-savepoint sp1)))
    (with-savepoint sp2
      (execute (:insert-into 'test-data :set 'value 2))
      (with-savepoint sp3
        (execute (:insert-into 'test-data :set 'value 3))
        (if (> x 0)
            (rollback-savepoint sp3)
            (release-savepoint sp3))
        (when y (rollback-savepoint sp2)))
      (if (= x 0)
          (rollback-savepoint sp2)
          (release-savepoint sp2)))
    (when (string= y \"abrt\")
      (abort-transaction lt1))))"

  `(call-with-savepoint ',name (lambda (,name)
                                 (declare (ignorable ,name)) ,@body)))


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

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

Input:
(c_?dbg
  nil
  nil)

Output:
(defmacro c_?dbg (&body body)
  "Lazy until asked, then eagerly propagating"
  `(make-c-dependent
    :code ',body
    :value-state :unevaluated
    :lazy :until-asked
    :rule (c-lambda ,@body)
    :debug t))


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

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

Input: (collect-last nil (progn))

Output: (defmacro COLLECT-LAST ...)


Instruction:
Generate a defmacro form that transforms code like this:
(c?+n
  'lol-gen::some-name)

Pattern to recognize: Macro call that should be transformed by C?+N

Input:
(c?+n
  'lol-gen::some-name)

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


Instruction:
Define a macro that eliminates this repetitive pattern:
(lexpr-$send nil :key nil)

Issue: Macro call that should be transformed by LEXPR-$SEND

Input: (lexpr-$send nil :key nil)

Output: (defmacro LEXPR-$SEND ...)


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

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

Input: (defmethod nil :key nil)

Output:
(defmacro defmethod (name &rest args)
  (handler-case
      (multiple-value-bind (qualifiers specializers lambda-list body)
          (parse-method args)

        (declare (ignore qualifiers))

        (with-gensyms (method)
          (let ((fn-name (gentemp (symbol-name (block-name name)) *method-function-package*)))
            `(progn
               ,(make-method-function name fn-name lambda-list body)

               (let ((,method
                      (walk-environment
                        (c2mop:defmethod ,name ,@args))))

                 (when (combination-options ',name)
                   ,(make-add-method-info name method fn-name body)
                   ,(make-static-dispatch name lambda-list specializers))

                 ,method)))))

    (error (e)
      (simple-style-warning "Error parsing DEFMETHOD form:~%~2T~a" e)
      `(walk-environment
         (c2mop:defmethod ,name ,@args)))))


Instruction:
Define a macro that eliminates this repetitive pattern:
(destructuring-bind () nil)

Issue: Macro call that should be transformed by DESTRUCTURING-BIND

Input: (destructuring-bind () nil)

Output: (defmacro DESTRUCTURING-BIND ...)


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

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

Input: (builder 'lol-gen::some-name)

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


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(appendf 'lol-gen::some-name)

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

Input: (appendf 'lol-gen::some-name)

Output: (defmacro APPENDF ...)


Instruction:
Generate a defmacro form that transforms code like this:
(when-match common-lisp:nil
    :key
  common-lisp:nil)

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

Input:
(when-match common-lisp:nil
    :key
  common-lisp:nil)

Output:
(defmacro when-match (pattern arg &body body)
  "Equivalent to (match ARG (PATTERN BODY...))."
  `(match ,arg (,pattern ,.body)))


Instruction:
Define a macro that eliminates this repetitive pattern:
(insert-into nil
  (progn))

Issue: Macro call that should be transformed by INSERT-INTO

Input:
(insert-into nil
  (progn))

Output:
(defmacro insert-into (table &body clauses)
  `(make-statement :insert-into
                   ,(expand-expression table)
                   ,@(if (and (listp (car clauses))
                              (keywordp (caar clauses)))
                         `(',(car clauses) ,@(cdr clauses))
                         clauses)))


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

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

Input: (finish nil)

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


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(maybe-once-only nil)

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

Input: (maybe-once-only nil)

Output: (defmacro MAYBE-ONCE-ONLY ...)


Instruction:
Write a Common Lisp macro to handle this code pattern:
(walk-environment
  'lol-gen::some-name)

Problem: Macro call that should be transformed by WALK-ENVIRONMENT

Input:
(walk-environment
  'lol-gen::some-name)

Output: (defmacro WALK-ENVIRONMENT ...)


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

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

Input:
(with-transaction nil
  nil)

Output:
(defmacro with-transaction ((&optional name isolation-level) &body body)
  "Execute the given body within a database transaction, committing it when the
body exits normally, and aborting otherwise. An optional name and/or
isolation-level can be given to the transaction. The name can be used to force
a commit or abort before the body unwinds. The isolation-level will set the
isolation-level used by the transaction.

You can specify the following isolation levels in postmodern transactions:

- :read-committed-rw (read committed with read and write)
- :read-committed-ro (read committed with read only)
- :repeatable-read-rw (repeatable read with read and write)
- :repeatable-read-ro (repeatable read with read only)
- :serializable (serializable with reand and write)

Sample usage where george is just the name given to the transaction (not quoted
or a string) and ... simply indicates other statements would be expected here:

    (with-transaction ()
      (execute (:insert-into 'test-data :set 'value 77))
      ...)

    (with-transaction (george)
      (execute (:insert-into 'test-data :set 'value 22))
      ...)

    (with-transaction (george :read-committed-rw)
      (execute (:insert-into 'test-data :set 'value 33))
      (query (:select '* :from 'test-data))
      ...)

    (with-transaction (:serializable)
      (execute (:insert-into 'test-data :set 'value 44))
      ...)

Further discussion of transactions and isolation levels can found in the
isolation notes file in the doc folder."
  (let ((transaction-name (or (when (not (isolation-level-p name))
                                name)
                              (gensym "anonymous-transaction"))))
    (when (and name (isolation-level-p name))
      (setf isolation-level name))
    `(call-with-transaction (lambda (,transaction-name)
                              (declare (ignorable ,transaction-name)) ,@body)
                            ,isolation-level)))


Instruction:
Write a Common Lisp macro to handle this code pattern:
(f-zerop nil :key nil)

Problem: Macro call that should be transformed by F-ZEROP

Input: (f-zerop nil :key nil)

Output:
(defmacro f-zerop (key &rest body)
  `(with-synapse ,key (prior-fire-value)
     (let ((new-basis (progn ,@body)))
       (values new-basis (if (xor prior-fire-value (zerop new-basis))
                             (progn
                               (setf prior-fire-value (zerop new-basis))
                               :propagate)
                           :no-propagate)))))


Instruction:
Define a macro that eliminates this repetitive pattern:
(sum-of nil
  :key
  nil)

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

Input:
(sum-of nil
  :key
  nil)

Output: (defmacro SUM-OF ...)


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

Problem: Macro call that should be transformed by DEFPACKAGE

Input: (defpackage nil)

Output: (defmacro DEFPACKAGE ...)


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

What needs to change: Macro call that should be transformed by DO-FOR

Input: (do-for nil)

Output: (defmacro DO-FOR ...)


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

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

Input: (js 'lol-gen::some-name)

Output: (defmacro JS ...)


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

Problem: Macro call that should be transformed by ALL-OF

Input:
(all-of nil
  (progn))

Output: (defmacro ALL-OF ...)


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

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

Input: (the 'lol-gen::some-name)

Output: (defmacro THE ...)


Instruction:
Generate a defmacro form that transforms code like this:
(once-only nil
  nil)

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

Input:
(once-only nil
  nil)

Output:
(defmacro once-only (specs &body forms)
  "Constructs code whose primary goal is to help automate the handling of
multiple evaluation within macros. Multiple evaluation is handled by introducing
intermediate variables, in order to reuse the result of an expression.

The returned value is a list of the form

  (let ((<gensym-1> <expr-1>)
        ...
        (<gensym-n> <expr-n>))
    <res>)

where GENSYM-1, ..., GENSYM-N are the intermediate variables introduced in order
to evaluate EXPR-1, ..., EXPR-N once, only. RES is code that is the result of
evaluating the implicit progn FORMS within a special context determined by
SPECS. RES should make use of (reference) the intermediate variables.

Each element within SPECS is either a symbol SYMBOL or a pair (SYMBOL INITFORM).
Bare symbols are equivalent to the pair (SYMBOL SYMBOL).

Each pair (SYMBOL INITFORM) specifies a single intermediate variable:

- INITFORM is an expression evaluated to produce EXPR-i

- SYMBOL is the name of the variable that will be bound around FORMS to the
  corresponding gensym GENSYM-i, in order for FORMS to generate RES that
  references the intermediate variable

The evaluation of INITFORMs and binding of SYMBOLs resembles LET. INITFORMs of
all the pairs are evaluated before binding SYMBOLs and evaluating FORMS.

Example:

  The following expression

  (let ((x '(incf y)))
    (once-only (x)
      `(cons ,x ,x)))

  ;;; =>
  ;;; (let ((#1=#:X123 (incf y)))
  ;;;   (cons #1# #1#))

  could be used within a macro to avoid multiple evaluation like so

  (defmacro cons1 (x)
    (once-only (x)
      `(cons ,x ,x)))

  (let ((y 0))
    (cons1 (incf y)))

  ;;; => (1 . 1)

Example:

  The following expression demonstrates the usage of the INITFORM field

  (let ((expr '(incf y)))
    (once-only ((var `(1+ ,expr)))
      `(list ',expr ,var ,var)))

  ;;; =>
  ;;; (let ((#1=#:VAR123 (1+ (incf y))))
  ;;;   (list '(incf y) #1# #1))

  which could be used like so

  (defmacro print-succ-twice (expr)
    (once-only ((var `(1+ ,expr)))
      `(format t \"Expr: ~s, Once: ~s, Twice: ~s~%\" ',expr ,var ,var)))

  (let ((y 10))
    (print-succ-twice (incf y)))

  ;;; >>
  ;;; Expr: (INCF Y), Once: 12, Twice: 12"
  (let ((gensyms (make-gensym-list (length specs) "ONCE-ONLY"))
        (names-and-forms (mapcar (lambda (spec)
                                   (etypecase spec
                                     (list
                                      (destructuring-bind (name form) spec
                                        (cons name form)))
                                     (symbol
                                      (cons spec spec))))
                                 specs)))
    ;; bind in user-macro
    `(let ,(mapcar (lambda (g n) (list g `(gensym ,(string (car n)))))
                   gensyms names-and-forms)
       ;; bind in final expansion
       `(let (,,@(mapcar (lambda (g n)
                           ``(,,g ,,(cdr n)))
                         gensyms names-and-forms))
          ;; bind in user-macro
          ,(let ,(mapcar (lambda (n g) (list (car n) g))
                         names-and-forms gensyms)
             ,@forms)))))


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

Issue: Macro call that should be transformed by AAND

Input: (aand nil :key nil)

Output:
(defmacro aand (first &rest rest)
  "Like AND, except binds the first argument to IT (via LET) for the
scope of the rest of the arguments."
  `(anaphoric and ,first ,@rest))


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

Issue: Macro call that should be transformed by WITH-PS-GENSYMS

Input: (with-ps-gensyms nil)

Output: (defmacro WITH-PS-GENSYMS ...)


Instruction:
Generate a defmacro form that transforms code like this:
(export-structure
  common-lisp:nil
  common-lisp:nil)

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

Input:
(export-structure
  common-lisp:nil
  common-lisp:nil)

Output: (defmacro EXPORT-STRUCTURE ...)


Instruction:
Write a Common Lisp macro to handle this code pattern:
(with-stemcell-infer-hook nil)

Problem: Macro call that should be transformed by WITH-STEMCELL-INFER-HOOK

Input: (with-stemcell-infer-hook nil)

Output:
(defmacro with-stemcell-infer-hook (func &body body)
  (let ((func-name (gensym "hook")))
    `(let* ((,func-name ,func)
            (*stemcell-infer-hook* ,func-name))
       ,@body)))


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(fm-otherv? nil nil)

Write a macro that addresses: Macro call that should be transformed by FM-OTHERV?

Input: (fm-otherv? nil nil)

Output:
(defmacro fm-otherv? (md-name &optional (starting 'self) (global-search t))
  `(fm-other-v ,md-name ,starting ,global-search))


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

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

Input: (~> 'lol-gen::some-name)

Output:
(defmacro ~> (needle &rest holes)
  "Threading macro from Clojure (by way of Racket).

Thread NEEDLE through HOLES, where each hole is either a
symbol (equivalent to `(hole needle)`) or a list (equivalent to `(hole
needle args...)`).

As an extension, an underscore in the argument list is replaced with
the needle, so you can pass the needle as an argument other than the
first."
  (thread-aux '~> needle holes
              (lambda (needle hole)
                (list* (car hole) needle (cdr hole)))))


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

Issue: Macro call that should be transformed by EXAMPLE

Input:
(example
  nil
  :key
  nil)

Output:
(defmacro example (&body body)
  "Like `comment'."
  `(comment ,@body))


Instruction:
Generate a defmacro form that transforms code like this:
(declaim nil
         (progn))

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

Input:
(declaim nil
         (progn))

Output: (defmacro DECLAIM ...)


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

Issue: Macro call that should be transformed by WITH-CONTRACTS-DISABLED

Input:
(with-contracts-disabled nil
  (progn))

Output:
(defmacro with-contracts-disabled (() &body body)
  "A shorthand for disabling all contracts for the extent of this form."
  (let ((enabled-contracts (gensym "ENABLED-CONTRACTS-")))
    `(let ((,enabled-contracts (enabled-contracts)))
       (unwind-protect
            (progn (disable-contracts)
                   ,@body)
         (apply #'enable-contracts ,enabled-contracts)))))


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

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

Input:
(with-packages-unlocked nil
  nil)

Output: (defmacro WITH-PACKAGES-UNLOCKED ...)


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

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

Input:
(summing
  nil
  nil)

Output:
(defmacro summing (&body body)
  "Within BODY, bind `sum' to a function that gathers numbers to sum.

If the first form in BODY is a literal number, it is used instead of 0
as the initial sum.

To see the running sum, call `sum' with no arguments.

Return the total."
  ;; TODO This should be numerically stable, at least if the zero is a
  ;; float.
  (let ((zero (if (numberp (first body)) (pop body) 0)))
    (with-gensyms (running-total x x-supplied?)
      (with-current-package-symbols (sum)
        `(let ((,running-total ,zero))
           (declare (number ,running-total))
           (flet ((,sum (&optional (,x 0 ,x-supplied?))
                    (if ,x-supplied?
                        (incf ,running-total ,x)
                        ,running-total)))
             (declare (ignorable (function ,sum)))
             ,@body)
           (the number ,running-total))))))


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

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

Input:
(with-slots nil
    (progn))

Output: (defmacro WITH-SLOTS ...)


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

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

Input:
(aetypecase nil
  nil)

Output:
(defmacro aetypecase (keyform &body cases)
  "Like ETYPECASE, except binds the result of the keyform to IT (via LET) for
the scope of the cases."
  `(anaphoric etypecase ,keyform ,@cases))


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

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

Input: (is-type nil :key nil)

Output:
(defmacro is-type (got expected-type &optional desc)
  (with-gensyms (duration result)
    (once-only (desc expected-type)
      `(with-catching-errors (:description ,desc :expected ,expected-type)
         (with-duration ((,duration ,result) ,got)
           (test ,result ,expected-type ,desc
                 :duration ,duration
                 :got-form ',got
                 :test-fn #'typep
                 :report-expected-label "be a type of"))))))


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

Problem: Macro call that should be transformed by ITER

Input: (iter)

Output: (defmacro ITER ...)


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

Issue: Macro call that should be transformed by QUASIQUOTE

Input: (quasiquote nil)

Output: (defmacro quasiquote (x) (quasiquote-expand x))


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

Problem: Macro call that should be transformed by HAVING

Input: (having nil)

Output:
(defmacro having (expression)
  `(make-clause :having
                ,(if (and (listp expression)
                          (keywordp (car expression)))
                     (expand-op expression)
                     `,expression)))


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(lambda-cmatch*
  common-lisp:nil
  :key
  common-lisp:nil)

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

Input:
(lambda-cmatch*
  common-lisp:nil
  :key
  common-lisp:nil)

Output:
(defmacro lambda-cmatch* (&body body)
  "Equivalent to (lambda (args...) (cmatch* (args...) BODY...))."
  (multiple-value-bind (preamble clauses) (parse-matcher-body body)
    (let ((gensyms (make-gensyms (caar clauses))))
      `(lambda ,gensyms
         ,@preamble
         (cmatch* ,gensyms
           ,@clauses)))))


Instruction:
Generate a defmacro form that transforms code like this:
(match-of nil
    nil)

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

Input:
(match-of nil
    nil)

Output:
(defmacro match-of (union expr &body clauses &environment env)
  "Do pattern matching on an algebraic data type.

UNION should be an algebraic data type.

Each clause in CLAUSES has a pattern as its first element.

If the pattern is a symbol, it matches a unit type.

If the pattern is a list, it matches a constructor.

If the pattern is an underscore, it introduces a default or
fallthrough clause.

If the pattern is a list that starts with `or', it is a disjunction of
other patterns."
  (check-match-exhaustive union clauses env)
  `(ematch ,expr
     ,@(loop for (pattern . body) in clauses
             collect `(,(nth-value 1 (pattern-type pattern union))
                       ,@body))))


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

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

Input: (eif nil :key nil)

Output:
(defmacro eif (&whole whole test then &optional (else nil else?))
  "Like `cl:if', but expects two branches.

If there is only one branch a warning is signaled.

This macro is useful when writing explicit decision trees; it will
warn you if you forget a branch.

Short for “exhaustive if”."
  (unless else?
    (warn "Missing else-branch in eif form:~%~a"
          whole))
  `(if ,test ,then ,else))


Instruction:
Generate a defmacro form that transforms code like this:
(finalize-dispatch-method nil nil)

Pattern to recognize: Macro call that should be transformed by FINALIZE-DISPATCH-METHOD

Input: (finalize-dispatch-method nil nil)

Output:
(defmacro finalize-dispatch-method (generic-function &rest args)
  "add a body to the method which dispatched the hooks for the given specialized-lambda-list
useful if you wanted to use call-next-method

For the definition to be effective, it must be defined after every specific hook for the same method hence finalize.

See defhook"
  (%destructure-defhook-args args
    (with-effective-qualifier generic-function qualifier
      (destructure-specialized-lambda-list descriptive-lambda-list vanilla-lambda-list type-list specialized-lambda-list
        `(%lay-method-base-for-dispatch ,generic-function ,qualifier ,type-list ,descriptive-lambda-list
           ,@body)))))


Instruction:
Generate a defmacro form that transforms code like this:
(fm-other? nil)

Pattern to recognize: Macro call that should be transformed by FM-OTHER?

Input: (fm-other? nil)

Output:
(defmacro fm-other? (md-name &optional (starting 'self) (global-search t))
    `(fm-find-one ,starting ,(if (consp md-name)
                                               `(list ',(car md-name) ,(cadr md-name))
                                               `',md-name)
          :must-find nil
          :global-search ,global-search))


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

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

Input: (assert! nil)

Output: (defmacro ASSERT! ...)


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

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

Input: (annotation nil nil)

Output: (defmacro ANNOTATION ...)


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

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

Input: (number-literal nil)

Output: (defmacro NUMBER-LITERAL ...)


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

Problem: Macro call that should be transformed by DEFSYNTAX

Input:
(defsyntax nil
  nil)

Output:
(defmacro defsyntax (name &body options)
  `(progn
     (setf (get ',name :options) ',options)
     (defvar ,name (defreadtable ,name ,@options))))


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

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

Input: (define-symbol-macro nil (progn))

Output: (defmacro DEFINE-SYMBOL-MACRO ...)


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

Problem: Macro call that should be transformed by PREPENDF

Input: (prependf nil)

Output: (defmacro PREPENDF ...)


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(jwhen 'lol-gen::some-name)

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

Input: (jwhen 'lol-gen::some-name)

Output:
(defmacro jwhen (test &body body)
  "JSON-aware version of `cl:when'.
If TEST is `jtruep' evaluate BODY."
  `(jif ,test
       (progn ,@body)))


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

Issue: Macro call that should be transformed by AND

Input: (and 'lol-gen::some-name)

Output: (defmacro AND ...)


Instruction:
Write a Common Lisp macro to handle this code pattern:
(boolean-when 'lol-gen::some-name)

Problem: Macro call that should be transformed by BOOLEAN-WHEN

Input: (boolean-when 'lol-gen::some-name)

Output:
(defmacro boolean-when (branch &body body &environment env)
  "Includes some forms based on whether a macroexpand-time branch is true. The
first argument must be a symbol naming a branch in the lexically enclosing
WITH-BOOLEAN form.
\
It is an error to use this macro outside the lexical environment established by
WITH-BOOLEAN."
  (cond (*boolean-bypass*
         `(when ,branch ,@body))
        ((not (member branch (macroexpand-1 '%all-branches% env)))
         (missing-branch branch))
        ((not (macroexpand-1 '%in-branching% env))
         (conditional-error 'when))
        ((not (member branch (macroexpand-1 '%true-branches% env)))
         `(progn))
        ((= 0 (length body))
         `(progn))
        ((= 1 (length body))
         (car body))
        (t `(progn ,@body))))


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

Issue: Macro call that should be transformed by C_IN

Input:
(c_in
  nil
  :key
  nil)

Output:
(defmacro c_in (&body body)
  `(c-input (:lazy :once-asked) (progn ,@body)))


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

Problem: Macro call that should be transformed by TRC

Input: (trc 'lol-gen::some-name)

Output:
(defmacro trc (tgt-form &rest os)
  (if (eql tgt-form 'nil)
      '(progn)
    (if (stringp tgt-form)
        `(without-c-dependency
          (call-trc t ,tgt-form ,@os))
      (let ((tgt (gensym)))
        ;(break "slowww? ~a" tgt-form)
        `(without-c-dependency
          (bif (,tgt ,tgt-form)
            (if (trcp ,tgt)
                (progn
                  (assert (stringp ,(car os)) () "trc with test expected string second, got ~a" ,(car os))
                  (call-trc t ,@os)) ;;,(car os) ,tgt ,@(cdr os)))
              (progn
                ;(trc "trcfailed")
                (count-it :trcfailed)))
            (count-it :tgtnileval)))))))


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

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

Input:
(op
  'lol-gen::some-name)

Output:
(defmacro op (&body body &environment env)
  "GOO's simple macro for positional lambdas.

An OP is like a lambda without an argument list. Within the body of the OP
form, an underscore introduces a new argument.

     (reduce (op (set-intersection _ _ :test #'equal))
             sets)

You can refer back to each argument by number, starting with _1.

     (funcall (op (+ _ _1)) 2) => 4

You can also use positional arguments directly:

     (reduce (op (funcall _2 _1)) ...)

Argument lists can be sparse:

     (apply (op (+ _1 _3 _5)) '(1 2 3 4 5)) => 9

Note that OP with a single argument is equivalent to CONSTANTLY:

     (funcall (op 1)) => 1

and that OP with a single placeholder is equivalent to IDENTITY:

     (funcall (op _) 1) => 1

OP can also be used to define variadic functions by using _* as the
placeholder. It is not necessary to use APPLY.

     (apply (op (+ _*)) '(1 2 3 4)) => 10

OP is intended for simple functions -- one-liners. Parameters are
extracted according to a depth-first walk of BODY. Macro expansion
may, or may not, be done depending on the implementation; it should
not be relied on. Lexical bindings may, or may not, shadow
placeholders -- again, it depends on the implementation. (This means,
among other things, that nested use of `op' is not a good idea.)
Because of the impossibility of a truly portable code walker, `op'
will never be a true replacement for `lambda'. But even if it were
possible to do better, `op' would still only be suited for one-liners.
If you need more than a one-liner, then you should be giving your
parameters names.

\(One thing you *can* count on is the ability to use `op' with
quasiquotes. If using placeholders inside quasiquotes does not work on
your Lisp implementation, that's a bug, not a limitation.)"
  (let ((env (extract-op-env body env)))
    (op-env-lambda env)))


Instruction:
Define a macro that eliminates this repetitive pattern:
(is-values nil :key nil)

Issue: Macro call that should be transformed by IS-VALUES

Input: (is-values nil :key nil)

Output:
(defmacro is-values (got expected &rest args)
  `(is (multiple-value-list ,got) ,expected ,@args))


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

Issue: Macro call that should be transformed by PSETQ

Input: (psetq)

Output: (defmacro PSETQ ...)


Instruction:
Define a macro that eliminates this repetitive pattern:
(with-simple-restart 'lol-gen::some-name)

Issue: Macro call that should be transformed by WITH-SIMPLE-RESTART

Input: (with-simple-restart 'lol-gen::some-name)

Output: (defmacro WITH-SIMPLE-RESTART ...)


Instruction:
Define a macro that eliminates this repetitive pattern:
(make-instance* 'lol-gen::some-name)

Issue: Macro call that should be transformed by MAKE-INSTANCE*

Input: (make-instance* 'lol-gen::some-name)

Output:
(defmacro make-instance* (class &rest arguments)
  "Convenience macro on top of `make-instance'.

Conveniences:

- First argument can be a (possibly empty) list of shortcut symbols,
  which is automatically converted into a KEYWORD+SYMBOL pairs where
  - KEYWORD is the same as shortcut name, but interned as keyword.
  - And SYMBOL is the same as shortcut.

- The last argument can be an apply argument---arbitrary
  list-producing form, which will be used as the last argument
  to (apply #'make-instance ...) idiom.

Note that using a singular shortcut list of apply argument is an
ambiguous case that will be interpreted in favor of apply argument. To
force either of interpretations, provide shortcuts and apply arguments
explicitly:
(make-instance* 'class (a b c)) ;; BAD
(make-instance* 'class (a b c) nil) ;; GOOD
(make-instance* 'class (when t nil)) ;; BAD
(make-instance* 'class () (when t nil)) ;; GOOD

Otherwise, the behavior is equivalent to `make-instance'.

Examples:

Shortcut args:
\(make-instance* 'class (a b c))
=>
\(make-instance 'class :a a :b b :c c)

Last form converted into `apply' argument:
\(make-instance* 'class :c c :b b (when something (list :a a)))
=>
\(apply #'make-instance 'class :c c :b b (when something (list :a a)))

Shortcut arguments, regular arguments, and form for `apply':
\(make-instance* 'class (b c) :x x (when something (list :a a)))
=>
\(apply #'make-instance 'class :b b :c c :x x (when something (list :a a)))

Form for `apply' (notice the empty shortcuts---these are required for
unambiguous parsing):
\(make-instance* 'class () (when something (list :a a)))
=>
\(apply #'make-instance 'class (when something (list :a a)))

Regular `make-instance'-like use:
\(make-instance* 'class :a a-value :b b-value)
=>
\(make-instance 'class :a a-value :b b-value)"
  (when (and (= 1 (length arguments))
             (listp (first arguments)))
    (style-warn "Body of MAKE-INSTANCE* contains a single list-like form ~a.

If you meant APPLY args, add empty shortcuts list:
(make-instance* 'class () (apply-form))

If you meant shortcut list, add empty APPLY args:
(make-instance* 'class (shortcuts) nil)

Interpreting as APPLY args for now, but this behavior may change in
the future." arguments))
  (let* ((shortcuts-p (and (listp (first arguments))
                           (> (length arguments) 1)))
         (shortcuts (when shortcuts-p
                      (first arguments)))
         (arguments (if shortcuts-p
                        (rest arguments)
                        arguments))
         (last-appendable-form-p (oddp (length arguments)))
         (last-appendable-form (when last-appendable-form-p
                                 (first (last arguments))))
         (arguments (if last-appendable-form-p
                        (butlast arguments)
                        arguments)))
    `(,@(if last-appendable-form-p
            `(apply #'make-instance)
            `(make-instance))
      ,class
      ,@(loop for shortcut in shortcuts
              append (list (intern (symbol-name shortcut) :keyword)
                           shortcut))
      ,@arguments
      ,@(when last-appendable-form-p
          (list last-appendable-form)))))