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

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

Input:
(with-tokens nil
  :key
  nil)

Output:
(defmacro with-tokens (tokens &body body)
  `(let ((*tokens* ,tokens)
         (*toplevel* nil))
     (trivial-with-current-source-form:with-current-source-form (*tokens*)
       ,@body)))


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

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

Input: (fm! nil)

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


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

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

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

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


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

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

Input:
(with-type-dispatch nil
    nil)

Output:
(defmacro with-type-dispatch ((&rest types) var &body body
                              &environment env)
  "A macro for writing fast sequence functions (among other things).

In the simplest case, this macro produces one copy of BODY for each
type in TYPES, with the appropriate declarations to induce your Lisp
to optimize that version of BODY for the appropriate type.

Say VAR is a string. With this macro, you can trivially emit optimized
code for the different kinds of string that VAR might be. And
then (ideally) instead of getting code that dispatches on the type of
VAR every time you call `aref', you get code that dispatches on the
type of VAR once, and then uses the appropriately specialized
accessors. (But see `with-string-dispatch'.)

But that's the simplest case. Using `with-type-dispatch' also provides
*transparent portability*. It examines TYPES to deduplicate types that
are not distinct on the current Lisp, or that are shadowed by other
provided types. And the expansion strategy may differ from Lisp to
Lisp: ideally, you should not have to pay for good performance on
Lisps with type inference with pointless code bloat on other Lisps.

There is an additional benefit for vector types. Around each version
of BODY, the definition of `vref' is shadowed to expand into an
appropriate accessor. E.g., within a version of BODY where VAR is
known to be a `simple-string', `vref' expands into `schar'.

Using `vref' instead of `aref' is obviously useful on Lisps that do
not do type inference, but even on Lisps with type inference it can
speed compilation times (compiling `aref' is relatively slow on SBCL).

Within `with-type-dispatch', VAR should be regarded as read-only.

Note that `with-type-dispatch' is intended to be used around
relatively expensive code, particularly loops. For simpler code, the
gains from specialized compilation may not justify the overhead of the
initial dispatch and the increased code size.

Note also that `with-type-dispatch' is relatively low level. You may
want to use one of the other macros in the same family, such as
`with-subtype-dispatch', `with-string-dispatch', or so forth.

The design and implementation of `with-type-dispatch' is based on a
few sources. It replaces a similar macro formerly included in
Serapeum, `with-templated-body'. One possible expansion is based on
the `string-dispatch' macro used internally in SBCL. But most of the
credit should go to the paper \"Fast, Maintable, and Portable Sequence
Functions\", by Irène Durand and Robert Strandh."
  `(locally (declare #+sbcl (sb-ext:muffle-conditions sb-ext:code-deletion-note))
     ,(let* ((types (simplify-subtypes types))
             (var-type (variable-type var env))
             ;; If the var has a declared type, remove excluded types.
             (types (remove-if-not (lambda (type)
                                     (subtypep type var-type env))
                                   types)))
        (cond ((null types)
               `(locally ,@body))
              ((not (speed-matters? env))
               `(locally ,@body))
              ;; The advantage of the CMUCL/SBCL way (I hope) is that the
              ;; compiler can decide /not/ to bother inlining if the type
              ;; is such that it cannot do any meaningful optimization.
              ((or #+(or cmucl sbcl) t)
               ;; Cf. sb-impl::string-dispatch.
               (with-unique-names ((fun type-dispatch-fun))
                 `(flet ((,fun (,var)
                           (with-read-only-vars (,var)
                             ,@body)))
                    (declare (inline ,fun))
                    (etypecase ,var
                      ,@(loop for type in types
                              collect `(,type (,fun (truly-the ,type ,var))))))))
              ((or #+ccl t)
               `(with-type-declarations-trusted ()
                  (etypecase ,var
                    ,@(loop for type in types
                            collect `(,type
                                      (locally (declare (type ,type ,var))
                                        (with-read-only-vars (,var)
                                          (with-vref ,type
                                            ,@body))))))))
              (t
               `(with-type-declarations-trusted ()
                  (etypecase ,var
                    ,@(loop for type in types
                            collect `(,type
                                      (let ((,var ,var))
                                        (declare (type ,type ,var))
                                        (with-read-only-vars (,var)
                                          (with-vref ,type
                                            ,@body))))))))))))


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

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

