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

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

Input: (cond-every)

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

Return the value of the last successful clause.

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

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

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


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

Problem: Macro call that should be transformed by XOR

Input: (xor 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:
(nth-value-or nil
  :key
  nil)

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

Input:
(nth-value-or nil
  :key
  nil)

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


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

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

Input: (.> common-lisp:nil common-lisp:nil)

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

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


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

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

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

Output:
(defmacro define-simple-definition-resolver (class lookup-function &body body)
  (let ((package (gensym "PACKAGE")))
    `(define-definition-resolver ,class (,class ,package)
       (when (ignore-errors ,(if body
                                 `(let ((,(first lookup-function) ,class))
                                    ,@body)
                                 `(,lookup-function ,class)))
         (list (make-instance ',class :designator ,class :package ,package))))))


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

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

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

Output:
(defmacro sor (first &rest rest)
  "Like OR, except binds the first argument to IT (via SYMBOL-MACROLET) for
the scope of the rest of the arguments. IT can be set with SETF."
  `(symbolic or ,first ,@rest))


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

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

Input:
(actypecase nil
  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:
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 *> (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:
Define a macro that eliminates this repetitive pattern:
(multiple-value-ematch 'lol-gen::some-name)

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

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

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:
Generate a defmacro form that transforms code like this:
(advisable-lambda 'lol-gen::some-name)

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

Input: (advisable-lambda 'lol-gen::some-name)

Output: (defmacro ADVISABLE-LAMBDA ...)


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

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

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

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


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

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

Input:
(cond-it
  nil
  (progn))

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


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

Problem: Macro call that should be transformed by DEFVAR

Input: (defvar nil :key nil)

Output: (defmacro DEFVAR ...)


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

Problem: Macro call that should be transformed by THE-PART

Input: (the-part nil)

Output: (defmacro THE-PART ...)


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

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

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

Output:
(defmacro quoty (item &environment env)
  "Quote undefined symbols, build functions from unknown lists"
  (cond ((eql item nil)
	 (values))
	((listp item)
	 (if (or (listp (first item))
		 (not (fboundp! (first item) env)))
	     `(function-call
	       (make-node ,(first item))
	       (make-nodelist ,(rest item)))
	     item))
	((symbolp item)
	 (if (vboundp! item env)
	     item
	     `',item))
	(t item)))


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

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

Input: (ekx nil)

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


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

Issue: Macro call that should be transformed by AND

Input: (and)

Output: (defmacro AND ...)


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

Problem: Macro call that should be transformed by C_1

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


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

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

Input: (fm-other?! 'lol-gen::some-name)

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


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

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

Input: (defprepared nil nil)

Output:
(defmacro defprepared (name query &optional (format :rows))
  "This is another macro variant of prepare. It is like prepare, but gives the
function a name which now becomes a top-level function for the prepared
statement. The name should not be a string but may be quoted."
  (when (consp name) (setf name (s-sql::dequote name)))
  `(let ((overwrite ,*allow-overwriting-prepared-statements*))
     ,(generate-prepared `(defun ,name) name query format)))


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

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

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

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


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

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

Input:
(ignore-some-conditions nil
  nil)

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


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

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

Input: (max-of nil)

Output: (defmacro MAX-OF ...)


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

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

Input: (keep-bops)

Output: (defmacro KEEP-BOPS ...)


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

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

Input:
(f_n
  nil
  (progn))

Output: (defmacro F_N ...)


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

Issue: Macro call that should be transformed by WITH-LOGICAL-TRANSACTION

Input:
(with-logical-transaction nil
  (progn))

Output:
(defmacro with-logical-transaction ((&optional (name nil name-p)
                                       (isolation-level *isolation-level*
                                                        isolation-level-p))
                                    &body body)
  "Executes body within a with-transaction form if no transaction is currently
in progress, otherwise simulates a nested transaction by executing it
within a with-savepoint form. The transaction or savepoint is bound to name
if one is supplied. The isolation-level will set the isolation-level used by
the transaction.

You can specify the following isolation levels in postmodern transactions:

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

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

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

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

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

  (with-logical-transaction (:serializable)
    (execute (:insert-into 'test-data :set 'value 44))
    ...)"
  (let* ((effective-name (if (and name-p (not (isolation-level-p name)))
                             name
                             (gensym)))
         (effective-body (if (and name-p (not (isolation-level-p name)))
                             `(lambda (,name) ,@body)
                             `(lambda (,effective-name)
                                (declare (ignore ,effective-name))
                                ,@body)))
         (effective-isolation-level (cond ((and isolation-level-p
                                                (isolation-level-p isolation-level))
                                           isolation-level)
                                          ((and name-p (isolation-level-p name))
                                           name)
                                          (t isolation-level))))
    `(call-with-logical-transaction ',effective-name ,effective-body
                                    ,effective-isolation-level)))


Instruction:
Define a macro that eliminates this repetitive pattern:
(with-standard-io-syntax nil)

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

Input: (with-standard-io-syntax nil)

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


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

Issue: Macro call that should be transformed by DYNAMIC-RELET*

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

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


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

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

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

Output:
(defmacro with-connection (spec &body body)
  "Evaluates the body with *database* bound to a connection as specified by spec,
which should be list that connect can be applied to."
  `(let ((*database* (apply #'connect ,spec)))
     (unwind-protect (progn ,@body)
       (disconnect *database*))))


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

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

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

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


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

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

Input: (fm^ nil)

Output:
(defmacro fm^ (md-name &key (skip-tree 'self) (must-find t))
  `(without-c-dependency
    (fm-find-one (fm-parent self) ,md-name
      :skip-tree ,skip-tree
      :must-find ,must-find
      :global-search t)))


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

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

Input: (collect-hash nil (progn))

Output: (defmacro COLLECT-HASH ...)


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

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

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

Output: (defmacro EXPORT ...)


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

What needs to change: Macro call that should be transformed by MAKE-NAME-TRANSFORMER

Input: (make-name-transformer)

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


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

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

Input:
(with-none-awake nil
  :key
  nil)

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


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

Issue: Macro call that should be transformed by DLET*

Input: (dlet* nil)

Output: (defmacro DLET* ...)


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

Problem: Macro call that should be transformed by WITH-READ-ONLY-VARS

Input:
(with-read-only-vars nil
  :key
  nil)

Output:
(defmacro with-read-only-vars ((&rest vars) &body body &environment env)
  "Make VARS read-only within BODY.

That is, within BODY, each var in VARS is bound as a symbol macro,
which expands into a macro whose setf expander, in turn, is defined to
signal a warning at compile time, and an error at run time.

Depending on your Lisp implementation this may or may not do anything,
and may or may not have an effect when used on special variables."
  (declare (ignorable env))
  (case uiop:*implementation-type*
    ((:ccl :sbcl :cmu :acl)
     ;; The use of temps here, while it is ugly and annoying when
     ;; debugging, is necessary to prevent symbol-macrolet from going
     ;; into an infinite loop.
     (let* ((vars (loop for var in vars
                        unless (variable-special? var env)
                          collect var))
            (temps
              (loop for var in vars
                    collect (gensym (string var)))))
       `(let ,(mapcar #'list temps vars)
          (declare (ignorable ,@temps))
          (symbol-macrolet ,(loop for var in vars
                                  for temp in temps
                                  collect `(,var (read-only-var ,temp ,var)))
            ,@body))))
    (t
     `(locally ,@body))))


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

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

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

Output:
(defmacro define-parse-method (name lambda-list &body body)
  "Define a type parser on NAME and lists whose CAR is NAME."
  (discard-docstring body)
  (warn-if-kw-or-belongs-to-cl name)
  `(eval-when (:compile-toplevel :load-toplevel :execute)
     (setf (find-type-parser ',name)
           (lambda ,lambda-list ,@body))
     ',name))


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

Problem: Macro call that should be transformed by OR

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

Output: (defmacro OR ...)


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

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

Input: (fail nil)

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


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

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

Input: (dict-of nil)

Output: (defmacro DICT-OF ...)


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

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

Input: (aif nil (progn))

Output: (defmacro AIF ...)


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

Problem: Macro call that should be transformed by IF-IT

Input: (if-it nil :key nil)

Output:
(defmacro if-it (test then &optional else)
  "Like IF. IT is bound to TEST."
  `(let ((it ,test))
     (if it ,then ,else)))


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

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

Input:
(flet* nil
  (progn))

Output: (defmacro FLET* ...)


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

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

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

Output:
(defmacro match2 (what &body clauses)
  "In match2/match2*, the last clause is not enclosed in a block.
Therefore, using `next' in the last clause results in jumping to the next innermost matching construct,
or results in a compilation error when this is the outermost matching construct."
  `(match2+ ,what t ,@clauses))


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

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

Input: (lambda () :key nil)

Output: (defmacro LAMBDA ...)


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

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

Input: (tree-case nil)

Output: (defmacro TREE-CASE ...)


Instruction:
Write a Common Lisp macro to handle this code pattern:
(loop-finish)

Problem: Macro call that should be transformed by LOOP-FINISH

Input: (loop-finish)

Output: (defmacro LOOP-FINISH ...)


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

Issue: Macro call that should be transformed by DEFUN-MATCH*

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

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


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

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

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

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


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

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

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

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

Example:

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

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

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

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

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

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

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


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

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

Input:
(define-vari-function nil
    nil)

Output:
(defmacro define-vari-function (name args &body body)
  (check-args-for-constant-names :function name args)
  (destructuring-bind (in-args uniforms context shared)
      (split-arguments args '(&uniform &context &shared))
    (declare (ignore context))
    (assert (not shared) () 'shared-in-function :name name)
    `(progn
       (add-external-function ',name ',in-args ',uniforms ',body)
       ',name)))


Instruction:
Generate a defmacro form that transforms code like this:
(compile-$flavor-$methods nil)

Pattern to recognize: Macro call that should be transformed by COMPILE-$FLAVOR-$METHODS

Input: (compile-$flavor-$methods nil)

Output: (defmacro COMPILE-$FLAVOR-$METHODS ...)


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

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

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

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

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

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

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

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

         ,name
         ,seqs
         ,@forms))))


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

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

Input: (prog2 nil nil)

Output: (defmacro PROG2 ...)


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

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

Input: (whichever nil)

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

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

Input:
(maybe-once-only nil
  nil)

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


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

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

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

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


Instruction:
Define a macro that eliminates this repetitive pattern:
(splice-seqf nil (progn))

Issue: Macro call that should be transformed by SPLICE-SEQF

Input: (splice-seqf nil (progn))

Output: (defmacro SPLICE-SEQF ...)


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

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

Input: (quoty nil)

Output:
(defmacro quoty (item &environment env)
  "Quote undefined symbols, build functions from unknown lists"
  (cond ((eql item nil)
	 (values))
	((listp item)
	 (if (or (listp (first item))
		 (not (fboundp! (first item) env)))
	     `(function-call
	       (make-node ,(first item))
	       (make-nodelist ,(rest item)))
	     item))
	((symbolp item)
	 (if (vboundp! item env)
	     item
	     `',item))
	(t item)))


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

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

Input: (-<> nil)

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


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

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

Input:
(dynamic-let* nil
  nil)

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


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

Problem: Macro call that should be transformed by PIPE

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

Output:
(defmacro pipe (cl:&rest items)
  "A syntactic convenience for function application, sometimes called a \"threading macro\". Transform

    (pipe x h g f)

to

    (f (g (h x)))."
  (cl:assert (cl:<= 2 (cl:list-length items)))
  `(nest ,@(cl:reverse items)))


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

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

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

Output: (defmacro MATRIX-CTYPECASE ...)


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

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

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

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


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

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

Input: (iter)

Output:
(defmacro iter (&body body &environment env)
  "Jonathan Amsterdam's powerful and extensible iteration facility,
providing multiple accumulation, generators, memory of previous
iterations, over 50 clauses to start with and a Lisp-like syntax.
Evaluate (iterate:display-iterate-clauses) for an overview of clauses"
  (let* ((*env* env)
	 (*result-var* (genvar 'result))
	 (*type-alist* nil)
	 (*declare-variables* *always-declare-variables*)
	 (*bindings* nil)
	 (*internal-variables* nil)
	 (*previous-vars-alist* nil)
	 (*declarations* nil)
	 (*loop-body-wrappers* nil)
	 (*accum-var-alist* nil)
	 (*shared-bindings-alist* nil)
	 (*top-level?* t)
	 (*binding-context?* nil)
	 (*temps* nil)
	 (*temps-in-use* nil)
	 (*driver-info-alist* nil)
	 (*loop-name* (if (symbolp (car body))
			  (car body)
			  (gensym "ITERATE")))
	 (*block-name* (if (symbolp (car body))
			   (pop body)
			   nil))
	 (*loop-top* (symbol-append 'loop-top- *block-name*))
	 (*loop-step* (symbol-append 'loop-step- *block-name*))
	 (*loop-end* (symbol-append 'loop-end- *block-name*))
	 (*loop-step-used?* nil)
	 (*loop-end-used?* nil))
    (process-top-level-decls body)
    (multiple-value-bind (body decls init-code steppers final-code final-prot)
	(walk-list body)
      (multiple-value-bind (init step)
	  (insert-previous-code)
	(augment init-code init)
	(augment steppers step))
      (prepend (default-driver-code) body)
      (let* ((it-bod `(block ,*loop-name*
			(tagbody
			  (progn ,.init-code)
			  ,*loop-top*
			  (progn ,.body)
			  ,.(if *loop-step-used?* (list *loop-step*))
			  (progn ,.steppers)
			  (go ,*loop-top*)
			  ,.(if *loop-end-used?* (list *loop-end*))
			  (progn ,.final-code))
			,(if (member *result-var* *bindings* :key #'car)
			   *result-var*
			   nil)))
	     (it-bod (if (eql *block-name* nil)
			 `(block nil ,it-bod)
			 it-bod)))
	(wrap-form *loop-body-wrappers*
		   `(let* ,(nreverse *bindings*)
		     ,.(if *declarations*
			   `((declare .,*declarations*)))
		     ,.decls
		     ,(if final-prot
			  `(unwind-protect ,it-bod .,final-prot)
			  it-bod)))))))


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

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

Input: (of-type nil nil)

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


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

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

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

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


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

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

Input: (appendf nil (progn))

Output: (defmacro APPENDF ...)


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

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

Input: (nodelist nil)

Output: (defmacro NODELIST ...)


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

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

Input:
(defprettymethod nil
    :key
  nil)

Output:
(defmacro defprettymethod (qualifier node &body body)
  (if (eql :self qualifier)
      `(progn (setf (gethash (find-class ',node) *ignore-node*) t)
	      (defmethod traverser
		  ((pp pretty-printer)
		   (item ,node) level)
		(declare (ignorable level))
		(with-slots (values subnodes) item .,body)
		(call-next-method)))
      `(defmethod traverser ,qualifier
	 ((pp pretty-printer)
	  (item ,node) level)
	 (declare (ignorable level))
	 (with-slots (values subnodes) item .,body))))


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

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

Input: (ps-html 'lol-gen::some-name)

Output: (defmacro PS-HTML ...)


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

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

Input: (define-method-combination nil)

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


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

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

Input:
(c_?dbg
  nil
  (progn))

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

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

Input:
(with-tokens nil
  (progn))

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


Instruction:
Define a macro that eliminates this repetitive pattern:
(make-name-transformer nil nil)

Issue: Macro call that should be transformed by MAKE-NAME-TRANSFORMER

Input: (make-name-transformer nil nil)

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


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

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

Input: (defdata nil)

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

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

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

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

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

Constructors is a list of clauses with the following grammar:

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

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

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

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

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

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

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

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


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

Problem: Macro call that should be transformed by APPENDF

Input: (appendf nil nil)

Output: (defmacro APPENDF ...)


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

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

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

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

Write a macro that addresses: Macro call that should be transformed by TRACE$METHOD

Input: (trace$method 'lol-gen::some-name)

Output: (defmacro TRACE$METHOD ...)


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

Problem: Macro call that should be transformed by MVLET

Input:
(mvlet nil
  nil)

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


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

Issue: Macro call that should be transformed by TRUE

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

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


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

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

Input: (finc nil (progn))

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


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

Problem: Macro call that should be transformed by DEFPATTERN

Input:
(defpattern nil
    :key
  nil)

Output: (defmacro DEFPATTERN ...)


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

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

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

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


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

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

Input:
(defrequirement nil
    nil)

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


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

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

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

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


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

Problem: Macro call that should be transformed by AECASE

Input:
(aecase nil
  nil)

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


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

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

Input:
(with-html-string
  nil
  (progn))

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:
(ematch* common-lisp:nil)

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

Input: (ematch* common-lisp:nil)

Output:
(defmacro ematch* (whats &body clauses)
  #.+match*-doc+
  (let ((temps (make-gensyms whats "OTHERWISE")))
    `(match2* ,whats
       ,@clauses
       (,temps
        (error 'match-error :pattern ',clauses :values (list ,@temps))))))


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

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

Input:
(sctypecase nil
  :key
  nil)

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


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

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

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

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


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

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

Input:
(defprettymethod nil
    (progn))

Output:
(defmacro defprettymethod (qualifier node &body body)
  (if (eql :self qualifier)
      `(progn (setf (gethash (find-class ',node) *ignore-node*) t)
	      (defmethod traverser
		  ((pp pretty-printer)
		   (item ,node) level)
		(declare (ignorable level))
		(with-slots (values subnodes) item .,body)
		(call-next-method)))
      `(defmethod traverser ,qualifier
	 ((pp pretty-printer)
	  (item ,node) level)
	 (declare (ignorable level))
	 (with-slots (values subnodes) item .,body))))


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

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

Input: (make-name-transformer nil)

Output:
(defmacro make-name-transformer (&rest elements)
  "Return an accessor name transformer.
The unquoted `name' symbol argument is substituted for the slot name.
Class option examples:

  :accessor-name-transformer (make-name-transformer \"FOO-\" name \"-BAR\")

Use the slot name directly:

  :accessor-name-transformer (make-name-transformer name)"
  `(lambda (name definition)
    (declare (ignorable definition))
    (concatenate-symbol ,@(mapcar (lambda (el)
                                    (if (and (symbolp el)
                                             (string= (symbol-name el) "NAME"))
                                        'name
                                        el))
                                  elements))))


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

Issue: Macro call that should be transformed by LEXPR-$SEND

Input: (lexpr-$send nil nil)

Output: (defmacro LEXPR-$SEND ...)


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

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

Input:
(once-only nil
  nil)

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

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

   Example:

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


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

Issue: Macro call that should be transformed by FOR

Input:
(for nil
    :key
  nil)

Output: (defmacro FOR ...)


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

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

Input:
(dispatch-caseql-let nil
  nil)

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


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

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

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

Output:
(defmacro with-connection ((conn-sym &rest rest) &body body)
  `(let ((,conn-sym (connect ,@rest)))
     (unwind-protect
          (progn ,@body)
       (disconnect ,conn-sym))))


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

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

Input:
(with-inactive-layers nil
  :key
  nil)

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


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

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

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

Output:
(defmacro let-match (bindings &body body)
  "Similar to LET, except not only a variable but also a pattern can
be used in BINDINGS."
  `(ematch* ,(mapcar #'cadr bindings)
     (,(mapcar #'car bindings) ,.body)))


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

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

Input: (whichever nil :key nil)

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

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

Input:
(once-only nil
  (progn))

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

Problem: Macro call that should be transformed by NEWQ

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

Output: (defmacro NEWQ ...)


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

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

Input: (defunit nil)

Output:
(defmacro defunit (name &optional docstring
                   &environment env)
  "Define a unit type.

A unit type is a type with only one instance.

You can think of a unit type as a singleton without state.

Unit types are useful for many of the same purposes as quoted symbols
\(or keywords) but, unlike a symbol, a unit type is tagged with its
own individual type."
  (let ((ctor (symbolicate '%make- name))
        (super (env-super env '%unit)))
    `(progn
       (eval-when (:compile-toplevel :load-toplevel :execute)
         (defstruct (,name
                     (:include ,super)
                     (:constructor ,ctor)
                     (:copier nil)
                     (:predicate nil)
                     (:print-function print-unit))
           ,@(unsplice docstring)))
       (eval-when (:compile-toplevel :load-toplevel :execute)
         (defmethod make-load-form ((x ,name) &optional env)
           (declare (ignore env))
           '(intern-unit ',name ',ctor)))
       (defmethod %constructor= ((x ,name) (y ,name))
         t)
       (defconst ,name (intern-unit ',name ',ctor))
       (declaim-freeze-type ,name)
       (fmakunbound ',ctor)
       ',name)))


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

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

Input:
(define-templated-dispatch nil
    :key
  nil)

Output: (defmacro DEFINE-TEMPLATED-DISPATCH ...)


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

Issue: Macro call that should be transformed by TYPECASE

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

Output: (defmacro TYPECASE ...)


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

Issue: Macro call that should be transformed by CLASS/STD

Input: (class/std 'lol-gen::some-name)

Output:
(defmacro class/std (name &body defaulted-slots)
  "The most concise shortcut macro to DEFCLASS.

  (class/std example slot1 slot2 slot3)

  expands to:

  (DEFCLASS/STD EXAMPLE ()
    ((SLOT1 SLOT2 SLOT3)))

  which expands to:

  (DEFCLASS EXAMPLE ()
    ((SLOT1 :ACCESSOR SLOT1 :INITARG :SLOT1 :INITFORM NIL)
    (SLOT2 :ACCESSOR SLOT2 :INITARG :SLOT2 :INITFORM NIL)
    (SLOT3 :ACCESSOR SLOT3 :INITARG :SLOT3 :INITFORM NIL)))
"
  `(defclass/std ,name ()
     ((,@defaulted-slots))))


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

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

Input: (incf nil nil)

Output: (defmacro INCF ...)


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

Issue: Macro call that should be transformed by ITERATE

Input: (iterate)

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


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

Issue: Macro call that should be transformed by NTH-VALUE

Input: (nth-value nil nil)

Output: (defmacro NTH-VALUE ...)


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

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

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

Output: (defmacro EXPORT-STRUCTURE ...)


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

Problem: Macro call that should be transformed by WITH-LOGICAL-TRANSACTION

Input: (with-logical-transaction nil)

Output:
(defmacro with-logical-transaction ((&optional (name nil name-p)
                                       (isolation-level *isolation-level*
                                                        isolation-level-p))
                                    &body body)
  "Executes body within a with-transaction form if no transaction is currently
in progress, otherwise simulates a nested transaction by executing it
within a with-savepoint form. The transaction or savepoint is bound to name
if one is supplied. The isolation-level will set the isolation-level used by
the transaction.

You can specify the following isolation levels in postmodern transactions:

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

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

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

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

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

  (with-logical-transaction (:serializable)
    (execute (:insert-into 'test-data :set 'value 44))
    ...)"
  (let* ((effective-name (if (and name-p (not (isolation-level-p name)))
                             name
                             (gensym)))
         (effective-body (if (and name-p (not (isolation-level-p name)))
                             `(lambda (,name) ,@body)
                             `(lambda (,effective-name)
                                (declare (ignore ,effective-name))
                                ,@body)))
         (effective-isolation-level (cond ((and isolation-level-p
                                                (isolation-level-p isolation-level))
                                           isolation-level)
                                          ((and name-p (isolation-level-p name))
                                           name)
                                          (t isolation-level))))
    `(call-with-logical-transaction ',effective-name ,effective-body
                                    ,effective-isolation-level)))


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

Issue: Macro call that should be transformed by HAVING

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

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


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

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

Input: (quasiquote nil nil)

Output: (defmacro QUASIQUOTE ...)


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

Issue: Macro call that should be transformed by SKIP

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

Output:
(defmacro skip (&rest reason)
  "Generates a TEST-SKIPPED result."
  `(add-result 'test-skipped :reason (format nil ,@reason)))


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

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

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

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


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

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

Input: (make-node nil)

Output:
(defmacro make-node (item)
  "Try to identify and make node object"
    `(make-node-function (quoty ,item)))


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

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

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

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

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

Input:
(static-let nil
  :key
  nil)

Output:
(defmacro static-let ((&rest bindings) &body body)
  "Like `let', except the variables are only initialized once and
retain their values between different invocations of `body'.

Every static binding is similar to a `let' binding, except it can have
additional keyword arguments:

- `type' Denotes the type of the variable.
- `once' If true, then binding initialization and mutation will be
         thread-safe.
- `flush' If true, this binding will be flushable. Defaults to true.
- `in' Denotes the static binding group in which the binding will be
       placed for flushing. Defaults to the value of `*package'.
- `read-only' If true, then the binding cannot be mutated with `setf'.

Static bindings can be flushed via `flush-static-binding-group' and
`flush-all-static-binding-groups'; the latter is automatically pushed
into `uiop:*dump-image-hooks*' by Serapeum.

An unflushable static binding will carry its value over into dumped
Lisp binaries."
  (parse-static-let bindings body))


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

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

Input:
(named-lambda nil
    (progn))

Output:
(defmacro named-lambda (name lambda-list &body body)
  "Expands into a lambda-expression within whose BODY NAME denotes the
corresponding function."
  `(labels ((,name ,lambda-list ,@body))
     #',name))


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

Problem: Macro call that should be transformed by DEFMACRO

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

Output: (defmacro DEFMACRO ...)


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

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

Input: (pass nil (progn))

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


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

Issue: Macro call that should be transformed by ALT

Input: (alt nil nil)

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


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

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

Input: (required common-lisp:nil)

Output: (defmacro REQUIRED ...)


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

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

Input:
(dletf nil
  nil)

Output: (defmacro DLETF ...)


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

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

Input:
(c?1
  nil)

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


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

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

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

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


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

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

Input: (some-> nil)

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


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

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

Input: (xor)

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

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

Input: (with nil)

Output: (defmacro WITH ...)


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

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

Input:
(with-guessing-encoder
  nil)

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


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

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

Input: (some-<>>)

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


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

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

Input:
(with nil
  :key
  nil)

Output: (defmacro WITH ...)


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

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

Input: (adowhile nil)

Output: (defmacro ADOWHILE ...)


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

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

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

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


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

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

Input:
(fluid-bind nil
  :key
  nil)

Output:
(defmacro fluid-bind ((&rest bindings) &body body)
  "Fluid-bind is an extension of bind that handles setting and resetting places. For example, suppose that an object of class foo has a slot named bar whose value is currently 3. The following code would evaluate the inner body with bar bound to 17 and restore it when the inner body is exited.

\(fluid-bind \(\(\(bar foo\) 17\)\)
  \(print \(bar foo\)\)\)
\(print \(bar foo\)\)
==> \(prints 17, then 3\)

This is similar to dynamic-binding but _much_ less robust."
  ;; does not handle declarations correctly
  (let ((setup-forms nil)
        (cleanup-forms nil)
        (gensyms nil))
    (loop for binding in bindings collect
          (destructuring-bind
		(setup-form cleanup-form)
	      (cond ((consp binding)
		     (destructuring-bind (var value) binding
		       (let ((g (gensym)))
			 (push g gensyms)
			 (cond ((atom var)
				`((:bind (,var ,value)) nil)
				#+(or)
				;; lexical or special?
				(if (boundp var)
				    `((:bind (,var ,value)) nil)
				    `((:setf (setf ,g ,var ,var ,value))
				      (setf ,var ,g))))
			       ((and (fboundp (first var))
				     (not (eq (first var) 'values)))
				;; putative place
				`((:setf (setf ,g ,var ,var ,value))
				  (setf ,var ,g)))
			       (t
				`((:bind (,var ,value)) nil))))))
		    (t
		     `((:bind (,binding nil)) nil)))
            (push setup-form setup-forms)
            (push cleanup-form cleanup-forms)))
    (let ((result body))
      (mapc (lambda (setup cleanup)
              (setf result
                    (ecase (first setup)
                      (:setf `((unwind-protect
                                 (progn
                                   ,(second setup)
                                   ,@result)
                                 ,cleanup)))
                      (:bind `((bind (,(second setup))
                                 ,@result)))))
              result)
            setup-forms cleanup-forms)
      `(let ,gensyms
         (declare (ignorable ,@gensyms))
         ,@result))))


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

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

Input:
(f0
  nil
  :key
  nil)

Output: (defmacro F0 ...)


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

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

Input: (current-decoder nil nil)

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


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

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

Input: (is-values nil (progn))

Output:
(defmacro is-values (got expected &rest args)
  `(is (multiple-value-list ,got) ,expected ,@args))


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

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

Input: (drelet* nil)

Output: (defmacro DRELET* ...)


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

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

Input: (fm-mapc nil (progn))

Output:
(defmacro fm-mapc (fn md-name)
   `(mapc ,fn (fm-find-all self ',md-name)))


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

Problem: Macro call that should be transformed by FILTERF

Input: (filterf nil :key nil)

Output: (defmacro FILTERF ...)


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

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

Input: (fgather-next nil nil)

Output: (defmacro FGATHER-NEXT ...)


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

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

Input: (finc nil nil)

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


Instruction:
Define a macro that eliminates this repetitive pattern:
(set-custom-vars)

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

Input: (set-custom-vars)

Output:
(defmacro set-custom-vars (&rest key-args)
  `(setq
    ,@(loop for (supplied-key value) on key-args by #'cddr
         append (loop for (var . var-key) in *custom-vars*
                   thereis (if (eql var-key supplied-key)
                               (list var value))))))


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

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

Input: (jor)

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


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


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

Issue: Macro call that should be transformed by HTML5

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

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


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

Issue: Macro call that should be transformed by VOID

Input: (void nil)

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


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

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

Input:
(multiple-value-cmatch nil
  nil)

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


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

Problem: Macro call that should be transformed by ->

Input: (-> nil)

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


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

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

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

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


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

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

Input:
(f_%
  nil
  (progn))

Output: (defmacro F_% ...)


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

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

Input:
(iter
  nil
  nil)

Output: (defmacro ITER ...)


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

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

Input:
(batch
  nil)

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

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

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

Output:
(defmacro make-name-transformer (&rest elements)
  "Return an accessor name transformer.
The unquoted `name' symbol argument is substituted for the slot name.
Class option examples:

  :accessor-name-transformer (make-name-transformer \"FOO-\" name \"-BAR\")

Use the slot name directly:

  :accessor-name-transformer (make-name-transformer name)"
  `(lambda (name definition)
    (declare (ignorable definition))
    (concatenate-symbol ,@(mapcar (lambda (el)
                                    (if (and (symbolp el)
                                             (string= (symbol-name el) "NAME"))
                                        'name
                                        el))
                                  elements))))