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

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

Input:
(defun-cmatch* common-lisp:nil
    :key
  common-lisp:nil)

Output:
(defmacro defun-cmatch* (name args &body body)
  "Equivalent to (defun (arg) [decl-and-docstring] (cmatch arg (PATTERN BODY...)))."
  (multiple-value-bind (preamble clauses) (parse-matcher-body body)
    `(defun ,name ,args
       ,@preamble
       (cmatch* ,args
         ,@clauses))))


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

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

Input: (lambda-bind nil)

Output:
(defmacro lambda-bind ((&rest instrs) &body body)
  "Use `bind' to allow restructuring of argument to lambda expressions.

This lets you funcall and destructure simultaneously. For example

    (let ((fn (lambda-bind ((a b) c) (cons a c))))
      (funcall fn '(1 2) 3))
    ;; => (1 . 3)

Via eschulte (see git://gist.github.com/902174.git).
"
  #+(or)
  (declare (indent 1))
  (let* ((evald-instrs instrs)
         (syms (mapcar (lambda (_)
			 (declare (ignore _))
			 (gensym))
		       evald-instrs)))
    `(lambda ,syms (bind ,(mapcar #'list evald-instrs syms) ,@body))))


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

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

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

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


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

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

Input:
(string-case nil
  nil)

Output: (defmacro STRING-CASE ...)


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

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

Input: (-> nil (progn))

Output: (defmacro -> ...)


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

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

Output: (defmacro F0 ...)


Instruction:
Define a macro that eliminates this repetitive pattern:
(on-conflict-do-nothing 'lol-gen::some-name)

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

Input: (on-conflict-do-nothing 'lol-gen::some-name)

Output:
(defmacro on-conflict-do-nothing (&optional (conflict-target nil))
  `(make-clause :on-conflict-do-nothing ,conflict-target))


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

Problem: Macro call that should be transformed by WITH-NONE-AWAKE

Input:
(with-none-awake nil
  nil)

Output:
(defmacro with-none-awake ((&key dbg diag) &body body)
  `(call-with-none-awake ,dbg (lambda () ,@body) ,diag))


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

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

Input:
(ensure-transaction
  nil)

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


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

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

Input:
(define-class-method nil
    (progn))

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


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

Write a macro that addresses: 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:
(raw 'lol-gen::some-name)

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

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

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


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

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

Input:
(c?1
  nil
  (progn))

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


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

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

Input: (with-capped-stack nil)

Output:
(defmacro with-capped-stack (() &body body)
  `(stack-capper (lambda () ,@body)))


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

Issue: Macro call that should be transformed by LAZY-SEQ

Input: (lazy-seq nil)

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

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


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

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

Input:
(subtest nil
  (progn))

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


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

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

Input: (when-failing nil)

Output: (defmacro WHEN-FAILING ...)


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

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

Input:
(necessarily?
  nil)

Output: (defmacro NECESSARILY? ...)


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

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

Input:
(defreply nil
    (progn))

Output: (defmacro DEFREPLY ...)


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

Problem: Macro call that should be transformed by NLET

Input:
(nlet nil
    (progn))

Output:
(defmacro nlet (name (&rest bindings) &body body &environment env)
  "Within BODY, bind NAME as a function, somewhat like LABELS, but
with the guarantee that recursive calls to NAME will not grow the
stack.

`nlet' resembles Scheme’s named let, and is used for the same purpose:
writing loops using tail recursion. You could of course do this with
`labels' as well, at least under some Lisp implementations, but `nlet'
guarantees tail call elimination anywhere and everywhere.

    (nlet rec ((i 1000000))
      (if (= i 0)
          0
          (rec (1- i))))
    => 0

Beware: because of the way it is written (literally, a GOTO with
arguments), `nlet' is limited: self calls must be tail calls. That is,
you cannot use `nlet' for true recursion.

The name comes from `Let Over Lambda', but this is a more careful
implementation: the function is not bound while the initial arguments
are being evaluated, and it is safe to close over the arguments."
  (setf bindings (loop for binding in bindings
                       if (symbolp binding)
                         collect `(,binding ,binding)
                       else collect binding))
  (multiple-value-bind (body decls)
      (parse-body body)
    (let* ((bindings (mapcar #'ensure-list bindings))
           (vars  (mapcar #'first bindings))
           (inits (mapcar #'second bindings))
           (temps (mapcar #'string-gensym vars))
           (alist (pairlis vars temps))
           (decls
             (map-declaration-env
              (lambda (id names env)
                (values id (sublis alist names) env))
              (parse-declarations decls env))))
      (with-gensyms (tag)
        `(block ,name
           (let ,(mapcar #'list temps inits)
             ,@(build-declarations 'declare decls)
             (macrolet ((,name ,vars
                          `(progn
                             (psetq
                              ,@(mapcan #'list
                                        ',temps
                                        (list ,@vars)))
                             (go ,',tag))))
               (tagbody
                  ,tag (return-from ,name
                         (let ,(mapcar #'list vars temps)
                           ,@body))))))))))


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

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

Input: (nsplice-seqf 'lol-gen::some-name)

Output: (defmacro NSPLICE-SEQF ...)


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

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

Input:
(with-gensyms nil
  nil)

Output:
(defmacro with-gensyms (names &body forms)
  "Binds a set of variables to gensyms and evaluates the implicit progn FORMS.

Each element within NAMES is either a symbol SYMBOL or a pair (SYMBOL
STRING-DESIGNATOR). Bare symbols are equivalent to the pair (SYMBOL SYMBOL).

Each pair (SYMBOL STRING-DESIGNATOR) specifies that the variable named by SYMBOL
should be bound to a symbol constructed using GENSYM with the string designated
by STRING-DESIGNATOR being its first argument."
  `(let ,(mapcar (lambda (name)
                   (multiple-value-bind (symbol string)
                       (etypecase name
                         (symbol
                          (values name (symbol-name name)))
                         ((cons symbol (cons string-designator null))
                          (values (first name) (string (second name)))))
                     `(,symbol (gensym ,string))))
                 names)
     ,@forms))


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

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

Input: (upper nil nil)

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


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

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

Input:
(while nil
  nil)

Output: (defmacro WHILE ...)


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

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

Output: (defmacro ->* ...)


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

Issue: Macro call that should be transformed by COERCEF

Input: (coercef nil (progn))

Output: (defmacro COERCEF ...)


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

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

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

Output: (defmacro CARDINALITY-CASE ...)


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

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

Input:
(define-vari-macro nil
    nil)

Output:
(defmacro define-vari-macro (name lambda-list &body body)
  (check-args-for-constant-names :macro name lambda-list)
  (vbind (func-code context) (gen-macro-function-code name lambda-list body)
    `(progn
       (add-global-form-binding
        (make-regular-macro ',name ,func-code ',context nil))
       ',name)))


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

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

Input:
(when-let nil
  nil)

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

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

All initial-forms are executed sequentially in the specified order. Then all
the variables are bound to the corresponding values.

If all variables were bound to true values, then FORMS are executed as an
implicit PROGN."
  (let* ((binding-list (if (and (consp bindings) (symbolp (car bindings)))
                           (list bindings)
                           bindings))
         (variables (mapcar #'car binding-list)))
    `(let ,binding-list
       (when (and ,@variables)
         ,@forms))))


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

Problem: Macro call that should be transformed by PREPARE

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

Output:
(defmacro prepare (query &optional (format :rows))
  "Wraps a query into a function that can be used as the interface to a prepared
statement. The given query (either a string or an S-SQL form) may contain
placeholders, which look like $1, $2, etc. The resulting function takes one
argument for every placeholder in the query, executes the prepared query, and
returns the result in the format specified. (Allowed formats are the same as for
query.)

For queries that have to be run very often, especially when they are complex,
it may help performance since the server only has to plan them once. See the
http://www.postgresql.org/docs/current/static/sql-prepare.html
in the PostgreSQL manual for details.

In some cases, the server will complain about not being able to deduce the type
of the arguments in a statement. In that case you should add type
declarations (either with the PostgreSQL's CAST SQL-conforming syntax or
historical :: syntax, or with S-SQL's :type construct) to help it out.

Note that it will attempt to automatically reconnect if database-connection-error,
or admin-shutdown. It will reset prepared statements triggering an
invalid-sql-statement-name error. It will overwrite old prepared statements
triggering a duplicate-prepared-statement error."
  `(let ((overwrite ,*allow-overwriting-prepared-statements*))
     ,(generate-prepared '(lambda) (next-statement-id) query format)))


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

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

Input: (isnt nil :key nil)

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


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(ps-package-prefix nil)

Write a macro that addresses: Macro call that should be transformed by PS-PACKAGE-PREFIX

Input: (ps-package-prefix nil)

Output: (defmacro PS-PACKAGE-PREFIX ...)


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

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

Input:
(ensure-get nil
    (progn))

Output:
(defmacro! ensure-get (o!key o!map &body (&optional default))
  `(multiple-value-bind (,g!value ,g!in-map?) (get ,g!key ,g!map)
     (if ,g!in-map?
	 (values ,g!value t)
	 (values
	  (setf (get ,g!key ,g!map) ,default)
	  nil))))


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

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

Input: (c-input nil)

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


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

Problem: Macro call that should be transformed by CMATCH

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

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

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

Input: (like nil :key nil)

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


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

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

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

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


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

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

Input:
(defmacro+ps nil
    (progn))

Output: (defmacro DEFMACRO+PS ...)


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

Problem: Macro call that should be transformed by MAKE-$INSTANCE

Input: (make-$instance 'lol-gen::some-name)

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


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

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

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

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


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

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

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

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


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

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

Input: (destructuring-ccase nil)

Output:
(defmacro destructuring-ccase (keyform &body clauses)
  (expand-destructuring-case keyform clauses 'ccase))


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

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

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

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

As an extension to the generalized `case' syntax, the keys of a clause
can be specified as a literal string.

    (defun vowel? (c)
      (char-case c
        (\"aeiouy\" t)))

Signals an error if KEYFORM does not evaluate to a character."
  `(char-case-1 ,keyform
     ,@(expand-char-case-keys clauses)))


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

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

Input: (whichever)

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

Issue: Macro call that should be transformed by BIND-CUSTOM-VARS

Input:
(bind-custom-vars nil
  (progn))

Output:
(defmacro bind-custom-vars ((&rest customizations) &body body)
  `(let ,(loop-on-custom (key var value) customizations
            collect (list var value))
     ,@body))


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

Problem: Macro call that should be transformed by EXECUTE

Input: (execute nil)

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


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

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

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

Output: (defmacro DOCUMENTATION ...)


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

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

Input:
(f-delta nil
    nil)

Output:
(defmacro f-delta (synapse-id (&key sensitivity (type 'number)) &body body)
  `(call-f-delta ,synapse-id ,sensitivity ',type (lambda () ,@body)))


Instruction:
Generate a defmacro form that transforms code like this:
(on-duplicate-key-update nil (progn))

Pattern to recognize: Macro call that should be transformed by ON-DUPLICATE-KEY-UPDATE

Input: (on-duplicate-key-update nil (progn))

Output:
(defmacro on-duplicate-key-update (&rest args)
  `(make-clause :on-duplicate-key-update ,@(mapcar #'expand-op args)))


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

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

Input:
(with-collectors nil
  nil)

Output:
(defmacro with-collectors ((&rest collectors) &body body)
  "Like `with-collector', with multiple collectors.
Returns the final value of each collector as multiple values.

     (with-collectors (x y z)
       (x 1)
       (y 2)
       (z 3))
     => '(1) '(2) '(3)"
  ;; Warn if there are duplications in COLLECTORS.
  (when (> (length collectors)
           (length (remove-duplicates collectors)))
    (warn "Duplicated collectors in with-collectors form: ~s" collectors))
  (with-gensyms (outer)
    `(block ,outer
       ,(reduce (lambda (form collector)
                  `(with-collector (,collector)
                     ,form))
                collectors
                :initial-value
                `(progn
                   ,@body
                   (return-from ,outer
                     (values ,@(mapcar #'list collectors))))))))


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

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

Input:
(dispatch-case nil
  (progn))

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

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

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

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

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

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

You can do this using `etypecase-of':

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

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

Alternately, you could do it with `defgeneric':

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

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

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

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

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

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

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

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

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


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

Issue: Macro call that should be transformed by RETURNING

Input: (returning nil (progn))

Output: (defmacro RETURNING ...)


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

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

Input: (reversef nil)

Output: (defmacro REVERSEF ...)


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

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

Input: (scond)

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


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

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

Input: (fm!v nil)

Output:
(defmacro fm!v (id)
  `(value (fm! ,id)))


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

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

Input: (cond->>)

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


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

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

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

Output:
(defmacro collecting (&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:
(with-mapping-collector 'lol-gen::some-name)

Problem: Macro call that should be transformed by WITH-MAPPING-COLLECTOR

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

Output: (defmacro WITH-MAPPING-COLLECTOR ...)


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

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

Input:
(actypecase nil
  :key
  nil)

Output:
(defmacro actypecase (keyform &body cases)
  "Like CTYPECASE, except binds the result of the keyform to IT (via LET) for
the scope of the cases. Unlike CTYPECASE, new values possible stored by the
STORE-VALUE restart are not received by the keyform/place, but by IT."
  `(anaphoric ctypecase ,keyform ,@cases))


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

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

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

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

Input: (collect-first nil nil)

Output: (defmacro COLLECT-FIRST ...)


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

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

Input: (dletf nil)

Output: (defmacro DLETF ...)


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

Issue: Macro call that should be transformed by DEFINE-COMPILER-MACRO

Input:
(define-compiler-macro nil
    nil)

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


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

Issue: Macro call that should be transformed by PCASE

Input: (pcase nil nil)

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

   Example usage:

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


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

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

Input:
(do-generators nil
  nil)

Output:
(defmacro do-generators (genspecs &body body)
  "Simultaneously iterate through multiple generators at once. By default
do-generators terminates when the shortest generator ends, but individual
generators can be padded out with the :fill-value keyword. Do-generators can
also iterate over lists in parallel with generators. To use lists, start the genspec with the :list keyword. Eg:
  (do-generators ((a (repeat 2))
			 (:list b '(4 5 6))
			 (c (list->generator '(8 9)) :fill-value 30))
	   (print (* a (+ b c))))
24
28
72
NIL"
  (let ((genspecs (mapcar #'proc-list-spec genspecs))
	(genr (gensym))
	(data (gensym))
	(sig (gensym)))
    (multiple-value-bind (varnames specs)
	(process-genspecs genspecs)

      `(let ((,genr (multi-gen ,@specs)))
	 (loop do
	   (destructuring-bind (,sig . ,data)
	       (multiple-value-list (next-generator-value ,genr))
	     (unless ,sig
	       (return))
	     ,(bind-clause data varnames body)))))))


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

Problem: Macro call that should be transformed by FALSE

Input: (false nil :key nil)

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


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

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

Input: (ensure-functionf nil :key nil)

Output:
(defmacro ensure-functionf (&rest places)
  "Multiple-place modify macro for ENSURE-FUNCTION: ensures that each of
PLACES contains a function."
  `(progn ,@(mapcar (lambda (x) `(ensure-functionf/1 ,x)) places)))


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(def-shadow-type-constructor nil nil)

What needs to change: Macro call that should be transformed by DEF-SHADOW-TYPE-CONSTRUCTOR

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

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


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

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

Input:
(for-all nil
  nil)

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

BINDINGS is a list of binding forms, each element is a list
of (BINDING VALUE &optional GUARD). Value, which is evaluated
once when the for-all is evaluated, must return a generator which
be called each time BODY is evaluated. BINDING is either a symbol
or a list which will be passed to destructuring-bind. GUARD is a
form which, if present, stops BODY from executing when IT returns
NIL. The GUARDS are evaluated after all the random data has been
generated and they can refer to the current value of any
binding. NB: Generator forms, unlike guard forms, can not contain
references to the bound variables.

Examples:

  (for-all ((a (gen-integer)))
    (is (integerp a)))

  (for-all ((a (gen-integer) (plusp a)))
    (is (integerp a))
    (is (plusp a)))

  (for-all ((less (gen-integer))
            (more (gen-integer) (< less more)))
    (is (<= less more)))

  (for-all (((a b) (gen-two-integers)))
    (is (integerp a))
    (is (integerp b)))"
  (with-gensyms (test-lambda-args)
    `(perform-random-testing
      (list ,@(mapcar #'second bindings))
      (lambda (,test-lambda-args)
        (destructuring-bind ,(mapcar #'first bindings)
            ,test-lambda-args
          (if (and ,@(delete-if #'null (mapcar #'third bindings)))
              (progn ,@body)
              (throw 'run-once
                (list :guard-conditions-failed))))))))


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

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

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

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


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

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

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

Output: (defmacro INCF ...)


Instruction:
Generate a defmacro form that transforms code like this:
(multiple-value-ematch nil)

Pattern to recognize: Macro call that should be transformed by MULTIPLE-VALUE-EMATCH

Input: (multiple-value-ematch nil)

Output:
(defmacro multiple-value-ematch (values-form &body clauses)
  "Same as MULTIPLE-VALUE-MATCH, except MATCH-ERROR will be raised if
not matched."
  (let* ((values (gensym "VALUES"))
         (else `(error '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:
Write a Common Lisp macro to handle this code pattern:
(ps-to-stream 'lol-gen::some-name)

Problem: Macro call that should be transformed by PS-TO-STREAM

Input: (ps-to-stream 'lol-gen::some-name)

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


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

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

Input: (with-compilation-unit nil :key nil)

Output: (defmacro WITH-COMPILATION-UNIT ...)


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

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

Input: (order-by nil)

Output: (defmacro ORDER-BY ...)


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

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

Input: (once-only nil)

Output:
(defmacro once-only (specs &body forms)
  "Constructs code whose primary goal is to help automate the handling of
multiple evaluation within macros. Multiple evaluation is handled by introducing
intermediate variables, in order to reuse the result of an expression.

The returned value is a list of the form

  (let ((<gensym-1> <expr-1>)
        ...
        (<gensym-n> <expr-n>))
    <res>)

where GENSYM-1, ..., GENSYM-N are the intermediate variables introduced in order
to evaluate EXPR-1, ..., EXPR-N once, only. RES is code that is the result of
evaluating the implicit progn FORMS within a special context determined by
SPECS. RES should make use of (reference) the intermediate variables.

Each element within SPECS is either a symbol SYMBOL or a pair (SYMBOL INITFORM).
Bare symbols are equivalent to the pair (SYMBOL SYMBOL).

Each pair (SYMBOL INITFORM) specifies a single intermediate variable:

- INITFORM is an expression evaluated to produce EXPR-i

- SYMBOL is the name of the variable that will be bound around FORMS to the
  corresponding gensym GENSYM-i, in order for FORMS to generate RES that
  references the intermediate variable

The evaluation of INITFORMs and binding of SYMBOLs resembles LET. INITFORMs of
all the pairs are evaluated before binding SYMBOLs and evaluating FORMS.

Example:

  The following expression

  (let ((x '(incf y)))
    (once-only (x)
      `(cons ,x ,x)))

  ;;; =>
  ;;; (let ((#1=#:X123 (incf y)))
  ;;;   (cons #1# #1#))

  could be used within a macro to avoid multiple evaluation like so

  (defmacro cons1 (x)
    (once-only (x)
      `(cons ,x ,x)))

  (let ((y 0))
    (cons1 (incf y)))

  ;;; => (1 . 1)

Example:

  The following expression demonstrates the usage of the INITFORM field

  (let ((expr '(incf y)))
    (once-only ((var `(1+ ,expr)))
      `(list ',expr ,var ,var)))

  ;;; =>
  ;;; (let ((#1=#:VAR123 (1+ (incf y))))
  ;;;   (list '(incf y) #1# #1))

  which could be used like so

  (defmacro print-succ-twice (expr)
    (once-only ((var `(1+ ,expr)))
      `(format t \"Expr: ~s, Once: ~s, Twice: ~s~%\" ',expr ,var ,var)))

  (let ((y 10))
    (print-succ-twice (incf y)))

  ;;; >>
  ;;; Expr: (INCF Y), Once: 12, Twice: 12"
  (let ((gensyms (make-gensym-list (length specs) "ONCE-ONLY"))
        (names-and-forms (mapcar (lambda (spec)
                                   (etypecase spec
                                     (list
                                      (destructuring-bind (name form) spec
                                        (cons name form)))
                                     (symbol
                                      (cons spec spec))))
                                 specs)))
    ;; bind in user-macro
    `(let ,(mapcar (lambda (g n) (list g `(gensym ,(string (car n)))))
                   gensyms names-and-forms)
       ;; bind in final expansion
       `(let (,,@(mapcar (lambda (g n)
                           ``(,,g ,,(cdr n)))
                         gensyms names-and-forms))
          ;; bind in user-macro
          ,(let ,(mapcar (lambda (n g) (list (car n) g))
                         names-and-forms gensyms)
             ,@forms)))))


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(pprint-coalton-codegen-ast)

Write a macro that addresses: Macro call that should be transformed by PPRINT-COALTON-CODEGEN-AST

Input: (pprint-coalton-codegen-ast)

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


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

Problem: Macro call that should be transformed by DEFJSMACRO

Input: (defjsmacro nil (progn))

Output: (defmacro DEFJSMACRO ...)


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

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

Input: (string-literal 'lol-gen::some-name)

Output: (defmacro STRING-LITERAL ...)


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

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

Input:
(if-match common-lisp:nil
    :key
  common-lisp:nil)

Output:
(defmacro if-match (pattern arg &body (then &optional else))
  "Equivalent to (match ARG (PATTERN THEN) (_ ELSE))."
  `(match ,arg
     (,pattern ,then)
     (_ ,else)))


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

Issue: Macro call that should be transformed by FBIND

Input: (fbind nil)

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

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

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

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


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

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

Input:
(*let nil
  nil)

Output: (defmacro *LET ...)


Instruction:
Define a macro that eliminates this repetitive pattern:
(ps-html)

Issue: Macro call that should be transformed by PS-HTML

Input: (ps-html)

Output: (defmacro PS-HTML ...)


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
;; Common pattern: test a value, use result in then-branch
(let ((result (compute-something)))
  (if result
      (format t "Got: ~a~%" result)
      :nothing))

;; Want: implicit 'it' bound to test result

Write a macro that addresses: Repeated pattern of binding test result then branching on it — want implicit 'it' anaphor

Input:
;; Common pattern: test a value, use result in then-branch
(let ((result (compute-something)))
  (if result
      (format t "Got: ~a~%" result)
      :nothing))

;; Want: implicit 'it' bound to test result

Output:
(defmacro aif (test then &optional else)
  `(let ((it ,test))
     (if it ,then ,else)))


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

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

Input: (assert common-lisp:nil)

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

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


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

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

Input: (brkx nil)

Output:
(defmacro brkx (msg)
  `(break "At ~a: OK?" ',msg))


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

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

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

Output: (defmacro LOOP ...)


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

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

Input: (with nil)

Output: (defmacro WITH ...)


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

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

Input: (-<> nil (progn))

Output: (defmacro -<> ...)


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

Issue: Macro call that should be transformed by LOCAL-OUTPUT

Input:
(local-output
  nil)

Output: (defmacro LOCAL-OUTPUT ...)


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

Issue: Macro call that should be transformed by PROXY

Input: (proxy nil nil)

Output: (defmacro PROXY ...)


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

Problem: Macro call that should be transformed by EKX

Input: (ekx nil :key nil)

Output:
(defmacro ekx (ekx-id &rest body)
  (let ((result (gensym)))
     `(let ((,result (,@body)))
         (trc ,(string-downcase (symbol-name ekx-id)) :=> ,result)
         ,result)))


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

Problem: Macro call that should be transformed by REDUCED-TYPECASE

Input: (reduced-typecase nil)

Output: (defmacro REDUCED-TYPECASE ...)


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(define-global-parameter* nil (progn))

Write a macro that addresses: Macro call that should be transformed by DEFINE-GLOBAL-PARAMETER*

Input: (define-global-parameter* nil (progn))

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


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

Problem: Macro call that should be transformed by PECASE

Input: (pecase nil nil)

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

   Example usage:

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


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

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

Input:
(block-compile nil
  nil)

Output:
(defmacro block-compile ((&key entry-points
                               (block-compile t))
                         &body body)
  "Shorthand for block compilation with `local*'.

Only the functions in ENTRY-POINTS will have global definitions. All
other functions in BODY will be compiled as purely local functions,
and all of their calls to one another will be compiled as local calls.
This includes calls to the entry points, and even self-calls from
within the entry points.

Note that `declaim' forms occuring inside of BODY will be translated
into local `declare' forms.

If you pass `:block-compile nil', this macro is equivalent to progn.
This may be useful during development."
  (if (not block-compile) `(progn ,@body)
      `(local*
         ,@body
         (progn
           ,@(loop for entry-point in entry-points
                   collect `(defalias ,entry-point #',entry-point))))))


Instruction:
Generate a defmacro form that transforms code like this:
(if-not-let nil
  (progn))

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

Input:
(if-not-let nil
  (progn))

Output:
(defmacro if-not-let (bindings &body (then-form &optional else-form))
  "Creates new variable bindings, and conditionally executes either
THEN-FORM or ELSE-FORM. ELSE-FORM defaults to NIL.
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))
All initial-forms are executed sequentially in the specified order. Then all
the variables are bound to the corresponding values.
If one of the variables was bound to NIL, the THEN-FORM is executed with the
bindings in effect, otherwise the ELSE-FORM is executed with the bindings in
effect.
Adapted from Alexandria if-let."
  (let* ((binding-list (if (and (consp bindings) (symbolp (car bindings)))
                           (list bindings)
                           bindings))
         (variables (mapcar #'car binding-list)))
    `(let ,binding-list
       (if-not (and ,@variables)
	       ,then-form
	       ,else-form))))


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

Problem: Macro call that should be transformed by LOCAL*

Input:
(local*
  nil
  :key
  nil)

Output:
(defmacro local* (&body body)
  "Like `local', but leave the last form in BODY intact.

     (local*
       (defun aux-fn ...)
       (defun entry-point ...))
     =>
     (labels ((aux-fn ...))
       (defun entry-point ...))"
  `(local
     ,@(butlast body)
     (without-internal-definitions ,@(last body))))


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

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

Input: (some->> nil nil)

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


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

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

Input: (c-envalue)

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


Instruction:
Write a Common Lisp macro to handle this code pattern:
(export-constructors
  common-lisp:nil
  :key
  common-lisp:nil)

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

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

Output: (defmacro EXPORT-CONSTRUCTORS ...)


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

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

Input: (join nil)

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


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

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

Input: (ps)

Output: (defmacro PS ...)


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

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

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

Output: (defmacro TYPE ...)


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

Problem: Macro call that should be transformed by TO-BOOLEAN

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

Output: (defmacro TO-BOOLEAN ...)


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

Problem: Macro call that should be transformed by PROG

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

Output: (defmacro PROG ...)


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

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

Input: (psib)

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


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


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

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

Input: (fdec nil)

Output:
(defmacro fdec (place &optional (delta 1))
  "DEPRECATED: use `shift-decf' instead."
  (simple-style-warning "~s is deprecated, use ~s instead"
                        'finc 'shift-incf)
  `(shift-decf ,place ,delta))


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

Issue: Macro call that should be transformed by XOR

Input: (xor nil nil)

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


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

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

Input:
(aecase nil
  (progn))

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


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

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

Input:
(with-dot nil
  (progn))

Output:
(defmacro with-dot (() &body body)
  `(progn ,@(replace-dot-calls body)))


Instruction:
Define a macro that eliminates this repetitive pattern:
;; Exporting closure variables requires building pandoric protocol manually
(let ((a 0))
  (let ((b 1))
    (let (this self)
      (setq
        this (lambda (n) (incf a n) (setq b (* b n)))
        self (dlambda
               (:pandoric-get (sym)
                 (case sym
                   ((a) a)
                   ((b) b)
                   (t (error "Unknown: ~a" sym))))
               (:pandoric-set (sym val)
                 (case sym
                   ((a) (setq a val))
                   ((b) (setq b val))))
               (t (&rest args) (apply this args)))))))

;; Manual self construction for every closure is painful

Issue: Need to export closure variables through pandoric protocol, but manually building the self dlambda for each set of variables is repetitive

Input:
;; Exporting closure variables requires building pandoric protocol manually
(let ((a 0))
  (let ((b 1))
    (let (this self)
      (setq
        this (lambda (n) (incf a n) (setq b (* b n)))
        self (dlambda
               (:pandoric-get (sym)
                 (case sym
                   ((a) a)
                   ((b) b)
                   (t (error "Unknown: ~a" sym))))
               (:pandoric-set (sym val)
                 (case sym
                   ((a) (setq a val))
                   ((b) (setq b val))))
               (t (&rest args) (apply this args)))))))

;; Manual self construction for every closure is painful

Output:
(defmacro plambda (largs pargs &rest body)
  (let ((pargs (mapcar #'list pargs)))
    `(let (this self)
       (setq
         this (lambda ,largs ,@body)
         self (dlambda
                (:pandoric-get (sym)
                  ,(pandoriclet-get pargs))
                (:pandoric-set (sym val)
                  ,(pandoriclet-set pargs))
                (t (&rest args)
                  (apply this args)))))))


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

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

Input: (terminate-producing)

Output: (defmacro TERMINATE-PRODUCING ...)


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

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

Input:
(with-shuffling
  nil)

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


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

Problem: Macro call that should be transformed by NCONCF

Input: (nconcf nil :key nil)

Output: (defmacro NCONCF ...)


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

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

Input: (next-in 'lol-gen::some-name)

Output: (defmacro NEXT-IN ...)


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

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

Input: (c-input 'lol-gen::some-name)

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


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

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

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

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


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

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

Input: (and nil)

Output: (defmacro AND ...)


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

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

Input: (defpackage nil)

Output: (defmacro DEFPACKAGE ...)


Instruction:
Define a macro that eliminates this repetitive pattern:
(unwind-protect-case nil
    (progn))

Issue: Macro call that should be transformed by UNWIND-PROTECT-CASE

Input:
(unwind-protect-case nil
    (progn))

Output:
(defmacro unwind-protect-case ((&optional abort-flag) protected-form &body clauses)
  "Like CL:UNWIND-PROTECT, but you can specify the circumstances that
the cleanup CLAUSES are run.

  clauses ::= (:NORMAL form*)* | (:ABORT form*)* | (:ALWAYS form*)*

Clauses can be given in any order, and more than one clause can be
given for each circumstance. The clauses whose denoted circumstance
occured, are executed in the order the clauses appear.

ABORT-FLAG is the name of a variable that will be bound to T in
CLAUSES if the PROTECTED-FORM aborted preemptively, and to NIL
otherwise.

Examples:

  (unwind-protect-case ()
       (protected-form)
     (:normal (format t \"This is only evaluated if PROTECTED-FORM executed normally.~%\"))
     (:abort  (format t \"This is only evaluated if PROTECTED-FORM aborted preemptively.~%\"))
     (:always (format t \"This is evaluated in either case.~%\")))

  (unwind-protect-case (aborted-p)
       (protected-form)
     (:always (perform-cleanup-if aborted-p)))
"
  (check-type abort-flag (or null symbol))
  (let ((gflag (gensym "FLAG+")))
    `(let ((,gflag t))
       (unwind-protect (multiple-value-prog1 ,protected-form (setf ,gflag nil))
	 (let ,(and abort-flag `((,abort-flag ,gflag)))
	   ,@(loop for (cleanup-kind . forms) in clauses
		   collect (ecase cleanup-kind
			     (:normal `(when (not ,gflag) ,@forms))
			     (:abort  `(when ,gflag ,@forms))
			     (:always `(progn ,@forms)))))))))


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

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

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

Output: (defmacro METACLASS ...)


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

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

Input: (ignore-errors nil :key nil)

Output: (defmacro IGNORE-ERRORS ...)


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

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

Input: (collect-plist nil nil)

Output: (defmacro COLLECT-PLIST ...)


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

Issue: Macro call that should be transformed by WITH-COLUMN-WRITERS

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

Output:
(defmacro with-column-writers ((&rest defs) &body body)
  "Provides control over the way get-dao, select-dao, and query-dao read values
from the database. This is not commonly needed, but can be used to reduce the
amount of queries a system makes. writers should be a list of alternating
column names (strings or symbols) and writers, where writers are either
symbols referring to a slot in the objects, or functions taking two arguments ―
an instance and a value ― which can be used to somehow store the value in the
new instance. When any DAO-fetching function is called in the body, and
columns matching the given names are encountered in the result, the writers
are used instead of the default behaviour (try and store the value in the slot
that matches the column name).

An example of using this is to add some non-column slots to a DAO class, and
use query-dao within a with-column-writers form to pull in extra information
about the objects, and immediately store it in the new instances."
  `(let ((*custom-column-writers*
           (append (list ,@(loop :for (field writer) :on defs :by #'cddr
                                 :collect `(cons (to-sql-name ,field nil) ,writer)))
                   *custom-column-writers*)))
     ,@body))


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

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

Input: (<$ nil (progn))

Output:
(defmacro <$ (item parser)
  "Run some parser, but substitute its inner value with some `item' if parsing was
  successful."
  (let ((offset (gensym "<$-OFFSET"))
        (res    (gensym "<$-RES"))
        (next   (gensym "<$-NEXT")))
    `(lambda (,offset)
       (multiple-value-bind (,res ,next) (funcall ,parser ,offset)
         (if (failure? ,res)
             (fail ,next)
             (values ,item ,next))))))


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

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

Input: (collect-max nil (progn))

Output: (defmacro COLLECT-MAX ...)


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

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

Input: (ensure-functionf nil)

Output:
(defmacro ensure-functionf (&rest places)
  "Multiple-place modify macro for ENSURE-FUNCTION: ensures that each of
PLACES contains a function."
  `(progn ,@(mapcar (lambda (x) `(ensure-functionf/1 ,x)) places)))


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

Issue: Macro call that should be transformed by CTYPECASE

Input: (ctypecase nil (progn))

Output: (defmacro CTYPECASE ...)


Instruction:
Generate a defmacro form that transforms code like this:
(eval-when-execute)

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

Input: (eval-when-execute)

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


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

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

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

Output: (defmacro WITH-RULES ...)


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

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

Input:
(batch
  nil
  (progn))

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

Issue: Macro call that should be transformed by CLL-OUTER

Input: (cll-outer nil)

Output:
(defmacro cll-outer (val &body body)
 `(let ((outer-val ,val))
    ,@body))


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

Issue: Macro call that should be transformed by DRELETF*

Input:
(dreletf* nil
  (progn))

Output: (defmacro DRELETF* ...)


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

What needs to change: Macro call that should be transformed by DO-INSTANCE-COMBINATIONS

Input: (do-instance-combinations nil)

Output: (defmacro DO-INSTANCE-COMBINATIONS ...)


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

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

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

Output:
(defmacro do-each ((var seq &optional return) &body body &environment env)
  "Iterate over the elements of SEQ, a sequence.
If SEQ is a list, this is equivalent to `dolist'."
  (unless (speed-matters? env)
    (return-from do-each
      `(do-each/map (,var ,seq ,@(unsplice return))
         ,@body)))
  ;; We hoist the body and use sb-ext:muffle-conditions to prevent
  ;; SBCL from spamming us with code deletion notes. (It may also be
  ;; desirable in itself to avoid needless code duplication in Lisps
  ;; without type inference.)
  (with-thunk ((body :name do-each) var)
    (let ((iter-spec `(,var ,seq ,@(unsplice return))))
      `(locally (declare #+sbcl (sb-ext:muffle-conditions sb-ext:code-deletion-note))
         #+(or sbcl abcl)
         (sequence:dosequence ,iter-spec
           (,body ,var))
         #-(or sbcl abcl)
         (%do-each ,iter-spec
           (,body ,var))))))


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

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

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

Output: (defmacro SUMMING-TO ...)


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

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

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

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


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

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

Input: (labels* nil)

Output: (defmacro LABELS* ...)


Instruction:
Generate a defmacro form that transforms code like this:
(define-test+run-interactively nil
  :key
  nil)

Pattern to recognize: Macro call that should be transformed by DEFINE-TEST+RUN-INTERACTIVELY

Input:
(define-test+run-interactively nil
  :key
  nil)

Output:
(defmacro define-test+run-interactively (name &body args-and-body)
  `(progn (define-test ,name ,@args-and-body)
          (eval-when (:execute)
            (values ',name (test ',name :report 'interactive)))))


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

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

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

Output: (defmacro ECASE ...)


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

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

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


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

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

Input:
(jwhen nil
  nil)

Output:
(defmacro jwhen (test &body body)
  "JSON-aware version of `cl:when'.
If TEST is `jtruep' evaluate BODY."
  `(jif ,test
       (progn ,@body)))


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

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

Input:
(caching-types
  nil
  (progn))

Output: (defmacro CACHING-TYPES ...)


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

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

Input:
(ifmatch nil
    :key
    nil)

Output: (defmacro IFMATCH ...)


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

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

Input:
(fbindrec* nil
  (progn))

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


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

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

Input: (c-lambda)

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


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

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

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

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


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

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

Input: (with-hook-restart)

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


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

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

Input: (do-generators nil)

Output:
(defmacro do-generators (genspecs &body body)
  "Simultaneously iterate through multiple generators at once. By default
do-generators terminates when the shortest generator ends, but individual
generators can be padded out with the :fill-value keyword. Do-generators can
also iterate over lists in parallel with generators. To use lists, start the genspec with the :list keyword. Eg:
  (do-generators ((a (repeat 2))
			 (:list b '(4 5 6))
			 (c (list->generator '(8 9)) :fill-value 30))
	   (print (* a (+ b c))))
24
28
72
NIL"
  (let ((genspecs (mapcar #'proc-list-spec genspecs))
	(genr (gensym))
	(data (gensym))
	(sig (gensym)))
    (multiple-value-bind (varnames specs)
	(process-genspecs genspecs)

      `(let ((,genr (multi-gen ,@specs)))
	 (loop do
	   (destructuring-bind (,sig . ,data)
	       (multiple-value-list (next-generator-value ,genr))
	     (unless ,sig
	       (return))
	     ,(bind-clause data varnames body)))))))


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

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

Input:
(with-collectors nil
  :key
  nil)

Output: (defmacro WITH-COLLECTORS ...)


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

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

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

Output:
(defmacro call-method (method &optional methods)
  `(cl:call-method ,method ,methods))


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

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

Input: (xml)

Output:
(defmacro xml (&rest tags)
  `(with-doctype :xml
     (loop for tag in ',tags
           append (tag->string tag))))


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

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

Input:
(dynamic-wind
  nil
  (progn))

Output: (defmacro DYNAMIC-WIND ...)


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

Problem: Macro call that should be transformed by ONE-VALUE

Input: (one-value nil nil)

Output: (defmacro ONE-VALUE ...)


Instruction:
Define a macro that eliminates this repetitive pattern:
(with-local-class-registry nil
  :key
  nil)

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

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

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


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

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

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

Output: (defmacro FN ...)


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

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

Input:
(eval-and-compile
  nil
  (progn))

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


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

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

Input:
(->>
  nil
  nil)

Output: (defmacro ->> ...)


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

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

Input: (ensure-functionf nil (progn))

Output:
(defmacro ensure-functionf (&rest places)
  "Multiple-place modify macro for ENSURE-FUNCTION: ensures that each of
PLACES contains a function."
  `(progn ,@(mapcar (lambda (x) `(ensure-functionf/1 ,x)) places)))


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

Issue: Macro call that should be transformed by ASSERT

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

Output: (defmacro ASSERT ...)


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 ~> (needle &rest holes)
  "Threading macro from Clojure (by way of Racket).

Thread NEEDLE through HOLES, where each hole is either a
symbol (equivalent to `(hole needle)`) or a list (equivalent to `(hole
needle args...)`).

As an extension, an underscore in the argument list is replaced with
the needle, so you can pass the needle as an argument other than the
first."
  (thread-aux '~> needle holes
              (lambda (needle hole)
                (list* (car hole) needle (cdr hole)))))


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

Issue: Macro call that should be transformed by V-DEFINE-COMPILER-MACRO

Input:
(v-define-compiler-macro nil
    :key
  nil)

Output:
(defmacro v-define-compiler-macro (name lambda-list &body body)
  `(define-vari-compiler-macro ,name ,lambda-list ,@body))


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

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

Input: (order-by nil nil)

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


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

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

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

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


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

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

Input:
(with-properties nil
    :key
  nil)

Output: (defmacro WITH-PROPERTIES ...)


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

Issue: Macro call that should be transformed by FTYPE

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

Output: (defmacro FTYPE ...)


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

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

Input:
(fbindrec* nil
  nil)

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


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

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

Input:
(cond-let nil
  (progn))

Output:
(defmacro cond-let (var &body clauses)
  "Cross between COND and LET.

     (cond-let x ((test ...)))
     ≡ (let (x)
         (cond ((setf x test) ...)))

Cf. `acond' in Anaphora."
  (match clauses
    (() nil)
    ((list* (list test) clauses)
     `(if-let1 ,var ,test
        ,var
        (cond-let ,var ,@clauses)))
    ((list* (list* t body) _)
     `(progn ,@body))
    ((list* (list* test body) clauses)
     `(let ((,var ,test))
        (if ,var
            ;; Rebind the variables for declarations.
            (let1 ,var ,var
              ,@body)
            (cond-let ,var ,@clauses))))))


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

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

Input: (multiple-value-bind nil nil)

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


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

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

Input: (psetf)

Output: (defmacro PSETF ...)


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

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

Input:
(define-screamer-package nil
  (progn))

Output:
(defmacro define-screamer-package (defined-package-name &body options)
  "Convenience wrapper around DEFPACKAGE. Passes its argument directly
to DEFPACKAGE, and automatically injects two additional options:

    \(:shadowing-import-from :screamer :defun :multiple-value-bind :y-or-n-p)
    \(:use :cl :screamer)"
  `(defpackage ,defined-package-name
     ,@options
     (:shadowing-import-from :screamer :defun :multiple-value-bind :y-or-n-p)
     (:use :cl :screamer)))


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

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

Input: (select-dao 'lol-gen::some-name)

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

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

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

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


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

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

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

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


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

Issue: Macro call that should be transformed by ASSERT

Input: (assert nil (progn))

Output: (defmacro ASSERT ...)


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

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

Input: (across nil)

Output: (defmacro ACROSS ...)


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

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

Input:
(swhen nil
  nil)

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


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

Issue: Macro call that should be transformed by RETURN

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

Output: (defmacro RETURN ...)


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

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

Input: (continue-whopper)

Output: (defmacro CONTINUE-WHOPPER ...)


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

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

Input: (prog1 nil :key nil)

Output: (defmacro PROG1 ...)


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

Issue: Macro call that should be transformed by DEFPACKAGE

Input: (defpackage nil nil)

Output: (defmacro DEFPACKAGE ...)


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

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

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

Output: (defmacro CCASE ...)


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

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

Input: (collect-first nil)

Output: (defmacro COLLECT-FIRST ...)


Instruction:
Define a macro that eliminates this repetitive pattern:
(walk-environment
  nil
  (progn))

Issue: Macro call that should be transformed by WALK-ENVIRONMENT

Input:
(walk-environment
  nil
  (progn))

Output: (defmacro WALK-ENVIRONMENT ...)


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

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

Input:
(for-effects
  nil
  (progn))

Output: (defmacro FOR-EFFECTS ...)


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

Problem: Macro call that should be transformed by FINALIZE-DISPATCH-METHOD

Input: (finalize-dispatch-method nil (progn))

Output:
(defmacro finalize-dispatch-method (generic-function &rest args)
  "add a body to the method which dispatched the hooks for the given specialized-lambda-list
useful if you wanted to use call-next-method

For the definition to be effective, it must be defined after every specific hook for the same method hence finalize.

See defhook"
  (%destructure-defhook-args args
    (with-effective-qualifier generic-function qualifier
      (destructure-specialized-lambda-list descriptive-lambda-list vanilla-lambda-list type-list specialized-lambda-list
        `(%lay-method-base-for-dispatch ,generic-function ,qualifier ,type-list ,descriptive-lambda-list
           ,@body)))))


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

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

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

Output:
(defmacro wtrc ((&optional (min 1) (max 50) &rest banner) &body body )
  `(let ((*trcdepth* (if *trcdepth*
                         (1+ *trcdepth*)
                       0)))
     ,(when banner `(when (>= *trcdepth* ,min)
                      (if (< *trcdepth* ,max)
                          (trc ,@banner)
                        (progn
                          (break "excess trace notttt!!! ~d" *trcdepth*) ;; ,@banner)
                          nil))))
     (when (< *trcdepth* ,max)
       ,@body)))


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

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

Input: (-> nil)

Output: (defmacro -> ...)


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

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

Input: (collect-nth nil nil)

Output: (defmacro COLLECT-NTH ...)