Input:
(with-guessing-encoder
  nil
  (progn))

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


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

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

Input:
(defun-advisable nil
    (progn))

Output: (defmacro DEFUN-ADVISABLE ...)


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

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

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

Output: (defmacro DEFWALKER-HANDLER ...)


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(delete-from-plistf nil :key nil)

What needs to change: Macro call that should be transformed by DELETE-FROM-PLISTF

Input: (delete-from-plistf nil :key nil)

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


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

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

Input: (enable-fn-syntax)

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


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

Issue: Macro call that should be transformed by DEFMD

Input: (defmd nil (progn))

Output:
(defmacro defmd (class superclasses &rest mdspec)
  `(defmodel ,class (,@superclasses model)
     ,@(let (definitargs class-options slots)
         (loop with skip
             for (spec next) on mdspec
             if skip
             do (setf skip nil)
             else do (etypecase spec
                       (cons
                        (cond
                         ((keywordp (car spec))
                          (assert (find (car spec) '(:documentation :metaclass)))
                          (push spec class-options))
                         ((find (cadr spec) '(:initarg :type :ps :persistable :cell :initform :allocation :reader :writer :accessor :documentation))
                          (push (apply 'defmd-canonicalize-slot spec) slots))
                         (t ;; shortform (slotname initform &rest slotdef-key-values)
                          (push (apply 'defmd-canonicalize-slot
                                  (list* (car spec) :initform (cadr spec) (cddr spec))) slots))))
                       (keyword
                        (setf definitargs (append definitargs (list spec next)))
                        (setf skip t))
                       (symbol (push (list spec :initform nil
                                       :initarg (intern (symbol-name spec) :keyword)
                                       :accessor spec) slots)))
             finally
               (return (list* (nreverse slots)
                         (delete nil
                           (list* `(:default-initargs ,@definitargs)
                             (nreverse class-options)))))))))


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

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

Input:
(min-of nil
  nil)

Output: (defmacro MIN-OF ...)


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

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

Input: (select-dao nil :key nil)

