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

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

Input: (drelet nil)

Output: (defmacro DRELET ...)


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

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

Input: (defmacro-clause 'lol-gen::some-name)

Output:
(defmacro defmacro-clause (clause-template &body body)
  "Macro for defining iterate clauses (with DEFMACRO)."
  (define-clause 'defmacro clause-template body nil))


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

Problem: Macro call that should be transformed by LAMBDA

Input: (lambda () nil)

Output: (defmacro LAMBDA ...)


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

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

Input:
(collecting
  nil
  nil)

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


Instruction:
Define a macro that eliminates this repetitive pattern:
(matrix-ccase nil)

Issue: Macro call that should be transformed by MATRIX-CCASE

Input: (matrix-ccase nil)

Output: (defmacro MATRIX-CCASE ...)


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


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

Issue: Macro call that should be transformed by LRET*

Input:
(lret* nil
  :key
  nil)

Output:
(defmacro lret* ((&rest bindings) &body body)
  "Cf. `lret'."
  `(lret-aux let* ,bindings
     ,@body))


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

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

Input:
(cond-every
  nil
  (progn))

Output:
(defmacro cond-every (&body clauses)
  "Like `cond', but instead of stopping after the first clause that
succeeds, run all the clauses that succeed.

Return the value of the last successful clause.

If a clause begins with `cl:otherwise', it runs only if no preceding
form has succeeded.

Note that this does *not* do the same thing as a series of `when'
forms: `cond-every' evaluates *all* the tests *before* it evaluates
any of the forms.

From Zetalisp."
  (let* ((otherwise-clause (find 'otherwise clauses :key #'car))
         (test-clauses (remove otherwise-clause clauses))
         (temps (make-gensym-list (length test-clauses))))
    `(let* ,(loop for temp in temps
                  for (test . nil) in test-clauses
                  collect `(,temp ,test))
       ;; Work around Iterate bug. See
       ;; <https://gitlab.common-lisp.net/iterate/iterate/-/issues/11>.
       (if (or ,@temps)
           ,(with-gensyms (ret)
              `(let (,ret)
                 ,@(loop for temp in temps
                         for (nil . body) in test-clauses
                         collect `(when ,temp
                                    (setf ,ret
                                          ,(if (null body)
                                               temp
                                               `(progn ,@body)))))
                 ,ret))
           (progn ,@(rest otherwise-clause))))))


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

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

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

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


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

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

Input:
(with-rules nil
  (progn))

Output: (defmacro WITH-RULES ...)


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

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

Input: (removef nil :key nil)

Output: (defmacro REMOVEF ...)


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

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

Input: (lambda* nil)

Output: (defmacro LAMBDA* ...)


Instruction:
Generate a defmacro form that transforms code like this:
(ensure-transaction-with-isolation-level nil)

Pattern to recognize: Macro call that should be transformed by ENSURE-TRANSACTION-WITH-ISOLATION-LEVEL

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

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:
(coalton-codegen-types)

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

Input: (coalton-codegen-types)

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


Instruction:
Write a Common Lisp macro to handle this code pattern:
(with-unknown-first-class-functions-allowed
  nil
  nil)

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

Input:
(with-unknown-first-class-functions-allowed
  nil
  nil)

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


Instruction:
Write a Common Lisp macro to handle this code pattern:
;; Explicit continuation-passing is verbose
(defun fact-cps (n cont)
  (if (zerop n)
      (funcall cont 1)
      (fact-cps (- n 1)
                (lambda (x) (funcall cont (* n x))))))

;; Every function must take an explicit continuation parameter.
;; Every call must thread the continuation through.
;; Simple sequential code becomes deeply nested.

Problem: Manual continuation-passing style requires explicit continuation parameters and nested lambdas — want syntactic sugar for CPS

Input:
;; Explicit continuation-passing is verbose
(defun fact-cps (n cont)
  (if (zerop n)
      (funcall cont 1)
      (fact-cps (- n 1)
                (lambda (x) (funcall cont (* n x))))))

;; Every function must take an explicit continuation parameter.
;; Every call must thread the continuation through.
;; Simple sequential code becomes deeply nested.

