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

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

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

Output:
(defmacro iter (&body body &environment env)
  "Jonathan Amsterdam's powerful and extensible iteration facility,
providing multiple accumulation, generators, memory of previous
iterations, over 50 clauses to start with and a Lisp-like syntax.
Evaluate (iterate:display-iterate-clauses) for an overview of clauses"
  (let* ((*env* env)
	 (*result-var* (genvar 'result))
	 (*type-alist* nil)
	 (*declare-variables* *always-declare-variables*)
	 (*bindings* nil)
	 (*internal-variables* nil)
	 (*previous-vars-alist* nil)
	 (*declarations* nil)
	 (*loop-body-wrappers* nil)
	 (*accum-var-alist* nil)
	 (*shared-bindings-alist* nil)
	 (*top-level?* t)
	 (*binding-context?* nil)
	 (*temps* nil)
	 (*temps-in-use* nil)
	 (*driver-info-alist* nil)
	 (*loop-name* (if (symbolp (car body))
			  (car body)
			  (gensym "ITERATE")))
	 (*block-name* (if (symbolp (car body))
			   (pop body)
			   nil))
	 (*loop-top* (symbol-append 'loop-top- *block-name*))
	 (*loop-step* (symbol-append 'loop-step- *block-name*))
	 (*loop-end* (symbol-append 'loop-end- *block-name*))
	 (*loop-step-used?* nil)
	 (*loop-end-used?* nil))
    (process-top-level-decls body)
    (multiple-value-bind (body decls init-code steppers final-code final-prot)
	(walk-list body)
      (multiple-value-bind (init step)
	  (insert-previous-code)
	(augment init-code init)
	(augment steppers step))
      (prepend (default-driver-code) body)
      (let* ((it-bod `(block ,*loop-name*
			(tagbody
			  (progn ,.init-code)
			  ,*loop-top*
			  (progn ,.body)
			  ,.(if *loop-step-used?* (list *loop-step*))
			  (progn ,.steppers)
			  (go ,*loop-top*)
			  ,.(if *loop-end-used?* (list *loop-end*))
			  (progn ,.final-code))
			,(if (member *result-var* *bindings* :key #'car)
			   *result-var*
			   nil)))
	     (it-bod (if (eql *block-name* nil)
			 `(block nil ,it-bod)
			 it-bod)))
	(wrap-form *loop-body-wrappers*
		   `(let* ,(nreverse *bindings*)
		     ,.(if *declarations*
			   `((declare .,*declarations*)))
		     ,.decls
		     ,(if final-prot
			  `(unwind-protect ,it-bod .,final-prot)
			  it-bod)))))))


Instruction:
Define a macro that eliminates this repetitive pattern:
(lambda-ematch)

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

Input: (lambda-ematch)

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


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

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

Input:
(with-hook-restart
  nil
  (progn))

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


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

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

Input: (-<> nil)

Output: (defmacro -<> ...)


Instruction:
Generate a defmacro form that transforms code like this:
(def-suite* nil (progn))

Pattern to recognize: Macro call that should be transformed by DEF-SUITE*

Input: (def-suite* nil (progn))

Output:
(defmacro def-suite* (name &rest def-suite-args)
  `(progn
     (def-suite ,name ,@def-suite-args)
     (in-suite ,name)))


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

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

Input: (m nil)

Output: (defmacro M ...)


Instruction:
Define a macro that eliminates this repetitive pattern:
(define-fixture-restore nil
    nil)

Issue: Macro call that should be transformed by DEFINE-FIXTURE-RESTORE

Input:
(define-fixture-restore nil
    nil)

Output:
(defmacro define-fixture-restore (name args &body body)
  `(progn (setf (gethash ',name *fixture-restores*)
                (lambda ,args ,@body))
          ',name))


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

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

Input:
(c?n
  nil
  :key
  nil)

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


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

Problem: Macro call that should be transformed by WITH-CAPPED-STACK

Input:
(with-capped-stack nil
  :key
  nil)

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


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

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

Input:
(block-compile nil
  :key
  nil)

Output:
(defmacro block-compile ((&key entry-points
                               (block-compile t))
                         &body body)
  "Shorthand for block compilation with `local*'.

Only the functions in ENTRY-POINTS will have global definitions. All
other functions in BODY will be compiled as purely local functions,
and all of their calls to one another will be compiled as local calls.
This includes calls to the entry points, and even self-calls from
within the entry points.

Note that `declaim' forms occuring inside of BODY will be translated
into local `declare' forms.

If you pass `:block-compile nil', this macro is equivalent to progn.
This may be useful during development."
  (if (not block-compile) `(progn ,@body)
      `(local*
         ,@body
         (progn
           ,@(loop for entry-point in entry-points
                   collect `(defalias ,entry-point #',entry-point))))))


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

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

Input: (boolean-if nil nil)

Output:
(defmacro boolean-if (branch then &optional else &environment env)
  "Chooses between the forms to include 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*
         `(if ,branch ,then ,else))
        ((not (member branch (macroexpand-1 '%all-branches% env)))
         (missing-branch branch))
        ((not (macroexpand-1 '%in-branching% env))
         (conditional-error 'if))
        ((member branch (macroexpand-1 '%true-branches% env))
         then)
        (t (or else `(progn)))))


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

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

Input:
(with-collectors nil
  (progn))

Output: (defmacro WITH-COLLECTORS ...)


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

Issue: Macro call that should be transformed by PREPENDF

Input: (prependf nil :key nil)

Output: (defmacro PREPENDF ...)


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

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

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

Output: (defmacro *LET ...)


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

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

Input:
(with* nil
  (progn))

Output: (defmacro WITH* ...)


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

Issue: Macro call that should be transformed by COMMENT

Input: (comment)

Output:
(defmacro comment (&body body)
  "A macro that ignores its body and does nothing. Useful for
comments-by-example.

Also, as noted in EXTENSIONS.LISP of 1992, \"This may seem like a
silly macro, but used inside of other macros or code generation
facilities it is very useful - you can see comments in the (one-time)
macro expansion!\""
  (declare (ignore body)))


Instruction:
Define a macro that eliminates this repetitive pattern:
(best-value nil nil)

Issue: Macro call that should be transformed by BEST-VALUE

Input: (best-value nil nil)

Output: (defmacro BEST-VALUE ...)


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

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

Input:
(defalias nil
  nil)

Output:
(defmacro defalias (alias &body (def &optional docstring)
                    &environment env)
  "Define a value as a top-level function.

     (defalias string-gensym (compose #'gensym #'string))

Like (setf (fdefinition ALIAS) DEF), but with a place to put
documentation and some niceties to placate the compiler.

Note that a function defined with `defalias' is declared `notinline'.
This is a matter of semantics: before we can assign to the function,
we must make it assignable (which is what `notinline' means).

Name from Emacs Lisp."
  `(progn
     (declaim (notinline ,alias))
     ,(multiple-value-bind (env decls lambda)
          (let-over-lambda def env)
        ;; If we can expand DEF into a lambda (possibly with some
        ;; variable bindings around it) then splice that lambda in
        ;; directly as the body of the function. (This is the same
        ;; function we use to resolve lambdas in `fbind'.)
        (if lambda
            (ematch lambda
              ((list* (and _ (eql 'lambda)) args body)
               `(let ,env
                  (declare ,@decls)
                  (defun ,alias ,args
                    ,@(unsplice docstring)
                    ,@body))))
            (with-unique-names (temp)
              `(let ((,temp (ensure-function ,def)))
                 (declare (type function ,temp))
                 ;; Give the function a temporary definition at
                 ;; compile time so the compiler doesn't complain
                 ;; about its being undefined.
                 (defun ,alias (&rest args)
                   (apply ,temp args))
                 (setf (fdefinition ',alias) ,temp)
                 ,@(unsplice
                    (and docstring
                         `(setf (documentation ',alias 'function) ,docstring)))))))))


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(print-object/std nil)

Write a macro that addresses: Macro call that should be transformed by PRINT-OBJECT/STD

Input: (print-object/std nil)

Output:
(defmacro print-object/std (class)
  "Old name for DEFINE-PRINT-OBJECT/STD."
  `(define-print-object/std ,class))


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

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

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

Output:
(defmacro with-shuffling (&body body)
  (let ((thunk (gensym "THUNK")))
    `(dolist (,thunk (shuffle
                      (list ,@(loop for form in body
                                    collect `(lambda () ,form)))))
       (funcall ,thunk))))


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

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

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

Output: (defmacro OR ...)


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

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

Input: (continue-whopper 'lol-gen::some-name)

Output: (defmacro CONTINUE-WHOPPER ...)


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

Problem: Macro call that should be transformed by DEFVAR*

Input: (defvar* nil nil)

Output: (defmacro DEFVAR* ...)


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

Problem: Macro call that should be transformed by PSETQ

Input: (psetq nil (progn))

Output: (defmacro PSETQ ...)


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

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

Input: (destructuring-bind () (progn))

Output: (defmacro DESTRUCTURING-BIND ...)


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

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

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

Output: (defmacro AWHEN ...)


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

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

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

Output: (defmacro FTYPE ...)


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

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

Input: (without-c-dependency)

Output:
(defmacro without-c-dependency (&body body)
  ` (let (*depender*)
      ,@body))


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

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

Input: (collect-length nil)

Output: (defmacro COLLECT-LENGTH ...)


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

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

Input: (typecase nil)

Output: (defmacro TYPECASE ...)


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

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

Input: (local)

Output: (defmacro LOCAL ...)


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

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

Input:
(def-fixture nil
    (progn))

Output:
(defmacro def-fixture (name (&rest args) &body body)
  "Defines a fixture named NAME. A fixture is very much like a
macro but is used only for simple templating. A fixture created
with DEF-FIXTURE is a macro which can use the special macrolet
&BODY to specify where the body should go.

See Also: WITH-FIXTURE
"
  `(eval-when (:compile-toplevel :load-toplevel :execute)
     (setf (get-fixture ',name) (cons ',args ',body))
     ',name))


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

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

Input:
(batch
  nil
  :key
  nil)

Output:
(defmacro batch (&body forms)
  "Batch assignments to the values of mutable cells.

The forms in FORMS are evaluated, in an implicit PROGN, with mutable
cell assignment batching in effect. This means that when the value of
a mutable cell is set by SETF within the dynamic extent of the BATCH
form, the observers of the cell are only notified after the last form
in FORMS is evaluated, or the BATCH form is exited by a non-local exit
such as by RETURN-FROM. The effect of this is that the cells appear to
have their values changed simultaneously.

.. note::

   When a BATCH form is nested in the dynamic extent of another BATCH
   form, the nested BATCH form has no effect other than to evaluate
   FORMS. The observers of the cells are only notified when exiting
   the outermost BATCH form.

Returns the value of the last form in FORMS."

  `(if *batch-in-effect-p*
       (progn ,@forms)

       (let ((*batch-in-effect-p* t)
             (*batch-list* nil))

         (unwind-protect (progn ,@forms)
           (end-batch)))))


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

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

Input: (defconstructor nil)

Output:
(defmacro defconstructor (type-name &body slots
                          &environment env)
  "A variant of `defstruct' for modeling immutable data.

The structure defined by `defconstructor' has only one constructor,
which takes its arguments as required arguments (a BOA constructor).
Thus, `defconstructor' is only appropriate for data structures that
require no initialization.

The printed representation of an instance resembles its constructor:

    (person \"Common Lisp\" 33)
    => (PERSON \"Common Lisp\" 33)

While the constructor is BOA, the copier takes keyword arguments,
allowing you to override the values of a selection of the slots of the
structure being copied, while retaining the values of the others.

    (defconstructor person
      (name string)
      (age (integer 0 1000)))

    (defun birthday (person)
      (copy-person person :age (1+ (person-age person))))

    (birthday (person \"Common Lisp\" 33))
    => (PERSON \"Common Lisp\" 34)

Obviously the copier becomes more useful the more slots the type has.

When `*print-readably*' is true, the printed representation is
readable:

    (person \"Common Lisp\" 33)
    => #.(PERSON \"Common Lisp\" 33)

\(Why override how a structure is normally printed? Structure types
are not necessarily readable unless they have a default \(`make-X')
constructor. Since the type defined by `defconstructor' has only one
constructor, we have to take over to make sure it re-readable.)

Besides being re-readable, the type is also externalizable, with a
method for `make-load-form':

    (make-load-form (person \"Common Lisp\" 33))
    => (PERSON \"Common Lisp\" 33)

Users of Trivia get an extra benefit: defining a type with
`defconstructor' also defines a symmetrical pattern for destructuring
that type.

    (trivia:match (person \"Common Lisp\" 33)
      ((person name age)
       (list name age)))
    => (\"Common Lisp\" 33)

Note that the arguments to the pattern are optional:

    (trivia:match (person \"Common Lisp\" 33)
      ((person name) name))
    => \"Common Lisp\"

If you don't use Trivia, you can still do destructuring with
`deconstruct', which returns the slots of a constructor as multiple
values:

    (deconstruct (person \"Common Lisp\" 33))
    => \"Common Lisp\", 33

Note also that no predicate is defined for the type, so to test for
the type you must either use `typep' or pattern matching as above.

While it is possible to inherit from a type defined with
`defconstructor' (this is Lisp, I can't stop you), it's a bad idea. In
particular, on Lisps which support it, a type defined with
`defconstructor' is declared to be frozen (sealed), so your new
subtype may not be recognized in type tests that have already been
compiled.

Because `defconstructor' is implemented on top of
`defstruct-read-only', it shares the limitations of
`defstruct-read-only'. In particular it cannot use inheritance.

The design of `defconstructor' is mostly inspired by Scala's [case
classes](https://docs.scala-lang.org/tour/case-classes.html), with
some implementation tricks from `cl-algebraic-data-type'."
  (let* ((super (env-super env))
         (docstring
           (and (stringp (first slots))
                (pop slots)))
         (slots
           (loop for slot in slots
                 collect (match slot
                           ((list (and slot-name (type symbol))
                                  type)
                            (list slot-name type))
                           (otherwise
                            (error "Constructor slots must have both ~
                            a name and a type.~%Constructor: ~a"
                                   type-name)))))
         (constructor type-name)
         (slot-names (mapcar #'first slots))
         (readers
           (mapcar (curry #'symbolicate type-name '-)
                   slot-names))
         (copier-name (symbolicate 'copy- type-name)))
    `(progn
       ;; Make sure the constructor is inlined. This is necessary on
       ;; SBCL to allow instances to be stack-allocated.
       (declaim (inline ,constructor))

       ;; Actually define the type.
       (defstruct-read-only
           (,type-name
            ,@(unsplice (and super `(:include ,super)))
            (:constructor ,constructor ,slot-names)
            (:predicate nil)
            (:print-function
             (lambda (object stream depth)
               (declare (ignore depth))
               ,(if (null readers)
                    `(print-constructor object stream nil)
                    (with-unique-names (fields)
                      `(let ((,fields
                               (list
                                ,@(loop for reader in readers
                                        collect `(,reader object)))))
                         (declare (dynamic-extent ,fields))
                         (print-constructor object stream ,fields)))))))
         ,@(unsplice docstring)
         ,@(loop for (slot-name slot-type) in slots
                 collect `(,slot-name :type ,slot-type)))

       ;; Freeze the type when possible.
       (declaim-freeze-type ,type-name)

       ;; Define the copier.
       (declaim (inline ,copier-name))
       ;; The gensym is needed in case one of the slots has the same
       ;; name as the type itself.
       ,(let ((orig (gensym (string type-name))))
          `(defun ,copier-name
               (,orig &key
                        ,@(loop for (slot-name nil) in slots
                                for reader in readers
                                collect `(,slot-name (,reader ,orig))))
             ,(format nil "Copy an instance of ~:@(~a~), optionally ~
overriding some or all of its slots." type-name)
             (declare (ignorable ,orig))
             ;; A copier without slots should be identity.
             ,(if (null readers)
                  orig
                  `(,type-name ,@slot-names))))

       ;; Define a load form.
       (defmethod make-load-form ((self ,type-name) &optional env)
         (declare (ignorable self env))
         (list ',type-name
               ,@(loop for reader in readers
                       collect `(quote-unless-constant (,reader self)
                                                       env))))

       ;; Define a comparison method.
       (defmethod %constructor= ((o1 ,type-name) (o2 ,type-name))
         ,(if readers
              `(and ,@(loop for reader in readers
                            collect `(constructor= (,reader o1)
                                                   (,reader o2))))
              t))

       ;; Define a destructor.
       (defmethod constructor-values/generic ((x ,type-name))
         (values ,@(loop for reader in readers
                         collect `(,reader x))))

       ;; Define a pattern to match.
       (defpattern ,type-name
           ,(if slot-names
                `(&optional ,@slot-names)
                ())
         (list
          'and
          (list 'type ',type-name)
          ,@(loop for reader in readers
                  for name in slot-names
                  collect `(list 'trivia:access '',reader ,name))))
       ',type-name)))


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

Problem: Macro call that should be transformed by AAND

Input: (aand nil 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:
(c?dbg
  nil)

Issue: Macro call that should be transformed by C?DBG

Input:
(c?dbg
  nil)

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


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

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

Input: (next-in nil)

Output: (defmacro NEXT-IN ...)


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

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

Input:
(fbind* nil
  :key
  nil)

Output:
(defmacro fbind* (bindings &body body &environment env)
  "Like `fbind', but creates bindings sequentially."
  (setf bindings (expand-fbindings bindings))
  (unless bindings
    (return-from fbind* `(locally ,@body)))
  (mvlet* ((fn (caar bindings))
           (body decls (parse-body body))
           (local others (partition-declarations `((function ,fn))
                                                 decls
                                                 env)))
    `(fbind (,(first bindings))
       ,@local
       (fbind* ,(rest bindings)
         ,@others
         ,@body))))


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

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

Input: (defgeneric nil :key nil)

Output: (defmacro DEFGENERIC ...)


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:
You are a Common Lisp macro expert. Given this code pattern:
(c-input nil nil)

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

Input: (c-input nil nil)

Output:
(defmacro c-input ((&rest keys) &optional (value nil valued-p))
  `(make-cell
    :inputp t
    :value-state ,(if valued-p :valid :unbound)
    :value ,value
    ,@keys))


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

Problem: Macro call that should be transformed by POSSIBLY?

Input:
(possibly?
  nil)

Output: (defmacro POSSIBLY? ...)


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

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

Input:
(lret nil
  :key
  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:
(collect-and 'lol-gen::some-name)

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

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

Output: (defmacro COLLECT-AND ...)


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

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

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

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


Instruction:
Write a Common Lisp macro to handle this code pattern:
(maybe-once-only nil
  :key
  nil)

Problem: Macro call that should be transformed by MAYBE-ONCE-ONLY

Input:
(maybe-once-only nil
  :key
  nil)

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


Instruction:
Define a macro that eliminates this repetitive pattern:
(ignore-errors nil nil)

Issue: Macro call that should be transformed by IGNORE-ERRORS

Input: (ignore-errors nil nil)

Output: (defmacro IGNORE-ERRORS ...)


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

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

Input: (js-inline nil)

Output: (defmacro JS-INLINE ...)


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

What needs to change: Macro call that should be transformed by DEF-SUITE*

Input: (def-suite* nil :key nil)

Output:
(defmacro def-suite* (name &rest def-suite-args)
  `(progn
     (def-suite ,name ,@def-suite-args)
     (in-suite ,name)))


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

Problem: Macro call that should be transformed by DEFCLAUSE-SEQUENCE

Input: (defclause-sequence nil nil)

Output: (defmacro DEFCLAUSE-SEQUENCE ...)


Instruction:
Define a macro that eliminates this repetitive pattern:
(without-symbol-access
  nil)

Issue: Macro call that should be transformed by WITHOUT-SYMBOL-ACCESS

Input:
(without-symbol-access
  nil)

Output: (defmacro WITHOUT-SYMBOL-ACCESS ...)


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

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

Input:
(char-ecase nil
  nil)

Output:
(defmacro char-ecase (keyform &body clauses)
  "Like `ecase', but specifically for characters.
Expands into `tree-case'."
  `(char-ecase-1 ,keyform
     ,@(expand-char-case-keys clauses)))


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

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

Input:
(sccase nil
  :key
  nil)

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


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

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

Input: (as->* nil)

Output: (defmacro AS->* ...)


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

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

Input: (with-savepoint 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:
Define a macro that eliminates this repetitive pattern:
(lambda-bind 'lol-gen::some-name)

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

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

Output:
(defmacro lambda-bind ((&rest instrs) &body body)
  "Use `bind' to allow restructuring of argument to lambda expressions.

This lets you funcall and destructure simultaneously. For example

    (let ((fn (lambda-bind ((a b) c) (cons a c))))
      (funcall fn '(1 2) 3))
    ;; => (1 . 3)

Via eschulte (see git://gist.github.com/902174.git).
"
  #+(or)
  (declare (indent 1))
  (let* ((evald-instrs instrs)
         (syms (mapcar (lambda (_)
			 (declare (ignore _))
			 (gensym))
		       evald-instrs)))
    `(lambda ,syms (bind ,(mapcar #'list evald-instrs syms) ,@body))))


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

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

Input:
(->>
  nil
  :key
  nil)

Output: (defmacro ->> ...)


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

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

Input: (letrec nil)

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

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


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

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

Input: (some-<>> nil)

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


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

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

Input: (define-hook-type nil :key nil)

Output:
(defmacro define-hook-type (name type &optional documentation)
  "Define hook class.
Type must be something like:

  (function (string) (values integer t))

The `handler-type' of the defined hook class has `:class' allocation
type, so that all hooks of such class have the same `handler-type'."
  (let* ((name (string name))
         (hook-class-name (intern (serapeum:concat "HOOK-" name))))
    `(defclass ,hook-class-name (hook)
       ((handler-type :initform ',type :allocation :class))
       (:metaclass closer-mop:funcallable-standard-class)
       ,@(when documentation
           `((:documentation ,documentation))))))


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(with-active-layers nil)

Write a macro that addresses: Macro call that should be transformed by WITH-ACTIVE-LAYERS

Input: (with-active-layers nil)

Output: (defmacro WITH-ACTIVE-LAYERS ...)


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

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

Input: (<* nil :key nil)

Output:
(defmacro <* (parser &rest parsers)
  "Combination of parsers yielding the result of the leftmost one."
  (let ((offset (gensym "<*-OFFSET")))
    `(lambda (,offset)
       ,(reduce (lambda (i p)
                  (let ((res0 (gensym "<*-RES"))
                        (next (gensym "<*-NEXT")))
                    `(multiple-value-bind (,res0 ,next) ,i
                       (if (ok? ,res0)
                           (multiple-value-bind (res next) (funcall ,p ,next)
                             (if (ok? res)
                                 (values ,res0 next)
                                 (fail next)))
                           (fail ,next)))))
                parsers
                :initial-value `(funcall ,parser ,offset)))))


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

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

Input: (is-values 'lol-gen::some-name)

Output:
(defmacro is-values (form &body body)
  (multiple-value-bind (comp-expected expected comparison description format-args)
      (destructure-is-values-body body)
    `(eval-in-context
      *context*
      (make-instance 'multiple-value-comparison-result
                     :expression '(is-values ,form ,@comp-expected)
                     :value-form ',form
                     :body (lambda () ,form)
                     :expected (list ,@expected)
                     :comparison (list ,@comparison)
                     ,@(when description
                         `(:description (format NIL ,description ,@format-args)))))))


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

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

Input: (best-value nil :key nil)

Output: (defmacro BEST-VALUE ...)


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

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

Input: (enable-interpol-syntax 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:
Generate a defmacro form that transforms code like this:
(lambda-cmatch1 common-lisp:nil)

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

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

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


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

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

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

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:
Define a macro that eliminates this repetitive pattern:
(do-instance-combinations 'lol-gen::some-name)

Issue: Macro call that should be transformed by DO-INSTANCE-COMBINATIONS

Input: (do-instance-combinations 'lol-gen::some-name)

Output: (defmacro DO-INSTANCE-COMBINATIONS ...)


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

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

Input: (returning nil (progn))

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:
Write a Common Lisp macro to handle this code pattern:
(destructuring-case-of nil
    nil)

Problem: Macro call that should be transformed by DESTRUCTURING-CASE-OF

Input:
(destructuring-case-of nil
    nil)

Output:
(defmacro destructuring-case-of (type expr &body body)
  "Like `destructuring-ecase-of', but an `otherwise' clause must also be supplied.

Note that the otherwise clauses must also be a list:

    ((otherwise &rest args) ...)"
  (expand-destructuring-case-of type expr body 'case-of))


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

Problem: Macro call that should be transformed by FLUID-BIND

Input: (fluid-bind nil)

Output:
(defmacro fluid-bind ((&rest bindings) &body body)
  "Fluid-bind is an extension of bind that handles setting and resetting places. For example, suppose that an object of class foo has a slot named bar whose value is currently 3. The following code would evaluate the inner body with bar bound to 17 and restore it when the inner body is exited.

\(fluid-bind \(\(\(bar foo\) 17\)\)
  \(print \(bar foo\)\)\)
\(print \(bar foo\)\)
==> \(prints 17, then 3\)

This is similar to dynamic-binding but _much_ less robust."
  ;; does not handle declarations correctly
  (let ((setup-forms nil)
        (cleanup-forms nil)
        (gensyms nil))
    (loop for binding in bindings collect
          (destructuring-bind
		(setup-form cleanup-form)
	      (cond ((consp binding)
		     (destructuring-bind (var value) binding
		       (let ((g (gensym)))
			 (push g gensyms)
			 (cond ((atom var)
				`((:bind (,var ,value)) nil)
				#+(or)
				;; lexical or special?
				(if (boundp var)
				    `((:bind (,var ,value)) nil)
				    `((:setf (setf ,g ,var ,var ,value))
				      (setf ,var ,g))))
			       ((and (fboundp (first var))
				     (not (eq (first var) 'values)))
				;; putative place
				`((:setf (setf ,g ,var ,var ,value))
				  (setf ,var ,g)))
			       (t
				`((:bind (,var ,value)) nil))))))
		    (t
		     `((:bind (,binding nil)) nil)))
            (push setup-form setup-forms)
            (push cleanup-form cleanup-forms)))
    (let ((result body))
      (mapc (lambda (setup cleanup)
              (setf result
                    (ecase (first setup)
                      (:setf `((unwind-protect
                                 (progn
                                   ,(second setup)
                                   ,@result)
                                 ,cleanup)))
                      (:bind `((bind (,(second setup))
                                 ,@result)))))
              result)
            setup-forms cleanup-forms)
      `(let ,gensyms
         (declare (ignorable ,@gensyms))
         ,@result))))


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(with-walker-handler-lexical-environment
  nil
  nil)

What needs to change: Macro call that should be transformed by WITH-WALKER-HANDLER-LEXICAL-ENVIRONMENT

Input:
(with-walker-handler-lexical-environment
  nil
  nil)

Output: (defmacro WITH-WALKER-HANDLER-LEXICAL-ENVIRONMENT ...)


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

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

Input:
(cmatch* common-lisp:nil
  (common-lisp:progn))

Output:
(defmacro cmatch* (whats &body clauses)
  #.+match*-doc+
  (let ((temps (make-gensyms whats "OTHERWISE")))
    `(match2* ,whats
       ,@clauses
       (,temps
        (cerror "continue" 'match-error :pattern ',clauses :values (list ,@temps))))))


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

Problem: Macro call that should be transformed by DESTRUCTURING-CASE-OF

Input:
(destructuring-case-of nil
    (progn))

Output:
(defmacro destructuring-case-of (type expr &body body)
  "Like `destructuring-ecase-of', but an `otherwise' clause must also be supplied.

Note that the otherwise clauses must also be a list:

    ((otherwise &rest args) ...)"
  (expand-destructuring-case-of type expr body 'case-of))


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

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

Input: (with-integrity nil (progn))

Output:
(defmacro with-integrity ((&optional opcode defer-info debug) &rest body)
  (declare (ignorable debug))
  (when opcode
    (assert (find opcode *ufb-opcodes*) ()
      "Invalid opcode for with-integrity: ~a. Allowed values: ~a" opcode *ufb-opcodes*))
  `(call-with-integrity ,opcode ,defer-info
     (lambda (opcode defer-info)
       (declare (ignorable opcode defer-info))
       ;;;       ,(when debug
       ;;;          `(trc "integrity action entry" opcode defer-info ',body))
       ;;;       (when *c-debug*
       ;;;         (when (eq opcode :change)
       ;;;           (trc "-------w/integ :change go--------------->:" defer-info)))
       ,@body)
     nil
     #+noway (when *c-debug* ',body)))


Instruction:
Define a macro that eliminates this repetitive pattern:
(local-output)

Issue: Macro call that should be transformed by LOCAL-OUTPUT

Input: (local-output)

Output: (defmacro LOCAL-OUTPUT ...)


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

Problem: Macro call that should be transformed by DELETE-FROM

Input:
(delete-from nil
  (progn))

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


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

Write a macro that addresses: Macro call that should be transformed by WITH-SPECIAL-INITARGS

Input: (with-special-initargs 'lol-gen::some-name)

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


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

Issue: Macro call that should be transformed by WITH-COMPILATION-UNIT

Input: (with-compilation-unit nil nil)

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


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

Problem: Macro call that should be transformed by WHERE

Input: (where nil)

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


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

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

Input: (and-bind nil)

Output: (defmacro AND-BIND ...)


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

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

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

Output: (defmacro COND-> ...)


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

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

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

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


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

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

Input: (drop-view 'lol-gen::some-name)

Output:
(defmacro drop-view (view-name)
  `(make-statement :drop-view ,view-name))


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

Problem: Macro call that should be transformed by COERCEF

Input: (coercef nil nil)

Output: (defmacro COERCEF ...)


Instruction:
Generate a defmacro form that transforms code like this:
(tree-ecase nil
  nil)

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

Input:
(tree-ecase nil
  nil)

Output: (defmacro TREE-ECASE ...)


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

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

Input:
(char-case nil
  (progn))

Output:
(defmacro char-case (keyform &body clauses)
  "Like `case', but specifically for characters.
Expands into `tree-case'.

As an extension to the generalized `case' syntax, the keys of a clause
can be specified as a literal string.

    (defun vowel? (c)
      (char-case c
        (\"aeiouy\" t)))

Signals an error if KEYFORM does not evaluate to a character."
  `(char-case-1 ,keyform
     ,@(expand-char-case-keys clauses)))


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

Problem: Macro call that should be transformed by C-ABS

Input:
(c-abs nil
  :key
  nil)

Output:
(defmacro c-abs (value &body body)
  `(make-c-drifter-absolute
    :code ',body
    :value-state :valid
    :value ,value
    :rule (c-lambda ,@body)))


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

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

Input:
(nlet nil
    (progn))

Output: (defmacro NLET ...)


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

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

Input: (some->>)

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


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

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

Input:
(define-declaration nil
    :key
  nil)

Output: (defmacro DEFINE-DECLARATION ...)


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

Issue: Macro call that should be transformed by OP

Input:
(op
  nil)

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:
Create a Common Lisp macro for the following transformation. Before code:
(unless nil :key nil)

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

Input: (unless nil :key nil)

Output: (defmacro UNLESS ...)


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

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

Input: (builder nil (progn))

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:
Define a macro that eliminates this repetitive pattern:
(check-type nil :key nil)

Issue: Macro call that should be transformed by CHECK-TYPE

Input: (check-type nil :key nil)

Output: (defmacro CHECK-TYPE ...)


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

Issue: Macro call that should be transformed by DLETF

Input:
(dletf nil
  (progn))

Output: (defmacro DLETF ...)


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

Issue: Macro call that should be transformed by ASSUREF

Input: (assuref nil nil)

Output:
(defmacro assuref (place type-spec)
  "Like `(progn (check-type PLACE TYPE-SPEC) PLACE)`, but evaluates
PLACE only once."
  (with-gensyms (temp)
    (let ((ts type-spec))
      `(the ,ts
            (values
             (let ((,temp ,place))
               (if (typep ,temp ',ts)
                   ,temp
                   (setf ,place (require-type-for ,temp ',ts ',place)))))))))


Instruction:
Generate a defmacro form that transforms code like this:
(enable-quasi-quoted-string-to-string-emitting-form-syntax nil)

Pattern to recognize: Macro call that should be transformed by ENABLE-QUASI-QUOTED-STRING-TO-STRING-EMITTING-FORM-SYNTAX

Input: (enable-quasi-quoted-string-to-string-emitting-form-syntax nil)

Output: (defmacro ENABLE-QUASI-QUOTED-STRING-TO-STRING-EMITTING-FORM-SYNTAX ...)


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

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

Input:
(with-access-values nil
    :key
  nil)

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

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


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(with-unique-js-names nil)

What needs to change: Macro call that should be transformed by WITH-UNIQUE-JS-NAMES

Input: (with-unique-js-names nil)

Output: (defmacro WITH-UNIQUE-JS-NAMES ...)


Instruction:
Define a macro that eliminates this repetitive pattern:
;; Threading a value through multiple dependent checks
(let ((user (find-user id)))
  (if user
      (let ((orders (get-orders user)))
        (if orders
            (let ((latest (first orders)))
              (if latest
                  (process latest)
                  :no-orders))
            :no-orders))
      :no-user))
;; Deeply nested ifs obscure the linear flow

Issue: Threading a value through dependent operations creates deep if-nesting — want linear, pipeline-like syntax

Input:
;; Threading a value through multiple dependent checks
(let ((user (find-user id)))
  (if user
      (let ((orders (get-orders user)))
        (if orders
            (let ((latest (first orders)))
              (if latest
                  (process latest)
                  :no-orders))
            :no-orders))
      :no-user))
;; Deeply nested ifs obscure the linear flow

Output:
(defmacro aand (&rest args)
  (cond ((null args) t)
        ((null (cdr args)) (car args))
        (t `(aif ,(car args) (aand ,@(cdr args))))))


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

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

Input:
(with-keys nil
    (progn))

Output:
(defmacro with-keys ((&rest kv-pairs) ht &body body)
  "Like WITH-ACCESSORS but for pairs in hash-table HT."
  (once-only (ht)
    `(let (,@(mapcar #`(list (car %) `(gethash ,(second %) ,ht))
                     kv-pairs))
       ,@body)))


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

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

Input:
(with-string-dispatch nil
    (progn))

Output:
(defmacro with-string-dispatch ((&rest types) var &body body)
  "Like `with-subtype-dispatch' with an overall type of `string'."
  `(with-subtype-dispatch string
       ;; Always specialize for (simple-array character (*)).
       ((simple-array character (*))
        (simple-array base-char (*))
        ,@types)
       ,var
     ,@body))


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

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

Input: (maybe-once-only 'lol-gen::some-name)

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


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

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

Input: (n^ 'lol-gen::some-name)

Output:
(defmacro n^ (type)
  `(nearest self ,type))


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

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

Input:
(defgenerator nil
    (progn))

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


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

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

Input: (econd)

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:
Define a macro that eliminates this repetitive pattern:
(aif nil nil)

Issue: Macro call that should be transformed by AIF

Input: (aif nil nil)

Output: (defmacro AIF ...)


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

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

Input:
(with-collectors nil
  nil)

Output: (defmacro WITH-COLLECTORS ...)


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

Issue: Macro call that should be transformed by BCOND

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

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:
You are a Common Lisp macro expert. Given this code pattern:
(brkx 'lol-gen::some-name)

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

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

Output:
(defmacro brkx (msg)
  `(break "At ~a: OK?" ',msg))


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

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

Input:
(when-failing nil
  :key
  nil)

Output: (defmacro WHEN-FAILING ...)


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

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

Input:
(defpattern-inline common-lisp:nil
    (common-lisp:progn))

Output:
(defmacro defpattern-inline (name args &body body)
  "Adds a new inlined derived pattern. These patterns are evaluated from the innermost ones.
The default value of &optional arguments are '_, instead of nil."
  `(eval-when (:compile-toplevel :load-toplevel :execute)
     (setf (symbol-inline-pattern ',name)
           #+sbcl
           (sb-int:named-lambda ',name ,(process-lambda-args args) ,@body)
           #-sbcl
           (lambda ,(process-lambda-args args) ,@body))
     ,@(when (stringp (first body))
         ;; lisp-namespace
         `((setf (documentation ',name 'inline-pattern)
                 ,(let ((*print-pretty* t))
                    #-clisp
                    (format nil "~<Lambda-List: ~s~
                                 ~:@_~<  ~@;~a~:>~
                                 ~:@_Defined in ~a~
                               ~:>"
                            (list args (list (first body)) *compile-file-pathname*))
                    #+clisp
                    (format nil "Lambda-List: ~s~%~a"
                            args (first body))))))))


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

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

Input:
(once-only nil
  (progn))

Output:
(defmacro once-only (specs &body forms)
  "Evaluate FORMS with names rebound to temporary variables, ensuring
   that each is evaluated only once.

   Each SPEC must be either a NAME, or a (NAME INITFORM), with plain
   NAME using the named variable as initform.

   Example:

       CL-USER> (defmacro cons1 (x)
                  (once-only (x)
                    `(cons ,x ,x)))
       CL-USER> (let ((y 0))
                  (cons1 (incf y)))
       (1 . 1)
"
  (let ((gensyms (make-gensym-list (length specs) "OO"))
        (names-and-forms (mapcar (lambda (spec)
                                   (etypecase spec
                                     (list
                                      (destructuring-bind (name form) spec
                                        (cons name form)))
                                     (symbol
                                      (cons spec spec))))
                                 (remove-if-not #`(or (symbolp %) (listp %))
                                                specs))))
    ;; bind in user-macro
    `(let ,(mapcar #`(list % `(gensym ,(string (car %%))))
                   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 #`(list (car %) %%)
                         names-and-forms gensyms)
             ,@forms)))))


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

Problem: Macro call that should be transformed by DLET*

Input:
(dlet* nil
  (progn))

Output: (defmacro DLET* ...)


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

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

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

Output: (defmacro WITH-UNBUILDER ...)


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

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

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

Output:
(defmacro fbind* (bindings &body body &environment env)
  "Like `fbind', but creates bindings sequentially."
  (setf bindings (expand-fbindings bindings))
  (unless bindings
    (return-from fbind* `(locally ,@body)))
  (mvlet* ((fn (caar bindings))
           (body decls (parse-body body))
           (local others (partition-declarations `((function ,fn))
                                                 decls
                                                 env)))
    `(fbind (,(first bindings))
       ,@local
       (fbind* ,(rest bindings)
         ,@others
         ,@body))))


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

Problem: Macro call that should be transformed by DO

Input: (do () (progn))

Output: (defmacro DO ...)


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(multiple-value-list nil)

Write a macro that addresses: Macro call that should be transformed by MULTIPLE-VALUE-LIST

Input: (multiple-value-list nil)

Output: (defmacro MULTIPLE-VALUE-LIST ...)


Instruction:
Generate a defmacro form that transforms code like this:
(export-accessors)

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

Input: (export-accessors)

Output: (defmacro EXPORT-ACCESSORS ...)


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

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

Input:
(define-parse-method nil
    nil)

Output:
(defmacro define-parse-method (name lambda-list &body body)
  "Define a type parser on NAME and lists whose CAR is NAME."
  (discard-docstring body)
  (warn-if-kw-or-belongs-to-cl name)
  `(eval-when (:compile-toplevel :load-toplevel :execute)
     (setf (find-type-parser ',name)
           (lambda ,lambda-list ,@body))
     ',name))


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

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

Input: (make-name-transformer 'lol-gen::some-name)

Output:
(defmacro make-name-transformer (&rest elements)
  "Return an accessor name transformer.
The unquoted `name' symbol argument is substituted for the slot name.
Class option examples:

  :accessor-name-transformer (make-name-transformer \"FOO-\" name \"-BAR\")

Use the slot name directly:

  :accessor-name-transformer (make-name-transformer name)"
  `(lambda (name definition)
    (declare (ignorable definition))
    (concatenate-symbol ,@(mapcar (lambda (el)
                                    (if (and (symbolp el)
                                             (string= (symbol-name el) "NAME"))
                                        'name
                                        el))
                                  elements))))


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

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

Input: (setf nil (progn))

Output: (defmacro SETF ...)


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

Issue: Macro call that should be transformed by LOOP

Input: (loop)

Output: (defmacro LOOP ...)


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

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

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

Output: (defmacro MATCH ...)


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

Problem: Macro call that should be transformed by LAMBDA-MATCH*

Input:
(lambda-match*
  common-lisp:nil
  common-lisp:nil)

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


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

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

Input: (custom-decoder 'lol-gen::some-name)

Output:
(defmacro custom-decoder (&rest customizations)
  "Return a function which is like DECODE-JSON called in a dynamic
environment with the given CUSTOMIZATIONS."
  `(lambda (&optional (stream *json-input*))
     (bind-custom-vars ,customizations
       (decode-json stream))))


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

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

Input: (case nil)

Output: (defmacro CASE ...)


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

Problem: Macro call that should be transformed by AAND

Input: (aand nil :key nil)

Output: (defmacro AAND ...)


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(fm-other? nil :key nil)

What needs to change: Macro call that should be transformed by FM-OTHER?

Input: (fm-other? nil :key 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:
Generate a defmacro form that transforms code like this:
(case nil)

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

Input: (case nil)

Output: (defmacro CASE ...)


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

Problem: Macro call that should be transformed by DECF

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

Output: (defmacro DECF ...)


Instruction:
Define a macro that eliminates this repetitive pattern:
(alter-table nil
  nil)

Issue: Macro call that should be transformed by ALTER-TABLE

Input:
(alter-table nil
  nil)

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


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

What needs to change: Macro call that should be transformed by WITH-ACTIVE-LAYERS*

Input:
(with-active-layers* nil
  :key
  nil)

Output: (defmacro WITH-ACTIVE-LAYERS* ...)


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

Issue: Macro call that should be transformed by C??

Input:
(c?? nil
  :key
  nil)

Output:
(defmacro c?? ((&key (tagp nil) (in nil) (out t))&body body)
  (let ((result (copy-symbol 'result))
        (thetag (gensym)))
     `(make-c-dependent
       :code ',body
       :value-state :unevaluated
       :rule (c-lambda
              (let ((,thetag (gensym "tag"))
                    (*trcdepth* (1+ *trcdepth*))
                    )
                (declare (ignorable self ,thetag))
                ,(when in
                   `(trc "c??> entry" (c-slot-name c) (c-model c) (when ,tagp ,thetag)))
                (count-it :c?? (c-slot-name c) (md-name (c-model c)))
                (let ((,result (progn ,@body)))
                  ,(when out `(trc "c?? result:" ,result (c-slot-name c) (when ,tagp ,thetag)))
                  ,result))))))


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

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

Input:
(with-accessors nil
    :key
  nil)

Output: (defmacro WITH-ACCESSORS ...)


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

Issue: Macro call that should be transformed by WITH

Input:
(with nil
  (progn))

Output: (defmacro WITH ...)


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

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

Input:
(special common-lisp:nil
  :key
  common-lisp:nil)

Output: (defmacro SPECIAL ...)


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

Issue: Macro call that should be transformed by OPTIONAL

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

Output: (defmacro OPTIONAL ...)


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

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

Input: (html)

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


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

Issue: Macro call that should be transformed by FDEC

Input: (fdec nil (progn))

Output:
(defmacro fdec (place &optional (delta 1))
  "DEPRECATED: use `shift-decf' instead."
  (simple-style-warning "~s is deprecated, use ~s instead"
                        'finc 'shift-incf)
  `(shift-decf ,place ,delta))


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

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

Input: (and-it nil :key nil)

Output:
(defmacro and-it (&rest args)
  "Like AND. IT is bound to the value of the previous AND form."
  (cond ((null args) t)
        ((null (cdr args)) (car args))
        (t `(when-it ,(car args) (and-it ,@(cdr args))))))


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

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

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

Output: (defmacro ITERATE ...)


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

Issue: Macro call that should be transformed by CALLF

Input: (callf nil (progn))

Output:
(defmacro callf (function place &rest args &environment env)
  "Set PLACE to the value of calling FUNCTION on PLACE, with ARGS."
  (multiple-value-bind (vars vals stores setter getter)
      (get-setf-expansion place env)
    `(let* ,(mapcar #'list vars vals)
       (multiple-value-bind ,stores
           (funcall ,function ,getter ,@args)
         ,setter))))


Instruction:
Write a Common Lisp macro to handle this code pattern:
(lambda-match*
  common-lisp:nil
  (common-lisp:progn))

Problem: Macro call that should be transformed by LAMBDA-MATCH*

Input:
(lambda-match*
  common-lisp:nil
  (common-lisp:progn))

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


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

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

Input:
(with-symbol-access
  nil
  nil)

Output: (defmacro WITH-SYMBOL-ACCESS ...)


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

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

Input: (*> nil)

Output:
(defmacro *> (parser &rest parsers)
  "Combination of parsers yielding the result of the rightmost one."
  (let ((offset (gensym "*>-OFFSET")))
    `(lambda (,offset)
       ,(reduce (lambda (i p)
                  (let ((res  (gensym "*>-RES"))
                        (next (gensym "*>-NEXT")))
                    `(multiple-value-bind (,res ,next) ,i
                       (if (ok? ,res)
                           (funcall ,p ,next)
                           (fail ,next)))))
                parsers
                :initial-value `(funcall ,parser ,offset)))))


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

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

Input: (fail nil (progn))

Output:
(defmacro fail (form &optional (type 'error) description &rest format-args)
  `(eval-in-context
    *context*
    (make-instance 'comparison-result
                   :expression '(fail ,form ,type)
                   :value-form '(capture-error ,form)
                   :body (lambda () (capture-error ,form ,(maybe-unquote 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:
(is-true nil)

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

Input: (is-true nil)

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


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(auto-permute-typecase nil
  (progn))

Write a macro that addresses: Macro call that should be transformed by AUTO-PERMUTE-TYPECASE

Input:
(auto-permute-typecase nil
  (progn))

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


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

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

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

Output: (defmacro WITH-GENERATOR ...)


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

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

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

Output:
(defmacro subtest (desc &body body)
  `(%subtest ,desc (lambda () ,@body)))


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(enable-static-dispatch)

Write a macro that addresses: Macro call that should be transformed by ENABLE-STATIC-DISPATCH

Input: (enable-static-dispatch)

Output:
(defmacro enable-static-dispatch (&rest names)
  (simple-style-warning "ENABLE-STATIC-DISPATCH is deprecated. Use STATIC-DISPATCH-TYPE declaration instead.")

  `(progn
     ,@(iter (for name in names)
             (match name
               ((list :inline name)
                (collect `(declaim (static-dispatch-type inline ,name))))

               ((list :function name)
                (collect `(declaim (static-dispatch-type function ,name))))))))


Instruction:
Generate a defmacro form that transforms code like this:
(static-load-time-value nil)

Pattern to recognize: Macro call that should be transformed by STATIC-LOAD-TIME-VALUE

Input: (static-load-time-value nil)

Output:
(defmacro static-load-time-value
    (form &optional (read-only-p nil read-only-p-supplied?))
  "Like `load-time-value', but signals an error if it cannot preserve identity.

On close reading of the standard, in a function that is evaluated but
not compiled, it is permissible for implementations to repeatedly
execute a `load-time-value' form, and in fact some implementations do
this \(including, at the time of writing, ABCL, CLISP, Allegro and
LispWorks).

When `static-load-time-value' is compiled, it behaves exactly like
`load-time-value'. Otherwise it conducts a run-time check to ensure
that `load-time-value' preserves identity."
  ;; Thanks to Jean-Philippe Paradis and Michał Herda for helping to
  ;; diagnose and treat the problem here.
  (if *compile-file-truename*
      `(load-time-value ,form
                        ,@(and read-only-p-supplied? (list read-only-p)))
      `(progn
         (flet ((fn () (load-time-value (random most-positive-fixnum))))
           (declare (dynamic-extent #'fn) (ignorable #'fn)
                    #+LispWorks (notinline fn))
           ;; Do the actual test out of line.
           (test-load-time-value #'fn ',form ',read-only-p))
         (load-time-value ,form
                          ,@(and read-only-p-supplied? (list read-only-p))))))


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

Issue: Macro call that should be transformed by AAND

Input: (aand nil (progn))

Output: (defmacro AAND ...)


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

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

Input:
(defiter nil
    nil)

Output: (defmacro DEFITER ...)


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

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

Input:
(do+
  nil
  :key
  nil)

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


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

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

Input: (incf nil nil)

Output: (defmacro INCF ...)


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

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

Input:
(letrec nil
  (progn))

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

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


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

Problem: Macro call that should be transformed by C-ENVALUE

Input:
(c-envalue
  nil)

Output:
(defmacro c-envalue (&body body)
  `(make-c-envaluer
    :envalue-rule (c-lambda ,@body)))


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

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

Input:
(with-transaction nil
  (progn))

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:
(define-vari-compiler-macro nil
    nil)

Problem: Macro call that should be transformed by DEFINE-VARI-COMPILER-MACRO

Input:
(define-vari-compiler-macro nil
    nil)

Output:
(defmacro define-vari-compiler-macro (name lambda-list &body body)
  (check-args-for-constant-names :compiler-macro name lambda-list)
  (labels ((namedp (name x)
             (when (symbolp x)
               (string= name x)))
           (maybe-nth (n x)
             (if (listp x) (nth n x) x)))
    (when (find-if λ(namedp :&uniforms _) lambda-list)
      (error 'uniform-in-cmacro :name name))
    (when (find-if λ(namedp :&shared _) lambda-list)
      (error 'shared-in-cmacro :name name))
    (when (find-if λ(namedp :&optional _) lambda-list)
      (error 'optional-in-cmacro :name name))
    (when (find-if λ(namedp :&key _) lambda-list)
      (error 'key-in-cmacro :func-name name))
    ;;
    (let ((llist (mapcar λ(if (listp _) (first _) _) lambda-list)))
      (vbind (func-code context) (gen-macro-function-code name llist body)
        (let* ((args (nth-value 1 (extract-arg-pair lambda-list :&whole)))
               (args (nth-value 1 (extract-arg-pair args :&environment)))
               (arg-names (mapcar λ(maybe-nth 0 _) args))
               (arg-types (mapcar λ(arg-form->type (maybe-nth 1 _)) args)))
          `(progn
             (add-global-compiler-macro
              (make-compiler-macro ',name ,func-code ',arg-names ',arg-types
                                   ',context))
             ',name))))))


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

Write a macro that addresses: Macro call that should be transformed by STATIC-LET*

Input:
(static-let* nil
  nil)

Output:
(defmacro static-let* ((&rest bindings) &body body &environment env)
  "Like `let*', except the variables are only initialized once and
retain their values between different invocations of `body'.

Every static binding is similar to a `let' binding, except it can have
additional keyword arguments:

- `type' Denotes the type of the variable.
- `once' If true, then binding initialization and mutation will be
         thread-safe.
- `flush' If true, this binding will be flushable. Defaults to true.
- `in' Denotes the static binding group in which the binding will be
       placed for flushing. Defaults to the value of `*package'.
- `read-only' If true, then the binding cannot be mutated with `setf'.

Static bindings can be flushed via `flush-static-binding-group' and
`flush-all-static-binding-groups'; the latter is automatically pushed
into `uiop:*dump-image-hooks*' by Serapeum.

An unflushable static binding will carry its value over into dumped
Lisp binaries."
  (parse-static-let* bindings body env))


Instruction:
Define a macro that eliminates this repetitive pattern:
(ensure-functionf nil nil)

Issue: Macro call that should be transformed by ENSURE-FUNCTIONF

Input: (ensure-functionf nil nil)

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:
Create a Common Lisp macro for the following transformation. Before code:
(defoptimizer common-lisp:nil
    (common-lisp:progn))

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

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

Output:
(defmacro defoptimizer (name args &body body)
  `(eval-when (:compile-toplevel :load-toplevel :execute)
     (setf (symbol-optimizer ',name)
           #+sbcl
           (sb-int:named-lambda ',name ,args ,@body)
           #-sbcl
           (lambda ,args ,@body))
     ,@(when (stringp (first body))
         ;; lisp-namespace
         `((setf (documentation ',name 'optimizer)
                 ,(let ((*print-pretty* t))
                    #-clisp
                    (format nil "~<Lambda-List: ~s~
                                 ~:@_~<  ~@;~a~:>~
                               ~:>"
                            (list args (list (first body))))
                    #+clisp
                    (format nil "Lambda-List: ~s~%~a"
                            args (first body))))))))


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

Problem: Macro call that should be transformed by SHIFT-DECF

Input: (shift-decf nil (progn))

Output: (defmacro SHIFT-DECF ...)


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

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

Input: (pass)

Output:
(defmacro pass (&rest message-args)
  "Simply generate a PASS."
  `(add-result 'test-passed
               :test-expr ',message-args
               ,@(when message-args
                   `(:reason (format nil ,@message-args)))))


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

Issue: Macro call that should be transformed by PSETF

Input: (psetf nil (progn))

Output: (defmacro PSETF ...)


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

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

Input:
(flet* nil
  nil)

Output: (defmacro FLET* ...)


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(multiple-value-prog2 nil
    (progn))

What needs to change: Macro call that should be transformed by MULTIPLE-VALUE-PROG2

Input:
(multiple-value-prog2 nil
    (progn))

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:
(raw nil nil)

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

Input: (raw nil nil)

Output:
(defmacro raw (&rest forms)
  `(list ,@forms))


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
;; eval loses lexical environment - can't access surrounding bindings
(let ((x 1))
  (eval '(+ 1 x)))  ;; Error: X is unbound!

;; Need: way to tunnel lexical variables into eval

What needs to change: eval cannot access lexical environment — want a 'tunnel' that bridges lexical scope into eval's dynamic world

Input:
;; eval loses lexical environment - can't access surrounding bindings
(let ((x 1))
  (eval '(+ 1 x)))  ;; Error: X is unbound!

;; Need: way to tunnel lexical variables into eval

Output:
(defvar pandoric-eval-tunnel)

(defmacro pandoric-eval (vars expr)
  `(let ((pandoric-eval-tunnel
           (plambda () ,vars t)))
     (eval `(with-pandoric
              ,',vars pandoric-eval-tunnel
              ,,expr))))


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

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

Input: (if-not nil nil)

Output:
(defmacro if-not (test then &optional else)
  "If TEST evaluates to NIL, evaluate THEN and return its values,
otherwise evaluate ELSE and return its values. ELSE defaults to NIL."
  `(if (not ,test)
       ,then
       ,else))


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

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

Input: (wtrc nil)

Output:
(defmacro wtrc ((&optional (min 1) (max 50) &rest banner) &body body )
  `(let ((*trcdepth* (if *trcdepth*
                         (1+ *trcdepth*)
                       0)))
     ,(when banner `(when (>= *trcdepth* ,min)
                      (if (< *trcdepth* ,max)
                          (trc ,@banner)
                        (progn
                          (break "excess trace notttt!!! ~d" *trcdepth*) ;; ,@banner)
                          nil))))
     (when (< *trcdepth* ,max)
       ,@body)))


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

Problem: Macro call that should be transformed by XML

Input: (xml nil)

Output:
(defmacro xml (&rest tags)
  `(with-doctype :xml
     (loop for tag in ',tags
           append (tag->string tag))))


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

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

Input: (define-global-parameter nil (progn))

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


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

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

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

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


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

Issue: Macro call that should be transformed by SCCASE

Input:
(sccase nil
  nil)

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


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

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

Input:
(dletf* nil
  (progn))

Output: (defmacro DLETF* ...)


Instruction:
Define a macro that eliminates this repetitive pattern:
(with-active-layers nil
  :key
  nil)

Issue: Macro call that should be transformed by WITH-ACTIVE-LAYERS

Input:
(with-active-layers nil
  :key
  nil)

Output: (defmacro WITH-ACTIVE-LAYERS ...)


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

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

Input: (make nil (progn))

Output: (defmacro MAKE ...)


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

Issue: Macro call that should be transformed by OK

Input: (ok nil nil)

Output:
(defmacro ok (offset value)
  "Parsing was successful."
  `(values ,value ,offset))


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

Write a macro that addresses: Macro call that should be transformed by EVAL-AND-COMPILE

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

Output:
(defmacro eval-and-compile (&body body)
  "Emacs's `eval-and-compile'.
Alias for `eval-always'."
  `(eval-always
     ,@body))


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

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

Input: (jor nil (progn))

Output:
(defmacro jor (&rest args)
  "JSON-aware version of `cl:or'."
  `(or ,@(loop for arg in args
               collecting `(jwhen ,arg ,arg))))


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

Problem: Macro call that should be transformed by NTH-VALUE-OR

Input:
(nth-value-or nil
  nil)

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:
Create a Common Lisp macro for the following transformation. Before code:
(summing-to-and-returning nil)

What needs to change: Macro call that should be transformed by SUMMING-TO-AND-RETURNING

Input: (summing-to-and-returning nil)

Output: (defmacro SUMMING-TO-AND-RETURNING ...)


Instruction:
Define a macro that eliminates this repetitive pattern:
(with-hash-table-iterator 'lol-gen::some-name)

Issue: Macro call that should be transformed by WITH-HASH-TABLE-ITERATOR

Input: (with-hash-table-iterator 'lol-gen::some-name)

Output: (defmacro WITH-HASH-TABLE-ITERATOR ...)


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

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

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

Output:
(defmacro with-transaction (conn &body body)
  "Start a transaction and commit at the end of this block. If the evaluation `body` is interrupted, the transaction is rolled back automatically."
  (let ((conn-var (gensym "CONN-VAR")))
    `(let ((,conn-var ,conn))
       (if (in-transaction ,conn-var)
           (with-savepoint ,conn-var ,@body)
           (%with-transaction ,conn-var ,@body)))))