Instruction:
You are a Common Lisp macro expert. Given this code pattern:
;; Manual dispatch by keyword with multiple lambdas is repetitive
(let ((count 0))
  (setf (symbol-function 'counter)
        (lambda (&rest args)
          (case (car args)
            (:inc (apply (lambda (n) (incf count n)) (cdr args)))
            (:dec (apply (lambda (n) (decf count n)) (cdr args)))
            (:reset (progn (setf count 0) nil))
            (t (error "Unknown: ~a" (car args)))))))

;; Every method: keyword, lambda wrapper, arg destructuring - repetitive

Write a macro that addresses: Repeated keyword-dispatch with automatic argument destructuring — each keyword maps to a lambda with its own parameter list

Input:
;; Manual dispatch by keyword with multiple lambdas is repetitive
(let ((count 0))
  (setf (symbol-function 'counter)
        (lambda (&rest args)
          (case (car args)
            (:inc (apply (lambda (n) (incf count n)) (cdr args)))
            (:dec (apply (lambda (n) (decf count n)) (cdr args)))
            (:reset (progn (setf count 0) nil))
            (t (error "Unknown: ~a" (car args)))))))

;; Every method: keyword, lambda wrapper, arg destructuring - repetitive

Output:
(defmacro! dlambda (&rest ds)
  `(lambda (&rest ,g!args)
     (case (car ,g!args)
       ,@(mapcar
           (lambda (d)
             `(,(if (eq t (car d))
                  t
                  (list (car d)))
               (apply (lambda ,@(cdr d))
                      ,(if (eq t (car d))
                         g!args
                         `(cdr ,g!args)))))
           ds))))


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

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

Input: (the-kids nil (progn))

Output:
(defmacro the-kids (&rest kids)
  `(let ((*parent* self))
     (packed-flat! ,@kids)))


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

Problem: Macro call that should be transformed by RIGHT-JOIN

Input: (right-join 'lol-gen::some-name)

Output:
(defmacro right-join (table &key on using)
  `(join ,table :kind :right :on ,on :using ,using))


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

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

Input: (use-syntax nil)

Output:
(defmacro use-syntax (name)
  `(eval-when (:compile-toplevel :load-toplevel :execute)
     (%use-syntax ,name)))


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

Issue: Macro call that should be transformed by DELETEF

Input: (deletef nil (progn))

Output: (defmacro DELETEF ...)


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

Issue: Macro call that should be transformed by UNIONF

Input: (unionf nil nil)

Output: (defmacro UNIONF ...)


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

Problem: Macro call that should be transformed by DEFINE-GLOBAL-VAR

Input: (define-global-var nil :key nil)

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


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

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

Input:
(cond-> nil
  :key
  nil)

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


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

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

Input: (collect-min nil nil)

Output: (defmacro COLLECT-MIN ...)


Instruction:
Define a macro that eliminates this repetitive pattern:
(define-simple-definition-resolver nil
    (progn))

Issue: Macro call that should be transformed by DEFINE-SIMPLE-DEFINITION-RESOLVER

Input:
(define-simple-definition-resolver nil
    (progn))

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


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

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

Input:
(jmatch nil
  (progn))

Output:
(defmacro jmatch (form &body clauses)
  "Similar to Trivia match macro, match the FORM (JSON value) against CLAUSES.
CLAUSES are (PATTERN . BODY) forms, where
- PATTERN is a `jbind' destructuring pattern.
- And BODY is an implicit progn.

If PATTERN matches successfully in `jbind', then BODY is executed with
the variables from the PATTERN bound to the respective values, as per
`jbind'.

The last clause could start with T, OTHERWISE, ELSE, or _, and it will
be invoked if other patterns don't match. If there's no such clause,
`jmatch' will simply return NIL on no matching patterns."
  (let ((form-sym (gensym "MATCH-FORM")))
    `(let ((,form-sym ,form))
       (cond
         ,@(loop for (pattern . body) in clauses
                 when (and (symbolp pattern)
                           (member (symbol-name pattern) '("T" "_" "OTHERWISE" "ELSE")
                                   :test #'string=))
                   collect `(t ,@body)
                 else
                   collect `((ignore-errors (jbind ,pattern ,form-sym t))
                             (jbind ,pattern ,form-sym ,@body)))))))


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

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

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

Output: (defmacro COLLECT ...)


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

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

Input: (some-<> nil nil)

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


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

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

Input:
(without-dependency-capture
  nil
  nil)

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


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

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

Input: (enable-curly-syntax)

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


Instruction:
Generate a defmacro form that transforms code like this:
(order-by nil nil)

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

Input: (order-by nil nil)

Output: (defmacro ORDER-BY ...)


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

Issue: Macro call that should be transformed by GATHERLET

Input: (gatherlet nil)

Output: (defmacro GATHERLET ...)


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

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

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

Output: (defmacro NODE ...)


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

Write a macro that addresses: Macro call that should be transformed by WITH-FOREIGN-POINTER-AS-STRING

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

Output:
(defmacro with-foreign-pointer-as-string
    ((var-or-vars size &rest args) &body body)
  "VAR-OR-VARS is not evaluated and should be a list of the form
\(VAR &OPTIONAL SIZE-VAR) or just a VAR symbol.  VAR is bound to
a foreign buffer of size SIZE within BODY.  The return value is
constructed by calling FOREIGN-STRING-TO-LISP on the foreign
buffer along with ARGS." ; fix wording, sigh
  (destructuring-bind (var &optional size-var)
      (ensure-list var-or-vars)
    `(with-foreign-pointer (,var ,size ,size-var)
       (progn
         ,@body
         (values (foreign-string-to-lisp ,var ,@args))))))


Instruction:
Define a macro that eliminates this repetitive pattern:
(do-variables-in-lexenv 'lol-gen::some-name)

Issue: Macro call that should be transformed by DO-VARIABLES-IN-LEXENV

Input: (do-variables-in-lexenv 'lol-gen::some-name)

Output: (defmacro DO-VARIABLES-IN-LEXENV ...)


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

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

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

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


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

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

Input: (ignore-errors nil)

Output: (defmacro IGNORE-ERRORS ...)


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

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

Input: (unwrap-as 'lol-gen::some-name)

Output:
(defmacro unwrap-as (type cl:&optional (expr cl:nil expr-supplied-p))
  "A syntactic convenience for type casting.

    (unwrap-as <type> <expr>)

is equivalent to

    (the <type> (uwrap (tryInto <expr>)))

and

    (unwrap-as <type>)

is equivalent to

    (fn (expr) (the <type> (unwrap (tryInto expr)))).

Note that this may copy the object or allocate memory."

  (cl:let ((try-into (cl:ignore-errors (cl:find-symbol "TRYINTO" "COALTON/CLASSES")))
           (unwrap (cl:ignore-errors (cl:find-symbol "UNWRAP" "COALTON/CLASSES"))))
    (cl:assert try-into () "`try-as` macro does not have access to `try-into` yet.")
    (cl:assert unwrap () "`unwrap` macro does not have access to `unwrap` yet.")
    (cl:if expr-supplied-p
           `(the ,type (,unwrap (,try-into ,expr)))
           (alexandria:with-gensyms (lexpr)
             `(fn (,lexpr)
                (the ,type (,unwrap (,try-into ,lexpr))))))))


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

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

Input:
(with-properties nil
    (progn))

Output: (defmacro WITH-PROPERTIES ...)


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

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

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

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


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

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

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

Output: (defmacro DOCUMENTATION ...)


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

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

Input: (-<> nil (progn))

Output: (defmacro -<> ...)


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

Problem: Macro call that should be transformed by FGATHERING

Input:
(fgathering nil
  (progn))

Output: (defmacro FGATHERING ...)


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

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

Input:
(example
  nil
  (progn))

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


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

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

Input:
(for nil
    (progn))

Output: (defmacro FOR ...)


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

Issue: Macro call that should be transformed by WTRC

Input:
(wtrc nil
  :key
  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:
Generate a defmacro form that transforms code like this:
(letmatch nil
    :key
  nil)

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

Input:
(letmatch nil
    :key
  nil)

Output: (defmacro LETMATCH ...)


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

Issue: Macro call that should be transformed by MATCH2*

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

Output:
(defmacro match2* (whats &body clauses)
  "In match2/match2*, the last clause is not enclosed in a block.
Therefore, using `next' in the last clause results in jumping to the next innermost matching construct,
or results in a compilation error when this is the outermost matching construct."
  `(match2*+ ,whats
       ,(make-list (length whats) :initial-element t)
     ;; ,(mapcar #'form-type whats)
     ;; ^^^^^^^^^^^^^^^^^^^^^^^^^^ TODO: use Bike/compiler-macro
     ,@clauses))


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

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

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

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


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

Pattern to recognize: Macro call that should be transformed by POSSIBLY?

Input:
(possibly?
  nil
  nil)

Output: (defmacro POSSIBLY? ...)


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

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

Input:
(with-savepoint nil
  (progn))

Output:
(defmacro with-savepoint (conn &body body)
  (let ((ok (gensym "SAVEPOINT-OK"))
        (state-var (gensym "STATE-VAR"))
        (ident-var (gensym "SAVEPOINT-IDENTIFIER-VAR")))
    `(let* ((,state-var (make-instance 'savepoint-state
                                       :conn ,conn))
            (,ident-var (get-identifier ,state-var))
            (*transaction-state*
              (cons ,state-var
                    *transaction-state*))
            ,ok)

       (savepoint ,conn ,ident-var)
       (unwind-protect
            (multiple-value-prog1
                (progn ,@body)
              (setf ,ok t))
         (when (eql (get-state ,state-var)
                    :in-progress)
           (if ,ok
               (release-savepoint ,conn ,ident-var)
               (rollback-savepoint ,conn ,ident-var)))))))


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

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

Input: (nix nil :key nil)

Output:
(defmacro nix (&rest places)
  "Set PLACES to nil and return the old value(s) of PLACES.

If there is more than one PLACE, return their old values as multiple values.

This may be more efficient than (shiftf place nil), because it only
sets PLACE when it is not already null."
  `(values
    ,@(loop for place in places
            collect `(nix-1 ,place))))


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

Problem: Macro call that should be transformed by XHTML

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

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


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

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

Input: (asif nil nil)

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


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

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

Input: (collect-min nil :key nil)

Output: (defmacro COLLECT-MIN ...)


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

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

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

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

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


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

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

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

Output: (defmacro APPENDF ...)


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

Issue: Macro call that should be transformed by ALET

Input:
(alet nil
  (progn))

Output:
(defmacro alet (form &body body)
  "Binds the FORM to IT (via LET) in the scope of the BODY."
  `(anaphoric ignore-first ,form (progn ,@body)))


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

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

Input:
(with-truncated-stack nil
  nil)

Output:
(defmacro with-truncated-stack (() &body body)
  `(stack-truncator (lambda () ,@body)))


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

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

Input:
(handler-bind nil
  :key
  nil)

Output: (defmacro HANDLER-BIND ...)


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

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

Input: (defun nil (progn))

Output: (defmacro DEFUN ...)


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

Problem: Macro call that should be transformed by ACOND

Input: (acond)

Output: (defmacro ACOND ...)


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

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

Input: (gather-next nil nil)

Output: (defmacro GATHER-NEXT ...)


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

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

Input: (f-plusp nil (progn))

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


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

Pattern to recognize: Macro call that should be transformed by FOR-ALL*

Input: (for-all* nil)

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

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

Example:

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


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

Problem: Macro call that should be transformed by EIF

Input: (eif nil nil)

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

If there is only one branch a warning is signaled.

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

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


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

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

Input: (defvar nil :key nil)

Output: (defmacro DEFVAR ...)


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

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

Input:
(with-symbol-access
  'lol-gen::some-name)

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


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

Issue: Macro call that should be transformed by WITH-HTML-STRING

Input:
(with-html-string
  nil
  nil)

Output:
(defmacro with-html-string (&body body)
  "Like WITH-HTML, but capture the output as a string."
  `(with-output-to-string (*html*)
     (with-html ,@body)))


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

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

Input: (op)

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

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

Input:
(gatherlet nil
  :key
  nil)

Output: (defmacro GATHERLET ...)


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

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

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


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

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

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

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


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(with-special-initargs* nil)

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

Input: (with-special-initargs* nil)

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


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

Issue: Macro call that should be transformed by MATCH2

Input: (match2 common-lisp:nil)

Output:
(defmacro match2 (what &body clauses)
  "In match2/match2*, the last clause is not enclosed in a block.
Therefore, using `next' in the last clause results in jumping to the next innermost matching construct,
or results in a compilation error when this is the outermost matching construct."
  `(match2+ ,what t ,@clauses))


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

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

Input: (with-packages-unlocked 'lol-gen::some-name)

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


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

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

Input:
(some-<> nil
  nil)

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


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

Problem: Macro call that should be transformed by DEFUNWALKER-HANDLER

Input:
(defunwalker-handler nil
    :key
  nil)

Output: (defmacro DEFUNWALKER-HANDLER ...)


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

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

Input: (failure? nil)

Output:
(defmacro failure? (x)
  "Did parsing fail?"
  `(eq :fail ,x))


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

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

Input:
(as-> nil
    :key
  nil)

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


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

Issue: Macro call that should be transformed by ACCASE

Input:
(accase nil
  nil)

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


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

Issue: Macro call that should be transformed by WTRC

Input:
(wtrc nil
  (progn))

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

Issue: Macro call that should be transformed by AND

Input: (and)

Output: (defmacro AND ...)


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

Problem: Macro call that should be transformed by SUNLESS

Input: (sunless nil)

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


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

Problem: Macro call that should be transformed by GATHERING

Input: (gathering nil)

Output: (defmacro GATHERING ...)


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

Problem: Macro call that should be transformed by LAMBDA*

Input: (lambda* nil)

Output: (defmacro LAMBDA* ...)


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

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

Input: (in-package common-lisp:nil)

Output: (defmacro IN-PACKAGE ...)


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

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

Input: (->> nil (progn))

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


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

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

Input: (define-alternate-type-name nil (progn))

Output:
(defmacro define-alternate-type-name (current-type-name alternate-type-name)
  `(add-alternate-type-name ',alternate-type-name ',current-type-name))


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

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

Input: (the nil (progn))

Output: (defmacro THE ...)


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

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

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

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


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

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

Input:
(jbind nil
    (progn))

Output:
(defmacro jbind (destructuring-pattern form &body body)
  "Match the FORM against DESTRUCTURING-PATTERN.
The pattern might be:
- A symbol, in which case the current chosen form is bound to it. If
  the symbol is _, simply skip the form.
- A literal form:
  - String or number: compare with `equal'.
  - Keywords :TRUE, :FALSE, and :NULL, matching T, NIL, and :NULL
    respectively.
- If the pattern is a property list of string+pattern pairs, match the
  string+pattern pairs inside it to the provided JSON object and
  resolve them recursively.
- If the pattern is a list of symbols (VAR &optional VAR-P), these are
  bound to the respective values of `jget'. It is a good way to make
  `jbind' to be more lenient to missing keys, because the default
  behavior is to error on missing data.
- If the pattern is an inline vector, match it against a JSON array
  with at least as many elements as provided in the vector. Match
  every form in the vector against the element with the same index.

If the DESTRUCTURING-PATTERN doesn't match the object, throw
`value-mismatch'.

Underlying `jget' can throw errors for the exceptionally malformed
inputs. See `jget' documentation for the types of errors it throws.

Example:
\(\"hello\" hello \"a\" _ \"b\" b
 \"array\" #(first second third _))

matches a JSON object
{\"hello\": 3, \"a\": 8, \"b\": 3, \"c\": null, \"array\": [1, 2, 3, 4]}

and binds
- HELLO to 3
- B to 3
- FIRST to 1
- SECOND to 2
- THIRD to 3

It also checks that \"a\" key is present in the object and there's a
fourth element in the nested array.

See more examples in njson tests."
  (let ((form-sym (gensym "BIND-FORM"))
        (bindings (list)))
    (labels ((parse-pattern (pattern &optional (current-path (list)))
               (etypecase pattern
                 ((or (member :true :false :null) string real)
                  (push (cons pattern (copy-list current-path))
                        bindings))
                 ((cons symbol *)
                  (push (cons pattern (copy-list current-path))
                        bindings))
                 (list
                  (loop for (key subpattern) on pattern by #'cddr
                        do (parse-pattern subpattern (append current-path (list key))))
                  (push (cons nil (copy-list current-path))
                        bindings))
                 ((and symbol (not keyword))
                  (push (cons (if (equal "_" (symbol-name pattern))
                                  (gensym "_PATTERN")
                                  pattern)
                              (copy-list current-path))
                        bindings))
                 (array
		  (loop for elem across pattern
                        for index from 0
                        do (parse-pattern elem (append current-path (list index))))
		  (push (cons #() (copy-list current-path))
			bindings)))))
      (check-type destructuring-pattern (or list (and array (not string))
                                            (and symbol (not keyword)))
                  "proper jbind destructuring pattern: list, array, or symbol")
      (parse-pattern destructuring-pattern)
      (let ((let-forms (loop for (binding . key) in bindings
                             do (check-type binding (or array real symbol
                                                        ;; For (VAR VAR-P) forms
                                                        (cons symbol (or (cons symbol null)
                                                                         null))))
                             if (typep binding '(or array real null
                                                 (member :true :false :null)))
                               collect `(,(gensym) (check-value ,binding (vector ,@key) ,form-sym))
                             else if (and (symbolp binding)
                                          (uiop:emptyp key))
                                    collect `(,binding ,form-sym)
                             else if (listp binding)
                                    append (destructuring-bind (var &optional (var-p nil var-p-provided))
                                               binding
                                             (append
                                              `((,var (jget (vector ,@key) ,form-sym)))
                                              (when var-p-provided
                                                `((,var-p (nth-value 1 (jget (vector ,@key) ,form-sym)))))))
                             else
                               collect `(,binding (check-value t (vector ,@key) ,form-sym)))))
        `(let* ((,form-sym ,form)
                ,@let-forms)
           (declare (ignorable ,form-sym ,@(mapcar #'first let-forms)))
           ,@body))))


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

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

Input: (generating nil (progn))

Output: (defmacro GENERATING ...)


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

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

Input:
(defloop nil
    nil)

Output:
(defmacro defloop (name args &body body)
  "Define a function, ensuring proper tail recursion.
This is entirely equivalent to `defun' over `nlet'."
  (multiple-value-bind (body decls docstring)
      (parse-body body :documentation t)
    (let ((vars (lambda-list-vars args)))
      `(defun ,name ,args
         ,@(unsplice docstring)
         ,@decls
         (nlet ,name ,(mapcar #'list vars vars)
           (flet ((,name ,args (,name ,@vars)))
             (declare (inline ,name))
             ,@body))))))


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

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

Input:
(local
  nil
  (progn))

Output: (defmacro LOCAL ...)


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

Issue: Macro call that should be transformed by NUNIONF

Input: (nunionf nil (progn))

Output: (defmacro NUNIONF ...)


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

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

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

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


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

Problem: Macro call that should be transformed by AS-ARRAY-MEMBER

Input: (as-array-member nil)

Output:
(defmacro as-array-member ((&optional (stream '*json-output*))
                           &body body)
  "BODY should be a program which encodes exactly one JSON datum to
STREAM.  AS-ARRAY-MEMBER ensures that the datum is properly formatted
as a Member of an Array, i. e. separated by comma from any preceding
or following Member."
  `(progn
     (next-aggregate-member 'array ,stream)
     ,@body))


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

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

Input:
(with-context-variables nil
  :key
  nil)

Output:
(defmacro with-context-variables ((&rest vars) &body body)
  `(symbol-macrolet
       ,(loop for var in vars
              for form = `(context ,(intern (string var) :keyword))
              collect `(,var ,form))
     ,@body))


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

Problem: Macro call that should be transformed by POSSIBLY?

Input: (possibly?)

Output: (defmacro POSSIBLY? ...)


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

Issue: Macro call that should be transformed by FROM

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

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


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

Issue: Macro call that should be transformed by XHTML

Input: (xhtml nil :key nil)

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


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(define-simple-object-lookup nil
    nil)

What needs to change: Macro call that should be transformed by DEFINE-SIMPLE-OBJECT-LOOKUP

Input:
(define-simple-object-lookup nil
    nil)

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


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

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

Input: (vect-of nil nil)

Output: (defmacro VECT-OF ...)


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

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

Input:
(sctypecase nil
  nil)

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


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

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

Input: (f-plusp nil)

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


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

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

Input:
(batch
  nil
  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:
Generate a defmacro form that transforms code like this:
(fields)

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

Input: (fields)

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


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

Issue: Macro call that should be transformed by QUASIQUOTE

Input: (quasiquote nil (progn))

Output: (defmacro QUASIQUOTE ...)


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

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

Input: (collect-file nil nil)

Output: (defmacro COLLECT-FILE ...)


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

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

Input: (->* nil (progn))

Output: (defmacro ->* ...)


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

Problem: Macro call that should be transformed by ->

Input: (-> nil (progn))

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

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

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

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

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

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


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

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

Input:
(defmethods nil
    (progn))

Output:
(defmacro defmethods (class (self . slots) &body body)
  "Concisely define methods that specialize on the same class.

You can already use `defgeneric' to define an arbitrary number of
methods on a single generic function without having to repeat the name
of the function:

    (defgeneric fn (x)
      (:method ((x string)) ...)
      (:method ((x number)) ...))

Which is equivalent to:

    (defgeneric fn (x))

    (defmethod fn ((x string))
      ...)

    (defmethod fn ((x number))
      ...)

Similarly, you can use `defmethods' to define methods that specialize
on the same class, and access the same slots, without having to
repeat the names of the class or the slots:

    (defmethods my-class (self x y)
      (:method initialize-instance :after (self &key)
        ...)
      (:method print-object (self stream)
        ...)
      (:method some-method ((x string) self)
        ...))

Which is equivalent to:

    (defmethod initialize-instance :after ((self my-class) &key)
      (with-slots (x y) self
        ...))

    (defmethod print-object ((self my-class) stream)
      (with-slots (x y) self
        ...))

    (defmethod some-method ((x string) (self my-class))
      (with-slots (y) self              ;!
        ...))

Note in particular that `self' can appear in any position, and that
you can freely specialize the other arguments.

Just as in `with-slots', slots can be renamed:

    (defmethods my-class (self (abscissa x) (ordinate y))
      ...)

You can also use `defmethods' in place of `with-accessors', by using a
function-quote:

    (defmethods my-class (self (x #'my-class-x)
                               (y #'my-class-y))
      ...)

\(The difference from using `with-slots' is the scope of the slot
bindings: they are established *outside* of the method definition,
which means argument bindings shadow slot bindings:

    (some-method \"foo\" (make 'my-class :x \"bar\"))
    => \"foo\"

Since slot bindings are lexically outside the argument bindings, this
is surely correct, even if it makes `defmethods' slightly harder to
explain in terms of simpler constructs.)

Is `defmethods' trivial? Yes, in terms of its implementation. This
docstring is far longer than the code it documents. But you may find
it does a lot to keep heavily object-oriented code readable and
organized, without any loss of power.

Note that `defmethods' may also be useful when converting state
machines written using `labels' into an object-oriented style.

This construct is very loosely inspired by impl blocks in Rust."
  (mvlet* ((slot-names slot-binds
            (loop for slot in slots
                  if (listp slot)
                    collect slot into slot-binds
                    and collect (first slot) into slot-names
                  else
                    collect slot into slot-names
                    and collect (list slot slot) into slot-binds
                  finally (return (values slot-names slot-binds))))
           (body decls
            (parse-body body))
           (slot-decls decls
            (partition-declarations slot-names decls)))
    `(macrolet ((:method (name &body args)
                  (mvlet* ((class ',class)
                           (self ',self)
                           (slot-binds ',slot-binds)
                           (qualifiers lambda-list body
                            (parse-defmethod-args args))
                           (body decls docstring (parse-body body :documentation t))
                           (ll-with-self (substitute (list self class) self lambda-list)))
                    (when (equal ll-with-self lambda-list)
                      (error "No binding for ~s in ~s" self lambda-list))
                    `(symbol-macrolet ,(loop for (alias ref) in slot-binds
                                             collect (ematch ref
                                                       ((and ref (type symbol))
                                                        `(,alias (slot-value ,self ',ref)))
                                                       ((list 'function fn)
                                                        `(,alias (,fn ,self)))))
                       ,@',slot-decls
                       (defmethod ,name ,@qualifiers ,ll-with-self
                         ,@(unsplice docstring)
                         ,@decls
                         ,@body)))))
       ,@decls
       ,@body)))


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

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

Input: (inline)

Output: (defmacro INLINE ...)


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

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

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

Output:
(defmacro let-match* (bindings &body body)
  "Similar to LET-MATCH but matches sequentially."
  (reduce (lambda (binding form) `(let-match (,binding) ,form))
          bindings
          :from-end t
          :initial-value `(locally ,.body)))


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

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

Input:
(export-constructors
  common-lisp:nil
  (common-lisp:progn))

Output: (defmacro EXPORT-CONSTRUCTORS ...)


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

Problem: Macro call that should be transformed by XOR

Input: (xor nil :key nil)

Output:
(defmacro xor (&rest args)
  "Evaluates the ARGS one at a time. If more than one is T,
   evaluation stops and NIL is returned. If exactly one arg is T,
   that value is returned."
  (let ((state (gensym "XOR-state-"))
        (block-name (gensym "XOR-block-"))
        (arg-temp (gensym "XOR-arg-temp-")))
    `(let (,state
           ,arg-temp)
       (block ,block-name
         ,@(loop
              :for arg :in args
              :collect `(setf ,arg-temp ,arg)
              :collect `(when ,arg-temp
                          ;; arg is T, this can change the state
                          (if ,state
                              ;; a second T value, return NIL
                              (return-from ,block-name nil)
                              ;; a first T, swap the state
                              (setf ,state ,arg-temp))))
         (return-from ,block-name ,state)))))


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

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

Input: (ith-value nil (progn))

Output: (defmacro ITH-VALUE ...)


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

Issue: Macro call that should be transformed by FGATHERLET

Input:
(fgatherlet nil
  (progn))

Output: (defmacro FGATHERLET ...)


Instruction:
Define a macro that eliminates this repetitive pattern:
(distinct-on nil (progn))

Issue: Macro call that should be transformed by DISTINCT-ON

Input: (distinct-on nil (progn))

Output:
(defmacro distinct-on (columns &rest fields)
  `(make-clause :distinct-on (list ,@columns) ,@(mapcar #'expand-op fields)))


Instruction:
Define a macro that eliminates this repetitive pattern:
(with-unknown-first-class-functions-allowed
  'lol-gen::some-name)

Issue: Macro call that should be transformed by WITH-UNKNOWN-FIRST-CLASS-FUNCTIONS-ALLOWED

Input:
(with-unknown-first-class-functions-allowed
  'lol-gen::some-name)

Output:
(defmacro with-unknown-first-class-functions-allowed (&body body)
  `(let ((*allow-call-function-signature* t))
     ,@body))


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

Issue: Macro call that should be transformed by OP

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

Write a macro that addresses: 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:
(product-of nil
  nil)

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

Input:
(product-of nil
  nil)

Output: (defmacro PRODUCT-OF ...)


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

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

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

Output:
(defmacro make-dispatcher (function-constructor)
  `(make-instance 'dispatcher :dispatch-function-constructor ',function-constructor
                  :dispatch-function ,function-constructor))


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

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

Input:
(walk-environment
  nil
  :key
  nil)

Output: (defmacro WALK-ENVIRONMENT ...)


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

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

Input:
(wait-on nil
    (progn))

Output:
(defmacro wait-on (hook args &body body)
  "Wait until HOOK is run.
Note that it does not necessarily wait until hook has finished running all
handlers.
Return the BODY return value."
  (alexandria:with-gensyms (promise)
    (let ((handler-name (gensym "wait-on-handler"))
          (args (alexandria:ensure-list args)))
      (alexandria:once-only (hook)
        `(let ((,promise (make-promise)))
           (add-hook
            ,hook (make-instance 'handler
                                 :fn (lambda ,args
                                       (declare (ignorable ,@args))
                                       (remove-hook ,hook (quote ,handler-name))
                                       (fulfill ,promise (progn ,@body)))
                                 :name (quote ,handler-name)))
           (force ,promise))))))


Instruction:
Generate a defmacro form that transforms code like this:
(re-setf nil)

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

Input: (re-setf nil)

Output:
(defmacro re-setf (var &rest clauses)
  "SETFs VAR to the value of each clause subsequently.
   Re-uses the new value of VAR in subsequent clauses.
   Expects VAR to be a valid place for SETF."
  `(progn ,@(mapcar (lambda (clause)
                      `(setf ,var ,clause))
                    clauses)))


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

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

Input:
(once-only nil
  :key
  nil)

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:
(once-only 'lol-gen::some-name)

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

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

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:
Generate a defmacro form that transforms code like this:
(del-proxy 'lol-gen::some-name)

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

Input: (del-proxy 'lol-gen::some-name)

Output:
(defmacro del-proxy (slot &key (node-name 'item))
  "Remove proxy-node in slot"
  (let ((val (gensym)) (node-list (gensym)))
    `(let ((,val (slot-value ,node-name ',slot)))
       (if (eql (find-class 'nodelist) (class-of (slot-value ,node-name ',slot)))
  	   (let ((,node-list (slot-value (slot-value ,node-name ',slot) 'nodes)))
 	     (setf (slot-value (slot-value ,node-name ',slot) 'nodes)
  		   (loop for i in ,node-list collect
  			(slot-value i 'proxy-subnode))))
  	   (if ,val (setf (slot-value ,node-name ',slot)
  			  (slot-value ,val 'proxy-subnode)))))))


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

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

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

Output:
(defmacro with-logical-transaction ((&optional (name nil name-p)
                                       (isolation-level *isolation-level*
                                                        isolation-level-p))
                                    &body body)
  "Executes body within a with-transaction form if no transaction is currently
in progress, otherwise simulates a nested transaction by executing it
within a with-savepoint form. The transaction or savepoint is bound to name
if one is supplied. 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-logical-transaction ()
    (execute (:insert-into 'test-data :set 'value 77))
    ...)

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

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

  (with-logical-transaction (:serializable)
    (execute (:insert-into 'test-data :set 'value 44))
    ...)"
  (let* ((effective-name (if (and name-p (not (isolation-level-p name)))
                             name
                             (gensym)))
         (effective-body (if (and name-p (not (isolation-level-p name)))
                             `(lambda (,name) ,@body)
                             `(lambda (,effective-name)
                                (declare (ignore ,effective-name))
                                ,@body)))
         (effective-isolation-level (cond ((and isolation-level-p
                                                (isolation-level-p isolation-level))
                                           isolation-level)
                                          ((and name-p (isolation-level-p name))
                                           name)
                                          (t isolation-level))))
    `(call-with-logical-transaction ',effective-name ,effective-body
                                    ,effective-isolation-level)))


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

Issue: Macro call that should be transformed by MAPPING

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

Output: (defmacro MAPPING ...)


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(c?+n
  nil)

What needs to change: Macro call that should be transformed by C?+N

Input:
(c?+n
  nil)

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


Instruction:
Define a macro that eliminates this repetitive pattern:
(stop-when nil)

Issue: Macro call that should be transformed by STOP-WHEN

Input: (stop-when nil)

Output: (defmacro STOP-WHEN ...)


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

Issue: Macro call that should be transformed by UNLESS

Input: (unless nil)

Output: (defmacro UNLESS ...)


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

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

Input:
(with-constant-inject-hook nil
  :key
  nil)

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


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

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

Input: (collect-file nil (progn))

Output: (defmacro COLLECT-FILE ...)


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

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

Input:
(cond->> nil
  nil)

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


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(with-local-class-registry nil
  nil)

What needs to change: Macro call that should be transformed by WITH-LOCAL-CLASS-REGISTRY

Input:
(with-local-class-registry nil
  nil)

Output:
(defmacro with-local-class-registry ((&key inherit) &body body)
  "Run BODY in a dynamic environment where *CLASS-REGISTRY* is a
temporary local list.  If :INHERIT is non-null, the local registry
shall initially have the same content as the exterior *CLASS-REGISTRY*,
otherwise it shall be NIL."
  `(let ((*class-registry*
          ,(if inherit
               `(copy-alist
                 ,(if (eql inherit t) '*class-registry* inherit)))))
     ,@body))


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

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

Input: (dcase nil)

Output:
(defmacro dcase (keyform &body clauses)
  "DCASE is a combination of CASE and DESTRUCTURING-BIND.
   KEYFORM must evaluate to a CONS.

   Clauses are of the form:

       ((CASE-KEYS . DESTRUCTURING-LAMBDA-LIST) FORM*)

   The clause whose CASE-KEYS matches CAR of KEY, as if by CASE,
   is selected, and FORMs are then executed with CDR of KEY is destructured and
   bound by the DESTRUCTURING-LAMBDA-LIST."
  (expand-destructuring-case keyform clauses 'case))


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

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

Input:
(with-symbol-access
  nil
  (progn))

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


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

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

Input: (defun nil ())

Output: (defmacro DEFUN ...)


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

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

Input:
(on nil
    :key
  nil)

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

ARGS can be
- A symbol if there's only one argument to the callback.
- A list of arguments.
- An empty list, if the hook handlers take no argument."
  (let ((handler-name (gensym "on-hook-handler"))
        (args (alexandria:ensure-list args)))
    `(add-hook
      ,hook (make-instance 'handler
                           :fn (lambda ,args
                                 (declare (ignorable ,@args))
                                 ,@body)
                           :name (quote ,handler-name)))))


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

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

Input:
(dispatch-case nil
  :key
  nil)

Output:
(defmacro dispatch-case ((&rest exprs-and-types) &body clauses)
  "Dispatch on the types of multiple expressions, exhaustively.

Say you are working on a project where you need to handle timestamps
represented both as universal times, and as instances of
`local-time:timestamp'. You start by defining the appropriate types:

    (defpackage :dispatch-case-example
      (:use :cl :alexandria :serapeum :local-time)
      (:shadow :time))
    \(in-package :dispatch-case-example)

    (deftype universal-time ()
      '(integer 0 *))

    (deftype time ()
      '(or universal-time timestamp))

Now you want to write a `time=' function that works on universal
times, timestamps, and any combination thereof.

You can do this using `etypecase-of':

    (defun time= (t1 t2)
      (etypecase-of time t1
        (universal-time
         (etypecase-of time t2
           (universal-time
            (= t1 t2))
           (timestamp
            (= t1 (timestamp-to-universal t2)))))
        (timestamp
         (etypecase-of time t2
           (universal-time
            (time= t2 t1))
           (timestamp
            (timestamp= t1 t2))))))

This has the advantage of efficiency and exhaustiveness checking, but
the serious disadvantage of being hard to read: to understand what
each branch matches, you have to backtrack to the enclosing branch.
This is bad enough when the nesting is only two layers deep.

Alternately, you could do it with `defgeneric':

    (defgeneric time= (t1 t2)
      (:method ((t1 integer) (t2 integer))
        (= t1 t2))
      (:method ((t1 timestamp) (t2 timestamp))
        (timestamp= t1 t2))
      (:method ((t1 integer) (t2 timestamp))
        (= t1 (timestamp-to-universal t2)))
      (:method ((t1 timestamp) (t2 integer))
        (time= t2 t1)))

This is easy to read, but it has three potential disadvantages. \(1)
There is no exhaustiveness checking. If, at some point in the future,
you want to add another representation of time to your project, the
compiler will not warn you if you forget to update `time='. \(This is
bad enough with only two objects to dispatch on, but with three or
more it gets rapidly easier to miss a case.) \(2) You cannot use the
`universal-time' type you just defined; it is a type, not a class, so
you cannot specialize methods on it. \(3) You are paying a run-time
price for extensibility -- the inherent overhead of a generic function
-- when extensibility is not what you want.

Using `dispatch-case' instead gives you the readability of
`defgeneric' with the efficiency and safety of `etypecase-of'.

    (defun time= (t1 t2)
      (dispatch-case ((t1 time)
                      (t2 time))
        ((universal-time universal-time)
         (= t1 t2))
        ((timestamp timestamp)
         (timestamp= t1 t2))
        ((universal-time timestamp)
         (= t1 (timestamp-to-universal t2)))
        ((timestamp universal-time)
         (time= t2 t1))))

The syntax of `dispatch-case' is much closer to `defgeneric' than it
is to `etypecase'. The order in which clauses are defined does not
matter, and you can define fallthrough clauses in the same way you
would define fallthrough methods in `defgeneric'.

Suppose you wanted to write a `time=' function like the one above, but
always convert times to timestamps before comparing them. You could
write that using `dispatch-case' like so:

    (defun time= (x y)
      (dispatch-case ((x time)
                      (y time))
        ((* universal-time)
         (time= x (universal-to-timestamp y)))
        ((universal-time *)
         (time= (universal-to-timestamp x) y))
        ((timestamp timestamp)
         (timestamp= x y))))

\(In the list of types, you can use as asterisk as a shorthand for the
type of the corresponding argument to `dispatch-case'; in that above,
`time'.)

Note that this requires only three clauses, where writing it out using
nested `etypecase-of' forms would require four clauses. This is a
small gain; but with more subtypes to dispatch on, or more objects,
such fallthrough clauses become more useful."
  (let ((*gensym-counter* 0))
    `(dispatch-case-let
         ,(loop for (expr type) in exprs-and-types
                for i from 0
                for var = (string-gensym 'arg)
                collect `((,var ,type) ,expr))
       ,@clauses)))


Instruction:
Generate a defmacro form that transforms code like this:
(insert-into nil
  nil)

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

Input:
(insert-into nil
  nil)

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


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

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

Input: (define-template nil (progn))

Output: (defmacro DEFINE-TEMPLATE ...)


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(as-array-member nil
  :key
  nil)

What needs to change: Macro call that should be transformed by AS-ARRAY-MEMBER

Input:
(as-array-member nil
  :key
  nil)

Output:
(defmacro as-array-member ((&optional (stream '*json-output*))
                           &body body)
  "BODY should be a program which encodes exactly one JSON datum to
STREAM.  AS-ARRAY-MEMBER ensures that the datum is properly formatted
as a Member of an Array, i. e. separated by comma from any preceding
or following Member."
  `(progn
     (next-aggregate-member 'array ,stream)
     ,@body))


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

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

Input: (defsynonym nil nil)

Output: (defmacro DEFSYNONYM ...)


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

Issue: Macro call that should be transformed by FULL-JOIN

Input: (full-join 'lol-gen::some-name)

Output:
(defmacro full-join (table &key on using)
  `(join ,table :kind :full :on ,on :using ,using))


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

Problem: Macro call that should be transformed by AETYPECASE

Input:
(aetypecase nil
  (progn))

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


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

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

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

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


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

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

Input: (define-global-var* nil :key nil)

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


Instruction:
Generate a defmacro form that transforms code like this:
(with-standard-io-syntax)

Pattern to recognize: Macro call that should be transformed by WITH-STANDARD-IO-SYNTAX

Input: (with-standard-io-syntax)

Output: (defmacro WITH-STANDARD-IO-SYNTAX ...)


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

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

Input:
(-<> nil
  nil)

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


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

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

Input:
(define-generic nil
    nil)

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

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

Example:

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

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

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


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

Issue: Macro call that should be transformed by FALSE

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

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


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

Issue: Macro call that should be transformed by WITH-OPEN-STREAM

Input: (with-open-stream 'lol-gen::some-name)

Output: (defmacro WITH-OPEN-STREAM ...)


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

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

Input: (compiler-macro-lambda 'lol-gen::some-name)

Output:
(defmacro compiler-macro-lambda (lambda-list &body body)
  (introspect-environment:parse-compiler-macro (gensym "COMPILER-MACRO-LAMBDA")
                                               lambda-list
                                               body))


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

Problem: Macro call that should be transformed by QUERY-DAO

Input: (query-dao nil :key nil)

Output:
(defmacro query-dao (type query &rest args)
  "Execute the given query (which can be either a string or an S-SQL expression)
and return the result as DAOs of the given type. If the query contains
placeholders ($1, $2, etc) their values can be given as extra arguments. The
names of the fields returned by the query must either match slots in the DAO
class, or be bound through with-column-writers."
  `(query-dao% ,type ,(real-query query) (dao-row-reader (find-class ,type)) ,@args))


Instruction:
Define a macro that eliminates this repetitive pattern:
(create-view nil)

Issue: Macro call that should be transformed by CREATE-VIEW

Input: (create-view nil)

Output:
(defmacro create-view (view-name &key or-replace as)
  `(make-statement :create-view ,view-name
                   :or-replace ,or-replace
                   :as ,as))


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


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

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

Input: (some-<>)

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


Instruction:
Define a macro that eliminates this repetitive pattern:
(lambda-match
  nil
  :key
  nil)

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

Input:
(lambda-match
  nil
  :key
  nil)

Output: (defmacro LAMBDA-MATCH ...)


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

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

Input: (dreletf nil)

Output: (defmacro DRELETF ...)


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

Problem: Macro call that should be transformed by DEFPLACE

Input:
(defplace nil
    nil)

Output:
(defmacro defplace (name args &body body)
  "Define NAME and (SETF NAME) in one go.

BODY is a list of forms, starting with an optional docstring. The last
form in BODY, however, must be a single, setf-able expression."
  (match body
    ((list (type string))
     (error "No form for ~s: ~a" 'defplace body))
    ((last (cons (type string) nil) 1)
     `(defplace ,name ,args ,@(reverse body)))
    (otherwise
     (with-gensyms (value)
       `(progn
          (defun ,name ,args
            ,@body)
          (defun (setf ,name) (,value ,@args)
            ,@(butlast body)
            (setf ,(lastcar body) ,value)))))))


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

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

Input: (minf nil :key nil)

Output: (defmacro MINF ...)


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

Problem: Macro call that should be transformed by FAIL

Input: (fail nil nil)

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:
(with-contracts-disabled nil
  nil)

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

Input:
(with-contracts-disabled nil
  nil)

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


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

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

Input: (maximizing nil)

Output: (defmacro MAXIMIZING ...)


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

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

Input:
(live
  nil
  nil)

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

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

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

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


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

Issue: Macro call that should be transformed by DOVEC

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

Output:
(defmacro dovec ((var vec &optional result-form) &body body)
  "Iterates over a vector (like in DOLIST)."
  (let ((index-var (gensym "INDEX")))
    (once-only (vec)
      `(dotimes (,index-var (length ,vec) ,result-form)
         (let ((,var (aref ,vec ,index-var)))
           ,@body)))))


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

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

Input: (initially nil nil)

Output: (defmacro INITIALLY ...)


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

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

Input:
(c_?
  nil
  :key
  nil)

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


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

Issue: Macro call that should be transformed by IGNORING

Input:
(ignoring nil
  :key
  nil)

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


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

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

Input: (handler-case 'lol-gen::some-name)

Output: (defmacro HANDLER-CASE ...)


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

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

Input:
(c_1
  nil)

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


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

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

Input:
(acase nil
  :key
  nil)

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


Instruction:
Write a Common Lisp macro to handle this code pattern:
(with-local-class-registry nil
  (progn))

Problem: Macro call that should be transformed by WITH-LOCAL-CLASS-REGISTRY

Input:
(with-local-class-registry nil
  (progn))

Output:
(defmacro with-local-class-registry ((&key inherit) &body body)
  "Run BODY in a dynamic environment where *CLASS-REGISTRY* is a
temporary local list.  If :INHERIT is non-null, the local registry
shall initially have the same content as the exterior *CLASS-REGISTRY*,
otherwise it shall be NIL."
  `(let ((*class-registry*
          ,(if inherit
               `(copy-alist
                 ,(if (eql inherit t) '*class-registry* inherit)))))
     ,@body))


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

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

Input:
(with-html
  nil
  :key
  nil)

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


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

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

Input: (matrix-ccase 'lol-gen::some-name)

Output: (defmacro MATRIX-CCASE ...)


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

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

Input: (pcase nil :key nil)

Output:
(defmacro pcase (pred keyform &rest clauses)
  "Like CASE, but uses given PRED instead of EQL to select appropriate CLAUSE.

   Example usage:

       CL-USER> (pcase '< 1
                  (0 (print \"Below zero\"))
                  (2 (print \"OK\"))
                  (otherwise (error \"Oops\")))
"
  (expand-predicate-case pred keyform clauses 'case))


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

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

Input: (collect-last nil nil)

Output: (defmacro COLLECT-LAST ...)


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

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

Input: (string-ecase nil)

Output: (defmacro STRING-ECASE ...)


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

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

Input:
(count-of nil
  nil)

Output: (defmacro COUNT-OF ...)


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

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

Input:
(with-pp
  nil
  :key
  nil)

Output:
(defmacro with-pp (&body body)
  `(symbol-macrolet ((stream (get-stream-generic pp))
		     (indent (get-indent-generic pp))
		     (--indent (dec-indent-generic pp))
		     (++indent (inc-indent-generic pp)))
     (macrolet ((push-sign (x) `(push-sign-generic pp ,x))
		(pop-sign () `(pop-sign-generic pp))
		(top-sign () `(top-sign-generic pp))
		(find-sign (x) `(find-sign-generic pp ,x))
		(push-info (x) `(push-info-generic pp ,x))
		(pop-info () `(pop-info-generic pp))
		(top-info () `(top-info-generic pp))
		(find-info (x) `(find-info-generic pp ,x))
		(info-size () `(info-size-generic pp))
		(node-slot (x) `(slot-value item ',x)))
       ,@body)))


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

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

Input:
(bind nil
  :key
  nil)

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

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

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

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