Output:
(defmacro select-dao (type &optional (test t) &rest ordering)
  "Select DAO objects for the rows in the associated table for which the given
test (either an S-SQL expression or a string) holds. When sorting arguments
are given, which can also be S-SQL forms or strings, these are used to sort
the result.

(Note that, if you want to sort, you have to pass the test argument.)

    (select-dao 'user (:> 'score 10000) 'name)"

  `(query-dao% ,type (sql ,(generate-dao-query type test ordering))
               (dao-row-reader (find-class ,type))))


Instruction:
Define a macro that eliminates this repetitive pattern:
(define-shared-method nil
    nil)

Issue: Macro call that should be transformed by DEFINE-SHARED-METHOD

Input:
(define-shared-method nil
    nil)

Output: (defmacro DEFINE-SHARED-METHOD ...)


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

Issue: Macro call that should be transformed by UNDEFREPLY

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

Output: (defmacro UNDEFREPLY ...)


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

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

Input: (deftable 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:
Create a Common Lisp macro for the following transformation. Before code:
(define-test 'lol-gen::some-name)

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

Input: (define-test 'lol-gen::some-name)

Output:
(defmacro define-test (name &body arguments-and-body)
  (destructuring-bind (nparent name) (if (listp name) name (list NIL name))
    (form-fiddle:with-body-options (body options parent home (test-class 'test) (compile-at :compile-time) defun) arguments-and-body
      (let ((body (remove 'define-test body :key (lambda (a) (when (listp a) (car a))) :test #'eql))
            (defs (remove 'define-test body :key (lambda (a) (when (listp a) (car a))) :test-not #'eql))
            (home-form (or home `(find-package ,(package-name *package*)))))
        (when (and parent nparent)
          (error "Cannot specify parent through name and through a keyword argument at the same time!"))
        `(let ((*package* (find-package ,(package-name *package*)))) ; Make sure package stays consistent throughout initialisation.
           (setf (find-test ',name ,home-form)
                 (ensure-test ',test-class
                              :name ',name
                              :home ,home-form
                              :tests (list ,@(loop for form in body
                                                   collect (ecase compile-at
                                                             (:compile-time `(lambda () ,form))
                                                             (:execute `(lambda () (call-compile ',form))))))
                              :parent ',(or parent nparent)
                              ,@(loop for option in options
                                      collect `',option)))
           ,@(loop for (def subname . body) in defs
                   collect `(,def (,name ,subname)
                              :home ,home
                              ,@body))
           ,@(when defun
               `((defun ,(if (stringp name) (read-symbol name) name) (&rest test-args)
                   (apply #'test (find-test ',name ,home-form) test-args))))
           ',name)))))


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

Problem: Macro call that should be transformed by DYNAMIC-RELET

Input:
(dynamic-relet nil
  :key
  nil)

Output: (defmacro DYNAMIC-RELET ...)


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

Problem: Macro call that should be transformed by FGATHERING

Input: (fgathering nil)

Output: (defmacro FGATHERING ...)


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

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

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

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


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

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

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

Output:
(defmacro when-let* (bindings &body body)
  "Creates new variable bindings, and conditionally executes BODY.

BINDINGS must be either single binding of the form:

 (variable initial-form)

or a list of bindings of the form:

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

Each INITIAL-FORM is executed in turn, and the variable bound to the
corresponding value. INITIAL-FORM expressions can refer to variables
previously bound by the WHEN-LET*.

Execution of WHEN-LET* stops immediately if any INITIAL-FORM evaluates to NIL.
If all INITIAL-FORMs evaluate to true, then BODY is executed as an implicit
PROGN."
  (let ((binding-list (if (and (consp bindings) (symbolp (car bindings)))
                          (list bindings)
                          bindings)))
    (labels ((bind (bindings body)
               (if bindings
                   `(let (,(car bindings))
                      (when ,(caar bindings)
                        ,(bind (cdr bindings) body)))
                   `(progn ,@body))))
      (bind binding-list body))))


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

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

Input: (untrace nil :key nil)

Output: (defmacro UNTRACE ...)


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

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

Input: (jif nil (progn))

Output:
(defmacro jif (test then &optional (else nil))
  "JSON-aware version of `cl:if'.
If TEST is `jtruep' evaluate THEN, otherwise evaluate ELSE."
  `(if (jtruep ,test)
       ,then
       ,else))


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

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

Input: (some-> nil nil)

Output: (defmacro SOME-> ...)


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

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

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

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


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

Problem: Macro call that should be transformed by MATCH

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

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

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

Input: (once-only nil)

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

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

   Example:

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


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

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

Input:
(advisable-lambda nil
  nil)

Output: (defmacro ADVISABLE-LAMBDA ...)


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

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

Input:
(for nil
    nil)

Output: (defmacro FOR ...)


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

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

Input: (decf nil (progn))

Output: (defmacro DECF ...)


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

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

Input:
(with-hook-restart
  nil
  nil)

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


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

Issue: Macro call that should be transformed by WITH-TOOK-USEC

Input: (with-took-usec 'lol-gen::some-name)

Output:
(defmacro with-took-usec (var &body body)
  (let ((before (gensym "BEFORE")))
    `(let ((,before (get-internal-real-time)))
       (multiple-value-prog1 (progn ,@body)
         (setf ,var (ceiling
                      (* (- (get-internal-real-time) ,before)
                         #.(/ 1000000 internal-time-units-per-second))))))))


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

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

Input: (ok nil (progn))

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


Instruction:
Write a Common Lisp macro to handle this code pattern:
(gen-lambda-with-sticky-stop)

Problem: Macro call that should be transformed by GEN-LAMBDA-WITH-STICKY-STOP

Input: (gen-lambda-with-sticky-stop)

Output:
(defmacro gen-lambda-with-sticky-stop (&rest rest)
  `(make-instance
    'basic-generator
    :function (sticky-stop-lambda ,@rest)))


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

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

Input: (define-script-symbol-macro 'lol-gen::some-name)

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


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

Problem: Macro call that should be transformed by FN

Input: (fn nil (progn))

Output:
(defmacro fn (name type)
  "A shorthand for declaiming function types."
  `(declaim (ftype ,type ,name)))


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

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

Input: (->> nil :key nil)

Output: (defmacro ->> ...)


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

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

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

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


Instruction:
Define a macro that eliminates this repetitive pattern:
(do-sequences! nil)

Issue: Macro call that should be transformed by DO-SEQUENCES!

Input: (do-sequences! nil)

Output:
(defmacro do-sequences! (name/seqs &body forms &environment env)
  "Mutable version of DO-SEQUENCES.

   This is the same as DO-SEQUENCES however each NAME, is the name of
   a symbol-macro, that is introduced, which expands to the 'place',
   suitable for use with SETF, of the current sequence element, rather
   than a variable storing its value. This allows the elements of the
   sequence to be mutated.

   NOTE: This macro does not support destructuring of the sequence
   elements."

  (let-if ((name name/seqs)
           (seqs (first forms) name/seqs)
           (forms (rest forms) forms))
      (symbolp name/seqs)

    (let ((safety (cadr (assoc 'safety (declaration-information 'optimize env)))))
      `(,(if (> safety 2)
             'do-sequences!-safe%
             'do-sequences!-fast%)

         ,name
         ,seqs
         ,@forms))))


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

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

Input:
(define-filtered-function nil
    nil)

Output: (defmacro DEFINE-FILTERED-FUNCTION ...)


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

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

Input:
(iterate
  nil
  :key
  nil)

Output: (defmacro ITERATE ...)


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

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

Input:
(is-values nil
  nil)

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


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

Problem: Macro call that should be transformed by ->

Input: (-> nil (progn))

Output:
(defmacro -> (functions (&rest args) &optional values)
  "Declaim the ftype of one or multiple FUNCTIONS from ARGS to VALUES.

     (-> mod-fixnum+ (fixnum fixnum) fixnum)
     (defun mod-fixnum+ (x y) ...)

     (-> (mod-float+ mod-single-float+) (float float) float)
     (defun mod-float+ (x y) ...)
     (defun mode-single-float+ (x y) ...)"
  `(declaim (ftype (-> (,@args) ,@(when values
                                    (list values)))
		   ,@(if (consp functions)
			 (if (find-symbol (symbol-name (first functions))
					  :cl)
			     (list functions)
			     functions)
			 (list functions)))))


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

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

Input: (vref nil (progn))

Output:
(defmacro vref (vec index &environment env)
  "When used globally, same as `aref'.

Inside of a with-type-dispatch form, calls to `vref' may be bound to
different accessors, such as `char' or `schar', or `bit' or `sbit',
depending on the type being specialized on."
  (if (symbolp vec)
      (let* ((type (variable-type vec env))
             (vref (type-vref type)))
        `(,vref ,vec ,index))
      `(aref ,vec ,index)))


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

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

Input: (make-kid nil :key 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:
Write a Common Lisp macro to handle this code pattern:
(unless 'lol-gen::some-name)

Problem: Macro call that should be transformed by UNLESS

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

Output: (defmacro UNLESS ...)


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

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

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

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

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

Output:
(defmacro doseq ((var seq-form &optional result-form) &body body)
  "doseq iterates over the elements of an sequence and binds value-var to successive values
and then evaluates body as a tagbody that can include declarations. Finally the result-form
is returned after the iteration completes."
  #+clisp
    `(ext:doseq (,var ,seq-form ,result-form)
       ,@body)
  #+sbcl
    `(sb-sequence:dosequence (,var ,seq-form ,result-form)
       ,@body)
  #-(or clisp sbcl)
    `(doseq* (,(gensym) ,var ,seq-form ,result-form)
       ,@body))


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

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

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

Output:
(defmacro scond (&body clauses)
  "Like COND, except each test-form is bound to IT (via SYMBOL-MACROLET) for the
scope of the corresponsing clause. IT can be set with SETF."
  (labels ((rec (clauses)
	     (if clauses
		 (destructuring-bind ((test &body body) . rest) clauses
		   (if body
		       `(symbolic if ,test (progn ,@body) ,(rec rest))
		       `(symbolic if ,test it ,(rec rest))))
		 nil)))
    (rec clauses)))


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

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

Input: (use-syntax 'lol-gen::some-name)

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


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

Issue: Macro call that should be transformed by MATCH

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

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


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

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

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

Output: (defmacro KEEP-BOPS ...)


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

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

Input: (with-pp)

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

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

Input:
(defstore nil
    (progn))

Output:
(defmacro defstore (store-name store-lambda-list &body body &environment env)
  (let* ((store-class-name (second (find :store-class body :key #'first)))
         (store-class (etypecase store-class-name
                        (null (find-class 'standard-store))
                        (symbol (find-class store-class-name))))
         (form (apply #'defstore-using-class store-class store-name store-lambda-list
                      :environment env
                      (mapcan #'(lambda (item)
                                  (cond ((eql (first item) :store-class)
                                         `(:store-class ',store-class-name))
                                        ((and (member (first item) '(:documentation :specialization-class)))
                                         (if (= 2 (length item))
                                             item
                                             (error "Invalid store definition option: ~W." item)))
                                        (t
                                         (list (first item) (rest item)))))
                              body))))
    `(eval-when (:compile-toplevel :load-toplevel :execute)
       ,form)))


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

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

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

Output: (defmacro COLLECT-APPEND ...)


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

Problem: Macro call that should be transformed by ALT

Input: (alt nil (progn))

Output:
(defmacro alt (parser &rest parsers)
  "Accept the results of the first parser from a group to succeed."
  (let ((offset (gensym "ALT-OFFSET")))
    `(lambda (,offset)
       ,(labels ((recurse (ps furthest)
                   (if (null ps)
                       `(fail ,furthest)
                       (let ((res  (gensym "ALT-RES"))
                             (next (gensym "ALT-NEXT")))
                         `(multiple-value-bind (,res ,next) (funcall ,(car ps) ,offset)
                            (if (ok? ,res)
                                (values ,res ,next)
                                ,(recurse (cdr ps) `(max ,next ,furthest))))))))
          (recurse (cons parser parsers) offset)))))


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

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

Input:
(defrule nil
  nil)

Output: (defmacro DEFRULE ...)


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

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

Input: (fm? nil nil)

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


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

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

Input: (eval-and-compile)

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


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

Issue: Macro call that should be transformed by WITH-STANDARD-IO-SYNTAX

Input: (with-standard-io-syntax 'lol-gen::some-name)

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


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

Issue: Macro call that should be transformed by <*

Input: (<* nil (progn))

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


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

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

Input: (order-by)

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


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

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

Input: (collecting-into nil)

Output: (defmacro COLLECTING-INTO ...)


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

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

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

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


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

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

Input: (nix nil)

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

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

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


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

Problem: Macro call that should be transformed by WITH*

Input:
(with* nil
  :key
  nil)

Output: (defmacro WITH* ...)


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

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

Input: (shift-incf 'lol-gen::some-name)

Output: (defmacro SHIFT-INCF ...)


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

Problem: Macro call that should be transformed by AWHEN

Input: (awhen nil)

Output: (defmacro AWHEN ...)


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

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

Input: (from nil (progn))

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


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

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

Input: (defvar nil nil)

Output: (defmacro DEFVAR ...)


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

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

Input:
(eval-always
  nil
  :key
  nil)

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


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

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

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

Output: (defmacro WITH-REDUCER ...)


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

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

Input: (splice-seqf nil :key nil)

Output: (defmacro SPLICE-SEQF ...)


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

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

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

Output: (defmacro ALL-OF ...)


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

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

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

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


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

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

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

Output: (defmacro EXPORT-CONSTRUCTORS ...)


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

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

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

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:
(with-standard-input-syntax
  nil
  :key
  nil)

What needs to change: Macro call that should be transformed by WITH-STANDARD-INPUT-SYNTAX

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

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

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


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

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

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

Output:
(defmacro with-type-dispatch ((&rest types) var &body body
                              &environment env)
  "A macro for writing fast sequence functions (among other things).

In the simplest case, this macro produces one copy of BODY for each
type in TYPES, with the appropriate declarations to induce your Lisp
to optimize that version of BODY for the appropriate type.

Say VAR is a string. With this macro, you can trivially emit optimized
code for the different kinds of string that VAR might be. And
then (ideally) instead of getting code that dispatches on the type of
VAR every time you call `aref', you get code that dispatches on the
type of VAR once, and then uses the appropriately specialized
accessors. (But see `with-string-dispatch'.)

But that's the simplest case. Using `with-type-dispatch' also provides
*transparent portability*. It examines TYPES to deduplicate types that
are not distinct on the current Lisp, or that are shadowed by other
provided types. And the expansion strategy may differ from Lisp to
Lisp: ideally, you should not have to pay for good performance on
Lisps with type inference with pointless code bloat on other Lisps.

There is an additional benefit for vector types. Around each version
of BODY, the definition of `vref' is shadowed to expand into an
appropriate accessor. E.g., within a version of BODY where VAR is
known to be a `simple-string', `vref' expands into `schar'.

Using `vref' instead of `aref' is obviously useful on Lisps that do
not do type inference, but even on Lisps with type inference it can
speed compilation times (compiling `aref' is relatively slow on SBCL).

Within `with-type-dispatch', VAR should be regarded as read-only.

Note that `with-type-dispatch' is intended to be used around
relatively expensive code, particularly loops. For simpler code, the
gains from specialized compilation may not justify the overhead of the
initial dispatch and the increased code size.

Note also that `with-type-dispatch' is relatively low level. You may
want to use one of the other macros in the same family, such as
`with-subtype-dispatch', `with-string-dispatch', or so forth.

The design and implementation of `with-type-dispatch' is based on a
few sources. It replaces a similar macro formerly included in
Serapeum, `with-templated-body'. One possible expansion is based on
the `string-dispatch' macro used internally in SBCL. But most of the
credit should go to the paper \"Fast, Maintable, and Portable Sequence
Functions\", by Irène Durand and Robert Strandh."
  `(locally (declare #+sbcl (sb-ext:muffle-conditions sb-ext:code-deletion-note))
     ,(let* ((types (simplify-subtypes types))
             (var-type (variable-type var env))
             ;; If the var has a declared type, remove excluded types.
             (types (remove-if-not (lambda (type)
                                     (subtypep type var-type env))
                                   types)))
        (cond ((null types)
               `(locally ,@body))
              ((not (speed-matters? env))
               `(locally ,@body))
              ;; The advantage of the CMUCL/SBCL way (I hope) is that the
              ;; compiler can decide /not/ to bother inlining if the type
              ;; is such that it cannot do any meaningful optimization.
              ((or #+(or cmucl sbcl) t)
               ;; Cf. sb-impl::string-dispatch.
               (with-unique-names ((fun type-dispatch-fun))
                 `(flet ((,fun (,var)
                           (with-read-only-vars (,var)
                             ,@body)))
                    (declare (inline ,fun))
                    (etypecase ,var
                      ,@(loop for type in types
                              collect `(,type (,fun (truly-the ,type ,var))))))))
              ((or #+ccl t)
               `(with-type-declarations-trusted ()
                  (etypecase ,var
                    ,@(loop for type in types
                            collect `(,type
                                      (locally (declare (type ,type ,var))
                                        (with-read-only-vars (,var)
                                          (with-vref ,type
                                            ,@body))))))))
              (t
               `(with-type-declarations-trusted ()
                  (etypecase ,var
                    ,@(loop for type in types
                            collect `(,type
                                      (let ((,var ,var))
                                        (declare (type ,type ,var))
                                        (with-read-only-vars (,var)
                                          (with-vref ,type
                                            ,@body))))))))))))


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

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

Input:
(global
  nil
  (progn))

Output: (defmacro GLOBAL ...)


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

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

Input:
(lambda* nil
  :key
  nil)

Output: (defmacro LAMBDA* ...)


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

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

Input:
(mvlet nil
  :key
  nil)

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


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

Issue: Macro call that should be transformed by DISPATCH-CASE

Input:
(dispatch-case nil
  nil)

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

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

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

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

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

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

You can do this using `etypecase-of':

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

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

Alternately, you could do it with `defgeneric':

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

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

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

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

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

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

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

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

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


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

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

Input: (destructuring-bind () nil)

Output: (defmacro DESTRUCTURING-BIND ...)


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

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

Input:
(do+
  nil)

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


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

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

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

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


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

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

Input: (like nil nil)

Output:
(defmacro like (got regex &optional desc)
  (with-gensyms (duration result)
    (once-only (regex desc)
      `(with-catching-errors (:description ,desc :expected ,regex)
         (with-duration ((,duration ,result) ,got)
           (test ,result ,regex ,desc
                 :duration ,duration
                 :test-fn (lambda (x y) (not (null (ppcre:scan y x))))
                 :report-expected-label "be like"))))))


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

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

Input: (builder)

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


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

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

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

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

Input: (optimize)

Output: (defmacro OPTIMIZE ...)


Instruction:
Write a Common Lisp macro to handle this code pattern:
(caching-types)

Problem: Macro call that should be transformed by CACHING-TYPES

Input: (caching-types)

Output: (defmacro CACHING-TYPES ...)


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

Issue: Macro call that should be transformed by LAMBDA

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

Output: (defmacro LAMBDA ...)


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

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

Input:
(ccase-of nil
    (progn))

Output:
(defmacro ccase-of (type keyplace &body body &environment env)
  "Like `ecase-of', but providing a `store-value' restart to correct KEYPLACE and try again."
  (check-exhaustiveness 'case type body env)
  `(ccase ,keyplace ,@body))


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

Issue: Macro call that should be transformed by DO+

Input: (do+)

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


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

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

Input: (cond-> nil (progn))

Output: (defmacro COND-> ...)


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

Problem: Macro call that should be transformed by DRELETF

Input:
(dreletf nil
  :key
  nil)

Output: (defmacro DRELETF ...)


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

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

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

Output: (defmacro WITH-YIELD ...)


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

Write a macro that addresses: Macro call that should be transformed by DEFMACRO/PS

Input:
(defmacro/ps nil
    (progn))

Output: (defmacro DEFMACRO/PS ...)


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

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

Input: (re-setf nil :key 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:
Define a macro that eliminates this repetitive pattern:
(fn common-lisp:nil
  (common-lisp:progn))

Issue: Macro call that should be transformed by FN

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

Output: (defmacro FN ...)


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

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

Input: (as->* nil)

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


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

Issue: Macro call that should be transformed by NIX

Input: (nix nil nil)

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

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

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


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

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

Input: (asif nil (progn))

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


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

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

Input: (resolving)

Output: (defmacro RESOLVING ...)


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

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

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

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


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

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

Input: (defmethod* nil)

Output: (defmacro DEFMETHOD* ...)


Instruction:
Write a Common Lisp macro to handle this code pattern:
(def-launched-iter nil
    nil)

Problem: Macro call that should be transformed by DEF-LAUNCHED-ITER

Input:
(def-launched-iter nil
    nil)

Output: (defmacro DEF-LAUNCHED-ITER ...)


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

Problem: Macro call that should be transformed by DO*

Input: (do* () (progn))

Output: (defmacro DO* ...)


Instruction:
Define a macro that eliminates this repetitive pattern:
(do-sequences! nil
  :key
  nil)

Issue: Macro call that should be transformed by DO-SEQUENCES!

Input:
(do-sequences! nil
  :key
  nil)

Output:
(defmacro do-sequences! (name/seqs &body forms &environment env)
  "Mutable version of DO-SEQUENCES.

   This is the same as DO-SEQUENCES however each NAME, is the name of
   a symbol-macro, that is introduced, which expands to the 'place',
   suitable for use with SETF, of the current sequence element, rather
   than a variable storing its value. This allows the elements of the
   sequence to be mutated.

   NOTE: This macro does not support destructuring of the sequence
   elements."

  (let-if ((name name/seqs)
           (seqs (first forms) name/seqs)
           (forms (rest forms) forms))
      (symbolp name/seqs)

    (let ((safety (cadr (assoc 'safety (declaration-information 'optimize env)))))
      `(,(if (> safety 2)
             'do-sequences!-safe%
             'do-sequences!-fast%)

         ,name
         ,seqs
         ,@forms))))


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

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

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

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

    (try-as <type> <expr>)

is equivalent to

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

and

    (try-as <type>)

is equivalent to

    (fn (expr) (the (Optional <type>) (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")))
           (Optional (cl:ignore-errors (cl:find-symbol "OPTIONAL" "COALTON/CLASSES"))))
    (cl:assert try-into () "`try-as` macro does not have access to `try-into` yet.")
    (cl:assert Optional () "`try-as` macro does not have access to `Optional` yet.")
    (cl:if expr-supplied-p
           `(the (,Optional ,type) (,try-into ,expr))
           (alexandria:with-gensyms (lexpr)
             `(fn (,lexpr)
                (the (,Optional ,type) (,try-into ,lexpr)))))))


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

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

Input: (gen-lambda-with-sticky-stop 'lol-gen::some-name)

Output:
(defmacro gen-lambda-with-sticky-stop (&rest rest)
  `(make-instance
    'basic-generator
    :function (sticky-stop-lambda ,@rest)))


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

Problem: Macro call that should be transformed by INITIALLY

Input: (initially nil)

Output: (defmacro INITIALLY ...)


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

Issue: Macro call that should be transformed by LETREC*

Input:
(letrec* nil
  :key
  nil)

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

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


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

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

Input:
(define-class-method nil
    nil)

Output: (defmacro DEFINE-CLASS-METHOD ...)


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

Issue: Macro call that should be transformed by ALET

Input:
(alet nil
  nil)

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


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

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

Input: (js-inline nil (progn))

Output: (defmacro JS-INLINE ...)


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

Issue: Macro call that should be transformed by INSTEAD

Input: (instead nil nil)

Output:
(defmacro instead (item parser)
  "Run some parser, but substitute its inner value with some `item' if parsing was
  successful."
  `(<$ ,item ,parser))


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

Write a macro that addresses: Macro call that should be transformed by DO-EXTERNAL-SYMBOLS

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

Output: (defmacro DO-EXTERNAL-SYMBOLS ...)


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

Issue: Macro call that should be transformed by LISTCASE

Input:
(listcase nil
  nil)

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