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

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

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

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


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

Problem: Macro call that should be transformed by PASS

Input: (pass nil :key nil)

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


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

Problem: Macro call that should be transformed by REMOVE-FROM-PLISTF

Input: (remove-from-plistf nil)

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


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

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

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

Output: (defmacro NCONCF ...)


Instruction:
Generate a defmacro form that transforms code like this:
(c?n-dbg
  nil
  :key
  nil)

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

Input:
(c?n-dbg
  nil
  :key
  nil)

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


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

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

Input:
(with-cc nil
  nil)

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


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

Issue: Macro call that should be transformed by WHICHEVER

Input: (whichever nil (progn))

Output:
(defmacro whichever (&rest possibilities &environment env)
  "Evaluates exactly one of POSSIBILITIES, chosen at random."
  (setf possibilities (mapcar (lambda (p) (macroexpand p env)) possibilities))
  (let ((length (length possibilities)))
    (cond
      ((= 1 length)
       (first possibilities))
      ((every #'constantp possibilities)
       `(svref (load-time-value (vector ,@possibilities))
               (random ,length)))
      (T
       (labels ((expand (possibilities position random-number)
                  (if (null (cdr possibilities))
                      (car possibilities)
                      (let* ((length (length possibilities))
                             (half (truncate length 2))
                             (second-half (nthcdr half possibilities))
                             (first-half (butlast possibilities (- length half))))
                        `(if (< ,random-number ,(+ position half))
                             ,(expand first-half position random-number)
                             ,(expand second-half (+ position half) random-number))))))
         (with-gensyms (random-number)
           `(let ((,random-number (random ,length)))
              ,(expand possibilities 0 random-number))))))))


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

Issue: Macro call that should be transformed by SUBTEST

Input: (subtest nil)

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


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

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

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

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

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

.. note::

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

Returns the value of the last form in FORMS."

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

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

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


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

Problem: Macro call that should be transformed by WITH-EXPLICIT-ENCODER

Input: (with-explicit-encoder)

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


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

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

Input:
(dynamic-let* nil
  :key
  nil)

Output: (defmacro DYNAMIC-LET* ...)


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

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

Input: (some->> nil)

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


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

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

Input: (mvlet* nil)

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

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

    (var var*... expr)

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

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

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


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

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

Input: (nunionf nil :key nil)

Output: (defmacro NUNIONF ...)


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

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

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

Output: (defmacro DLET ...)


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

Problem: Macro call that should be transformed by NOTINLINE

Input: (notinline)

Output: (defmacro NOTINLINE ...)


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

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

Input:
(isnt-values nil
  nil)

Output:
(defmacro isnt-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 '(isnt-values ,form ,@comp-expected)
                     :value-form ',form
                     :body (lambda () ,form)
                     :expected (list ,@expected)
                     :comparison (list ,@comparison)
                     :comparison-geq NIL
                     ,@(when description
                         `(:description (format NIL ,description ,@format-args)))))))


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

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

Input: (defconstant nil (progn))

Output: (defmacro DEFCONSTANT ...)


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

Problem: Macro call that should be transformed by WITH-SPECIAL-INITARGS*

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

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


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

Issue: Macro call that should be transformed by MAKE-METHOD

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

Output: (defmacro MAKE-METHOD ...)


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

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

Input: (->> nil nil)

Output: (defmacro ->> ...)


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

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

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

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

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

    (var var*... expr)

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

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

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


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

Issue: Macro call that should be transformed by UNLESS

Input: (unless nil)

Output: (defmacro UNLESS ...)


