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

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

Input:
(define-package-syntax
  'lol-gen::some-name)

Output:
(defmacro define-package-syntax (&body (package . options))
  (unless (typep package 'package-designator)
    (push package options)
    (setq package *package*))
  `(defsyntax ,(package-syntax-name package)
     ,@options))


Instruction:
Define a macro that eliminates this repetitive pattern:
(with-item-key-function 'lol-gen::some-name)

Issue: Macro call that should be transformed by WITH-ITEM-KEY-FUNCTION

Input: (with-item-key-function 'lol-gen::some-name)

Output:
(defmacro with-item-key-function ((key &optional (key-form key))
                                  &body body &environment env)
  "For each of the most common key functions used in sequences, emit a
copy of BODY with KEY bound to a local macro that calls KEY-FORM.

If current optimization declarations favor space over speed, or
compilation speed over runtime speed, then BODY is only emitted once."
  (check-type key symbol)
  (with-unique-names (ukey)
    `(let* ((,key (canonicalize-key ,key-form))
            (,ukey ,key))
       ,@(expect-form-list
          (if (not (speed-matters? env))
              `((macrolet ((,key (x) (list 'funcall ',ukey x)))
                  ,@body))
              `((cond ((eql ,ukey #'identity)
                       (macrolet ((,key (x) x))
                         ,@body))
                      (t (macrolet ((,key (x) (list 'funcall ',ukey x)))
                           ,@body)))))))))


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

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

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

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


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

Issue: Macro call that should be transformed by DEFPARAMETER*

Input: (defparameter* nil :key nil)

Output: (defmacro DEFPARAMETER* ...)


Instruction:
Define a macro that eliminates this repetitive pattern:
(eif-let nil
  :key
  nil)

Issue: Macro call that should be transformed by EIF-LET

Input:
(eif-let nil
  :key
  nil)

Output:
(defmacro eif-let (&whole whole binds &body (then &optional (else nil else?)))
  "Like `alexandria:if-let', but expects two branches.
Compare `eif'."
  (unless else?
    (warn "Missing else-branch in eif-let form:~%~a"
          whole))
  `(if-let ,binds ,then ,else))


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

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

Input:
(with-object nil
  (progn))

Output:
(defmacro with-object ((&optional (stream '*json-output*)) &body body)
  "Open a JSON Object, run BODY, then close the Object.  Inside the BODY,
AS-OBJECT-MEMBER or ENCODE-OBJECT-MEMBER should be called to encode
Members of the Object."
  `(with-aggregate (object #\{ #\} ,stream) ,@body))


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

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

Input:
(with-shuffling
  nil
  :key
  nil)

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


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

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

Input: (export-always 'lol-gen::some-name)

Output:
(defmacro export-always (symbols &optional (package nil package-supplied?))
  "Like `export', but also evaluated at compile time."
  `(eval-when (:compile-toplevel :load-toplevel :execute)
     (export ,symbols ,@(and package-supplied? (list package)))))


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

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

Input: (fm! nil (progn))

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


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

Problem: Macro call that should be transformed by APPEND-AT-END

Input: (append-at-end nil :key nil)

Output: (defmacro APPEND-AT-END ...)


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

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

Input:
(with-slots nil
    :key
  nil)

Output: (defmacro WITH-SLOTS ...)


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

Problem: Macro call that should be transformed by EXPORT-CLASS

Input:
(export-class
  'lol-gen::some-name)

Output: (defmacro EXPORT-CLASS ...)


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

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

Input:
(delete-from nil
  :key
  nil)

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


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

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

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

Output: (defmacro ->> ...)


Instruction:
Generate a defmacro form that transforms code like this:
(the-kids)

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

Input: (the-kids)

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


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

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

Input:
(dlet nil
  (progn))

Output: (defmacro DLET ...)


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

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

Input:
(with-active-layers nil
  nil)

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


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

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

Input: (count-of nil)

Output: (defmacro COUNT-OF ...)


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

Problem: Macro call that should be transformed by IS-TRUE

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

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


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

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

Input: (dotimes (quote lol-gen::some-name))

Output: (defmacro DOTIMES ...)


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

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

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

Output:
(defmacro for (update-type &key of nowait skip-locked)
  (let ((ident-list (if (keywordp of)
                        `(list ,of)
                        `(quote ,of))))
    `(make-clause :updatability ,update-type :of ,ident-list :nowait ,nowait :skip-locked ,skip-locked)))


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

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

Input: (some-> nil :key nil)

Output: (defmacro SOME-> ...)


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

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

Input: (accumulating-to 'lol-gen::some-name)

Output: (defmacro ACCUMULATING-TO ...)


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

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

Input: (fbindrec* nil)

Output:
(defmacro fbindrec* (bindings &body body &environment *lexenv*)
  "Like `fbindrec`, but the function defined in each binding can be
used in successive bindings."
  (setf bindings (expand-fbindings bindings))
  (unless bindings
    (return-from fbindrec* `(locally ,@body)))
  (mvlet* ((env env-decls binds lambdas (analyze-fbinds bindings *lexenv*))
           (simple complex lambda unref
            (partition-fbinds (append binds lambdas)
                              body))
           (temps (mapcar (op (gensym (string (first _)))) complex))
           (body decls (parse-body body))
           (simple-decls complex-decls lambda-decls others
            (partition-declarations-by-kind simple complex lambda decls)))
    `(let
         ;; Use dummies when we can (with ensure-function).
         ,(loop for (var init) in env
                collect (if (and (listp init)
                                 (eql (car init) 'ensure-function))
                            `(,var #'invalid)
                            var))
       ,@(unsplice (and env-decls `(declare ,@env-decls)))
       (comment "fbind: Simple bindings")
       (fbind ,simple
         ,@simple-decls
         (comment "fbind: Temps for complex bindings")
         (let ,(loop for temp in temps collect `(,temp #'invalid))
           (declare ,@(loop for temp in temps collect `(function ,temp)))
           (flet ,(loop for (name nil) in complex
                        for temp in temps
                        collect (build-bind/ftype name temp complex-decls env))
             ,@complex-decls
             (comment "fbind: Lambdas")
             (labels (,@(loop for (name lambda) in lambda
                              collect `(,name ,@(cdr lambda))))
               ,@lambda-decls
               (comment "fbind: Interleave unreferenced and complex bindings in order.")
               ,@(remove nil
                         (loop for (name nil) in bindings
                               append (or (loop for (uname init) in unref
                                                if (eql uname name)
                                                  return (list init))
                                          (loop for (cname init) in complex
                                                for temp in temps
                                                if (eql cname name)
                                                  return `((setf ,temp (ensure-function ,init)))))))
               (comment "fbind: Set the `env` variables for the lambdas")
               (setf ,@(apply #'append env))
               (locally ,@others
                 ,@body))))))))


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

Problem: Macro call that should be transformed by ITERATE

Input: (iterate nil (progn))

Output: (defmacro ITERATE ...)


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

Problem: Macro call that should be transformed by ATYPECASE

Input: (atypecase nil)

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


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

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

Input:
(resolving
  nil
  (progn))

Output: (defmacro RESOLVING ...)


Instruction:
Generate a defmacro form that transforms code like this:
(dispatch-case-error)

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

Input: (dispatch-case-error)

Output:
(defmacro dispatch-case-error (&key type datum &environment env)
  (let ((%matched-types (macroexpand-1 'matched-types env)))
    `(error 'dispatch-case-error
            :expected-type ,type
            :datum ,datum
            :matched-types ',(butlast %matched-types))))


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

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

Input: (with-active-layers 'lol-gen::some-name)

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


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

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

Input:
(unwind-protect nil
    nil)

Output: (defmacro UNWIND-PROTECT ...)


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

Issue: Macro call that should be transformed by FALSE

Input: (false nil (progn))

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:
(do-symbols (quote lol-gen::some-name))

Issue: Macro call that should be transformed by DO-SYMBOLS

Input: (do-symbols (quote lol-gen::some-name))

Output: (defmacro DO-SYMBOLS ...)


Instruction:
Generate a defmacro form that transforms code like this:
(c?_
  nil
  (progn))

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

Input:
(c?_
  nil
  (progn))

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


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

Problem: Macro call that should be transformed by RTE-ECASE

Input: (rte-ecase nil)

Output: (defmacro RTE-ECASE ...)


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

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

Input: (rem-bops 'lol-gen::some-name)

Output: (defmacro REM-BOPS ...)


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

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

Input: (group-by nil :key nil)

Output: (defmacro GROUP-BY ...)


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

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

Input: (string-case nil)

Output: (defmacro STRING-CASE ...)


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

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

Input:
(selector nil
    (progn))

Output: (defmacro SELECTOR ...)


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

Issue: Macro call that should be transformed by MODF

Input: (modf nil (progn))

Output:
(defmacro modf (place value &rest more &environment env)
  "Make a new object \(which may use some of the old object) such that PLACE
evaluates to VALUE.

MORE should have the form...

MORE : NIL
     | (TEMPORARY-BINDING ANOTHER-MODF-PLACE ANOTHER-VALUE . MORE)

Use it to specify a temporary binding for the new object created which will be
used in the subsequence MODF-PLACE NEW-VALUE pairs until the end of the MODF
form."
  (if more
      (destructuring-bind (next-symbol next-place next-value &rest next-more) more
        `(let ((,next-symbol ,(modf-expand value place nil env)))
           (modf ,next-place ,next-value ,@next-more)))
      (modf-expand value place nil env)))


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

Problem: Macro call that should be transformed by UNIONF

Input: (unionf nil (progn))

Output: (defmacro UNIONF ...)


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

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

Input:
(summing
  nil
  (progn))

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

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

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

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


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

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

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


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

Problem: Macro call that should be transformed by VAR

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

Output: (defmacro VAR ...)


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

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

Input: (is-expand nil nil)

Output:
(defmacro is-expand (got expected &optional desc)
  (with-gensyms (duration expanded)
    (once-only (desc)
      `(with-duration ((,duration ,expanded) (macroexpand-1 ',got))
         (let (*gensym-alist*)
           (test ,expanded ',expected ,desc
                 :duration ,duration
                 :got-form ',got
                 :report-expected-label "be expanded to"
                 :test-fn #'gensym-tree-equal))))))


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

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

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

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:
Generate a defmacro form that transforms code like this:
(with-guessing-encoder)

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

Input: (with-guessing-encoder)

Output:
(defmacro with-guessing-encoder  (&body body)
  `(with-local-encoder (use-guessing-encoder)
     ,@body))


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

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

Input: (left nil :key nil)

Output:
(defmacro left (parser &rest parsers)
  "Combination of parsers yielding the result of the leftmost one."
  `(<* ,parser ,@parsers))


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

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

Input: (define-interface)

Output: (defmacro DEFINE-INTERFACE ...)


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

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

Input:
(if-and-let* nil
  :key
  nil)

Output:
(defmacro if-and-let* (bindings &body (then-form &optional else-form))
  "Like `and-let*', but with an `else' clause.
Note that unlike `if-let*', the variables in BINDINGS are only bound
for THEN-FORM."
  (with-unique-names (block-name)
    `(block ,block-name
       (and-let* ,bindings
         (return-from ,block-name ,then-form))
       ,else-form)))


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

Problem: Macro call that should be transformed by UPPER

Input: (upper nil)

Output:
(defmacro upper (self &optional (type t))
  `(container-typed ,self ',type))


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

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

Input: (defmacro nil (progn))

Output: (defmacro DEFMACRO ...)


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

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

Input: (destructuring-case nil)

Output: (defmacro DESTRUCTURING-CASE ...)


Instruction:
Define a macro that eliminates this repetitive pattern:
(without-recursion nil
  :key
  nil)

Issue: Macro call that should be transformed by WITHOUT-RECURSION

Input:
(without-recursion nil
  :key
  nil)

Output:
(defmacro without-recursion ((&key) &body body)
  "If BODY calls itself, at any depth, signal a (continuable) error of
type `recursion-forbidden'."
  (with-unique-names (recursion-id)
    `(progn
       (when (member ',recursion-id *recursions*)
         (cerror "Recurse anyway."
                 'recursion-forbidden
                 :form ',body))
       (let ((*recursions* (cons ',recursion-id *recursions*)))
         (declare (dynamic-extent *recursions*))
         ,@body))))


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

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

Input:
(dreletf* nil
  nil)

Output: (defmacro DRELETF* ...)


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

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

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

Output: (defmacro COUNT-OF ...)


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

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

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

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


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

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

Input:
(with-truncated-stack nil
  (progn))

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


Instruction:
Define a macro that eliminates this repetitive pattern:
;; Functions that build code also need gensyms for hygiene
(defun build-setter (var)
  (let ((g (gensym)))
    `(lambda (,g)
       (setf ,var ,g))))
;; Gensym boilerplate in code-generating functions

Issue: Functions that generate code also need gensyms — want same G! prefix convention extended to defun

Input:
;; Functions that build code also need gensyms for hygiene
(defun build-setter (var)
  (let ((g (gensym)))
    `(lambda (,g)
       (setf ,var ,g))))
;; Gensym boilerplate in code-generating functions

Output:
(defmacro defun! (name args &body body)
  (let ((syms (remove-duplicates
               (remove-if-not #'g!-symbol-p
                              (flatten body)))))
    (multiple-value-bind (body declarations docstring)
        (parse-body body :documentation t)
      `(defun ,name ,args
         ,@(when docstring
             (list docstring))
         ,@declarations
         (let ,(mapcar (lambda (s)
                         `(,s (gensym ,(subseq (symbol-name s)
                                               2))))
                       syms)
           ,@body)))))


Instruction:
Generate a defmacro form that transforms code like this:
(js-inline nil nil)

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

Input: (js-inline nil nil)

Output: (defmacro JS-INLINE ...)


Instruction:
Generate a defmacro form that transforms code like this:
(c?+n
  nil
  (progn))

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

Input:
(c?+n
  nil
  (progn))

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


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

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

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

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


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

Pattern to recognize: Macro call that should be transformed by WITH-UNIQUE-JS-NAMES

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

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


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

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

Input: (defparameter nil nil)

Output: (defmacro DEFPARAMETER ...)


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

Issue: Macro call that should be transformed by DEFPROXY

Input: (defproxy nil)

Output:
(defmacro defproxy (name)
  "Define node derived from proxy"
  `(progn
     (defclass# ,name (proxy) (values subnodes parent))
     (make-instance# ,name () ())))


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

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

Input:
(count-of nil
  (progn))

Output: (defmacro COUNT-OF ...)


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

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

Input:
(with-yield
  nil)

Output: (defmacro WITH-YIELD ...)


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

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

Input: (defun nil :key nil)

Output: (defmacro DEFUN ...)


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

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

Input: (multiple-value-setq nil nil)

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


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

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

Input:
(ecase-using nil
    (progn))

Output:
(defmacro ecase-using (pred keyform &body clauses)
  "Exhaustive variant of `case-using'."
  (once-only (keyform)
    `(case-using ,pred ,keyform
       ,@clauses
       (otherwise
        (error "~s fell through ~a with ~s"
               ,keyform
               'ecase-using
               ',pred)))))


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

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

Input: (gen-lambda nil)

Output:
(defmacro gen-lambda (params &body rest)
  "Version of lambda that wraps the anonymous function in an instance of the basic-generator class. This allows the lambda to be identified as a generator by its type. Basic-generator objects are derived from funcallable-standard-class, therefore they can be called as functions."
  `(let ((values-handler (create-values-handler)))
     (declare (ignorable values-handler))
     (make-instance
      'basic-generator
      :function (lambda ,params ,@rest))))


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

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

Input:
(slet nil
  :key
  nil)

Output:
(defmacro slet (form &body body)
  "Binds the FORM to IT (via SYMBOL-MACROLET) in the scope of the BODY. IT can
be set with SETF."
  `(symbolic ignore-first ,form (progn ,@body)))


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

Issue: Macro call that should be transformed by DO+

Input:
(do+
  nil
  nil)

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


Instruction:
Generate a defmacro form that transforms code like this:
(make-$instance nil)

Pattern to recognize: Macro call that should be transformed by MAKE-$INSTANCE

Input: (make-$instance nil)

Output: (defmacro MAKE-$INSTANCE ...)


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

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

Input:
(select-dao nil
  nil)

Output:
(defmacro select-dao (class &body clauses)
  "Build custom queries with SxQL.

Example:

  (select-dao 'tweet
    (where (:like :status \"%Japan%\")))

You can use \"includes\" to eagerly load another table and prevent the \"N+1 query\" performance problem:

  (select-dao 'tweet
    (includes 'user)
    (where (:like :status \"%Japan%\")))

You can use \"joins\" to add JOIN clauses for filtering by related table columns.
Note: \"joins\" does NOT automatically load foreign objects. Use \"includes\" if you need the ghost slots populated:

  ;; Filter by related table - ghost slot NOT populated
  (select-dao 'blog
    (joins 'user)
    (where (:= :user.status \"active\")))

  ;; Filter AND load foreign objects
  (select-dao 'blog
    (joins 'user)
    (includes 'user)
    (where (:= :user.status \"active\")))

See the SxQL documentation for the available clauses and operators."
  (with-gensyms (sql clause results include-classes foreign-class)
    (once-only (class)
      `(#+sb-package-locks locally #+sb-package-locks (declare (sb-ext:disable-package-locks sxql:where))
        #-sb-package-locks cl-package-locks:with-packages-unlocked #-sb-package-locks (sxql)
        (progn
          (setf ,class (ensure-class ,class))
          (let* ((sxql:*sql-symbol-conversion* #'unlispify)
                 (,sql
                   (sxql:select :*
                                (sxql:from (sxql:make-sql-symbol (table-name ,class)))))
                 (,include-classes '()))
            (macrolet ((where (expression)
                         `(sxql:make-clause :where ,(expand-op expression ',class))))
              ;; ignore compiler-note when includes is not used
              #+sbcl (declare (sb-ext:muffle-conditions sb-ext:code-deletion-note))
              (flet ((includes (&rest classes)
                       (appendf ,include-classes (mapcar #'ensure-class classes))
                       nil)
                     (joins (foreign-class &key (type :inner))
                       (let ((foreign-class (ensure-class foreign-class)))
                         (add-child ,sql
                                   (ecase type
                                     (:inner (sxql:inner-join
                                               (sxql:make-sql-symbol (table-name foreign-class))
                                               :on (make-join-condition ,class foreign-class)))
                                     (:left (sxql:left-join
                                              (sxql:make-sql-symbol (table-name foreign-class))
                                              :on (make-join-condition ,class foreign-class)))))
                         nil)))
                (dolist (,clause (list ,@clauses))
                  (when ,clause
                    (add-child ,sql ,clause)))
                (let ((,results (select-by-sql ,class ,sql)))
                  (unless *want-cursor*
                    (dolist (,foreign-class (remove-duplicates ,include-classes))
                      (include-foreign-objects ,foreign-class ,results)))
                  (values ,results ,sql))))))))))


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

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

Input: (with-foreign-objects nil)

Output:
(defmacro with-foreign-objects (bindings &body body)
  (if bindings
      `(with-foreign-object ,(car bindings)
         (with-foreign-objects ,(cdr bindings)
           ,@body))
      `(progn ,@body)))


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

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

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

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


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

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

Input:
(with-foreign-objects nil
  (progn))

Output:
(defmacro with-foreign-objects (bindings &body body)
  (if bindings
      `(with-foreign-object ,(car bindings)
         (with-foreign-objects ,(cdr bindings)
           ,@body))
      `(progn ,@body)))


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

Issue: Macro call that should be transformed by POP

Input: (pop nil)

Output: (defmacro POP ...)


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

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

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

Output: (defmacro TIME ...)


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

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

Input: (local)

Output:
(defmacro local (&body orig-body &environment env)
  "Make internal definitions using top-level definition forms.

Within `local' you can use top-level definition forms and have them
create purely local definitions, like `let', `labels', and `macrolet':

     (fboundp 'plus) ; => nil

     (local
       (defun plus (x y)
         (+ x y))
       (plus 2 2))
     ;; => 4

     (fboundp 'plus) ; => nil

Each form in BODY is subjected to partial expansion (with
`macroexpand-1') until either it expands into a recognized definition
form (like `defun') or it can be expanded no further.

\(This means that you can use macros that expand into top-level
definition forms to create local definitions.)

Just as at the real top level, a form that expands into `progn' (or an
equivalent `eval-when') is descended into, and definitions that occur
within it are treated as top-level definitions.

\(Support for `eval-when' is incomplete: `eval-when' is supported only
when it is equivalent to `progn').

The recognized definition forms are:

- `def', for lexical variables (as with `letrec')
- `define-values', for multiple lexical variables at once
- `defun', for local functions (as with `labels')
- `defalias', to bind values in the function namespace (like `fbindrec*')
- `declaim', to make declarations (as with `declare')
- `defconstant' and `defconst', which behave exactly like symbol macros
- `define-symbol-macro', to bind symbol macros (as with `symbol-macrolet')

Also, with serious restrictions, you can use:

- `defmacro', for local macros (as with `macrolet')

\(Note that the top-level definition forms defined by Common Lisp
are (necessarily) supplemented by three from Serapeum: `def',
`define-values', and `defalias'.)

The exact order in which the bindings are made depends on how `local'
is implemented at the time you read this. The only guarantees are that
variables are bound sequentially; functions can always close over the
bindings of variables, and over other functions; and macros can be
used once they are defined.

     (local
       (def x 1)
       (def y (1+ x))
       y)
     => 2

     (local
       (defun adder (y)
         (+ x y))
       (def x 2)
       (adder 1))
     => 3

Perhaps surprisingly, `let' forms (as well as `let*' and
`multiple-value-bind') *are* descended into; the only difference is
that `defun' is implicitly translated into `defalias'. This means you
can use the top-level idiom of wrapping `let' around `defun'.

    (local
      (let ((x 2))
        (defun adder (y)
          (+ x y)))
      (adder 2))
    => 4

Support for macros is sharply limited. (Symbol macros, on the other
hand, are completely supported.)

1. Macros defined with `defmacro' must precede all other expressions.

2. Macros cannot be defined inside of binding forms like `let'.

3. `macrolet' is not allowed at the top level of a `local' form.

These restrictions are undesirable, but well justified: it is
impossible to handle the general case both correctly and portably, and
while some special cases could be provided for, the cost in complexity
of implementation and maintenance would be prohibitive.

The value returned by the `local' form is that of the last form in
BODY. Note that definitions have return values in `local' just like
they do at the top level. For example:

     (local
       (plus 2 2)
       (defun plus (x y)
         (+ x y)))

Returns `plus', not 4.

The `local' macro is loosely based on Racket's support for internal
definitions."
  (multiple-value-bind (body decls) (parse-body orig-body)
    (catch 'local
      (generate-internal-definitions
       (make 'internal-definitions-env
             :decls decls
             :env env)
       body))))


Instruction:
Define a macro that eliminates this repetitive pattern:
(eval-always)

Issue: Macro call that should be transformed by EVAL-ALWAYS

Input: (eval-always)

Output:
(defmacro eval-always (&body body)
  "Shorthand for
        (eval-when (:compile-toplevel :load-toplevel :execute) ...)"
  `(eval-when (:compile-toplevel :load-toplevel :execute)
     ,@body))


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

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

Input: (gather-result nil)

Output: (defmacro GATHER-RESULT ...)


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

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

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

Output:
(defmacro is-false (condition &rest reason-args)
  "Generates a pass if CONDITION returns false, generates a
  failure otherwise. Like IS-TRUE, and unlike IS, IS-FALSE does
  not inspect CONDITION to determine what reason to give it case
  of test failure"
  (with-gensyms (value)
    `(let ((,value ,condition))
       (if ,value
           (process-failure ',condition
                            ,@(or reason-args
                                  `("~S returned the value ~S, which is true" ',condition ,value)))
           (add-result 'test-passed :test-expr ',condition)))))


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

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

Input: (some-> nil :key nil)

Output: (defmacro SOME-> ...)


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

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

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

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

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

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

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

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

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

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


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

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

Input:
(match nil
    (progn))

Output:
(defmacro match (adt obj &body clauses)
  "Perform pattern matching on OBJ with (adt-type) ADT.

Each clause must have the following syntax:

<var> := <symbol> | '_'
<lhs> := '_'
       | (<symbol> <var>*)
<clause> := (<lhs> <lisp code>)

The symbol '_' denotes a wildcard, as well as a fallthough.

Note that pattern matching is only shallow (patterns are one-level
deep).
"
  (assert (symbolp adt)
          (adt)
          "MATCH requires a symbol for the first argument. Given ~S."
          adt)

  (let ((ctors (mapcar #'car (get-constructors adt)))
        (types (mapcar (lambda (clause)
                         (ensure-car (car clause)))
                       clauses))
        (once (gensym "OBJ-")))

    ;; Check for duplicate matches.
    (let ((dupes (duplicates types)))
      (when dupes
        (warn "Duplicate matching clauses exist. Duplicate pattern ~
               constructors:~{ ~S~}"
              dupes)))

    ;; Check for match exhaustiveness.
    (unless (some #'wild? types)
      (let ((diff (set-difference ctors types)))
        (when diff
          (warn "Non-exhaustive match on ~A data ~
                 type. Missing cases:~{ ~S~}" adt diff))))

    ;; Generate the matching code.
    `(let ((,once ,obj))
       (check-type ,once ,adt)
       (etypecase ,once
         ,@(loop :for (bindings . body) :in clauses
                 :collect (let ((type (ensure-car bindings)))
                            (if (wild? type)
                                `(t ,@body)
                                `(,type
                                  (with-data ,(ensure-list bindings)
                                             ,once
                                    ,@body)))))))))


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

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

Input:
(bcond
  nil
  nil)

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

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

     (test :=> recipient)

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

As an extension, a clause like this:

     (test :=> var ...)

Can be used as a shorthand for

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

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


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

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

Input: (as-> nil (progn))

Output: (defmacro AS-> ...)


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

Write a macro that addresses: Macro call that should be transformed by DEF-SHADOW-TYPE-CONSTRUCTOR

Input: (def-shadow-type-constructor nil (progn))

Output:
(defmacro def-shadow-type-constructor (shadow-type function-identifier)
  (warn 'v-deprecated
        :old 'def-shadow-type-constructor
        :new 'define-shadow-type-constructor)
  `(define-shadow-type-constructor ,shadow-type ,function-identifier))


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

Problem: Macro call that should be transformed by PRINT-UNREADABLE-OBJECT

Input: (print-unreadable-object 'lol-gen::some-name)

Output: (defmacro PRINT-UNREADABLE-OBJECT ...)


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

Issue: Macro call that should be transformed by DEFPATTERN

Input:
(defpattern nil
    (progn))

Output: (defmacro DEFPATTERN ...)


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

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

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

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


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

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

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

Output: (defmacro FN ...)


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

Problem: Macro call that should be transformed by DO-FOR

Input: (do-for 'lol-gen::some-name)

Output: (defmacro DO-FOR ...)


Instruction:
Generate a defmacro form that transforms code like this:
(c?once)

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

Input: (c?once)

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


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

Issue: Macro call that should be transformed by DEFPATTERN

Input:
(defpattern nil
    nil)

Output:
(defmacro defpattern (name lambda-list &body body)
  "Defines a derived pattern specifier named NAME. This is analogous
to DEFTYPE.

Examples:

    ;; Defines a LIST pattern.
    (defpattern list (&rest args)
      (when args
        `(cons ,(car args) (list ,@(cdr args)))))"
  `(eval-when (:compile-toplevel :load-toplevel :execute)
     (setf (pattern-expand-function ',name) (lambda ,lambda-list ,@body))))


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

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

Input: (all nil nil)

Output:
(defmacro all (parser &rest parsers)
  "Combination of parsers yielding all results as a list."
  `(<*> ,parser ,@parsers))


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

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

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

Output: (defmacro COLLECTING ...)


Instruction:
Define a macro that eliminates this repetitive pattern:
(current-decoder nil)

Issue: Macro call that should be transformed by CURRENT-DECODER

Input: (current-decoder nil)

Output:
(defmacro current-decoder (&rest keys)
  "Capture current values of custom variables and return a custom
decoder which restores these values in its dynamic environment."
  (let (exterior-bindings customizations)
    (flet ((collect (key var)
             (let ((exterior (gensym)))
               (push (list exterior var) exterior-bindings)
               (push exterior customizations)
               (push key customizations))))
      (if keys
          (loop for key in keys
             do (collect key (custom-key-to-variable key)))
          (loop-on-custom (key var)
             do (collect key var)))
      `(let ,exterior-bindings
         (custom-decoder ,@customizations)))))


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

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

Input:
(with-rules nil
  nil)

Output: (defmacro WITH-RULES ...)


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

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

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

Output: (defmacro -<> ...)


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

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

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

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


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

Issue: Macro call that should be transformed by PMAP

Input: (pmap nil (progn))

Output:
(defmacro pmap (f parser)
  "Similar to `fmap', but this transforms a parser into another one, altering
its inner result if it happened to be successful."
  `(lambda (offset)
     (fmap ,f (funcall ,parser offset))))


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

Issue: Macro call that should be transformed by EXECUTE

Input: (execute nil (progn))

Output:
(defmacro execute (query &rest args)
  "Execute a query, ignore the results. So, in effect, like a query called with
format :none. Returns the amount of affected rows as its first returned
value. (Also returns this amount as the second returned value, but use of this
is deprecated.)"
  `(let ((rows (nth-value 1 (query ,query ,@args :none))))
     (if rows (values rows rows) 0)))


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

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

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

Output: (defmacro ALL-VALUES ...)


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

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

Input:
(match2 common-lisp:nil
  :key
  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:
Write a Common Lisp macro to handle this code pattern:
(ltbdd-with-new-hash nil
  :key
  nil)

Problem: Macro call that should be transformed by LTBDD-WITH-NEW-HASH

Input:
(ltbdd-with-new-hash nil
  :key
  nil)

Output: (defmacro LTBDD-WITH-NEW-HASH ...)


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


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

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

Input:
(fbind nil
  nil)

Output:
(defmacro fbind (bindings &body body &environment *lexenv*)
  "Binds values in the function namespace.

That is,
     (fbind ((fn (lambda () ...))))
     ≡ (flet ((fn () ...))),

except that a bare symbol in BINDINGS is rewritten as (symbol
symbol)."
  (setf bindings (expand-fbindings bindings))
  (unless bindings
    (return-from fbind `(locally ,@body)))
  ;; When possible (if the binding expands to a simple
  ;; let-over-lambda), we hoist the bindings to the top and bind
  ;; the lambda directly with flet.

  ;; Failing that, if we know that the function is never directly
  ;; dereferenced with sharp-quote, we can bind with `macrolet'
  ;; instead of `flet', leaving no runtime overhead vs. `funcall'.
  (mvlet* ((env env-decls bindings lambdas (analyze-fbinds bindings *lexenv*))
           (macro-vars
            (merely-syntactic-functions (mapcar #'first bindings)
                                        body
                                        *lexenv*))
           (vars  (mapcar #'first bindings))
           (exprs (mapcar #'second bindings))
           (temps (mapcar #'string-gensym vars))
           (body decls (parse-body body)))
    `(let ,env
       ,@(unsplice (and env-decls `(declare ,@env-decls)))
       (comment "fbind: Hidden variable bindings to close over.")
       (let ,(loop for temp in temps
                   for expr in exprs
                   collect `(,temp (ensure-function ,expr)))
         ,@(when temps
             (unsplice
              `(declare (function ,@temps))))
         (comment "fbind: Hidden variable bindings for function values.")
         (flet (,@(loop for (name lambda) in lambdas
                        collect `(,name ,@(cdr lambda)))
                ,@(loop for var in vars
                        for temp in temps
                        unless (member var macro-vars)
                          collect (build-bind/ftype var temp decls env)))
           #-sbcl (declare (inline ,@(set-difference vars macro-vars)))
           ,@decls
           (comment "fbind: Functions that might be sharp-quoted.")
           (macrolet (,@(loop for var in vars
                              for temp in temps
                              when (member var macro-vars)
                                collect `(,var
                                          (&rest args)
                                          (list* 'funcall ',temp args))))
             (comment "fbind: Macros for functions provably never sharp-quoted.")
             ,@body))))))


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

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

Input:
(v-defstruct nil
    nil)

Output:
(defmacro v-defstruct (name context &body slots)
  `(define-vari-struct ,name ,context ,@slots))


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

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

Input: (destructuring-case nil)

Output:
(defmacro destructuring-case (keyform &body clauses)
  "DESTRUCTURING-CASE, -CCASE, and -ECASE are 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, CCASE, or ECASE,
is selected, and FORMs are then executed with CDR of KEY is destructured and
bound by the DESTRUCTURING-LAMBDA-LIST.

Example:

 (defun dcase (x)
   (destructuring-case x
     ((:foo a b)
      (format nil \"foo: ~S, ~S\" a b))
     ((:bar &key a b)
      (format nil \"bar: ~S, ~S\" a b))
     (((:alt1 :alt2) a)
      (format nil \"alt: ~S\" a))
     ((t &rest rest)
      (format nil \"unknown: ~S\" rest))))

  (dcase (list :foo 1 2))        ; => \"foo: 1, 2\"
  (dcase (list :bar :a 1 :b 2))  ; => \"bar: 1, 2\"
  (dcase (list :alt1 1))         ; => \"alt: 1\"
  (dcase (list :alt2 2))         ; => \"alt: 2\"
  (dcase (list :quux 1 2 3))     ; => \"unknown: 1, 2, 3\"

 (defun decase (x)
   (destructuring-case x
     ((:foo a b)
      (format nil \"foo: ~S, ~S\" a b))
     ((:bar &key a b)
      (format nil \"bar: ~S, ~S\" a b))
     (((:alt1 :alt2) a)
      (format nil \"alt: ~S\" a))))

  (decase (list :foo 1 2))        ; => \"foo: 1, 2\"
  (decase (list :bar :a 1 :b 2))  ; => \"bar: 1, 2\"
  (decase (list :alt1 1))         ; => \"alt: 1\"
  (decase (list :alt2 2))         ; => \"alt: 2\"
  (decase (list :quux 1 2 3))     ; =| error
"
  (expand-destructuring-case keyform clauses 'case))


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

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

Input:
(special-symbol-progv nil
    (progn))

Output: (defmacro SPECIAL-SYMBOL-PROGV ...)


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

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

Input:
(lambda-coro
  nil
  :key
  nil)

Output: (defmacro LAMBDA-CORO ...)


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

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

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

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


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

Problem: Macro call that should be transformed by IN-SUITE*

Input: (in-suite* nil)

Output:
(defmacro in-suite* (suite-name &key in)
  "Just like in-suite, but silently creates missing suites."
  `(eval-when (:compile-toplevel :load-toplevel :execute)
     (%in-suite ,suite-name :in ,in :fail-on-error nil)))


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

Problem: Macro call that should be transformed by ESC

Input: (esc nil)

Output:
(defmacro esc (&rest forms)
  `(list
    ,@(loop for form in forms
            collect (%escape-string-form form))))


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

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

Input:
(c?dbg
  nil
  :key
  nil)

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


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

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

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

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


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

Problem: Macro call that should be transformed by DEFINE-TRAIN

Input:
(define-train nil
    :key
  nil)

Output:
(defmacro define-train (name args &body body)
  "Define a higher-order function and its compiler macro at once.

When defining a higher-order function it is often a good idea to
write a compiler macro so compilers can inline the resulting lambda
form.

For the special case of a fixed-arity function that only takes other
functions as arguments, you can use `define-train' to define the
function and the compiler macro in one go. The catch is that you have
to write the single definition as a macro.

E.g., if `complement' did not exist, you could define it like so:

    (define-train complement (fn)
      `(lambda (&rest args)
         (not (apply ,fn args))))

Besides providing an implicit compiler macro, `define-train' also
inserts the proper declarations to ensure the compiler recognizes the
function arguments as functions, avoiding runtime type checks.

The term \"train\" is from J."
  (multiple-value-bind (body decls docstring)
      (parse-body body :documentation t)
    `(progn
       (define-compiler-macro ,name ,args
         ,@decls
         (rebinding-functions ,args
           ,@body))
       (defun ,name ,args
         ,@(unsplice docstring)
         (macrolet ((,name ,args
                      ,@decls
                      (rebinding-functions ,args
                        ,@body)))
           (,name ,@args))))))


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

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

Input: (aecase nil)

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


Instruction:
Define a macro that eliminates this repetitive pattern:
(and-let nil)

Issue: Macro call that should be transformed by AND-LET

Input: (and-let nil)

Output:
(defmacro and-let (var &rest args)
  "Like AND. VAR will be bound to the value of the previous AND form"
  (cond ((null args) t)
        ((null (cdr args)) (car args))
        (t `(when-let (,var ,(car args))
              (and ,@(cdr args))))))


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

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

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

Output: (defmacro DESTRUCTURING-BIND ...)


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

Issue: Macro call that should be transformed by LAMBDA-CMATCH*

Input: (lambda-cmatch*)

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


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

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

Input: (-<>> nil)

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


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

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

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

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


Instruction:
Write a Common Lisp macro to handle this code pattern:
(ensure-transaction-with-isolation-level nil
  (progn))

Problem: Macro call that should be transformed by ENSURE-TRANSACTION-WITH-ISOLATION-LEVEL

Input:
(ensure-transaction-with-isolation-level nil
  (progn))

Output:
(defmacro ensure-transaction-with-isolation-level (isolation-level &body body)
  "Executes body within a with-transaction form if and only if no transaction is
already in progress. This adds the ability to specify an isolation level other
than the current default"
  `(call-with-ensured-transaction (lambda () ,@body) ,isolation-level))


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

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

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

Output:
(defmacro with-html-output ((var &optional stream
                                 &rest rest
                                 &key prologue indent)
                            &body body)
  "Transform the enclosed BODY consisting of HTML as s-expressions
into Lisp code to write the corresponding HTML as strings to VAR -
which should either hold a stream or which'll be bound to STREAM if
supplied."
  (declare (ignore prologue))
  (multiple-value-bind (declarations forms) (extract-declarations body)
  `(let ((,var ,(or stream var)))
       ,@declarations
     (check-type ,var stream)
     (macrolet ((htm (&body body)
                  `(with-html-output (,',var nil :prologue nil :indent ,,indent)
                     ,@body))
                (fmt (&rest args)
                  `(format ,',var ,@args))
                (esc (thing)
                  (with-unique-names (result)
                    `(let ((,result ,thing))
                       (when ,result (write-string (escape-string ,result) ,',var)))))
                (str (thing)
                  (with-unique-names (result)
                    `(let ((,result ,thing))
                       (when ,result (princ ,result ,',var))))))
         ,@(apply 'tree-to-commands forms var rest)))))


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

Issue: Macro call that should be transformed by XOR

Input: (xor nil (progn))

Output:
(defmacro xor (&rest datums)
  "Evaluates its arguments one at a time, from left to right. If more than one
argument evaluates to a true value no further DATUMS are evaluated, and NIL is
returned as both primary and secondary value. If exactly one argument
evaluates to true, its value is returned as the primary value after all the
arguments have been evaluated, and T is returned as the secondary value. If no
arguments evaluate to true NIL is returned as primary, and T as secondary
value."
  (with-gensyms (xor tmp true)
    `(let (,tmp ,true)
       (declare (ignorable ,tmp))
       (block ,xor
         ,@(mapcar (lambda (datum)
                     `(if (setf ,tmp ,datum)
                          (if ,true
                              (return-from ,xor (values nil nil))
                              (setf ,true ,tmp))))
                   datums)
         (return-from ,xor (values ,true t))))))


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

Issue: Macro call that should be transformed by NLET

Input:
(nlet nil
    nil)

Output: (defmacro NLET ...)


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

Problem: Macro call that should be transformed by IGNORE-SOME-CONDITIONS

Input: (ignore-some-conditions 'lol-gen::some-name)

Output:
(defmacro ignore-some-conditions ((&rest conditions) &body body)
  "Similar to CL:IGNORE-ERRORS but the (unevaluated) CONDITIONS
list determines which specific conditions are to be ignored."
  `(handler-case
       (progn ,@body)
     ,@(loop for condition in conditions collect
             `(,condition (c) (values nil c)))))


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

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

Input: (-> nil)

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

Issue: Macro call that should be transformed by UNDEFREPLY

Input: (undefreply nil :key nil)

Output: (defmacro UNDEFREPLY ...)


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

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

Input:
(export-accessors
  'lol-gen::some-name)

Output: (defmacro EXPORT-ACCESSORS ...)


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

Issue: Macro call that should be transformed by EXAMPLE

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

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


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

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

Input: (lazy-seq nil (progn))

Output:
(defmacro lazy-seq (head &optional tail)
  "Creates a `LAZY-SEQ' where HEAD is the first element in the
   sequence and TAIL is a form which computes the remainder of the
   sequence. TAIL is wrapped in a function that stores the result of
   evaluating FORM, the first time it is invoked, and returns the
   stored result in future invocations."

  `(make-lazy-seq :head ,head :tail (thunk ,tail)))


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

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

Input:
(define-fixture-restore nil
    (progn))

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


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

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

Input: (defclause-sequence nil (progn))

Output:
(defmacro defclause-sequence (element-name index-name
                              &key access-fn size-fn
                              element-type sequence-type
                              element-doc-string index-doc-string)
  "A simple way to define a FOR-like &sequence clause."

;Package subtlety: FOR should be in the same package as the
;element-name or index-name."
  (let* ((seq-for (when element-name
                    (intern (symbol-name 'for) (symbol-package element-name))))
         (seq-def (when element-name
                    `(defclause-driver
                         (,seq-for var ,element-name seq &sequence)
                       ,element-doc-string
                       (return-sequence-code :element-var var
                                             :sequence seq
                                             :access-fn ,access-fn
                                             :size-fn ,size-fn
                                             :element-type  ,element-type
                                             :sequence-type ,sequence-type))))
         #+nil
         (inx-for (when index-name
                    (intern (symbol-name 'for) (symbol-package index-name))))
         (inx-def (when index-name
                    `(defclause-driver (:for var ,index-name seq &sequence)
                       ,index-doc-string
                       (if with-index
                           (clause-error "WITH-INDEX keyword should not ~
be specified for this clause")
                           (progn
                             (setq with-index var)
                             (return-sequence-code
                              :sequence seq
                              :size-fn ,size-fn
                              :sequence-type ,sequence-type)))))))
    `(progn ,seq-def ,inx-def)))


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

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

Input:
(->> nil
  (progn))

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


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

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

Input: (sif nil :key nil)

Output:
(defmacro sif (test then &optional else)
  "Like IF, except binds the test form to IT (via SYMBOL-MACROLET) for
the scope of the then and else expressions. IT can be set with SETF"
  `(symbolic if ,test ,then ,else))


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

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

Input: (defclause-sequence nil nil)

Output:
(defmacro defclause-sequence (element-name index-name
			      &key access-fn size-fn
			      element-type sequence-type
			      element-doc-string index-doc-string)
  "A simple way to define a simple FOR ... &sequence clause"
  ;; Package subtlety: the FOR should be in the same package as the
  ;; element-name or index-name.
  (let* ((seq-for (if element-name
		      (intern (symbol-name 'for) (symbol-package element-name))))
	 (seq-def (if element-name
		      `(defclause-driver (,seq-for var ,element-name seq
						   &sequence)
			 ,element-doc-string
			 (return-sequence-code
			  :element-var   var
			  :sequence      seq
			  :access-fn   ,access-fn
			  :size-fn     ,size-fn
			  :element-type  ,element-type
			  :sequence-type ,sequence-type))))
	 (inx-for (if index-name
		      (intern (symbol-name 'for) (symbol-package index-name))))
	 (inx-def (if index-name
		      `(defclause-driver (,inx-for var ,index-name seq
						   &sequence)
			 ,index-doc-string
			 (cond
			  (with-index
			   (clause-error
			    "WITH-INDEX should not be specified for this clause"))
			  (t
			   (setq with-index var)
			   (return-sequence-code
			    :sequence seq
			    :size-fn ,size-fn
			    :sequence-type ,sequence-type)))))))
    `(progn ,seq-def ,inx-def)))


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(with-html-string)

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

Input: (with-html-string)

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

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

Input: (set-dynamic nil (progn))

Output: (defmacro SET-DYNAMIC ...)


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

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

Input: (type common-lisp:nil)

Output: (defmacro TYPE ...)


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

Problem: Macro call that should be transformed by RTE-CASE

Input: (rte-case nil)

Output: (defmacro RTE-CASE ...)


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

Problem: Macro call that should be transformed by FMAP

Input: (fmap nil (progn))

Output:
(defmacro fmap (f thing)
  "Apply a pure function to the inner contents of some parsing operation, if the
parsing itself was successful."
  `(multiple-value-bind (res next) ,thing
     (if (failure? res)
         (fail next)
         (values (funcall ,f res) next))))


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

Problem: Macro call that should be transformed by MVLET*

Input:
(mvlet* nil
  :key
  nil)

Output:
(defmacro mvlet* ((&rest bindings) &body body &environment env)
  "Expand a series of nested `multiple-value-bind' forms.

`mvlet*' is similar in intent to Scheme’s `let-values', but with a
different and less parenthesis-intensive syntax. Each binding is a
list of

    (var var*... expr)

A simple example should suffice to show both the implementation and
the motivation:

    (defun uptime (seconds)
      (mvlet* ((minutes seconds (truncate seconds 60))
               (hours minutes (truncate minutes 60))
               (days hours (truncate hours 24)))
        (declare ((integer 0 *) days hours minutes seconds))
        (fmt \"~d day~:p, ~d hour~:p, ~d minute~:p, ~d second~:p\"
             days hours minutes seconds)))

Note that declarations work just like `let*'."
  (cond ((null bindings)
         `(locally ,@body))
        ((every #'simple-binding-p bindings)
         `(let* ,bindings ,@body))
        (t (multiple-value-bind (body decls)
               (parse-body body)
             (let* ((bindings (canonicalize-bindings bindings))
                    (mvbinds (member-if-not #'simple-binding-p bindings))
                    (simple-binds (ldiff bindings mvbinds)))
               (if simple-binds
                   (multiple-value-bind (local other)
                       (partition-declarations (mapcar #'car simple-binds) decls env)
                     `(let* ,simple-binds
                        ,@local
                        (mvlet* ,mvbinds
                          ,@other
                          ,@body)))
                   (let* ((vars (butlast (car bindings)))
                          (expr (lastcar (car bindings))))
                     (multiple-value-bind (local other)
                         (partition-declarations vars decls env)
                       `(multiple-value-bind ,vars
                            ,expr
                          ,@local
                          (mvlet* ,(cdr bindings)
                            ,@other
                            ,@body))))))))))


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

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

Input:
(defvar-unbound nil
  (progn))

Output:
(defmacro defvar-unbound (var &body (docstring))
  "Define VAR as if by `defvar' with no init form, and set DOCSTRING
as its documentation.

I believe the name comes from Edi Weitz."
  `(progn
     (defvar ,var)
     (setf (documentation ',var 'variable) ,docstring)
     ',var))


Instruction:
Define a macro that eliminates this repetitive pattern:
(on-conflict-do-update nil :key nil)

Issue: Macro call that should be transformed by ON-CONFLICT-DO-UPDATE

Input: (on-conflict-do-update nil :key nil)

Output:
(defmacro on-conflict-do-update (conflict-target update-set &optional where-condition)
  `(make-clause :on-conflict-do-update
                ,conflict-target
                ,update-set
                ,where-condition))


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

Problem: Macro call that should be transformed by GATHERING

Input:
(gathering nil
  nil)

Output: (defmacro GATHERING ...)


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

Issue: Macro call that should be transformed by DEFMETHOD

Input: (defmethod nil :key nil)

Output: (defmacro DEFMETHOD ...)


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

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

Input:
(compiler-macro-lambda nil
  nil)

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


Instruction:
Generate a defmacro form that transforms code like this:
(c-assert nil)

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

Input: (c-assert nil)

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


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

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

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

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

    (as <type> <expr>)

is equivalent to

    (the <type> (into <expr>))

and

    (as <type>)

is equivalent to

    (fn (expr) (the <type> (into expr))).

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

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


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

Problem: Macro call that should be transformed by DEFVAR

Input: (defvar nil)

Output: (defmacro DEFVAR ...)


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(without-symbol-access)

Write a macro that addresses: Macro call that should be transformed by WITHOUT-SYMBOL-ACCESS

Input: (without-symbol-access)

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


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

Problem: Macro call that should be transformed by UPDATE

Input: (update nil nil)

Output:
(defmacro update (place value-form)
  (etypecase place
    (symbol `(setf ,place ,value-form))
    (list
     (let ((result (gensym "RESULT"))
           (var (gensym "VAR")))
       (lambda-fiddle:with-destructured-lambda-list (:required req :optional opt :rest rest :body body :key key) place
         (let ((rest (or rest body)))
           `(let ((,result ,value-form))
              ;; Convert required into test and POP
              ,@(loop for var in req
                      do (assert (and (not (null var)) (symbolp var)))
                      collect `(if ,result
                                   (setf ,var (pop ,result))
                                   (error "Not enough arguments to satisfy lambda-list ~a." ',place)))
              ;; Convert &OPTIONAL into POP and default.
              ,@(loop for o in opt
                      for (var default) = (enlist o)
                      do (assert (and (not (null var)) (symbolp var)))
                      collect `(setf ,var (or (pop ,result) ,default)))
              ;; If we don't have &REST or &KEY, error if there are some elements left.
              ,@(when (and (not rest) (not (find '&key place)))
                  `((when ,result (error "Too many elements supplied to satisfy lambda-list ~a." ',place))))
              ;; Convert &REST by just setting it to the remainder.
              ,@(when rest `((setf ,rest ,result)))
              ;; Convert &KEY into GETF and default.
              ,@(loop for k in key
                      for (var default) = (enlist k)
                      do (assert (and (not (null var)) (symbolp var)))
                      collect `(setf ,var (or (getf ,result ,(intern (string var) :keyword)) ,default)))
              ;; If we have a non-empty &KEY list and don't have &ALLOW-OTHER-KEYS, check the keys.
              ,@(when (and key (not (find '&allow-other-keys place)))
                  `((loop for ,var in ,result by #'cddr
                          do (unless (find ,var ',(loop for k in key collect (intern (string k) :keyword)))
                               (error "Keyword argument ~s not found in lambda-list ~a."
                                      ,var ',place))))))))))))


Instruction:
Define a macro that eliminates this repetitive pattern:
(parse-conjunctive-clauses nil :key nil)

Issue: Macro call that should be transformed by PARSE-CONJUNCTIVE-CLAUSES

Input: (parse-conjunctive-clauses nil :key nil)

Output:
(defmacro parse-conjunctive-clauses (client region read-name-p &rest args)
  (with-unique-names (clauses next)
    `(prog (,clauses)
      ,next
        (push (do-parse-clause ,client ,region *index* ,read-name-p ,@args)
              ,clauses)
        (when (maybe-parse-token :keywords '(:and))
          (go ,next))
        (return (nreverse ,clauses)))))


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

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

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

Output:
(defmacro nest (cl:&rest items)
  "A syntactic convenience for function application. Transform

    (nest f g h x)

to

    (f (g (h x)))."
  (cl:assert (cl:<= 2 (cl:list-length items)))
  (cl:let ((last (cl:last items))
           (butlast (cl:butlast items)))
    (cl:reduce (cl:lambda (x acc)
                 (cl:list x acc))
               butlast :from-end cl:t :initial-value (cl:first last))))


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

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

Input:
(defun-advisable nil
    :key
  nil)

Output: (defmacro DEFUN-ADVISABLE ...)


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

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

Input:
(once-on nil
    nil)

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

Remove the handler after it fires the first time.

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


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

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

Input:
(some-<>> nil
  nil)

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


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

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

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

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


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

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

Input: (alet nil)

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

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

Input:
(mvlet nil
  (progn))

Output:
(defmacro mvlet ((&rest bindings) &body body)
  "Parallel (`let'-like) version of `mvlet*'."
  (cond ((null bindings)
         `(locally ,@body))
        ((null (rest bindings))
         (let* ((bindings (canonicalize-bindings bindings))
                (b (first bindings)))
           `(multiple-value-bind ,(butlast b) ,(lastcar b)
              ,@body)))
        ((every #'simple-binding-p bindings)
         `(let ,bindings
            ,@body))
        (t (let* ((bindings (canonicalize-bindings bindings))
                  (binds
                    (mapcar #'butlast bindings))
                  (exprs
                    (mapcar #'lastcar bindings))
                  (temp-binds
                    (loop for vars in binds
                          collect (mapcar #'string-gensym vars)))
                  (temp-bindings
                    (loop for temp-bind in temp-binds
                          for expr in exprs
                          collect (append temp-bind (list expr))))
                  (rebindings
                    (loop for vars in binds
                          for temp-vars in temp-binds
                          append (loop for var in vars
                                       for temp-var in temp-vars
                                       collect (list var temp-var)))))
             `(mvlet* ,temp-bindings
                (let ,rebindings
                  ,@body))))))


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

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

Input: (left nil nil)

Output:
(defmacro left (parser &rest parsers)
  "Combination of parsers yielding the result of the leftmost one."
  `(<* ,parser ,@parsers))


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

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

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

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


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

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

Input:
(with-boolean nil
  (progn))

Output:
(defmacro with-boolean ((&rest branches) &body body
                        &environment env)
  "Establishes a lexical environment in which it is possible to use
macroexpand-time branching. Within the lexical scope of
`with-boolean', it is possible to use `boolean-if', `boolean-when',
and `boolean-unless' to conditionalize whether some forms are included
at compilation time. (You may also use `:if', `:when', or `:unless'
for brevity.)
\
The first argument must be a list of symbols which name variables. This macro
will expand into a series of conditionals"
  (cond (*boolean-bypass*
         `(progn ,@body))
        (t (let ((all-branches (macroexpand-1 '%all-branches% env)))
             `(macrolet ((:if (cond then else)
                              (list 'boolean-if cond then else))
                         (:when (cond &body then)
                           (list* 'boolean-when cond then))
                         (:unless (cond &body then)
                           (list* 'boolean-unless cond then)))
                (locally
                    (declare #+sbcl (sb-ext:disable-package-locks
                                     %in-branching% %all-branches%)
                             #+sbcl (sb-ext:muffle-conditions
                                     sb-ext:code-deletion-note))
                  (symbol-macrolet ((%in-branching% t)
                                    (%all-branches% (,@branches ,@all-branches))
                                    (%true-branches% ()))
                    (locally (declare #+sbcl (sb-ext:enable-package-locks
                                              %in-branching% %all-branches%))
                      (%with-boolean ,branches ,@body)))))))))


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

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

Input: (char-ecase nil)

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