Output:
(defmacro =lambda (parms &body body)
  `#'(lambda (*cont* ,@parms) ,@body))

(defmacro =defun (name parms &body body)
  (let ((f (intern (concatenate 'string
                                "=" (symbol-name name)))))
    `(progn
       (defmacro ,name ,parms
         `(,',f *cont* ,,@parms))
       (defun ,f (*cont* ,@parms) ,@body))))

(defmacro =bind (parms expr &body body)
  `(let ((*cont* #'(lambda ,parms ,@body))) ,expr))

(defmacro =values (&rest retvals)
  `(funcall *cont* ,@retvals))


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

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

Input: (with-unique-names nil)

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


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

Problem: Macro call that should be transformed by PCCASE

Input: (pccase nil nil)

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

   Example usage:

       CL-USER> (pccase '< 1
                  (0 (print \"Below zero\"))
                  (2 (print \"OK\")))
"
  (expand-predicate-case pred keyform clauses 'ccase))


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

Issue: Macro call that should be transformed by NECESSARILY?

Input:
(necessarily?
  'lol-gen::some-name)

Output: (defmacro NECESSARILY? ...)


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

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

Input:
(eval-and-compile
  nil)

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


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

Problem: Macro call that should be transformed by WITH-FOREIGN-OBJECTS

Input:
(with-foreign-objects nil
  :key
  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:
Define a macro that eliminates this repetitive pattern:
(join 'lol-gen::some-name)

Issue: Macro call that should be transformed by JOIN

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

Output:
(defmacro join (table &key (kind :inner) on using)
  `(make-clause :join ,(expand-op table)
                :kind ,kind
                ,@(if on
                      `(:on ,(if (and (listp on)
                                      (keywordp (car on)))
                                 (expand-op on)
                                 `,on))
                      nil)
                ,@(if using
                      `(:using ',using)
                      nil)))


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

Issue: Macro call that should be transformed by NCONCF

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

Output: (defmacro NCONCF ...)


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

Problem: Macro call that should be transformed by DEFMACRO+PS

Input:
(defmacro+ps nil
    :key
  nil)

Output: (defmacro DEFMACRO+PS ...)


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

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

Input:
(define-definition-resolver nil
    :key
  nil)

Output:
(defmacro define-definition-resolver (name args &body body)
  `(progn (setf (definition-resolver ',name)
                (lambda ,args ,@body))
          ',name))


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

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

Output: (defmacro ->* ...)


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

Problem: Macro call that should be transformed by DOC

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

Output: (defmacro DOC ...)


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

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

Input: (make-proxy nil nil)

Output:
(defmacro make-proxy (slot node-type &key (node-name 'item) (parent 'item))
  "Add proxy nodes to slot. Note: all uses in c-mera and cm-c implicitly assue that the node is called ITEM."
  (let ((val (gensym)))
    `(if (or (eql (find-class 'nodelist) (class-of (slot-value ,node-name ',slot))))
  	 (let ((,val (slot-value (slot-value ,node-name ',slot) 'nodes)))
  	   (setf (slot-value (slot-value ,node-name ',slot) 'nodes)
  		 (loop for i in ,val collect
  		      (make-instance ,node-type
				     :parent ,parent
  				     :proxy-subnode i
  				     :values '()
  				     :subnodes '(proxy-subnode)))))
  	 (let ((,val (slot-value ,node-name ',slot)))
  	   (if ,val
  	       (setf (slot-value ,node-name ',slot)
  		     (make-instance ,node-type
				    :parent ,parent
  				    :proxy-subnode ,val
  				    :values '()
  				    :subnodes '(proxy-subnode)))
  	       (setf (slot-value ,node-name ',slot)
  	       	     (make-instance ,node-type
				    :parent ,parent
  	       			    :proxy-subnode nil
  	       			    :values '()
  	       			    :subnodes '(proxy-subnode))))))))


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

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

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

Output: (defmacro EITHER ...)


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

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

Input:
(for nil
  (progn))

Output:
(defmacro for (&environment env bindings &body body)
  (let ((*environment* env))
    (multiple-value-bind (bind-init bind-forms bind-exit bind-post) (convert-bindings bindings)
      (multiple-value-bind (clause-init body-forms clause-exit) (convert-clauses body)
        `(with-interleaving
           ,@bind-init
           ,@clause-init
           (with-for-block ()
             (with-for-tagbody
                 (progn ,@bind-forms
                        ,@body-forms
                        ,@bind-post)
               (return-for
                ,@clause-exit
                ,@bind-exit))))))))


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

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

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

Output: (defmacro EXPORT-ACCESSORS ...)


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

Pattern to recognize: Macro call that should be transformed by DEFINE-SIMPLE-OBJECT-LOOKUP

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

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


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

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

Input: (var nil)

Output: (defmacro VAR ...)


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

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

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

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


Instruction:
Generate a defmacro form that transforms code like this:
;; Recursive factorial - stack overflow on large N in CL
;; (CL does not guarantee tail-call optimization)
(defun fact (n)
  (labels ((iter (n acc)
             (if (zerop n)
               acc
               (iter (- n 1) (* n acc)))))
    (iter n 1)))
;; (fact 1000000) => stack overflow on most implementations

Pattern to recognize: Need guaranteed tail-call elimination for recursive algorithms — CL doesn't mandate TCO

Input:
;; Recursive factorial - stack overflow on large N in CL
;; (CL does not guarantee tail-call optimization)
(defun fact (n)
  (labels ((iter (n acc)
             (if (zerop n)
               acc
               (iter (- n 1) (* n acc)))))
    (iter n 1)))
;; (fact 1000000) => stack overflow on most implementations

Output:
(defmacro! nlet-tail (n letargs &body body)
  (let ((gs (loop for i in letargs
               collect (gensym))))
    `(macrolet
         ((,n ,gs
            `(progn
               (psetq
                ,@(apply #'nconc
                         (mapcar
                          #'list
                          ',(mapcar #'car letargs)
                          (list ,@gs))))
               (go ,',g!n))))
       (block ,g!b
         (let ,letargs
           (tagbody
              ,g!n (return-from
                    ,g!b (progn ,@body))))))))


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

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

Input: (rem-bops nil :key nil)

Output: (defmacro REM-BOPS ...)


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

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

Input: (bind nil)

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

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

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

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


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(symbol-value-in-$instance nil nil)

Write a macro that addresses: Macro call that should be transformed by SYMBOL-VALUE-IN-$INSTANCE

Input: (symbol-value-in-$instance nil nil)

Output: (defmacro SYMBOL-VALUE-IN-$INSTANCE ...)


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

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

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

Output:
(defmacro etypecase-let ((var expr) &body cases)
  "Like (let ((VAR EXPR)) (etypecase VAR ...)), with VAR read-only."
  `(let1 ,var ,expr
     (etypecase ,var
       ,@cases)))


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

Problem: Macro call that should be transformed by WITH-VECTOR-DISPATCH

Input:
(with-vector-dispatch nil
    :key
  nil)

Output:
(defmacro with-vector-dispatch ((&rest types) var &body body)
  "Like `with-subtype-dispatch' with an overall type of `vector'."
  ;; Always specialize for simple vectors.
  `(with-subtype-dispatch vector (simple-vector ,@types) ,var
     ,@body))


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

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

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

Output:
(defmacro assert (datum cl:&optional (format-string "") cl:&rest format-data)
  "Signal an error unless `datum` is `True`.

If the assertion fails, the signaled error will apply the `format-data`
to the `format-string` via `cl:format` to produce an error message."
  ;; OPTIMIZE: lazily evaluate the FORMAT-DATA only when the assertion fails
  (cl:check-type format-string cl:string)
  (cl:let* ((datum-temp (cl:gensym "ASSERT-DATUM-"))
            (format-data-temps (alexandria:make-gensym-list (cl:length format-data)
                                                            "ASSERT-FORMAT-DATUM-")))
    `(let ((,datum-temp ,datum)
           ,@(cl:mapcar #'cl:list format-data-temps format-data))
       (progn
         (lisp (-> :any) (,datum-temp ,@format-data-temps)
           (cl:assert ,datum-temp ()
                      ,(cl:format cl:nil
                                  "Assertion ~a failed: ~a"
                                  datum format-string)
                      ,@format-data-temps))
         Unit))))


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

Problem: Macro call that should be transformed by SUMMING

Input: (summing)

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:
(unwrap-as common-lisp:nil (common-lisp:progn))

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

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

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

    (unwrap-as <type> <expr>)

is equivalent to

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

and

    (unwrap-as <type>)

is equivalent to

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

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

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


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

Problem: Macro call that should be transformed by SKIP

Input:
(skip nil
  :key
  nil)

Output:
(defmacro skip (desc &body tests)
  `(with-forced-status (:skipped ,@(if (listp desc) desc (list desc)))
     ,@tests))


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

Issue: Macro call that should be transformed by LOCAL

Input:
(local
  nil)

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:
Write a Common Lisp macro to handle this code pattern:
(define-module-extension 'lol-gen::some-name)

Problem: Macro call that should be transformed by DEFINE-MODULE-EXTENSION

Input: (define-module-extension 'lol-gen::some-name)

Output:
(defmacro define-module-extension ((module-identifier name) &body options)
  (let ((module (gensym "MODULE"))
        (name (string name)))
    `(eval-when (:compile-toplevel :load-toplevel :execute)
       (with-module (,module ,module-identifier)
         (pushnew ,name (module-storage ,module :extensions) :test #'string=)
         (pushnew ,(make-identifier name) (module-storage ,module :extensions) :test #'string=)
         ;; Add nicknames so the extension can be IN-PACKAGEd as if it
         ;; were a proper module.
         (extend-package ,module '((:nicknames
                                    ,(make-symbol name)
                                    ,(make-symbol (make-identifier name)))))
         (expand-module ,module ',options)
         ,module))))


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

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

Input: (dict-of nil nil)

Output: (defmacro DICT-OF ...)


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

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

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

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


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

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

Input:
(with-pp
  nil
  (progn))

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


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

Problem: Macro call that should be transformed by NCONCF

Input: (nconcf nil nil)

Output: (defmacro NCONCF ...)


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

Problem: Macro call that should be transformed by ORDER-BY

Input: (order-by nil)

Output:
(defmacro order-by (&rest expressions)
  `(make-clause :order-by ,@(expand-expression expressions)))


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

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

Input:
(ps-once-only nil
  (progn))

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


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

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

Input:
(with-properties nil
    nil)

Output: (defmacro WITH-PROPERTIES ...)


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

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

Input: (mk-part nil (progn))

Output:
(defmacro mk-part (md-name (md-class) &rest initargs)
  `(make-part ',md-name ',md-class ,@initargs
     :fm-parent (progn (assert self () "mk-part null self for parent") self)))


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

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

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

Output: (defmacro ETYPECASE ...)


Instruction:
Write a Common Lisp macro to handle this code pattern:
;; Common pattern: read a value, apply a function, store back
(let ((old (car place)))
  (setf (car place) (1+ old)))

;; Or with a more complex place:
(let ((old (getf plist :count)))
  (setf (getf plist :count) (* old 2)))

;; Every operation needs manual read-modify-write boilerplate

Problem: Read-modify-write on places requires manual let + access + setf — want a single operator that applies any function to a place

Input:
;; Common pattern: read a value, apply a function, store back
(let ((old (car place)))
  (setf (car place) (1+ old)))

;; Or with a more complex place:
(let ((old (getf plist :count)))
  (setf (getf plist :count) (* old 2)))

;; Every operation needs manual read-modify-write boilerplate

Output:
(defmacro _f (op place &rest args)
  (multiple-value-bind (vars forms var set access)
                       (get-setf-method place)
    `(let* (,@(mapcar #'list vars forms)
            (,(car var) (,op ,access ,@args)))
       ,set)))


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

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

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

Output:
(defmacro ensure-transaction (&body body)
  "Ensures that body is executed within a transaction, but does not begin a new
transaction if one is already in progress."
  `(call-with-ensured-transaction (lambda () ,@body)))


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
;; format with constant control strings interprets directives at runtime
(format nil "Value: ~a, Name: ~a" val name)
;; Every call: parse the ~a directives, resolve them, dispatch formatting
;; The format string is known at compile time but still interpreted at runtime

Write a macro that addresses: format with compile-time-constant control strings wastes time interpreting directives at runtime — want compile-time compilation of format strings

Input:
;; format with constant control strings interprets directives at runtime
(format nil "Value: ~a, Name: ~a" val name)
;; Every call: parse the ~a directives, resolve them, dispatch formatting
;; The format string is known at compile time but still interpreted at runtime

Output:
(defun fformat (&rest all)
  (apply #'format all))

(define-compiler-macro fformat
                       (&whole form
                        stream fmt &rest args)
  (if (constantp fmt)
    (if stream
      `(funcall (formatter ,fmt)
         ,stream ,@args)
      (let ((g!stream (gensym "stream")))
        `(with-output-to-string (,g!stream)
           (funcall (formatter ,fmt)
             ,g!stream ,@args))))
    form))


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

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

Input: (fmap nil nil)

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:
Generate a defmacro form that transforms code like this:
(eko-if nil (progn))

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

Input: (eko-if nil (progn))

Output:
(defmacro eko-if ((&rest trcargs) &rest body)
  (let ((result (gensym)))
     `(let ((,result ,@body))
         (when ,result
           (trc ,(car trcargs) :res ,result ,@(cdr trcargs)))
         ,result)))


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(enable-quasi-quoted-bivalent-to-bivalent-emitting-form-syntax
 'lol-gen::some-name)

Write a macro that addresses: Macro call that should be transformed by ENABLE-QUASI-QUOTED-BIVALENT-TO-BIVALENT-EMITTING-FORM-SYNTAX

Input:
(enable-quasi-quoted-bivalent-to-bivalent-emitting-form-syntax
 'lol-gen::some-name)

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


Instruction:
Write a Common Lisp macro to handle this code pattern:
(rem-plist-val! nil nil)

Problem: Macro call that should be transformed by REM-PLIST-VAL!

Input: (rem-plist-val! nil nil)

Output:
(defmacro rem-plist-val! (id place &key (test '(default-test)) (key '(default-key)))
  `(setf ,place
    (rem-plist-val ,id ,place :test ,test :key ,key)))


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

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

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

Output: (defmacro FOR-EFFECTS ...)


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

Problem: Macro call that should be transformed by INEXT-NOEXIT

Input: (inext-noexit 'lol-gen::some-name)

Output: (defmacro INEXT-NOEXIT ...)


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

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

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

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


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

Problem: Macro call that should be transformed by NECESSARILY?

Input:
(necessarily?
  nil
  (progn))

Output: (defmacro NECESSARILY? ...)


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

Write a macro that addresses: Macro call that should be transformed by DO-MACROS-IN-LEXENV

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

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


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

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

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

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


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

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

Input:
(dowhile-it nil
  :key
  nil)

Output:
(defmacro dowhile-it (test &body body)
  "Like DOWHILE. IT is bound to TEST."
  `(do ((it ,test ,test))
       ((not it))
     ,@body))


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

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

Input: (defcell nil nil)

Output:
(defmacro defcell (name value-form &environment env)
  "Define a global cell identified by NAME.

This macro defines a cell identified by NAME with its value computed
by VALUE-FORM. The value of the cell can be referenced by the symbol
NAME following the DEFCELL form.

If VALUE-FORM is a constant, by CONSTANTP, a mutable cell is defined
which can have its value set directly using SETF or SETQ on the symbol
NAME.

If VALUE-FORM is not a constant a computed cell is created. A computed
cell may reference one or more argument cells in VALUE-FORM or a
function called during the evaluation of VALUE-FORM.  When the values
of any of the argument cells change, the value of the computed cell is
recomputed by evaluating VALUE-FORM again. The referenced argument
cells are determined automatically when the VALUE-FORM is evaluated.

This macro creates a cell definition that is visible globally to all
forms unless it is lexically shadowed by a definition with the same
NAME using CELL-LET. Note that despite being visible globally, the
cell definition is still lexically scoped and not dynamically scoped
like global variables defined with DEFVAR or DEFPARAMETER."

  (if (constantp value-form env)
      `(define-mutable-cell% ,name ,value-form)
      `(define-computed-cell% ,name ,value-form)))


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

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

Input: (->> nil :key nil)

Output: (defmacro ->> ...)


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

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

Input:
(with-gensyms nil
  (progn))

Output:
(defmacro with-gensyms ((&rest names) &body body)
  "Provide gensyms for given NAMES."
  `(let ,(loop :for n :in names :collect `(,n (gensym)))
     ,@body))


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

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

Input: (is-false nil (progn))

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

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

Input: (js nil nil)

Output: (defmacro JS ...)


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

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

Input:
(any-of nil
  :key
  nil)

Output: (defmacro ANY-OF ...)


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

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

Input: (set-bop nil :key nil)

Output: (defmacro SET-BOP ...)


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

Problem: Macro call that should be transformed by DEFPROXY

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

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

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

Input: (defparameter* nil (progn))

Output: (defmacro DEFPARAMETER* ...)


Instruction:
Define a macro that eliminates this repetitive pattern:
(pprint-coalton-codegen)

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

Input: (pprint-coalton-codegen)

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


Instruction:
Define a macro that eliminates this repetitive pattern:
(ltbdd-with-new-hash nil)

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

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

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


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

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

Input:
(max-of nil
  :key
  nil)

Output: (defmacro MAX-OF ...)


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

Problem: Macro call that should be transformed by DEFINE-DIRECT-BINDING

Input:
(define-direct-binding nil
    (progn))

Output:
(defmacro define-direct-binding (name args &body body)
  (let ((env (or (lambda-fiddle:environment-lambda-var args) (gensym "ENVIRONMENT"))))
    `(progn (setf (binding ',name)
                  (lambda ,(lambda-fiddle:remove-environment-part args)
                    (let ((,env *environment*))
                      (declare (ignorable ,env))
                      ,@body)))
            ',name)))


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

What needs to change: Macro call that should be transformed by DO-FUNCTIONS-IN-LEXENV

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

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


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

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

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

Output:
(defmacro alambda (lambda-list &body body)
  "Like LAMBDA, except that SELF is bound to the resulting function (via LABELS)
within BODY."
  `(labels ((self ,lambda-list ,@body))
     #'self))


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

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

Input: (some-<> nil)

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


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

Issue: Macro call that should be transformed by SHRINKF

Input: (shrinkf nil (progn))

Output: (defmacro SHRINKF ...)


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

Issue: Macro call that should be transformed by M

Input:
(m nil
  (progn))

Output: (defmacro M ...)


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

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

Input:
(cond->
  nil
  nil)

Output: (defmacro COND-> ...)


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

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

Input: (is-condition nil :key nil)

Output:
(defmacro is-condition (form condition &optional desc)
  (with-gensyms (error duration)
    `(with-duration ((,duration ,error) (handler-case ,form
                                          (condition (,error) ,error)))
       (test ,error
             ,(if (and (listp condition) (eq 'quote (car condition)))
                  condition
                  `(quote ,condition))
             ,desc
             :duration ,duration
             :got-form ',form
             :test-fn #'typep
             :report-expected-label "raise a condition"))))


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

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

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

Output: (defmacro F0 ...)


Instruction:
Define a macro that eliminates this repetitive pattern:
(c-abs nil)

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

Input: (c-abs nil)

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


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

What needs to change: Macro call that should be transformed by WITH-SUBSTITUTE-PRINTED-REPRESENTATION-RESTART

Input: (with-substitute-printed-representation-restart 'lol-gen::some-name)

Output:
(defmacro with-substitute-printed-representation-restart ((object stream)
                                                          &body body)
  "Establish a SUBSTITUTE-PRINTED-REPRESENTATION restart for OBJECT
and execute BODY."
  `(restart-case (progn ,@body)
     (substitute-printed-representation ()
       (let ((repr (with-output-to-string (s)
                     (write ,object :stream s :escape nil)
                     nil)))
         (write-json-string repr ,stream)))))


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

Problem: Macro call that should be transformed by IDENTIFIER

Input: (identifier nil)

Output: (defmacro IDENTIFIER ...)


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

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

Input: (defobject nil)

Output: (defmacro DEFOBJECT ...)


Instruction:
Define a macro that eliminates this repetitive pattern:
(re-setf nil nil)

Issue: Macro call that should be transformed by RE-SETF

Input: (re-setf nil nil)

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


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

Problem: Macro call that should be transformed by DEFINE-HOOK-TYPE

Input: (define-hook-type nil nil)

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

  (function (string) (values integer t))

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


Instruction:
Define a macro that eliminates this repetitive pattern:
(as->* nil :key nil)

Issue: Macro call that should be transformed by AS->*

Input: (as->* nil :key nil)

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


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

Problem: Macro call that should be transformed by ADOWHILE

Input:
(adowhile nil
  nil)

Output: (defmacro ADOWHILE ...)


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

Issue: Macro call that should be transformed by VAR

Input: (var nil :key nil)

Output: (defmacro VAR ...)


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

Issue: Macro call that should be transformed by DIG

Input: (dig nil)

Output: (defmacro DIG ...)


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

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

Input:
(listcase nil
  (progn))

Output:
(defmacro listcase (list &body cases)
  "A typecase-like macro to destinguish between 3 possible kinds of LIST:
   simple lists, alists, and dlists.
   Evaluates the appropriate key-form depending on the kind:
   ALIST, DLIST or simple list (T)."
  (once-only (list)
    `(if (consp (first ,list))
         (cond ((consp (second ,list))
                (progn ,@(assoc1 'alist cases)))
               ((second ,list)
                (progn ,@(assoc1 'dlist cases)))
               (t
                (progn ,@(assoc1 't cases))))
         (progn ,@(assoc1 't cases)))))


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

Pattern to recognize: Macro call that should be transformed by WITH-WALKER-HANDLER-LEXICAL-ENVIRONMENT

Input:
(with-walker-handler-lexical-environment
  'lol-gen::some-name)

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


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

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

Input: (defmethod nil nil)

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

        (declare (ignore qualifiers))

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

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

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

                 ,method)))))

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


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

Problem: Macro call that should be transformed by ACOND

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

Output: (defmacro ACOND ...)


Instruction:
Generate a defmacro form that transforms code like this:
(with-unknown-first-class-functions-allowed)

Pattern to recognize: Macro call that should be transformed by WITH-UNKNOWN-FIRST-CLASS-FUNCTIONS-ALLOWED

Input: (with-unknown-first-class-functions-allowed)

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


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

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

Input: (with-rules nil)

Output: (defmacro WITH-RULES ...)


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

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

Input: (collect-ignore nil)

Output: (defmacro COLLECT-IGNORE ...)


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

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

Input: (do () (progn))

Output: (defmacro DO ...)


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

Pattern to recognize: Macro call that should be transformed by REMOVE-FROM-PLISTF

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

Output: (defmacro REMOVE-FROM-PLISTF ...)


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

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

Input: (define-symbol-macro nil nil)

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


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

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

Input:
(with-live-scope
  nil
  :key
  nil)

Output:
(defmacro with-live-scope (&body body)
  "Stop all live blocks defined in BODY on exiting the form.

All live blocks, defined using LIVE, are stopped when exiting the
dynamic extent defined by this form.

Multiple WITH-LIVE-SCOPE forms can be nested, in which case each form
stops the live blocks defined immediately within it."

  (with-gensyms (stoppers forms global-live)
    `(let ((,stoppers nil))
       (macrolet ((,global-live (&body ,forms)
                    (macroexpand `(live ,@,forms)))

                  (live (&body ,forms)
                    `(push (,',global-live ,@,forms) ,',stoppers)))
         (unwind-protect (progn ,@body)
           (foreach #'funcall ,stoppers))))))


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

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

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

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

Input: (undefreply nil)

Output: (defmacro UNDEFREPLY ...)


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

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

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

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


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

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

Input: (deletef nil nil)

Output: (defmacro DELETEF ...)


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

Problem: Macro call that should be transformed by DEFINE-FOREIGN-TYPE

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

Output:
(defmacro define-foreign-type (name supers slots &rest options)
  (multiple-value-bind (new-options simple-parser actual-type initargs)
      (let ((keywords '(:simple-parser :actual-type :default-initargs)))
        (apply #'values
               (remove-if (lambda (opt) (member (car opt) keywords)) options)
               (mapcar (lambda (kw) (cdr (assoc kw options))) keywords)))
    `(eval-when (:compile-toplevel :load-toplevel :execute)
       (defclass ,name ,(or supers '(enhanced-foreign-type))
         ,slots
         (:default-initargs ,@(when actual-type `(:actual-type ',actual-type))
             ,@initargs)
         ,@new-options)
       ,(when simple-parser
          `(define-parse-method ,(car simple-parser) (&rest args)
             (apply #'make-instance ',name args)))
       ',name)))


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

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

Input: (fm-otherv? nil :key nil)

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


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

Issue: Macro call that should be transformed by FIELDS

Input: (fields nil)

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


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

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

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

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


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

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

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

Output: (defmacro MATRIX-ETYPECASE ...)


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

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

Input: (ccase nil (progn))

Output: (defmacro CCASE ...)


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(enable-quasi-quoted-string-to-binary-emitting-form-syntax nil)

Write a macro that addresses: Macro call that should be transformed by ENABLE-QUASI-QUOTED-STRING-TO-BINARY-EMITTING-FORM-SYNTAX

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

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


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

Issue: Macro call that should be transformed by RIGHT

Input: (right nil)

Output:
(defmacro right (parser &rest parsers)
  "Combination of parsers yielding the result of the rightmost one."
  `(*> ,parser ,@parsers))


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(disable-dot-syntax)

Write a macro that addresses: Macro call that should be transformed by DISABLE-DOT-SYNTAX

Input: (disable-dot-syntax)

Output:
(defmacro disable-dot-syntax ()
  "Restore readtable which was active before last call to If there was no such call, the standard
readtable is used."
  `(eval-when (:compile-toplevel :load-toplevel :execute)
    (%disable-dot-syntax)))


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

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

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

Output: (defmacro MATRIX-CASE ...)


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

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

Input:
(iterate
  nil
  nil)

Output:
(defmacro iterate (&body body)
  "Jonathan Amsterdam's powerful iteration facility"
  `(iter .,body))


Instruction:
Generate a defmacro form that transforms code like this:
(push-end-new nil (progn))

Pattern to recognize: Macro call that should be transformed by PUSH-END-NEW

Input: (push-end-new nil (progn))

Output:
(defmacro push-end-new (item place
                        &rest kwargs
                        &key key test test-not
                        &environment env)
  "Pushes ITEM to the end of place (like `push-end') but only if it not already a member of PLACE (like `pushnew').

For the use of KEY, TEST, and TEST-NOT, see `pushnew'."
  (declare (ignore key test test-not))
  (once-only (item)
    (multiple-value-bind (dummies vals temps setter getter)
        (get-setf-expansion place env)
      (when (rest temps) (error "Invalid place for push-end"))
      (let ((temp (car temps)))
        `(let* (,@(mapcar #'list dummies vals)
                (,temp ,getter))
           (unless (member ,item ,temp ,@kwargs)
             (setf ,temp (nconc1 ,temp ,item)))
           ,setter)))))


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

Pattern to recognize: Macro call that should be transformed by SPECIAL-SYMBOL-REPROGV

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

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


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

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

Input: (with-yield)

Output: (defmacro WITH-YIELD ...)


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

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

Input: (shift-incf nil (progn))

Output: (defmacro SHIFT-INCF ...)


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

Problem: Macro call that should be transformed by DEFTABLE

Input:
(deftable nil
  :key
  nil)

Output:
(defmacro deftable (name &body definitions)
  "Define a table. name can be either a symbol or a (symbol string) list. In the
first case, the table name is derived from the symbol by S-SQL's rules, in the
second case, the name is given explicitly. The body of definitions can contain
anything that evaluates to a string, as well as S-SQL expressions. In this body,
the variables *table-name* and *table-symbol* are bound to the relevant values.
Note that the evaluation of the definition is ordered, so you will generally
want to create your table first and then define indices on it."
  (multiple-value-bind (symbol name)
      (if (consp name) (values-list name) (values name (to-sql-name name nil)))
    (flet ((check-s-sql (form)
             (if (and (consp form) (keywordp (car form))) (list 'sql form) form)))
      `(add-table-definition
        ',symbol
        (lambda ()
          (let ((*table-name* ,name) (*table-symbol* ',symbol))
            (dolist (stat (list ,@(mapcar #'check-s-sql definitions)))
              (execute stat))))))))


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

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

Input:
(c?1
  nil
  :key
  nil)

Output:
(defmacro c?1 (&body body)
  `(c?once ,@body))


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

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

Input:
(dynamic-extent common-lisp:nil
  common-lisp:nil)

Output: (defmacro DYNAMIC-EXTENT ...)


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

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

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

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


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

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

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

Output: (defmacro EXPORT-CLASS ...)


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

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

Input:
(cond-it
  nil)

Output:
(defmacro cond-it (&body body)
  "Like COND. IT is bound to the passed COND test."
  `(let (it)
     (cond
       ,@(mapcar (lambda (clause)
                   `((setf it ,(car clause)) ,@(cdr clause)))
                 ;; uses the fact, that SETF returns the value set
                 body))))


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

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

Input:
(ematch nil
  nil)

Output:
(defmacro ematch (arg &body clauses)
  "Same as MATCH, except MATCH-ERROR will be raised if not matched."
  (once-only (arg)
    (let ((else `(error 'match-error
                        :values (list ,arg)
                        :patterns ',(mapcar (lambda (c) (list (car c))) clauses))))
      (compile-match-1 arg clauses else))))


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

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

Input: (ap nil nil)

Output:
(defmacro ap (f parser &rest parsers)
  "Run many parsers that must all succeed, and apply their success values to a
given lambda. More memory-efficient than the combination of `<*>' and `fmap'."
  (let ((offset (gensym "ap-OFFSET"))
        (final  (gensym "ap-FINAL")))
    `(lambda (,offset)
       ,(labels ((recurse (ps rs i)
                   (if (null ps)
                       (let ((ordered (nreverse rs)))
                         ;; NOTE: 2025-10-20 This final check allows the user to
                         ;; yield `:fail' from within the passed lambda as well.
                         ;; It will be detected here and the failure offset will
                         ;; be set to the original offset, not the last one it
                         ;; got to. Overall this improves error reporting, as
                         ;; there was already nothing preventing the user from
                         ;; yielding `:fail' anyway.
                         `(let ((,final (funcall ,f ,@ordered)))
                            (if (failure? ,final)
                                (fail ,offset)
                                (values ,final ,i))))
                       (let ((res  (gensym "ap-RES"))
                             (next (gensym "ap-NEXT")))
                         `(multiple-value-bind (,res ,next) (funcall ,(car ps) ,i)
                            (if (failure? ,res)
                                (fail ,next)
                                ,(recurse (cdr ps) (cons res rs) next)))))))
          (recurse (cons parser parsers) '() offset)))))


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

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

Input: (->> nil (progn))

Output: (defmacro ->> ...)


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 (arg &body clauses)
  "Matches ARG with CLAUSES. CLAUSES is a list of the form of (PATTERN
. BODY) where PATTERN is a pattern specifier and BODY is an implicit
progn. If ARG matches some PATTERN, `match` then evaluates
the corresponding BODY and returns the evaluated value.  If no pattern matches,
then returns NIL.

Evaluating a form (FAIL) in the clause body causes the latest pattern
matching to fail. For example,

    (match 1
      (x (if (eql x 1)
             (fail)
             x))
      (_ 'ok))

returns OK, because the form (FAIL) in the first clause is
evaluated.

If BODY starts with the symbols WHEN or UNLESS, then the next form
will be used to introduce (FAIL). That is,

    (match list ((list x) when (oddp x) x))
    (match list ((list x) unless (evenp x) x))

will be translated to

    (match list ((list x) (if (oddp x) x (fail))))
    (match list ((list x) (if (evenp x) (fail) x)))

Examples:

    (match 1 (1 1))
    => 1
    (match 1 (2 2))
    => 2
    (match 1 (x x))
    => 1
    (match (list 1 2 3)
      (list x y z) (+ x y z))
    => 6"
  (compile-match-1 arg clauses nil))


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

Issue: Macro call that should be transformed by SUMMING

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

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

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

Input:
(v-defun nil
    :key
  nil)

Output:
(defmacro v-defun (name args &body body)
  `(define-vari-function ,name ,args ,@body))


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

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

Input:
(ecase-using nil
    :key
  nil)

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:
(^fm-next-sib nil)

Issue: Macro call that should be transformed by ^FM-NEXT-SIB

Input: (^fm-next-sib nil)

Output:
(defmacro ^fm-next-sib (&optional (self 'self))
     (let ((s (gensym)))
        `(let ((,s ,self))
             (car (cdr (member ,s (kids (fm-parent ,s))))))))


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

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

Input: (is-error nil (progn))

Output: (defmacro IS-ERROR ...)


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

Issue: Macro call that should be transformed by NOTINLINE

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

Output: (defmacro NOTINLINE ...)


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

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

Input:
(c-lambda
  nil
  nil)

Output:
(defmacro c-lambda (&body body)
  `(c-lambda-var (slot-c) ,@body))


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

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

Input: (sort-values nil (progn))

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

Equivalent to

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

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


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

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

Input: (setypecase nil)

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


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

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

Input: (collect-product nil)

Output: (defmacro COLLECT-PRODUCT ...)


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

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

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

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

Input: (lambda () :key nil)

Output: (defmacro LAMBDA ...)


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

Problem: Macro call that should be transformed by GLOBAL

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

Output: (defmacro GLOBAL ...)


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

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

Input: (make-kid nil)

Output:
(defmacro make-kid (class &rest ia)
  (with-gensyms (c)
    `(let ((,c ,class))
       (make-instance ,c
         ,@ia
         :fm-parent (progn (assert self () "make-kid: self nil making ~a" ,c)
                      self)))))


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

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

Input: (in-compile-time nil)

Output: (defmacro IN-COMPILE-TIME ...)


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

Problem: Macro call that should be transformed by DEFINE-DAO-CLASS

Input: (define-dao-class nil :key nil)

Output:
(defmacro define-dao-class (name direct-superclasses direct-slots &rest options)
  "Like defclass except two postmodern specific changes:
1. The dao-class metaclass options is automatically added.
2. If second value in a slot is not a keyword, it is assumed to be col-type.

Example:
(define-dao-class id-class ()
  ((id integer :initarg :id :accessor test-id)
   (email :col-type text :initarg :email :accessor email))
  (:keys id))"
  (flet ((expand-slot (rest)
	   (let ((second
		   (second rest)))
	     (if (keywordp second)
		 rest
		 (cons (first rest)
		       (append (list :col-type second)
			       (cddr rest)))))))
    (list* 'defclass name direct-superclasses
	   (mapcar #'expand-slot direct-slots)
	   (list :metaclass 'dao-class)
	   options)))


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

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

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

Output:
(defmacro with-cc (id &body body)
  `(with-integrity (:change ,id)
     ,@body))


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(define-alternate-type-name nil nil)

What needs to change: Macro call that should be transformed by DEFINE-ALTERNATE-TYPE-NAME

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

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


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

Issue: Macro call that should be transformed by DEFGENERIC

Input: (defgeneric nil (progn))

Output: (defmacro DEFGENERIC ...)


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

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

Input: (collect-or nil)

Output: (defmacro COLLECT-OR ...)


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

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

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

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:
(export)

Issue: Macro call that should be transformed by EXPORT

Input: (export)

Output: (defmacro EXPORT ...)


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

Issue: Macro call that should be transformed by IGNORING

Input:
(ignoring nil
  nil)

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


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

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

Input: (cond)

Output: (defmacro COND ...)


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

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

Input:
(is-every nil
  :key
  nil)

Output:
(defmacro is-every (predicate &body clauses)
  "The input is either a list of lists, or a list of pairs. Generates (is (,predicate ,expr ,value))
   for each pair of elements or (is (,predicate ,expr ,value) ,@reason) for each list."
  `(progn
     ,@(if (every #'consp clauses)
           (loop for (expected actual . reason) in clauses
                 collect `(is (,predicate ,expected ,actual) ,@reason))
           (progn
             (assert (evenp (list-length clauses)))
             (loop for (expr value) on clauses by #'cddr
                   collect `(is (,predicate ,expr ,value)))))))


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

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

Input:
(define-train nil
    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:
Write a Common Lisp macro to handle this code pattern:
(match common-lisp:nil)

Problem: Macro call that should be transformed by MATCH

Input: (match common-lisp:nil)

Output:
(defmacro match (what &body clauses)
  #.+match-doc+
  `(match2 ,what
     ,@clauses
     (_ nil)))


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

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

Input:
(eval-always
  nil
  (progn))

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

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

Input:
(c-formula nil
  (progn))

Output:
(defmacro c-formula ((&rest keys &key lazy &allow-other-keys) &body forms)
  (assert (member lazy '(nil t :once-asked :until-asked :always)))
  `(make-c-dependent
    :code ',forms
    :value-state :unevaluated
    :rule (c-lambda ,@forms)
    ,@keys))


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

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

Input: (fields nil nil)

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


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

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

Input: (right-join nil)

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


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

What needs to change: Macro call that should be transformed by TRANSLATION-FORMS-FOR-CLASS

Input: (translation-forms-for-class nil (progn))

Output:
(defmacro translation-forms-for-class (class type-class)
  "Make forms for translation of foreign structures to and from a standard class.  The class slots are assumed to have the same name as the foreign structure."
  ;; Possible improvement: optional argument to map structure slot names to/from class slot names.
  `(progn
     (defmethod translate-from-foreign (pointer (type ,type-class))
       ;; Make the instance from the plist
       (apply 'make-instance ',class (call-next-method)))
     (defmethod translate-into-foreign-memory ((object ,class) (type ,type-class) pointer)
       (call-next-method
        ;; Translate into a plist and call the general method
        (loop for slot being the hash-value of (structure-slots type)
              for name = (slot-name slot)
              append (list slot-name (slot-value object slot-name)))
        type
        pointer))))


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

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

Input: (ensure-gethash nil (progn))

Output:
(defmacro ensure-gethash (key hash-table &optional default)
  "Like GETHASH, but if KEY is not found in the HASH-TABLE saves the DEFAULT
under key before returning it. Secondary return value is true if key was
already in the table."
  (once-only (key hash-table)
    (with-unique-names (value presentp)
      `(multiple-value-bind (,value ,presentp) (gethash ,key ,hash-table)
         (if ,presentp
             (values ,value ,presentp)
             (values (setf (gethash ,key ,hash-table) ,default) nil))))))


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

Problem: Macro call that should be transformed by FM-OTHERV?

Input: (fm-otherv? nil (progn))

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


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

Pattern to recognize: Macro call that should be transformed by MAKE-NAME-TRANSFORMER

Input: (make-name-transformer nil :key nil)

Output: (defmacro MAKE-NAME-TRANSFORMER ...)


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

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

Input: (fail-compile nil :key nil)

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


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

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

Input: (js nil (progn))

Output: (defmacro JS ...)


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

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

Input:
(awhen nil
  :key
  nil)

Output:
(defmacro awhen (test &body body)
  "Like WHEN, except binds the result of the test to IT (via LET) for the scope
of the body."
  `(anaphoric when ,test ,@body))


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

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

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

Output: (defmacro TYPE ...)


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

Problem: Macro call that should be transformed by FALSE

Input: (false nil)

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:
Write a Common Lisp macro to handle this code pattern:
(next-in nil (progn))

Problem: Macro call that should be transformed by NEXT-IN

Input: (next-in nil (progn))

Output: (defmacro NEXT-IN ...)


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

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

Input:
(with-transaction nil
  :key
  nil)

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


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

Problem: Macro call that should be transformed by RETURNING

Input: (returning)

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


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

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

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

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


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

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

Input:
(unless-match common-lisp:nil
    common-lisp:nil)

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


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

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

Input:
(with-object nil
  nil)

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

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

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

Output:
(defmacro with-module ((var &optional (module var)) &body body)
  `(let ((,var (module ,module)))
     ,@body))


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

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

Input: (with-shuffling)

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

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

Input:
(with-yield
  nil
  (progn))

Output: (defmacro WITH-YIELD ...)


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

Issue: Macro call that should be transformed by UNLESS

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

Output: (defmacro UNLESS ...)


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

Problem: Macro call that should be transformed by DRELET*

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

Output: (defmacro DRELET* ...)


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

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

Input:
(skip-on nil
    :key
  nil)

Output:
(defmacro skip-on (features desc &body tests)
  (let ((thunk (gensym "THUNK")))
    `(flet ((,thunk ()
              ,@tests))
       (if (featurep '(or ,@features))
           (with-forced-status (:skipped ,@(if (listp desc) desc (list desc)))
             (,thunk))
           (,thunk)))))


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

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

Input: (-> nil nil)

Output:
(defmacro -> (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:
(collect-fn nil :key nil)

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

Input: (collect-fn nil :key nil)

Output: (defmacro COLLECT-FN ...)