Instruction:
Define a macro that eliminates this repetitive pattern:
(make-simple-collector-to-place 'lol-gen::some-name)

Issue: Macro call that should be transformed by MAKE-SIMPLE-COLLECTOR-TO-PLACE

Input: (make-simple-collector-to-place 'lol-gen::some-name)

Output: (defmacro MAKE-SIMPLE-COLLECTOR-TO-PLACE ...)


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

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

Input: (collect-stream nil :key nil)

Output: (defmacro COLLECT-STREAM ...)


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

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

Input: (removef nil :key nil)

Output: (defmacro REMOVEF ...)


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

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

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

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

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

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


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

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

Input: (in-readtable nil)

Output:
(defmacro in-readtable (name)
  "Set *READTABLE* to the readtable referred to by the symbol NAME and
  return the readtable. This may signal READTABLE-DOES-NOT-EXIST.

  - Everything IN-READTABLE does is also performed at [compile time][
    pax:clhs] if the call appears as a [top level form][ pax:clhs].

  - The effects of IN-READTABLE are file-local since both COMPILE-FILE
    and LOAD rebind *READTABLE*."
  (check-type name symbol)
  `(eval-when (:compile-toplevel :load-toplevel :execute)
     ;; NB. The :LOAD-TOPLEVEL is needed for cases like (DEFVAR *FOO*
     ;; (GET-MACRO-CHARACTER #\"))
     (setf *readtable* (ensure-readtable ',name))
     (when (or (find-package :swank) (find-package :slynk))
       (%frob-swank-readtable-alist *package* *readtable*))
     *readtable*))


Instruction:
Define a macro that eliminates this repetitive pattern:
(declare-deprecated-operators nil)

Issue: Macro call that should be transformed by DECLARE-DEPRECATED-OPERATORS

Input: (declare-deprecated-operators nil)

Output: (defmacro DECLARE-DEPRECATED-OPERATORS ...)


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

Problem: Macro call that should be transformed by WHEN

Input: (when nil (progn))

Output: (defmacro WHEN ...)


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

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

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

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

Input:
(defdata nil
  nil)

Output:
(defmacro defdata (adt-name &body constructors)
  "Define a new ADT. ADT-name has the following grammar:

ADT-NAME := <symbol>
          | (<symbol> <options>*)

There is no difference between specifying it as a symbol or as a
singleton list. There are two possible options, specified as a
property list:

    * :MUTABLE {T, NIL} (default: NIL): Specifies whether the fields
      of the type are mutable, allowing the use of SET-DATA.

    * :INCLUDE <adt-type>: Specifies whether another defined ADT
      should be inherited.

Constructors is a list of clauses with the following grammar:

<clause> := <symbol>
          | (<symbol> <type-specifier>*)

Each clause defines a constructor for the ADT. Nullary constructors
will define constants and all other constructors will define
functions."
  ;; Do some extreme sanity checking.
  (assert
   (or
    ;; Must be a symbol, or...
    (symbolp adt-name)
    (and
     ;; a list that is...
     (listp adt-name)
     ;; non-empty
     (not (null adt-name))
     ;; whose first element is a symbol (the name of the adt)
     (symbolp (first adt-name))
     ;; and the rest is a property list
     (property-list-p (rest adt-name))))
   (adt-name)
   "ADT-NAME must either be a symbol, a singleton list with the ADT ~
      name as a symbol, or a list of two elements with the ADT name ~
      and :MUTABLE respectively. Given ~S."
   adt-name)
  (let ((valid-options (list ':mutable ':include)))
    (when (and (listp adt-name) (= (mod (length (rest adt-name)) 2) 0))
      (loop for opt in (rest adt-name) by #'cddr do
	   (when (not (member opt valid-options))
	     (error "Option ~A is not valid, valid options are member of ~A." opt valid-options)))))

  (let ((adt-name (ensure-car adt-name))
        (mutable? (and (listp adt-name)
                       (getf (rest adt-name) ':mutable)
                       t))
        (include (or (and (listp adt-name)
                          (getf (rest adt-name) ':include))
                     'algebraic-data-type))
        (object (gensym "OBJECT-"))
        (stream (gensym "STREAM-"))
        (depth (gensym "DEPTH-"))
        (env (gensym "ENVIRONMENT-"))
        (documentation
          (when (stringp (car constructors))
            (pop constructors))))

    ;; Sanity check that INCLUDE is a proper algebraic data type.
    (assert (algebraic-data-type-p include)
            ()
            "When defining the algebraic data type ~S, the :INCLUDE option ~
             was specified with ~S, which is not another algebraic data ~
             type."
            adt-name
            include)

    ;; Add constructors and their arity to the database.
    (flet ((constructor-and-arity (ctor)
             (if (listp ctor)
                 (list (first ctor) (length (rest ctor)))
                 (list ctor 0))))
      (set-constructors adt-name (append (get-constructors include)
                                         (mapcar #'constructor-and-arity constructors))))

    (flet ((make-printer (name &optional (nfields 0))
             "Make a printer function for the structs."
             `(lambda (,object ,stream ,depth)
                (declare (ignore ,depth)
                         (ignorable ,object))
                ;; We don't check *PRINT-READABLY* because these can
                ;; be readably printed always, provided the arguments
                ;; can be printed readably.
                ;;
                ;; However, we do respect a convenience option
                ;; *PRINT-ADT-READABLY* in case someone finds the
                ;; printing of the #. to be annoying.
                (when *print-adt-readably*
                  (write-string "#." ,stream))
                ,(when (plusp nfields)
                   `(write-char #\( ,stream))
                (prin1 ',name ,stream)
                ,@(when (plusp nfields)
                    (loop :for i :below nfields
                          :append (list
                                   `(write-char #\Space ,stream)
                                   `(prin1 (,(field name i) ,object)
                                           ,stream))))
                ,(when (plusp nfields)
                   `(write-char #\) ,stream)))))
      ;; Define everything.
      (let ((component-documentation
             ;; Force the adt-name symbol to print with a package
             ;; prefix
             (let ((*package* (find-package :keyword)))
               (format nil "A component of ADT ~S" adt-name))))
        `(eval-when (:compile-toplevel :load-toplevel :execute)
           ;; Define the data type.
           (defstruct (,adt-name (:constructor nil)
                                 (:copier nil)
                                 (:predicate nil)
                                 (:include ,include))
             ,@(unsplice documentation))

           ;; Define each of the field constructors.
           ,@(loop :for ctor :in (unwrap-singletons constructors)
                   :collect
                   (etypecase ctor
                     ;; Nullary constructor
                     (symbol `(progn
                                (eval-when (:compile-toplevel :load-toplevel :execute)
                                  (defstruct
                                      (,ctor
                                       (:include ,adt-name)
                                       (:constructor ,(internal ctor))
                                       (:copier nil)
                                       (:predicate nil)
                                       (:print-function ,(make-printer ctor)))
                                    ,component-documentation))
                                #+sbcl (declaim (sb-ext:freeze-type ,ctor))
                                (defmethod make-load-form ((,object ,ctor) &optional ,env)
                                  (make-load-form-saving-slots ,object
                                                               :slot-names nil
                                                               :environment ,env))
                                (define-constant ,ctor (,(internal ctor))
                                  ,component-documentation)
                                (fmakunbound ',(internal ctor))))

                     ;; N-ary constructors
                     (list (let* ((ctor-name (first ctor))
                                  (field-types (rest ctor))
                                  (field-names (gen-names (length field-types))))
                             `(progn
                                (defstruct (,ctor-name
                                            (:include ,adt-name)
                                            (:constructor ,ctor-name (,@field-names))
                                            (:conc-name ,ctor-name)
                                            (:copier nil)
                                            (:predicate nil)
                                            (:print-function
                                             ,(make-printer ctor-name
                                                            (length field-names))))
                                  ,component-documentation
                                  ,@(mapcar (lambda (name type)
                                              `(,name (error "Unspecified field.")
                                                      :type ,type
                                                      ,@(if mutable?
                                                            nil
                                                            '(:read-only t))))
                                     field-names
                                     field-types))
                                #+sbcl (declaim (sb-ext:freeze-type ,ctor-name))
                                (defmethod make-load-form ((,object ,ctor-name) &optional ,env)
                                  (make-load-form-saving-slots ,object
                                                               :slot-names ',field-names
                                                               :environment ,env)))))))
           ;; Return the type name
           ',adt-name)))))


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

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

Input:
(dispatch-caseql nil
  nil)

Output:
(defmacro dispatch-caseql ((&rest exprs-and-types) &body clauses)
  "Like `dispatch-case', but types in clauses are implicitly wrapped in `eql'.
The syntax of `dispatch-caseql' is tohus closer to `case' than to
`typecase'."
  (expect-form-list
   `(dispatch-case ,exprs-and-types
      ,@(expand-dispatch-caseql-clauses clauses))))


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

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

Input:
(dynamic-relet nil
  nil)

Output: (defmacro DYNAMIC-RELET ...)


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

Problem: Macro call that should be transformed by AND

Input: (and nil :key nil)

Output: (defmacro AND ...)


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

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

Input: ($send nil :key nil)

Output: (defmacro $SEND ...)


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

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

Input: (multiple-value-cmatch 'lol-gen::some-name)

Output:
(defmacro multiple-value-cmatch (values-form &body clauses)
  "Same as MULTIPLE-VALUE-MATCH, except a continuable MATCH-ERROR will
be raised if none of the clauses match."
  (let* ((values (gensym "VALUES"))
         (else `(cerror "Continue."
                        'match-error
                        :values ,values
                        :patterns ',(mapcar #'car clauses))))
    ;; FIXME: remove allocations
    `(let ((,values (multiple-value-list ,values-form)))
       ,(compile-multiple-value-match `(values-list ,values) clauses else))))


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

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

Input:
(c_in
  nil
  nil)

Output:
(defmacro c_in (&body body)
  `(c-input (:lazy :once-asked) (progn ,@body)))


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

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

Input:
(c?n-dbg
  nil
  nil)

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


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

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

Input: (with-unique-js-names 'lol-gen::some-name)

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


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

Problem: Macro call that should be transformed by DECF

Input: (decf nil nil)

Output: (defmacro DECF ...)


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

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

Input: (decf nil nil)

Output: (defmacro DECF ...)


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

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

Input: (fsetf nil (progn))

Output:
(defmacro fsetf (place value &rest more)
  ;; First we need to find the "container" variable
  (let ((container (find-container place)))
    (with-gensyms (val-sym)
      (if more
          `(let ((,val-sym ,value))
             (setf ,container (modf ,place ,val-sym))
             (fsetf ,@more))
          `(let ((,val-sym ,value))
             (setf ,container (modf ,place ,val-sym))
             ,val-sym)))))


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

Issue: Macro call that should be transformed by MULTIPLE-VALUE-MATCH

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

Output:
(defmacro multiple-value-match (values-form &body clauses)
  "Matches the multiple values of VALUES-FORM with CLAUSES. Unlike
MATCH, CLAUSES have to have the form of (PATTERNS . BODY), where
PATTERNS is a list of patterns. The number of values that will be used
to match is determined by the maximum arity of PATTERNS among CLAUSES.

Examples:

    (multiple-value-match (values 1 2)
     ((2) 1)
     ((1 y) y))
    => 2"
  (compile-multiple-value-match values-form clauses nil))


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

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

Input:
(deftest nil
  (progn))

Output:
(defmacro deftest (name &body test-forms)
  (let ((tests (gensym "TESTS"))
        (test (gensym "TEST"))
        (test-fn (gensym "TEST-FN")))
    `(progn
       (unless (nth-value 1 (gethash *package* *package-tests*))
         (setf (gethash *package* *package-tests*) '()))
       (let* ((,tests (gethash *package* *package-tests*))
              (,test (assoc ',name ,tests :test #'string=))
              (,test-fn (lambda ()
                          (subtest (princ-to-string ',name)
                            ,@test-forms))))
         (if ,test
             (rplacd ,test ,test-fn)
             (push (cons ',name ,test-fn) (gethash *package* *package-tests*)))
         ',name))))


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

Problem: Macro call that should be transformed by DEFMACRO

Input: (defmacro nil ())

Output: (defmacro DEFMACRO ...)


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

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

Input:
(with-packages-unlocked nil
  :key
  nil)

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


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

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

Input:
(collecting
  nil
  :key
  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:
Write a Common Lisp macro to handle this code pattern:
(all-values)

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

Input: (all-values)

Output: (defmacro ALL-VALUES ...)


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

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

Input:
(c-envalue
  nil
  (progn))

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


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

Issue: Macro call that should be transformed by CMATCH

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

Output:
(defmacro cmatch (what &body clauses)
  #.+match-doc+
  (with-gensyms (otherwise)
    `(match2 ,what
       ,@clauses
       (,otherwise (cerror "continue" 'match-error :pattern ',clauses :values (list ,otherwise))))))


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

Problem: Macro call that should be transformed by F

Input:
(f nil
  :key
  nil)

Output: (defmacro F ...)


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


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

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

Input: (in-optimizer common-lisp:nil (common-lisp:progn))

Output:
(defmacro in-optimizer (name &optional verbose)
  `(eval-when (:compile-toplevel :load-toplevel :execute)
     ,@(when verbose
         `((when ,verbose (format *trace-output* "~&Switching to the ~A optimizer~%" ',name))))
     (setf *optimizer* ',name)))


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

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

Input:
(with-savepoint nil
  (progn))

Output:
(defmacro with-savepoint (name &body body)
  "Can only be used within a transaction. Establishes a savepoint with the given
name at the start of body, and binds the same name to a handle for that savepoint.
The body is executed and, at the end of body, the savepoint is released, unless a
condition is thrown, in which case it is rolled back. Execute the body within a
savepoint, releasing savepoint when the body exits normally, and rolling back
otherwise. NAME is both the variable that can be used to release or rolled back
before the body unwinds, and the SQL name of the savepoint.

An example might look like this:

(defun test12 (x &optional (y nil))
  (with-logical-transaction (lt1 :read-committed-rw)
    (execute (:insert-into 'test-data :set 'value 0))
    (with-savepoint sp1
      (execute (:insert-into 'test-data :set 'value 1))
      (if (< x 0)
          (rollback-savepoint sp1)
          (release-savepoint sp1)))
    (with-savepoint sp2
      (execute (:insert-into 'test-data :set 'value 2))
      (with-savepoint sp3
        (execute (:insert-into 'test-data :set 'value 3))
        (if (> x 0)
            (rollback-savepoint sp3)
            (release-savepoint sp3))
        (when y (rollback-savepoint sp2)))
      (if (= x 0)
          (rollback-savepoint sp2)
          (release-savepoint sp2)))
    (when (string= y \"abrt\")
      (abort-transaction lt1))))"

  `(call-with-savepoint ',name (lambda (,name)
                                 (declare (ignorable ,name)) ,@body)))


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

Issue: Macro call that should be transformed by PROG2

Input: (prog2 nil :key nil)

Output: (defmacro PROG2 ...)


Instruction:
Define a macro that eliminates this repetitive pattern:
(accumulating-to nil)

Issue: Macro call that should be transformed by ACCUMULATING-TO

Input: (accumulating-to nil)

Output: (defmacro ACCUMULATING-TO ...)


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

Problem: Macro call that should be transformed by OP

Input:
(op
  nil
  nil)

Output:
(defmacro op (&body body &environment env)
  "GOO's simple macro for positional lambdas.

An OP is like a lambda without an argument list. Within the body of the OP
form, an underscore introduces a new argument.

     (reduce (op (set-intersection _ _ :test #'equal))
             sets)

You can refer back to each argument by number, starting with _1.

     (funcall (op (+ _ _1)) 2) => 4

You can also use positional arguments directly:

     (reduce (op (funcall _2 _1)) ...)

Argument lists can be sparse:

     (apply (op (+ _1 _3 _5)) '(1 2 3 4 5)) => 9

Note that OP with a single argument is equivalent to CONSTANTLY:

     (funcall (op 1)) => 1

and that OP with a single placeholder is equivalent to IDENTITY:

     (funcall (op _) 1) => 1

OP can also be used to define variadic functions by using _* as the
placeholder. It is not necessary to use APPLY.

     (apply (op (+ _*)) '(1 2 3 4)) => 10

OP is intended for simple functions -- one-liners. Parameters are
extracted according to a depth-first walk of BODY. Macro expansion
may, or may not, be done depending on the implementation; it should
not be relied on. Lexical bindings may, or may not, shadow
placeholders -- again, it depends on the implementation. (This means,
among other things, that nested use of `op' is not a good idea.)
Because of the impossibility of a truly portable code walker, `op'
will never be a true replacement for `lambda'. But even if it were
possible to do better, `op' would still only be suited for one-liners.
If you need more than a one-liner, then you should be giving your
parameters names.

\(One thing you *can* count on is the ability to use `op' with
quasiquotes. If using placeholders inside quasiquotes does not work on
your Lisp implementation, that's a bug, not a limitation.)"
  (let ((env (extract-op-env body env)))
    (op-env-lambda env)))


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

Issue: Macro call that should be transformed by WHEN-LET*

Input:
(when-let* nil
  :key
  nil)

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

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

Input:
(eval-when-load
  'lol-gen::some-name)

Output: (defmacro EVAL-WHEN-LOAD ...)


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

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

Input: (continue-whopper nil :key nil)

Output: (defmacro CONTINUE-WHOPPER ...)


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

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

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

Output:
(defmacro void (place)
  "Nullify PLACE."
  `(setf ,place nil))


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

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

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

Output: (defmacro HANDLER-BIND ...)


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

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

Input:
(c?once
  nil)

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


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

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

Input:
(pprint-coalton-codegen
  common-lisp:nil
  (common-lisp:progn))

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


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

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

Input:
(with-transaction nil
  :key
  nil)

Output:
(defmacro with-transaction ((&optional name isolation-level) &body body)
  "Execute the given body within a database transaction, committing it when the
body exits normally, and aborting otherwise. An optional name and/or
isolation-level can be given to the transaction. The name can be used to force
a commit or abort before the body unwinds. The isolation-level will set the
isolation-level used by the transaction.

You can specify the following isolation levels in postmodern transactions:

- :read-committed-rw (read committed with read and write)
- :read-committed-ro (read committed with read only)
- :repeatable-read-rw (repeatable read with read and write)
- :repeatable-read-ro (repeatable read with read only)
- :serializable (serializable with reand and write)

Sample usage where george is just the name given to the transaction (not quoted
or a string) and ... simply indicates other statements would be expected here:

    (with-transaction ()
      (execute (:insert-into 'test-data :set 'value 77))
      ...)

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

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

    (with-transaction (:serializable)
      (execute (:insert-into 'test-data :set 'value 44))
      ...)

Further discussion of transactions and isolation levels can found in the
isolation notes file in the doc folder."
  (let ((transaction-name (or (when (not (isolation-level-p name))
                                name)
                              (gensym "anonymous-transaction"))))
    (when (and name (isolation-level-p name))
      (setf isolation-level name))
    `(call-with-transaction (lambda (,transaction-name)
                              (declare (ignorable ,transaction-name)) ,@body)
                            ,isolation-level)))


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

Issue: Macro call that should be transformed by WITHOUT-DEPENDENCY-CAPTURE

Input:
(without-dependency-capture
  'lol-gen::some-name)

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


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

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

Output: (defmacro F_ ...)


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

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

Input:
(gen-lambda nil
  nil)

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


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

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

Input:
(-<>
  nil
  :key
  nil)

Output: (defmacro -<> ...)


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

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

Input: (define-method-combination nil :key nil)

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


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

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

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

Output:
(defmacro define-form-binding (name (var &rest args) &body body)
  (emit-binding-definition name var args body))


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

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

Input: (group-by 'lol-gen::some-name)

Output:
(defmacro group-by (&rest expressions)
  `(apply #'make-clause :group-by ',expressions))


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

Problem: Macro call that should be transformed by UPPER

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

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


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

Problem: Macro call that should be transformed by RAW

Input: (raw)

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


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

Problem: Macro call that should be transformed by DEFGUARANTEE

Input:
(defguarantee nil
    nil)

Output:
(defmacro defguarantee (name (&rest lambda-list) &body body)
  "Adds a postcondition to the NAMEd function. It can be either a generic or
   non-generic function. If it's the former, then use a specialized lambda list,
   otherwise use an ordinary lambda list. The docstring, if any, will be used in
   failure reports."
  #+qpq-postcondition-checks-disabled
  (declare (ignore name lambda-list body))
  #+qpq-postcondition-checks-disabled
  (values)
  #-qpq-postcondition-checks-disabled
  (multiple-value-bind (remaining-forms declarations doc-string)
      (parse-body body :documentation t)
    (declare (ignore declarations))
    (let* ((stripped-ll (strip-lambda-list lambda-list))
           (lambda-vars (remove-if (rcurry #'member
                                           '(&optional &rest
                                             &key &allow-other-keys &aux))
                                   stripped-ll))
           (method `(progn
                      (ensure-contracted-function ',name ',stripped-ll)
                      (defmethod ,name
                          :guarantee
                          ,(or doc-string
                            (format nil "~A"
                             (description<-remaining-forms
                              remaining-forms)))
                        ,lambda-list
                        (declare (ignorable ,@lambda-vars))
                        ,@body))))
      (if (every #'symbolp lambda-list)
          `(if (and (fboundp ',name)
                    (not (typep (fdefinition ',name) 'generic-function)))
               (defcontract ,name :guarantee ,lambda-list
                 (declare (ignorable ,@lambda-vars))
                 ,@body)
               ,method)
          method))))


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

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

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

Output: (defmacro EXPORT-STRUCTURE ...)


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

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

Input:
(when-it nil
  :key
  nil)

Output:
(defmacro when-it (test &body body)
  "Like WHEN. IT is bound to TEST."
  `(let ((it ,test))
     (when it
       ,@body)))


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

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

Input:
(cond-every
  nil)

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

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

Input:
(local
  nil
  :key
  nil)

Output: (defmacro LOCAL ...)


Instruction:
Write a Common Lisp macro to handle this code pattern:
(^k-last)

Problem: Macro call that should be transformed by ^K-LAST

Input: (^k-last)

Output: (defmacro ^k-last () `(last-kid self))


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

Issue: Macro call that should be transformed by UPDATE

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

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


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

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

Input: (match* common-lisp:nil)

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


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

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

Input: (~>> nil)

Output:
(defmacro ~>> (needle &rest holes)
  "Like `~>' but, by default, thread NEEDLE as the last argument
instead of the first."
  (thread-aux '~>> needle holes
              (lambda (needle hole)
                (append hole (list needle)))))


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

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

Input:
(all-values
  nil
  :key
  nil)

Output: (defmacro ALL-VALUES ...)


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

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

Input: (return)

Output: (defmacro RETURN ...)


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

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

Input: (insert-into nil)

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


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

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

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

Output: (defmacro WITH ...)


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

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

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

Output:
(defmacro ccase-let ((var expr) &body cases)
  "Like (let ((VAR EXPR)) (ccase VAR ...)), with VAR correctable."
  `(let ((,var ,expr))
     (ccase ,var
       ,@cases)))


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

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

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

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


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

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

Input: (pass nil nil)

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


Instruction:
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 ~>> (needle &rest holes)
  "Like `~>' but, by default, thread NEEDLE as the last argument
instead of the first."
  (thread-aux '~>> needle holes
              (lambda (needle hole)
                (append hole (list needle)))))


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

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

Input:
(tree-case nil
  nil)

Output: (defmacro TREE-CASE ...)


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

Problem: Macro call that should be transformed by EXPORT-ONLY-ALWAYS

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

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


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

Issue: Macro call that should be transformed by PSIB

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

Output:
(defmacro psib (&optional (self-form 'self))
  (let ((self (gensym)))
    `(bwhen (,self ,self-form)
        (find-prior ,self (kids (fm-parent ,self))))))


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

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

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

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


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(gen-lambda-with-sticky-stop nil)

What needs to change: Macro call that should be transformed by GEN-LAMBDA-WITH-STICKY-STOP

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

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


Instruction:
Generate a defmacro form that transforms code like this:
;; Closure variables are opaque - can't inspect or modify them
(let ((acc 0) (mul 1))
  (lambda (n)
    (incf acc n)
    (setf mul (* mul n))))

;; To access acc/mul: must add specific getter/setter methods
;; This doesn't scale - every variable needs its own accessor

Pattern to recognize: Closure internals are opaque — want a general protocol for reading/writing any closed-over variable

Input:
;; Closure variables are opaque - can't inspect or modify them
(let ((acc 0) (mul 1))
  (lambda (n)
    (incf acc n)
    (setf mul (* mul n))))

;; To access acc/mul: must add specific getter/setter methods
;; This doesn't scale - every variable needs its own accessor

Output:
(defun pandoriclet-get (letargs)
  `(case sym
     ,@(mapcar #`((,(car a1)) ,(car a1))
               letargs)
     (t (error
          "Unknown pandoric get: ~a"
          sym))))

(defun pandoriclet-set (letargs)
  `(case sym
     ,@(mapcar #`((,(car a1))
                   (setq ,(car a1) val))
               letargs)
     (t (error
          "Unknown pandoric set: ~a"
          sym val))))

(defmacro pandoriclet (letargs &rest body)
  (let ((letargs (cons
                   '(this)
                   (let-binding-transform
                     letargs))))
    `(let (,@letargs)
       (setq this ,@(last body))
       ,@(butlast body)
       (dlambda
         (:pandoric-get (sym)
           ,(pandoriclet-get letargs))
         (:pandoric-set (sym val)
           ,(pandoriclet-set letargs))
         (t (&rest args)
           (apply this args))))))


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(^fm-next-sib)

What needs to change: Macro call that should be transformed by ^FM-NEXT-SIB

Input: (^fm-next-sib)

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


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

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

Input:
(summing
  nil)

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

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

Input: (collect-first nil (progn))

Output: (defmacro COLLECT-FIRST ...)


Instruction:
Generate a defmacro form that transforms code like this:
(dispatch-caseql-let nil)

Pattern to recognize: Macro call that should be transformed by DISPATCH-CASEQL-LET

Input: (dispatch-caseql-let nil)

Output:
(defmacro dispatch-caseql-let ((&rest bindings) &body clauses)
  "Like `dispatch-case-let', but using the clause syntax of `dispatch-caseql'."
  `(dispatch-case-let ,bindings
     ,@(expand-dispatch-caseql-clauses clauses)))


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

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

Input:
(drelet* nil
  (progn))

Output: (defmacro DRELET* ...)


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

Problem: Macro call that should be transformed by C-INPUT-DBG

Input: (c-input-dbg nil)

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


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

Issue: Macro call that should be transformed by WITHOUT-DEPENDENCY-CAPTURE

Input:
(without-dependency-capture
  nil
  :key
  nil)

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


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

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

Input:
(eif-let nil
  nil)

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


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

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

Input:
(secase nil
  :key
  nil)

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


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(define-port-value-slot nil nil)

Write a macro that addresses: Macro call that should be transformed by DEFINE-PORT-VALUE-SLOT

Input: (define-port-value-slot nil nil)

Output: (defmacro DEFINE-PORT-VALUE-SLOT ...)


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

Issue: Macro call that should be transformed by WITH-CONDITION-RESTARTS

Input:
(with-condition-restarts nil
    (progn))

Output: (defmacro WITH-CONDITION-RESTARTS ...)


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

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

Input: (with-iterators nil)

Output:
(defmacro with-iterators (seqs &body forms &environment env)
  "Create static iterators for one or more sequence.

   This macro attempts to determine the type of each sequence, and calls
   MAKE-DOSEQ to generate optimal static iterator code for the given
   sequence types, rather than creating dynamic iterator objects.

   SEQS:

     A list where each element is of the form (ITER SEQUENCE . ARGS)
     where ITER is a symbol identifying the iterator for the sequence,
     SEQUENCE is the form which evaluates to a sequence, and ARGS are
     the remaining iteration arguments, interpreted as they are to the
     ITERATOR function.

     Each iterator identifier (ITER) can be passed to
     WITH-ITER-VALUE, within the body forms of WITH-ITERATORS, to
     retrieve the values of the elements of the sequence.

     The iterator identifiers are in a namespace of their own that is
     they do not name lexical variables/symbol-macros nor functions/macros.

   FORMS:

     A list of forms evaluated in an implicit TAGBODY, thus symbols
     are interpreted as tag names.

     The WITH-ITER-VALUE macro can be used, within FORMS, to retrieve
     the current element of the sequence and advance the iterator to
     the next position.

     The WITH-ITER-PLACE macro can be used, within FORMS, both to
     retrieve and set the value of the current element of the
     sequence, and advance the iterator to the next position.

     NOTE: The value of the last form is not returned, due to it being
     evaluated in a TAGBODY, instead NIL is returned. RETURN-FROM, to
     an outer BLOCK, should be used to return a value from this form.

     NOTE: Whilst the intended use of WITH-ITERATORS is to implement
     iteration macros, such as DOSEQ, the FORMS are only evaluated
     once. It is up to the user to implement the actual loop, using
     the provided TAGBODY facility."

  (with-gensyms (end-tag)
    (labels ((expand-doseq (seq args body env)
               (-> (nth-form-type seq env)
                   (make-doseq seq args end-tag body env)
                   multiple-value-list))

             (make-form (bindings get-values places body)
               (->> (make-macros get-values places body)
                    (make-bindings bindings)))

             (make-macros (get-values places body)
               `(symbol-macrolet
                    ((iter-value-macros
                      ,(append get-values (iter-value-macros env)))

                     (iter-place-macros
                      ,(append places (iter-place-macros env))))

                  ,@body))

             ;; Tagbody

             (make-tagbody (body)
               `((tagbody
                    ,@body
                    ,end-tag)))

             ;; Bindings

             (make-bindings (bindings body)
               (loop
                  for binding in bindings
                  for (init constant?) = (multiple-value-list (make-binding binding))
                  if constant? collect init into constants
                  else collect init into vars
                  finally
                    (return
                      `(symbol-macrolet ,constants
                         (let* ,vars ,body)))))

             (make-binding (binding)
               (destructuring-bind (var init &key constant) binding
                 (if constant
                     (multiple-value-bind (value constant?)
                         (constant-form-value init env)

                       (values
                        `(,var ,value)
                        constant?))

                     (values
                      `(,var ,init)
                      nil)))))

      (loop
         for (var seq . args) in seqs
         for (bindings body value place) =
           (expand-doseq seq args (make-tagbody forms) env) then
           (expand-doseq seq args form-body env)

         for iter-value = (gensym "ITER-VALUE")
         for iter-place = (gensym "ITER-PLACE")
         for form-body = `((macrolet ((,iter-value ,@value)
                                      (,iter-place
                                          ,@(or place
                                                `((&rest args)
                                                  (declare (ignore args))
                                                  (error "In WITH-ITER-PLACE: Iterator ~s points to immutable sequence." ',var)))))
                             ,@body))

         append bindings into all-bindings
         collect (cons var iter-value) into get-values
         collect (cons var iter-place) into places

         finally
           (return
             (make-form all-bindings get-values places form-body))))))


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

Problem: Macro call that should be transformed by DEFGENERIC

Input: (defgeneric nil :key nil)

Output: (defmacro DEFGENERIC ...)


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

Problem: Macro call that should be transformed by NECESSARILY?

Input: (necessarily?)

Output: (defmacro NECESSARILY? ...)


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

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

Input:
(count-failures
  nil
  :key
  nil)

Output: (defmacro COUNT-FAILURES ...)


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

Problem: Macro call that should be transformed by C-IN-LAZY

Input:
(c-in-lazy
  nil)

Output:
(defmacro c-in-lazy (&body body)
  `(c-input (:lazy :once-asked) (progn ,@body)))


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

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

Input:
(select-dao nil
  (progn))

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

Example:

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

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

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

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

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

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

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


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

Problem: Macro call that should be transformed by OK

Input: (ok nil)

Output:
(defmacro ok (test &optional desc)
  (with-gensyms (duration result)
    (once-only (test desc)
      `(with-catching-errors (:expected T :description ,desc)
         (with-duration ((,duration ,result) ,test)
           (test ,result t ,desc
                 :duration ,duration
                 :test-fn (lambda (x y)
                            (eq (not (null x)) y))
                 :got-form ,test))))))


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

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

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

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


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

Write a macro that addresses: Macro call that should be transformed by ENABLE-QUASIQUOTE-2.0

Output: (defmacro ENABLE-QUASIQUOTE-2.0 ...)


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

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

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

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

    (nest f g h x)

to

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


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

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

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

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


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

Problem: Macro call that should be transformed by FN

Input: (fn nil nil)

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:
(define-script-symbol-macro nil
  nil)

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

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

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


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

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

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

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


Instruction:
Define a macro that eliminates this repetitive pattern:
(export-slots)

Issue: Macro call that should be transformed by EXPORT-SLOTS

Input: (export-slots)

Output: (defmacro EXPORT-SLOTS ...)


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

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

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

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


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

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

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

Output:
(defmacro acond (&body clauses)
  "Like COND, except result of each test-form is bound to IT (via LET) for the
scope of the corresponding clause."
  (labels ((rec (clauses)
	     (if clauses
		 (destructuring-bind ((test &body body) . rest)  clauses
		   (if body
		       `(anaphoric if ,test (progn ,@body) ,(rec rest))
		       `(anaphoric if ,test it ,(rec rest))))
		 nil)))
    (rec clauses)))


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

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

Input: (with-proxynodes nil)

Output:
(defmacro with-proxynodes (proxy-nodes &body body)
  "define proxy nodes for local usage"
  (if (not (listp proxy-nodes))
      (setf proxy-nodes (list proxy-nodes)))
  (if proxy-nodes
      (let ((tmp (gensym (format nil "~:@(proxy-~a-~)" (first proxy-nodes)))))
	;(format t "Symbol:: ~s" tmp)
	(setf (gethash (first proxy-nodes) *proxy-node*) tmp)
	;;for debug/swank, else comment out
	;;(eval `(defnode ,tmp (proxy) ()))
	;;
	`(let ((,(first proxy-nodes) ',tmp))

	     ;(defnode ,tmp (proxy) ())
	     (defproxy ,tmp)

	     (with-proxynodes ,(rest proxy-nodes) ,@body)))
      `(progn ,@body)))


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

Issue: Macro call that should be transformed by FLET*

Input:
(flet* nil
  :key
  nil)

Output: (defmacro FLET* ...)


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

Write a macro that addresses: Macro call that should be transformed by DO-AST-LINKS

Input: (do-ast-links 'lol-gen::some-name)

Output: (defmacro DO-AST-LINKS ...)


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

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

Input:
(->*
  nil
  nil)

Output: (defmacro ->* ...)


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

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

Input: (define-foreign-library 'lol-gen::some-name)

Output:
(defmacro define-foreign-library (name-and-options &body pairs)
  "Defines a foreign library NAME that can be posteriorly used with
the USE-FOREIGN-LIBRARY macro."
  (destructuring-bind (name . options)
      (ensure-list name-and-options)
    (check-type name symbol)
    `(register-foreign-library ',name ',pairs ,@options)))


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

Problem: Macro call that should be transformed by WITH-LIVE-SCOPE

Input:
(with-live-scope
  nil
  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:
Write a Common Lisp macro to handle this code pattern:
(define-fixture-restore nil
    :key
  nil)

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

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

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


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

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

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

Output: (defmacro -> ...)


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

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

Input:
(define-train nil
    (progn))

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:
Generate a defmacro form that transforms code like this:
(with-decoder-simple-clos-semantics
  'lol-gen::some-name)

Pattern to recognize: Macro call that should be transformed by WITH-DECODER-SIMPLE-CLOS-SEMANTICS

Input:
(with-decoder-simple-clos-semantics
  'lol-gen::some-name)

Output:
(defmacro with-decoder-simple-clos-semantics (&body body)
  "Execute BODY in a dynamic environement where the decoder semantics
is such as set by SET-DECODER-SIMPLE-CLOS-SEMANTICS."
  `(with-shadowed-custom-vars
     (set-decoder-simple-clos-semantics)
     ,@body))


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

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

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

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


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

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

Input:
(c_?dbg
  nil
  :key
  nil)

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


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

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

Input: (define-modularize-hook 'lol-gen::some-name)

Output:
(defmacro define-modularize-hook ((modulevar &optional identifier) &body body)
  `(eval-when (:compile-toplevel :load-toplevel :execute)
     (setf (modularize-hook
            (or ,identifier
                (intern (package-name *package*) "KEYWORD")))
           (lambda (,modulevar) ,@body))))


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

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

Input: (function-call nil nil)

Output: (defmacro FUNCTION-CALL ...)


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

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

Input:
(with-gensyms nil
  nil)

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


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

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

Input: (untrace)

Output: (defmacro UNTRACE ...)


Instruction:
Define a macro that eliminates this repetitive pattern:
(use-foreign-library nil)

Issue: Macro call that should be transformed by USE-FOREIGN-LIBRARY

Input: (use-foreign-library nil)

Output:
(defmacro use-foreign-library (name)
  `(load-foreign-library ',name))


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

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

Input: (to-boolean common-lisp:nil)

Output: (defmacro TO-BOOLEAN ...)


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

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

Input:
(ensure2 nil
  (progn))

Output:
(defmacro ensure2 (place &body newval &environment env)
  "Like `ensure', but specifically for accessors that return a second
value like `gethash'."
  (multiple-value-bind (vars vals stores setter getter)
      (get-setf-expansion place env)
    (with-gensyms (old presentp)
      `(let* ,(mapcar #'list vars vals)
         (multiple-value-bind (,old ,presentp)
             ,getter
           (if ,presentp
               ,old
               (multiple-value-bind ,stores
                   (progn ,@newval)
                 ,setter)))))))


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

Issue: Macro call that should be transformed by DEFMACRO*

Input:
(defmacro* nil
    (progn))

Output: (defmacro DEFMACRO* ...)


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

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

Input: (returning nil :key nil)

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:
(enable-quasi-quoted-bivalent-to-binary-emitting-form-syntax
 'lol-gen::some-name)

What needs to change: Macro call that should be transformed by ENABLE-QUASI-QUOTED-BIVALENT-TO-BINARY-EMITTING-FORM-SYNTAX

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

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


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

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

Input:
(wait-on nil
    :key
  nil)

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


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

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

Input:
(with-vector-dispatch nil
    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:
Write a Common Lisp macro to handle this code pattern:
($send nil nil)

Problem: Macro call that should be transformed by $SEND

Input: ($send nil nil)

Output: (defmacro $SEND ...)


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

Problem: Macro call that should be transformed by JAND

Input: (jand)

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


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

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

Input: (<*> nil :key nil)

Output:
(defmacro <*> (parser &rest parsers)
  "Combination of parsers yielding all results as a list."
  (let ((offset (gensym "<*>-OFFSET")))
    `(lambda (,offset)
       ,(labels ((recurse (ps i)
                   (if (null ps)
                       `(ok ,i nil)
                       (let ((res  (gensym "<*>-RES"))
                             (next (gensym "<*>-NEXT")))
                         `(multiple-value-bind (,res ,next) (funcall ,(car ps) ,i)
                            (if (failure? ,res)
                                (fail ,next)
                                (fmap (lambda (xs) (cons ,res xs))
                                      ,(recurse (cdr ps) `,next))))))))
          (recurse (cons parser parsers) offset)))))


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

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

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

Output:
(defmacro defsyntax (name &body options)
  `(progn
     (setf (get ',name :options) ',options)
     (defvar ,name (defreadtable ,name ,@options))))


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

Issue: Macro call that should be transformed by DICTQ

Input: (dictq nil (progn))

Output:
(defmacro dictq (&rest keys-and-values)
  "A literal hash table.
Like `dict', but the keys and values are implicitly quoted, and the
hash table is inlined as a literal object."
  (apply #'dict keys-and-values))


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

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

Input: (matrix-case nil)

Output: (defmacro MATRIX-CASE ...)


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

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

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

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


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

Problem: Macro call that should be transformed by LETMATCH

Input:
(letmatch nil
    (progn))

Output: (defmacro LETMATCH ...)


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

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

Input: (make-list common-lisp:nil)

Output:
(defmacro make-list (cl:&rest forms)
  "Create a heterogeneous Coalton `List` of objects. This macro is
deprecated; use `coalton/list:make`."
  (cl:labels
      ((list-helper (forms)
         (cl:if (cl:endp forms)
                `coalton:Nil
                `(coalton:Cons ,(cl:car forms) ,(list-helper (cl:cdr forms))))))
    (list-helper forms)))


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

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

Input: (builder nil :key nil)

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


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

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

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

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


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

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

Input: (shift-decf nil)

Output: (defmacro SHIFT-DECF ...)


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(pprint-coalton-codegen-types
  common-lisp:nil
  common-lisp:nil)

What needs to change: Macro call that should be transformed by PPRINT-COALTON-CODEGEN-TYPES

Input:
(pprint-coalton-codegen-types
  common-lisp:nil
  common-lisp:nil)

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


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

Issue: Macro call that should be transformed by PRODUCING

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

Output: (defmacro PRODUCING ...)


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

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

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

Output:
(defmacro dotree ((subtree tree &optional result) &body body)
  "Iterate over each SUBTREE of the TREE in depth-first order.
   Optionally return RESULT."
  (with-gensyms (rec child)
    `(block nil
       (labels ((,rec (,subtree)
                  ,@body
                  (unless (atom ,subtree)
                    (dolist (,child ,subtree)
                      (,rec ,child)))))
         (when-it ,tree
           (,rec it))
         ,result))))


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

Problem: Macro call that should be transformed by DEFMETHOD*

Input:
(defmethod* nil
    :key
  nil)

Output: (defmacro DEFMETHOD* ...)


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

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

Input: (the-part)

Output: (defmacro THE-PART ...)


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

Pattern to recognize: Macro call that should be transformed by SET=

Input: (set=)

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


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

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

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

Output:
(defmacro with-unique-names (names &body forms)
  "Alias for WITH-GENSYMS."
  `(with-gensyms ,names ,@forms))


Instruction:
Generate a defmacro form that transforms code like this:
(ps-to-stream nil)

Pattern to recognize: Macro call that should be transformed by PS-TO-STREAM

Input: (ps-to-stream nil)

Output: (defmacro PS-TO-STREAM ...)


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

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

Input:
(c?dbg
  'lol-gen::some-name)

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


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

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

Input: (defconst nil :key nil)

Output:
(defmacro defconst (symbol init &optional docstring)
  "Define a constant, lexically.

`defconst' defines a constant using a strategy similar to `def', so
you don’t have to +cage+ your constants.

The constant is only redefined on re-evaluation if INIT has a
different literal representation than the old value.

A constant defined with `defconst' is guaranteed to be available as
soon as it has been defined (for example, for use with reader macros
later in the same file). This is not guaranteed to be portably true
for `defconstant'.

The name is from Emacs Lisp."
  (let ((backing-var (symbolicate '#:+storage-for-deflex-var- symbol '+)))
    `(eval-when (:compile-toplevel :load-toplevel :execute)
       (define-constant ,backing-var ,init
         :test 'same-literal-p
         :documentation ,docstring)
       (define-symbol-macro ,symbol ,backing-var))))


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

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

Input:
(with-fixtures nil
  :key
  nil)

Output:
(defmacro with-fixtures (fixtures &body body)
  `(call-with-fixtures (lambda () ,@body) ,fixtures))


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

Problem: Macro call that should be transformed by NEWQ

Input: (newq nil nil)

Output: (defmacro NEWQ ...)


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

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

Input:
(create-table nil
    (progn))

Output:
(defmacro create-table (table column-definitions &body options)
  `(make-statement :create-table
                   ',(expand-expression table)
                   ,(if (listp (car column-definitions))
                        `(list ,@(if column-definitions
                                     (mapcar
                                      (lambda (column)
                                        `(make-column-definition-clause ',(car column) ,@(cdr column)))
                                      column-definitions)
                                     nil))
                        `,column-definitions)
                   ,@(if (and (null (cdr options))
                              (null (car options)))
                         nil
                         options)))


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

Problem: Macro call that should be transformed by DEFPROXYPRINT

Input:
(defproxyprint nil
    :key
  nil)

Output:
(defmacro defproxyprint (qualifier node &body body)
  "define a pretty-print method for a proxy node"
  `(defproxymethod ,qualifier (pp pretty-printer) ,node ,@body))


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

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

Input: (custom-decoder nil nil)

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


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

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

Input: (initially)

Output: (defmacro INITIALLY ...)


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

Issue: Macro call that should be transformed by RG?

Input: (rg? nil)

Output:
(defmacro rg? (id)
  `(fm-find-registered ,id self nil))


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

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

Input: (growf nil nil)

Output: (defmacro GROWF ...)