Instruction:
Define a macro that eliminates this repetitive pattern:
(with-walker-handler-lexical-environment)

Issue: Macro call that should be transformed by WITH-WALKER-HANDLER-LEXICAL-ENVIRONMENT

Input: (with-walker-handler-lexical-environment)

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


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

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

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

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


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

Issue: Macro call that should be transformed by PCCASE

Input: (pccase nil (progn))

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

   Example usage:

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


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

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

Input:
(dreletf nil
  (progn))

Output: (defmacro DRELETF ...)


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

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

Input: (pop-assoc nil nil)

Output:
(defmacro pop-assoc (key alist &rest args &environment env)
  "Like `assoc' but, if there was a match, delete it from ALIST.

From Newlisp."
  (multiple-value-bind (vars vals new setter getter)
      (get-setf-expansion alist env)
    (with-gensyms (match)
      `(let* (,@(mapcar #'list vars vals)
              (,(car new) ,getter))
         (let ((,match (assoc ,key ,(car new) ,@args)))
           (declare (list ,match))
           (prog1 ,match
             (when ,match
               (setf ,(car new) (efface ,match ,(car new))))
             ,setter))))))


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

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

Input:
(dynamic-wind
  nil)

Output: (defmacro DYNAMIC-WIND ...)


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

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

Input: (c?? nil)

Output:
(defmacro c?? ((&key (tagp nil) (in nil) (out t))&body body)
  (let ((result (copy-symbol 'result))
        (thetag (gensym)))
     `(make-c-dependent
       :code ',body
       :value-state :unevaluated
       :rule (c-lambda
              (let ((,thetag (gensym "tag"))
                    (*trcdepth* (1+ *trcdepth*))
                    )
                (declare (ignorable self ,thetag))
                ,(when in
                   `(trc "c??> entry" (c-slot-name c) (c-model c) (when ,tagp ,thetag)))
                (count-it :c?? (c-slot-name c) (md-name (c-model c)))
                (let ((,result (progn ,@body)))
                  ,(when out `(trc "c?? result:" ,result (c-slot-name c) (when ,tagp ,thetag)))
                  ,result))))))


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

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

Input: (alter nil nil)

Output: (defmacro ALTER ...)


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

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

Input: (select-dao nil nil)

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

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

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

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


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

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

Input: (group-by)

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


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

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

Input: (vref nil nil)

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

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


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

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

Input:
(named-lambda nil
    nil)

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:
You are a Common Lisp macro expert. Given this code pattern:
(with-c-syntax common-lisp:nil
  common-lisp:nil)

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

Input:
(with-c-syntax common-lisp:nil
  common-lisp:nil)

Output:
(defmacro with-c-syntax ((&rest options
			  &key (preprocess t)
                            (reader-level *with-c-syntax-reader-level*)
                            (readtable-case (or *with-c-syntax-reader-case*
                                                (readtable-case *readtable*)))
                            (input-file-pathname nil)
			    (try-add-{} t))
			 &environment *wcs-expanding-environment*
			 &body body)
  "This macro is a entry point of the with-c-syntax system. BODY will be
interpreted as C syntax, executed, and return values.

This macro returns the last form's value if BODY is a compound
statement, or returns NIL if BODY is a compilation unit.

PREPROCESS specifies how to do preprocess. If nil, this macro compiles
BODY without preprocessing. If t, preprocesses and compiles BODY. If
`:preprocess-only', this macro preprocesses BODY and returns the
result as-is.

READER-LEVEL specifies the reader level (see `*with-c-syntax-reader-level*').
This is used when '#include' or '_Pragma()' was used.

READTABLE-CASE specifies the readtable case of symbols in BODY when it
was read.  This affects how to intern C keywords by the preprocessor.

INPUT-FILE-PATHNAME is passed to the preprocessor and used when
'__FILE__' macro was used.

If TRY-ADD-{} is t and an error occurred at parsing, `with-c-syntax'
adds '{' and '}' into the head and tail of FORM respectively, and
tries to parse again."
  (cond
    ((null body)
     nil)
    ((and (length= 1 (the list body))	; with-c-syntax is nested.
	  (starts-with 'with-c-syntax (first body)))
     (destructuring-bind (op_ options2 &body body2)
	 (first body)
       (declare (ignore op_))
       `(with-c-syntax (,@options ,@options2) ,@body2)))
    (t
     (ecase preprocess
       (:preprocess-only
        (preprocessor body reader-level readtable-case input-file-pathname))
       (t
        `(with-c-syntax (:preprocess nil :try-add-{} ,try-add-{})
           ,@(preprocessor body reader-level readtable-case input-file-pathname)))
       ((nil)
        (expand-c-syntax body
		         try-add-{}))))))


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

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

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

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


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

Problem: Macro call that should be transformed by DEFPROXYPRINT

Input:
(defproxyprint nil
    (progn))

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


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

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

Input:
(is-values nil
  (progn))

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


Instruction:
Write a Common Lisp macro to handle this code pattern:
(coalton-toplevel)

Problem: Macro call that should be transformed by COALTON-TOPLEVEL

Input: (coalton-toplevel)

Output: (defmacro COALTON-TOPLEVEL ...)


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

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

Input:
(fbind* nil
  nil)

Output:
(defmacro fbind* (bindings &body body &environment env)
  "Like `fbind', but creates bindings sequentially."
  (setf bindings (expand-fbindings bindings))
  (unless bindings
    (return-from fbind* `(locally ,@body)))
  (mvlet* ((fn (caar bindings))
           (body decls (parse-body body))
           (local others (partition-declarations `((function ,fn))
                                                 decls
                                                 env)))
    `(fbind (,(first bindings))
       ,@local
       (fbind* ,(rest bindings)
         ,@others
         ,@body))))


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

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

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

Output: (defmacro SOME-> ...)


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

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

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

Output: (defmacro NONE-OF ...)


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

Issue: Macro call that should be transformed by OR

Input: (or nil (progn))

Output: (defmacro OR ...)


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

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

Input: (make-instance* nil (progn))

Output:
(defmacro make-instance* (class &rest arguments)
  "Convenience macro on top of `make-instance'.

Conveniences:

- First argument can be a (possibly empty) list of shortcut symbols,
  which is automatically converted into a KEYWORD+SYMBOL pairs where
  - KEYWORD is the same as shortcut name, but interned as keyword.
  - And SYMBOL is the same as shortcut.

- The last argument can be an apply argument---arbitrary
  list-producing form, which will be used as the last argument
  to (apply #'make-instance ...) idiom.

Note that using a singular shortcut list of apply argument is an
ambiguous case that will be interpreted in favor of apply argument. To
force either of interpretations, provide shortcuts and apply arguments
explicitly:
(make-instance* 'class (a b c)) ;; BAD
(make-instance* 'class (a b c) nil) ;; GOOD
(make-instance* 'class (when t nil)) ;; BAD
(make-instance* 'class () (when t nil)) ;; GOOD

Otherwise, the behavior is equivalent to `make-instance'.

Examples:

Shortcut args:
\(make-instance* 'class (a b c))
=>
\(make-instance 'class :a a :b b :c c)

Last form converted into `apply' argument:
\(make-instance* 'class :c c :b b (when something (list :a a)))
=>
\(apply #'make-instance 'class :c c :b b (when something (list :a a)))

Shortcut arguments, regular arguments, and form for `apply':
\(make-instance* 'class (b c) :x x (when something (list :a a)))
=>
\(apply #'make-instance 'class :b b :c c :x x (when something (list :a a)))

Form for `apply' (notice the empty shortcuts---these are required for
unambiguous parsing):
\(make-instance* 'class () (when something (list :a a)))
=>
\(apply #'make-instance 'class (when something (list :a a)))

Regular `make-instance'-like use:
\(make-instance* 'class :a a-value :b b-value)
=>
\(make-instance 'class :a a-value :b b-value)"
  (when (and (= 1 (length arguments))
             (listp (first arguments)))
    (style-warn "Body of MAKE-INSTANCE* contains a single list-like form ~a.

If you meant APPLY args, add empty shortcuts list:
(make-instance* 'class () (apply-form))

If you meant shortcut list, add empty APPLY args:
(make-instance* 'class (shortcuts) nil)

Interpreting as APPLY args for now, but this behavior may change in
the future." arguments))
  (let* ((shortcuts-p (and (listp (first arguments))
                           (> (length arguments) 1)))
         (shortcuts (when shortcuts-p
                      (first arguments)))
         (arguments (if shortcuts-p
                        (rest arguments)
                        arguments))
         (last-appendable-form-p (oddp (length arguments)))
         (last-appendable-form (when last-appendable-form-p
                                 (first (last arguments))))
         (arguments (if last-appendable-form-p
                        (butlast arguments)
                        arguments)))
    `(,@(if last-appendable-form-p
            `(apply #'make-instance)
            `(make-instance))
      ,class
      ,@(loop for shortcut in shortcuts
              append (list (intern (symbol-name shortcut) :keyword)
                           shortcut))
      ,@arguments
      ,@(when last-appendable-form-p
          (list last-appendable-form)))))


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

Issue: Macro call that should be transformed by ITERATE

Input:
(iterate
  nil)

Output: (defmacro ITERATE ...)


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

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

Input: (maxf nil (progn))

Output: (defmacro MAXF ...)


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

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

Input:
(do-for nil
  :key
  nil)

Output: (defmacro DO-FOR ...)


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

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

Input:
(define-generic* nil
    (progn))

Output: (defmacro DEFINE-GENERIC* ...)


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

What needs to change: Macro call that should be transformed by FOREIGN-FUNCALL-POINTER

Input: (foreign-funcall-pointer nil nil)

Output:
(defmacro foreign-funcall-pointer (pointer options &rest args)
  (foreign-funcall-form pointer options args t))


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

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

Input: (js-inline 'lol-gen::some-name)

Output: (defmacro JS-INLINE ...)


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

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

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

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


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

Problem: Macro call that should be transformed by MAKE-PROXY

Input: (make-proxy nil (progn))

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


Instruction:
Generate a defmacro form that transforms code like this:
(walk-environment
  nil)

Pattern to recognize: Macro call that should be transformed by WALK-ENVIRONMENT

Input:
(walk-environment
  nil)

Output: (defmacro WALK-ENVIRONMENT ...)


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

Problem: Macro call that should be transformed by XHTML

Input: (xhtml nil)

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


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

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

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

Output: (defmacro DECIDE ...)


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

Issue: Macro call that should be transformed by DEFPROXYPRINT

Input:
(defproxyprint nil
    nil)

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


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

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

Input: (with-none-awake 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:
(define-method-combination 'lol-gen::some-name)

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

Input: (define-method-combination 'lol-gen::some-name)

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


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

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

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

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


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

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

Input:
(count-failures
  nil)

Output: (defmacro COUNT-FAILURES ...)


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

Problem: Macro call that should be transformed by F_N

Output: (defmacro F_N ...)


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

Issue: Macro call that should be transformed by DEFGENERIC

Input:
(defgeneric nil
    nil)

Output: (defmacro DEFGENERIC ...)


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

Problem: Macro call that should be transformed by PUSH

Input: (push nil (progn))

Output: (defmacro PUSH ...)


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

Problem: Macro call that should be transformed by ITER

Input:
(iter
  nil
  :key
  nil)

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:
(lambda-coro)

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

Input: (lambda-coro)

Output: (defmacro LAMBDA-CORO ...)


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

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

Input:
(with-open-files nil
  nil)

Output:
(defmacro with-open-files ((&rest args) &body body)
  "A simple macro to open one or more files providing the streams for the BODY. The ARGS is a list of `(stream filespec options*)` as supplied to WITH-OPEN-FILE."
  (case (length args)
    ((0)
     `(progn ,@body))
    ((1)
     `(with-open-file ,(first args) ,@body))
    (t `(with-open-file ,(first args)
          (with-open-files
              ,(rest args) ,@body)))))


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

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

Input: (best-value nil (progn))

Output: (defmacro BEST-VALUE ...)


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

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

Input:
(with-dot nil
  nil)

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


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

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

Input:
(with-array nil
  (progn))

Output:
(defmacro with-array ((&optional (stream '*json-output*)) &body body)
  "Open a JSON Array, run BODY, then close the Array.  Inside the BODY,
AS-ARRAY-MEMBER or ENCODE-ARRAY-MEMBER should be called to encode
Members of the Array."
  `(with-aggregate (array #\[ #\] ,stream) ,@body))


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

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

Input:
(ecase-of nil
    nil)

Output:
(defmacro ecase-of (type x &body body)
  "Like `ecase' but, given a TYPE (which should be defined as `(member
...)'), warn, at compile time, unless the keys in BODY are all of TYPE
and, taken together, they form an exhaustive partition of TYPE."
  (once-only (x)
    `(case-of ,type ,x
       ,@body
       (otherwise
        (error 'type-error
               :datum ,x
               :expected-type ',type)))))


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

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

Input:
(wait-on nil
    nil)

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


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

Issue: Macro call that should be transformed by DOC

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

Output: (defmacro DOC ...)


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

Issue: Macro call that should be transformed by FBINDREC

Input:
(fbindrec nil
  :key
  nil)

Output:
(defmacro fbindrec (bindings &body body &environment *lexenv*)
  "Like `fbind', but creates recursive bindings.

The consequences of referring to one binding in the expression that
generates another are undefined."
  (setf bindings (expand-fbindings bindings))
  (unless bindings
    (return-from fbindrec `(locally ,@body)))
  (mvlet* ((env env-decls bindings lambdas (analyze-fbinds bindings *lexenv*))
           (body decls (parse-body body))
           (simple complex lambda unref
            (partition-fbinds (append bindings lambdas)
                              body))
           (temps (mapcar (op (gensym (string (first _)))) complex))
           (simple-decls complex-decls lambda-decls others
            (partition-declarations-by-kind simple complex lambda decls)))
    `(let ,env
       ,@(unsplice (and env-decls `(declare ,@env-decls)))
       ;; Simple expressions reference functions already defined
       ;; outside of the letrec, so we can handle them with fbind.
       (comment "fbind: Simple")
       (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: Unreferenced")
               (progn ,@(mapcar #'second unref))
               (comment "fbind: Complex")
               (psetf ,@(loop for temp in temps
                              for (nil expr) in complex
                              append `(,temp (ensure-function ,expr))))
               (locally ,@others
                 ,@body))))))))


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

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

Input:
(with-shuffling
  nil
  nil)

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


Instruction:
Define a macro that eliminates this repetitive pattern:
(make-simple-appender-to-place nil)

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

Input: (make-simple-appender-to-place nil)

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


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

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

Input:
(iter
  nil
  :key
  nil)

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 (iter:display-iter-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)
         (*declaration-context?* nil)
         (*temps* nil)
         (*temps-in-use* nil)
         (*driver-info-alist* nil)
         (*block-name* (when (symbolp (car body))
                         (pop body)))
         (*loop-top*  (ensure-symbol *block-name* :format "loop-top-~a"))
         (*loop-step* (ensure-symbol *block-name* :format "loop-step-~a"))
         (*loop-end*  (ensure-symbol *block-name* :format "loop-end-~a"))
         (*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 ,*block-name*
                         (tagbody
                            ,.init-code
                            ,*loop-top*
                            ,.body
                            ,.(when *loop-step-used?* (list *loop-step*))
                            ,.steppers
                            (go ,*loop-top*)
                            ,.(when *loop-end-used?* (list *loop-end*))
                            ,.final-code)
                         ,(if (member *result-var* *bindings* :key #'car)
                              *result-var*
                              nil))))
          (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:
Write a Common Lisp macro to handle this code pattern:
(incf nil (progn))

Problem: Macro call that should be transformed by INCF

Input: (incf nil (progn))

Output: (defmacro INCF ...)


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

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

Input: (ignorable common-lisp:nil)

Output: (defmacro IGNORABLE ...)


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

Problem: Macro call that should be transformed by EVAL-WHEN-EXECUTE

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

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


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

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

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

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


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

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

Input:
(swhen nil
  :key
  nil)

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


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

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

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

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

You can specify the following isolation levels in postmodern transactions:

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

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

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

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

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

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

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


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

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

Input: (-> nil :key nil)

Output:
(defmacro -> (x &rest forms)
  "Threads the expr through FORMS. Inserts X as the
   second item in the first form, or in place of % if it is present in the form,
   making a list of it if it is not a list already.
   If there are more forms, inserts the first form
   as the second item in second form, etc."
  (if (first forms)
      (let* ((form (first forms))
             (threaded (if (listp form)
                           (if (member '% form)
                               `(funcall (lambda (%) ,form) ,x)
                               `(,(first form) ,x ,@(rest form)))
                           `(,form ,x))))
        `(-> ,threaded ,@(rest forms)))
      x))


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

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

Input:
(class/std nil
  (progn))

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:
(as-> nil
    nil)

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

Input:
(as-> nil
    nil)

Output: (defmacro AS-> ...)


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

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

Input: (inext nil (progn))

Output: (defmacro INEXT ...)


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

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

Input: (define-global-parameter nil nil)

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


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

Issue: Macro call that should be transformed by BCOND

Input: (bcond)

Output:
(defmacro bcond (&body clauses)
  "Scheme's extended COND.

This is exactly like COND, except for clauses having the form

     (test :=> recipient)

In that case, if TEST evaluates to a non-nil result, then RECIPIENT, a
function, is called with that result, and the result of RECIPIENT is
return as the value of the `cond`.

As an extension, a clause like this:

     (test :=> var ...)

Can be used as a shorthand for

     (test :=> (lambda (var) ...))

The name `bcond' for a “binding cond” goes back at least to the days
of the Lisp Machines. I do not know who was first to use it, but the
oldest examples I have found are by Michael Parker and Scott L.
Burson."
  (flet ((send-clause? (clause)
           (let ((second (second clause)))
             (and (symbolp second)
                  (string= second :=>))))
         (parse-send-clause (clause)
           (destructuring-bind (test => . body) clause
             (declare (ignore =>))
             (cond ((null body) (error "Missing clause"))
                   ((null (rest body))
                    (values test (car body)))
                   (t (destructuring-bind (var . body) body
                        (let ((fn `(lambda (,var) ,@body)))
                          (values test fn))))))))
    ;; Note that we expand into `cond' rather than `if' so we don't
    ;; have to handle tests without bodies.
    (cond ((null clauses) nil)
          ((member-if #'send-clause? clauses)
           (let* ((tail (member-if #'send-clause? clauses))
                  (preceding (ldiff clauses tail))
                  (clause (car tail))
                  (clauses (cdr tail)))
             (multiple-value-bind (test fn)
                 (parse-send-clause clause)
               (with-gensyms (tmp)
                 `(cond ,@preceding
                        (t (if-let1 ,tmp ,test
                             (funcall ,fn ,tmp)
                             (bcond ,@clauses))))))))
          (t `(cond ,@clauses)))))


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

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

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

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


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

Problem: Macro call that should be transformed by ECASE

Input: (ecase nil)

Output: (defmacro ECASE ...)


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

Problem: Macro call that should be transformed by WITH-TRUNCATED-STACK

Input:
(with-truncated-stack nil
  :key
  nil)

Output:
(defmacro with-truncated-stack (() &body body)
  `(stack-truncator (lambda () ,@body)))


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

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

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

Output: (defmacro DRELET ...)


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

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

Input: (in-package nil)

Output: (defmacro IN-PACKAGE ...)


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

Problem: Macro call that should be transformed by .>

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

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

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

Output:
(defmacro left (parser &rest parsers)
  "Combination of parsers yielding the result of the leftmost one."
  `(<* ,parser ,@parsers))


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

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

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

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


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

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

Input: (full-join nil)

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


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

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

Input:
(c_in
  nil)

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


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

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

Input: (-> nil nil)

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

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

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


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

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

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

Output: (defmacro INLINE ...)


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

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

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

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


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

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

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

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


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


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

Problem: Macro call that should be transformed by INCF

Input: (incf nil)

Output: (defmacro INCF ...)


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

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

Input: (make nil :key nil)

Output: (defmacro MAKE ...)


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

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

Input: (jif nil nil)

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


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

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

Input:
(with-attributes nil
    :key
  nil)

Output: (defmacro WITH-ATTRIBUTES ...)


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

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

Input: (vect-of nil (progn))

Output: (defmacro VECT-OF ...)


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

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

Input: (->> nil)

Output: (defmacro ->> ...)


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

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

Input:
(for-effects
  nil
  :key
  nil)

Output: (defmacro FOR-EFFECTS ...)


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

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

Input:
(with-cc nil
  :key
  nil)

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


Instruction:
Define a macro that eliminates this repetitive pattern:
(def$flavor nil :key nil)

Issue: Macro call that should be transformed by DEF$FLAVOR

Input: (def$flavor nil :key nil)

Output: (defmacro DEF$FLAVOR ...)


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

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

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

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


Instruction:
Generate a defmacro form that transforms code like this:
(keep-bops nil)

Pattern to recognize: Macro call that should be transformed by KEEP-BOPS

Input: (keep-bops nil)

Output: (defmacro KEEP-BOPS ...)


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

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

Input: (with-collectors nil)

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

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


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

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

Input: (ignore-errors nil (progn))

Output: (defmacro IGNORE-ERRORS ...)


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

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

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

Output: (defmacro COLLECT-OR ...)


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

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

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

Output: (defmacro ADOWHILE ...)


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

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

Input: (lambda () nil)

Output: (defmacro LAMBDA ...)


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

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

Input:
(once-only nil
  :key
  nil)

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

The returned value is a list of the form

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

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

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

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

- INITFORM is an expression evaluated to produce EXPR-i

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

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

Example:

  The following expression

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

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

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

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

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

  ;;; => (1 . 1)

Example:

  The following expression demonstrates the usage of the INITFORM field

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

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

  which could be used like so

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

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

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


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

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

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

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


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

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

Input: (group-by nil nil)

Output: (defmacro GROUP-BY ...)


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

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

Input: (jif nil :key nil)

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


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

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

Input: (with-integrity nil :key nil)

Output:
(defmacro with-integrity ((&optional opcode defer-info debug) &rest body)
  (declare (ignorable debug))
  (when opcode
    (assert (find opcode *ufb-opcodes*) ()
      "Invalid opcode for with-integrity: ~a. Allowed values: ~a" opcode *ufb-opcodes*))
  `(call-with-integrity ,opcode ,defer-info
     (lambda (opcode defer-info)
       (declare (ignorable opcode defer-info))
       ;;;       ,(when debug
       ;;;          `(trc "integrity action entry" opcode defer-info ',body))
       ;;;       (when *c-debug*
       ;;;         (when (eq opcode :change)
       ;;;           (trc "-------w/integ :change go--------------->:" defer-info)))
       ,@body)
     nil
     #+noway (when *c-debug* ',body)))


Instruction:
Define a macro that eliminates this repetitive pattern:
(caching-types
  nil
  :key
  nil)

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

Input:
(caching-types
  nil
  :key
  nil)

Output: (defmacro CACHING-TYPES ...)


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

Problem: Macro call that should be transformed by SLET

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

Output:
(defmacro slet (form &body body)
  "Binds the FORM to IT (via SYMBOL-MACROLET) in the scope of the BODY. IT can
be set with SETF."
  `(symbolic ignore-first ,form (progn ,@body)))


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

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

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

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


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

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

Input:
(as-> nil
    :key
  nil)

Output: (defmacro AS-> ...)


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

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

Input:
(with-synapse nil
    :key
  nil)

Output:
(defmacro with-synapse (synapse-id (&rest closure-vars) &body body)
  (let ((syn-id (gensym)))
    `(let* ((,syn-id ,synapse-id)
            (synapse (or (find ,syn-id (cd-useds *depender*) :key 'c-slot-name)
                       (let ((new-syn
                              (let (,@closure-vars)
                                (make-c-dependent
                                 :model (c-model *depender*)
                                 :slot-name ,syn-id
                                 :code ',body
                                 :synaptic t
                                 :rule (c-lambda ,@body)))))
                         (record-caller new-syn)
                         new-syn))))
       (prog1
           (multiple-value-bind (v p)
               (with-integrity ()
                 (ensure-value-is-current synapse :synapse *depender*))
             (values v p))
         (record-caller synapse)))))


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

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

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

Output: (defmacro OPTIMIZE ...)


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

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

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

Output: (defmacro WHEN ...)


Instruction:
Write a Common Lisp macro to handle this code pattern:
;; Accessing pandoric variables requires verbose funcall
(let ((sum (funcall box :pandoric-get 'sum))
      (count (funcall box :pandoric-get 'count)))
  (format t "sum=~a count=~a~%" sum count))

;; Setting is even worse:
(progn
  (funcall box :pandoric-set 'sum new-value)
  new-value)

;; Want: regular variable syntax for pandoric access

Problem: Pandoric get/set requires verbose keyword funcalls — want transparent variable syntax using symbol-macrolet

Input:
;; Accessing pandoric variables requires verbose funcall
(let ((sum (funcall box :pandoric-get 'sum))
      (count (funcall box :pandoric-get 'count)))
  (format t "sum=~a count=~a~%" sum count))

;; Setting is even worse:
(progn
  (funcall box :pandoric-set 'sum new-value)
  new-value)

;; Want: regular variable syntax for pandoric access

Output:
(defun get-pandoric (box sym)
  (funcall box :pandoric-get sym))

(defsetf get-pandoric (box sym) (val)
  `(progn
     (funcall ,box :pandoric-set ,sym ,val)
     ,val))

(defmacro with-pandoric (syms box &rest body)
  (let ((g!box (gensym "box")))
    `(let ((,g!box ,box))
       (declare (ignorable ,g!box))
       (symbol-macrolet
         (,@(mapcar #`(,a1 (get-pandoric ,g!box ',a1))
                    syms))
         ,@body))))


Instruction:
Write a Common Lisp macro to handle this code pattern:
(rem-bops)

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

Input: (rem-bops)

Output: (defmacro REM-BOPS ...)


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

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

Input:
(with-explicit-encoder
  nil
  nil)

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


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

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

Input: (left nil)

Output:
(defmacro left (parser &rest parsers)
  "Combination of parsers yielding the result of the leftmost one."
  `(<* ,parser ,@parsers))


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

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

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

Output: (defmacro SPECIAL ...)


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

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

Input: (one-value nil (progn))

Output: (defmacro ONE-VALUE ...)


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

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

Input: (html nil)

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


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

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

Input:
(define-dispatch nil
    (progn))

Output:
(defmacro define-dispatch (name lambda-list &body body)
  "the lambda list should accept two arguments:
the list of arguments given by the current method call.
the specific hooks (as named or unamed functions) for the qualified method (that we will be dispatching from).

you should then use the arguments to dispatch the specific hooks as you wish in the body.
if the body returns a result, by default the method will also return that result, this can be overriden with finalize-dispatch-method.

See finalize-dispatch-method
See dispatch"
  `(let ((new-dispatch (make-dispatcher (lambda ,lambda-list ,@body))))
     (setf (gethash ',name *dispatch-table*)
           new-dispatch)))


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

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

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

Output:
(defmacro let-match* (bindings &body body)
  "Similar to LET-MATCH but matches sequentially."
  (reduce (lambda (binding form) `(let-match (,binding) ,form))
          bindings
          :from-end t
          :initial-value `(locally ,.body)))


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

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

Input: (where nil)

Output: (defmacro WHERE ...)


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

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

Input: (is nil)

Output:
(defmacro is (test &rest reason-args)
  "The DWIM checking operator.

If TEST returns a true value a test-passed result is generated,
otherwise a test-failure result is generated. The reason, unless
REASON-ARGS is provided, is generated based on the form of TEST:

 (predicate expected actual) - Means that we want to check
 whether, according to PREDICATE, the ACTUAL value is
 in fact what we EXPECTED.

 (predicate value) - Means that we want to ensure that VALUE
 satisfies PREDICATE.

 Wrapping the TEST form in a NOT simply produces a negated reason
 string."
  (assert (listp test)
          (test)
          "Argument to IS must be a list, not ~S" test)
  (let (bindings effective-test default-reason-args)
    (with-gensyms (e a v)
      (flet ((process-entry (predicate expected actual &optional negatedp)
               ;; make sure EXPECTED is holding the entry that starts with 'values
               (when (and (consp actual)
                          (eq (car actual) 'values))
                 (assert (not (and (consp expected)
                                   (eq (car expected) 'values))) ()
                                   "Both the expected and actual part is a values expression.")
                 (rotatef expected actual))
               (let ((setf-forms))
                 (if (and (consp expected)
                          (eq (car expected) 'values))
                     (progn
                       (setf expected (copy-list expected))
                       (setf setf-forms (loop for cell = (rest expected) then (cdr cell)
                                              for i from 0
                                              while cell
                                              when (eq (car cell) '*)
                                              collect `(setf (elt ,a ,i) nil)
                                              and do (setf (car cell) nil)))
                       (setf bindings (list (list e `(list ,@(rest expected)))
                                            (list a `(multiple-value-list ,actual)))))
                     (setf bindings (list (list e expected)
                                          (list a actual))))
                 (setf effective-test `(progn
                                         ,@setf-forms
                                         ,(if negatedp
                                              `(not (,predicate ,e ,a))
                                              `(,predicate ,e ,a)))))))
        (list-match-case test
          ((not (?predicate ?expected ?actual))
           (process-entry ?predicate ?expected ?actual t)
           (setf default-reason-args
                 (list "~2&~S~2% evaluated to ~2&~S~2% which is ~2&~S~2%to ~2&~S~2% (it should not be)"
                       `',?actual a `',?predicate e)))
          ((not (?satisfies ?value))
           (setf bindings (list (list v ?value))
                 effective-test `(not (,?satisfies ,v))
                 default-reason-args
                 (list "~2&~S~2% evaluated to ~2&~S~2% which satisfies ~2&~S~2% (it should not)"
                       `',?value v `',?satisfies)))
          ((?predicate ?expected ?actual)
           (process-entry ?predicate ?expected ?actual)
           (setf default-reason-args
                 (list "~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%"
                       `',?actual a `',?predicate e)))
          ((?satisfies ?value)
           (setf bindings (list (list v ?value))
                 effective-test `(,?satisfies ,v)
                 default-reason-args
                 (list "~2&~S~2% evaluated to ~2&~S~2% which does not satisfy ~2&~S~2%"
                       `',?value v `',?satisfies)))
          (?_
           (setf bindings '()
                 effective-test test
                 default-reason-args (list "~2&~S~2% was NIL." `',test)))))
      `(let ,bindings
         (if ,effective-test
             (add-result 'test-passed :test-expr ',test)
             (process-failure ',test
                              ,@(or reason-args default-reason-args)))))))


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

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

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

Output: (defmacro DEFMETHOD ...)


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

What needs to change: Macro call that should be transformed by WITH-LOCAL-CLASS-REGISTRY

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

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


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

Issue: Macro call that should be transformed by SETYPECASE

Input:
(setypecase nil
  nil)

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


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

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

Input: (undefreply nil (progn))

Output: (defmacro UNDEFREPLY ...)


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

What needs to change: Macro call that should be transformed by PS-ONCE-ONLY

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

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


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

Issue: Macro call that should be transformed by CUSTOM-DECODER

Input: (custom-decoder)

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


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

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

Input: (ap nil (progn))

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


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

Problem: Macro call that should be transformed by DEFMACRO-DRIVER

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

Output:
(defmacro defmacro-driver (clause-template &body body)
  "Create iterators which may also be used as generators"
  (define-clause 'defmacro clause-template body t))


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

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

Input: (query-dao nil nil)

Output:
(defmacro query-dao (type query &rest args)
  "Execute the given query (which can be either a string or an S-SQL expression)
and return the result as DAOs of the given type. If the query contains
placeholders ($1, $2, etc) their values can be given as extra arguments. The
names of the fields returned by the query must either match slots in the DAO
class, or be bound through with-column-writers."
  `(query-dao% ,type ,(real-query query) (dao-row-reader (find-class ,type)) ,@args))


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

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

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

Output:
(defmacro with-savepoint (conn &body body)
  (let ((ok (gensym "SAVEPOINT-OK"))
        (state-var (gensym "STATE-VAR"))
        (ident-var (gensym "SAVEPOINT-IDENTIFIER-VAR")))
    `(let* ((,state-var (make-instance 'savepoint-state
                                       :conn ,conn))
            (,ident-var (get-identifier ,state-var))
            (*transaction-state*
              (cons ,state-var
                    *transaction-state*))
            ,ok)

       (savepoint ,conn ,ident-var)
       (unwind-protect
            (multiple-value-prog1
                (progn ,@body)
              (setf ,ok t))
         (when (eql (get-state ,state-var)
                    :in-progress)
           (if ,ok
               (release-savepoint ,conn ,ident-var)
               (rollback-savepoint ,conn ,ident-var)))))))


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

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

Input:
(define-declaration nil
    nil)

Output: (defmacro DEFINE-DECLARATION ...)


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

Problem: Macro call that should be transformed by DLET

Input:
(dlet nil
  nil)

Output: (defmacro DLET ...)


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

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

Input:
(with-live-scope
  nil)

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

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

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

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

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


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

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

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

Output: (defmacro CALL-METHOD ...)


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

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

Input: (export-class)

Output: (defmacro EXPORT-CLASS ...)


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

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

Input:
(dynamic-relet* nil
  nil)

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


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

Issue: Macro call that should be transformed by PROG

Input: (prog ())

Output: (defmacro PROG ...)


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

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

Input:
(ctypecase-of nil
    (progn))

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


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

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

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

Output: (defmacro DECLARATION ...)


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

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

Input: (with nil nil)

Output: (defmacro WITH ...)


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

Problem: Macro call that should be transformed by XOR

Input: (xor nil nil)

Output:
(defmacro xor (&rest args)
  "Evaluates the ARGS one at a time. If more than one is T,
   evaluation stops and NIL is returned. If exactly one arg is T,
   that value is returned."
  (let ((state (gensym "XOR-state-"))
        (block-name (gensym "XOR-block-"))
        (arg-temp (gensym "XOR-arg-temp-")))
    `(let (,state
           ,arg-temp)
       (block ,block-name
         ,@(loop
              :for arg :in args
              :collect `(setf ,arg-temp ,arg)
              :collect `(when ,arg-temp
                          ;; arg is T, this can change the state
                          (if ,state
                              ;; a second T value, return NIL
                              (return-from ,block-name nil)
                              ;; a first T, swap the state
                              (setf ,state ,arg-temp))))
         (return-from ,block-name ,state)))))


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

Problem: Macro call that should be transformed by NAND

Input: (nand)

Output:
(defmacro nand (&rest forms)
  "Equivalent to (not (and ...))."
  (if (null forms) nil
      (if (null (rest forms))
          `(not ,(first forms))
          `(if ,(first forms)
               (nand ,@(rest forms))
               t))))


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

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

Input:
(in-compile-time nil
  :key
  nil)

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


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

Problem: Macro call that should be transformed by LAMBDA

Input: (lambda () (progn))

Output: (defmacro LAMBDA ...)


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

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

Input:
(awhen nil
  (progn))

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


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

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

Input:
(defreply nil
    :key
  nil)

Output: (defmacro DEFREPLY ...)


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

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

Input:
(c?_
  nil
  nil)

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


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

Problem: Macro call that should be transformed by DEFTEST

Input:
(deftest nil
  :key
  nil)

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


Instruction:
Generate a defmacro form that transforms code like this:
(walk-environment/augment! nil :key nil)

Pattern to recognize: Macro call that should be transformed by WALK-ENVIRONMENT/AUGMENT!

Input: (walk-environment/augment! nil :key nil)

Output: (defmacro WALK-ENVIRONMENT/AUGMENT! ...)


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

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

Input: (product-of nil)

Output: (defmacro PRODUCT-OF ...)


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

Issue: Macro call that should be transformed by DLET

Input:
(dlet nil
  :key
  nil)

Output: (defmacro DLET ...)


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

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

Input: (nconcf nil)

Output: (defmacro NCONCF ...)


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

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

Input: (aif nil nil)

Output:
(defmacro aif (test then &optional else)
  "Like IF, except binds the result of the test to IT (via LET) for
the scope of the then and else expressions."
  `(anaphoric if ,test ,then ,else))


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

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

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

Output: (defmacro DEFMETHOD* ...)


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

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

Input: (ap nil :key nil)

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


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

Issue: Macro call that should be transformed by WHERE

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

Output: (defmacro WHERE ...)


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

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

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

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


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

Issue: Macro call that should be transformed by EVAL-ALWAYS

Input:
(eval-always
  common-lisp:nil
  (common-lisp:progn))

Output: (defmacro EVAL-ALWAYS ...)


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

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

Input: (jand nil)

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


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

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

Input: (true nil (progn))

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

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

Input:
(deftable nil
  (progn))

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


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

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

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

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


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

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

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

Output:
(defmacro with-yield (&body body)
  (let ((point (gensym))
        (current (gensym)))
    `(let (,point ,current)
       (with-call/cc
	 (labels ((yield (&rest values)
		    (setf ,current values)
		    (let/cc k
		      (setf ,point k))))
	   ,@body
	   (setf ,point nil)))
       (gen-lambda ()
	 (cond ((null ,point)
		'generator-stop)
	       (t
		(let ((current ,current))
		  (funcall ,point nil)
		  ;values-handler: see gen-lambda
		  (apply #'values (funcall values-handler current)))))))))


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

Problem: Macro call that should be transformed by DEFSUBST

Input:
(defsubst nil
    nil)

Output:
(defmacro defsubst (name params &body body)
  "Define an inline function.

     (defsubst fn ...)
     ≡ (declaim (inline fn))
       (defun fn ...)

The advantage of a separate defining form for inline functions is that
you can't forget to declaim the function inline before defining it –
without which it may not actually end up being inlined.

From Emacs and other ancient Lisps."
  `(progn
     (declaim (inline ,name))
     (defun ,name ,params
       ,@body)))


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

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

Input:
(cond-<>>
  nil
  nil)

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


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

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

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

Output:
(defmacro econd-let (symbol &body clauses)
  "Like `cond-let' for `econd'."
  `(cond-let ,symbol
     ,@clauses
     (t (error 'econd-failure))))


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

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

Input:
(local
  nil
  :key
  nil)

Output:
(defmacro local (&body orig-body &environment env)
  "Make internal definitions using top-level definition forms.

Within `local' you can use top-level definition forms and have them
create purely local definitions, like `let', `labels', and `macrolet':

     (fboundp 'plus) ; => nil

     (local
       (defun plus (x y)
         (+ x y))
       (plus 2 2))
     ;; => 4

     (fboundp 'plus) ; => nil

Each form in BODY is subjected to partial expansion (with
`macroexpand-1') until either it expands into a recognized definition
form (like `defun') or it can be expanded no further.

\(This means that you can use macros that expand into top-level
definition forms to create local definitions.)

Just as at the real top level, a form that expands into `progn' (or an
equivalent `eval-when') is descended into, and definitions that occur
within it are treated as top-level definitions.

\(Support for `eval-when' is incomplete: `eval-when' is supported only
when it is equivalent to `progn').

The recognized definition forms are:

- `def', for lexical variables (as with `letrec')
- `define-values', for multiple lexical variables at once
- `defun', for local functions (as with `labels')
- `defalias', to bind values in the function namespace (like `fbindrec*')
- `declaim', to make declarations (as with `declare')
- `defconstant' and `defconst', which behave exactly like symbol macros
- `define-symbol-macro', to bind symbol macros (as with `symbol-macrolet')

Also, with serious restrictions, you can use:

- `defmacro', for local macros (as with `macrolet')

\(Note that the top-level definition forms defined by Common Lisp
are (necessarily) supplemented by three from Serapeum: `def',
`define-values', and `defalias'.)

The exact order in which the bindings are made depends on how `local'
is implemented at the time you read this. The only guarantees are that
variables are bound sequentially; functions can always close over the
bindings of variables, and over other functions; and macros can be
used once they are defined.

     (local
       (def x 1)
       (def y (1+ x))
       y)
     => 2

     (local
       (defun adder (y)
         (+ x y))
       (def x 2)
       (adder 1))
     => 3

Perhaps surprisingly, `let' forms (as well as `let*' and
`multiple-value-bind') *are* descended into; the only difference is
that `defun' is implicitly translated into `defalias'. This means you
can use the top-level idiom of wrapping `let' around `defun'.

    (local
      (let ((x 2))
        (defun adder (y)
          (+ x y)))
      (adder 2))
    => 4

Support for macros is sharply limited. (Symbol macros, on the other
hand, are completely supported.)

1. Macros defined with `defmacro' must precede all other expressions.

2. Macros cannot be defined inside of binding forms like `let'.

3. `macrolet' is not allowed at the top level of a `local' form.

These restrictions are undesirable, but well justified: it is
impossible to handle the general case both correctly and portably, and
while some special cases could be provided for, the cost in complexity
of implementation and maintenance would be prohibitive.

The value returned by the `local' form is that of the last form in
BODY. Note that definitions have return values in `local' just like
they do at the top level. For example:

     (local
       (plus 2 2)
       (defun plus (x y)
         (+ x y)))

Returns `plus', not 4.

The `local' macro is loosely based on Racket's support for internal
definitions."
  (multiple-value-bind (body decls) (parse-body orig-body)
    (catch 'local
      (generate-internal-definitions
       (make 'internal-definitions-env
             :decls decls
             :env env)
       body))))


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

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

Input: (as-> nil (progn))

Output: (defmacro AS-> ...)


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

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

Input: (query nil nil)

Output:
(defmacro query (query &rest args/format)
  "Execute the given query, which can be either a string or an S-SQL form (list
starting with a keyword). If the query contains placeholders ($1, $2, etc)
their values can be given as extra arguments. If one of these arguments is a
keyword occurring in the table below, it will not be used as a query
argument, but will determine the format in which the results are returned
instead. Any of the following formats can be used, with the default being :rows:

| :none	             | Ignore the result values.                                 |
| :lists, :rows      | Return a list of lists, each list containing the values   |
|                    | for a row.                                                |
| :list, :row        | Return a single row as a list.                            |
| :alists	           | Return a list of alists which map column names to values, |
|                    | with the names represented as keywords.                   |
| :alist	           | Return a single row as an alist.                          |
| :array-hash        | Return an array of hashtables which map column names to   |
|                    | hash table keys. NOTE: It will return an empty array      |
|                    | if there is no result.                                    |
| :vectors           | Returns a vector of vectors where each internal vector is |
|                    | a returned row from the query. The field names are not    |
|                    | included. NOTE: It will return an empty vector instead of |
|                    | NIL if there is no result.                                |
| :str-alists        | Like :alists, but use the original column names.          |
| :str-alist	       | Return a single row as an alist, with strings for names.  |
| :plists	           | Return a list of plists which map column names to values, |
|                    | with the names represented as keywords.                   |
| :plist	           | Return a single row as a plist.                           |
| :column	           | Return a single column as a list.                         |
| :single	           | Return a single value.                                    |
| :single!	         | Like :single, but raise an error when the number of       |
|                    | selected rows is not equal to 1.                          |
| (:dao type)	       | Return a list of DAOs of the given type. The names of the |
|                    | fields returned by the query must match slots in the DAO  |
|                    | class the same way as with query-dao.                     |
| (:dao type :single)| Return a single DAO of the given type.                    |
| :json-strs         | Return a list of strings where each row is a json object  |
|                    | expressed as a string                                     |
| :json-str          | Return a single string where the row returned is a json   |
|                    | object expressed as a string.                             |
| :json-array-str    | Return a string containing a json array, each element in  |
|                    | the array is a selected row expressed as a json object.   |
|                    | NOTE: If there is no result, it will return a string with |
|                    | an empty json array.                                      |

If the database returns information about the amount rows that were affected,
such as with updating or deleting queries, this is returned as a second value."
  (let* ((format :rows)
         (args (loop :for arg :in args/format
                     :if (or (dao-spec-for-format arg)
                             (assoc arg *result-styles*)) :do (setf format arg)
                     :else :collect arg)))
    (destructuring-bind (reader result-form) (reader-for-format format)
      (let ((base (if args
		      (let ((vars (loop :for x :in args :collect (gensym))))
			`(let ,(loop :for v :in vars :for a :in args :collect `(,v ,a))
			   (prepare-query *database* "" ,(real-query query) (list ,@vars))
			   (exec-prepared *database* "" (list ,@vars) ,reader)))
		      `(exec-query *database* ,(real-query query) ,reader))))
        `(,result-form ,base)))))


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(multiple-value-match nil)

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

Input: (multiple-value-match nil)

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

Examples:

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


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

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

Input: (nunionf nil :key nil)

Output: (defmacro NUNIONF ...)