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

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

Input:
(bind nil
  (progn))

Output:
(defmacro bind ((&rest bindings) &body body)
  "Bind is a replacement for let*, destructuring-bind, multiple-value-bind and more.

An example is probably the best way to describe its syntax:

    \(bind \(\(a 2\)
           \(\(b &rest args &key \(c 2\) &allow-other-keys\) '\(:a :c 5 :d 10 :e 54\)\)
           \(\(:values d e\) \(truncate 4.5\)\)
           \(\(:structure xxx- slot1 slot2\) \(make-xxx\)\)
           \(\(:flet name \(arg1 arg2\)\) \(+ arg1 arg2\)\)\)
         \(list a b c d e args\)\)

Simple bindings are as in let*. Destructuring is done if the first item
in a binding is a list. Multiple value binding is done if the first item
in a binding is a list and the first item in the list is ':values'. Other
forms have their own syntax. For example, :structure first has the conc
name and then slot names whereas :flet has the function name and a list
of arguments and then the function body (in an implicit progn)."
  (let (declarations)
    (loop while (and (consp (car body)) (eq (caar body) 'declare)) do
          (push (first body) declarations)
          (setf body (rest body)))
    (if bindings
	(let ((*all-declarations* (bind-expand-declarations (nreverse declarations))))
	  (prog1
	      (bind-macro-helper bindings body)
	    (check-for-unused-variable-declarations *all-declarations*)))
        `(locally
             ,@declarations
           ,@body))))


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

Problem: Macro call that should be transformed by EMATCH

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

Output:
(defmacro ematch (arg &body clauses)
  "Same as MATCH, except MATCH-ERROR will be raised if not matched."
  (once-only (arg)
    (let ((else `(error 'match-error
                        :values (list ,arg)
                        :patterns ',(mapcar (lambda (c) (list (car c))) clauses))))
      (compile-match-1 arg clauses else))))


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

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

Input: (->* nil)

Output: (defmacro ->* ...)


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

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

Input: (collecting-into-and-returning nil)

Output: (defmacro COLLECTING-INTO-AND-RETURNING ...)


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

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

Input: ($send nil (progn))

Output: (defmacro $SEND ...)


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

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

Input: (fm! nil nil)

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


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

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

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

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


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

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

Input:
(with-special-initargs nil
  (progn))

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


Instruction:
Define a macro that eliminates this repetitive pattern:
;; Manual gensym binding is verbose
(let ((g1 (gensym))
      (g2 (gensym))
      (g3 (gensym)))
  `(let ((,g1 ,x)
         (,g2 ,y))
     (f ,g1 ,g2 ,g3)))
;; The let-bindings for gensyms obscure the macro logic

Issue: Manual gensym creation with let-bindings is verbose — want concise declaration of gensym-intended symbols

Input:
;; Manual gensym binding is verbose
(let ((g1 (gensym))
      (g2 (gensym))
      (g3 (gensym)))
  `(let ((,g1 ,x)
         (,g2 ,y))
     (f ,g1 ,g2 ,g3)))
;; The let-bindings for gensyms obscure the macro logic

Output:
(defmacro with-gensyms (syms &body body)
  `(let ,(mapcar #'(lambda (s)
                     `(,s (gensym)))
                 syms)
     ,@body))


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

Problem: Macro call that should be transformed by PECASE

Input: (pecase nil :key nil)

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

   Example usage:

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


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

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

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

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

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

Output: (defmacro CTYPECASE ...)


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

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

Input:
(multiple-value-prog2 nil
    :key
  nil)

Output:
(defmacro multiple-value-prog2 (first-form second-form &body forms)
  "Evaluates FIRST-FORM, then SECOND-FORM, and then FORMS. Yields as its value
   all the value returned by SECOND-FORM."
  `(progn ,first-form (multiple-value-prog1 ,second-form ,@forms)))


Instruction:
Generate a defmacro form that transforms code like this:
(with-decoder-simple-clos-semantics
  nil
  :key
  nil)

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

Input:
(with-decoder-simple-clos-semantics
  nil
  :key
  nil)

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


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

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

Input:
(string-case nil
  (progn))

Output: (defmacro STRING-CASE ...)


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

Issue: Macro call that should be transformed by FSETF

Input: (fsetf nil :key nil)

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


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

Write a macro that addresses: Macro call that should be transformed by SPLICE-SEQF

Input: (splice-seqf nil)

Output: (defmacro SPLICE-SEQF ...)


Instruction:
Define a macro that eliminates this repetitive pattern:
(as~> nil (progn))

Issue: Macro call that should be transformed by AS~>

Input: (as~> nil (progn))

Output:
(defmacro as~> (expr name &rest exprs)
  "Like `~>' or `~>', but instead of threading by position, threading is
done based on NAME."
  `(let* ,(loop for expr in (cons expr exprs)
                collect (list name expr))
     ,name))


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

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

Input: (trace)

Output: (defmacro TRACE ...)


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

Problem: Macro call that should be transformed by FAIL

Input: (fail nil)

Output:
(defmacro fail (&rest message-args)
  "Simply generate a FAIL."
  `(process-failure ',message-args
                    ,@message-args))


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

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

Input:
(json-bind nil
    :key
  nil)

Output:
(defmacro json-bind ((&rest vars) json-source &body body)
  (let-gensyms (decoder validator value-handler key-handler pass)
    (let ((vars-tmp (loop repeat (length vars) collect (gensym))))
      `(let (,@vars-tmp (,pass (constantly t)))
         (let ((,validator
                (custom-decoder
                 :beginning-of-object ,pass :object-key ,pass
                 :object-value ,pass :end-of-object ,pass
                 :beginning-of-array ,pass :array-member ,pass
                 :end-of-array ,pass :beginning-of-string ,pass
                 :string-char ,pass :end-of-string ,pass
                 :internal-decoder 'decode-json))
               (,decoder (current-decoder))
               (,key-handler *object-key-handler*)
               (,value-handler *object-value-handler*))
           (declare (ignorable ,decoder ,key-handler ,value-handler))
           ,(if (null vars)
                `(decode-json-from-source ,json-source ,validator)
                `(bind-custom-vars
                     (,@(json-bind-level-customizations
                         (loop for var in vars for var-tmp in vars-tmp
                           collect (cons var-tmp (symbol-name var)))
                         nil decoder validator
                         key-handler value-handler pass)
                      :aggregate-scope
                        (union *aggregate-scope-variables*
                               '(*object-key-handler*
                                 *object-value-handler*
                                 *internal-decoder*)))
                   (decode-json-from-source ,json-source))))
         (let ,(mapcar #'list vars vars-tmp)
           ,@body)))))


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

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

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

Output: (defmacro MAXF ...)


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

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

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

Output:
(defmacro accase (keyform &body cases)
  "Like CCASE, except binds the result of the keyform to IT (via LET) for the
scope of the cases. Unlike CCASE, the keyform/place doesn't receive new values
possibly stored with STORE-VALUE restart; the new value is received by IT."
  `(anaphoric ccase ,keyform ,@cases))


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

Problem: Macro call that should be transformed by NAMED-LAMBDA

Input:
(named-lambda nil
    :key
  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:
Write a Common Lisp macro to handle this code pattern:
(with-foreign-objects 'lol-gen::some-name)

Problem: Macro call that should be transformed by WITH-FOREIGN-OBJECTS

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

Output:
(defmacro with-foreign-objects (bindings &body body)
  (if bindings
      `(with-foreign-object ,(car bindings)
         (with-foreign-objects ,(cdr bindings)
           ,@body))
      `(progn ,@body)))


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

Write a macro that addresses: Macro call that should be transformed by DEFINE-SCREAMER-PACKAGE

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

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

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


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

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

Input: (matrix-etypecase nil)

Output: (defmacro MATRIX-ETYPECASE ...)


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

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

Input:
(with-proxynodes nil
  :key
  nil)

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

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

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


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

What needs to change: Macro call that should be transformed by COMPILE-$FLAVOR-$METHODS

Input: (compile-$flavor-$methods 'lol-gen::some-name)

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


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

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

Input: (and nil nil)

Output: (defmacro AND ...)


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

Write a macro that addresses: Macro call that should be transformed by INCF-POINTER

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

Output: (defmacro INCF-POINTER ...)


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

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

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

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

Issue: Macro call that should be transformed by SECASE

Input: (secase nil)

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


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(c?n-until nil
  nil)

What needs to change: Macro call that should be transformed by C?N-UNTIL

Input:
(c?n-until nil
  nil)

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


Instruction:
Define a macro that eliminates this repetitive pattern:
(etypecase-of nil
    (progn))

Issue: Macro call that should be transformed by ETYPECASE-OF

Input:
(etypecase-of nil
    (progn))

Output:
(defmacro etypecase-of (type x &body body)
  "Like `etypecase' but, at compile time, warn unless each clause in
BODY is a subtype of TYPE, and the clauses in BODY form an exhaustive
partition of TYPE."
  (once-only (x)
    `(typecase-of ,type ,x
       ,@body
       (otherwise
        (error 'type-error
               :datum ,x
               :expected-type ',type)))))


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

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

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

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


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

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

Input: (with-inactive-layers nil)

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


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

Issue: Macro call that should be transformed by PSETQ

Input: (psetq)

Output: (defmacro PSETQ ...)


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

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

Input:
(some->
  nil
  nil)

Output: (defmacro SOME-> ...)


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

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

Input:
(eval-when-execute
  common-lisp:nil)

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


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

Problem: Macro call that should be transformed by DEFGENERIC

Input: (defgeneric nil :key nil)

Output:
(defmacro defgeneric (name (&rest lambda-list) &rest options)
  (with-gensyms (gf)
    (flet ((make-save-method (args)
             (with-gensyms (method)
               (multiple-value-bind (qualifiers specializers lambda-list body)
                   (parse-method args)

                 (let ((fn-name (gentemp (symbol-name (block-name name)) *method-function-package*)))
                   (list `(let ((,method (find-method% ,gf ',qualifiers ',specializers)))
                            ,(make-add-method-info name method fn-name body :remove-on-redefine-p t))

                         (make-method-function name fn-name lambda-list body)

                         (make-static-dispatch name lambda-list specializers)))))))

      (let ((combination 'standard)
            (combination-options))

        `(progn
           (walk-environment
             (c2mop:defgeneric ,name ,lambda-list ,@options))

           (eval-when (:compile-toplevel :load-toplevel :execute)
             (add-compiler-macro ',name)
             (remove-defined-methods ',name))

           (let ((,gf (fdefinition ',name)))
             (when (typep ,gf 'generic-function)
               ,@(handler-case
                     (append
                      (mappend
                       (lambda-match
                         ((list* :method args)
                          (make-save-method args))

                         ((list* :method-combination name options)
                          (setf combination name)
                          (setf combination-options options)))

                       options)

                      `((setf (combination-options ',name)
                              '(,combination ,combination-options))))

                   (error (e)
                     (simple-style-warning "Error parsing DEFGENERIC form:~%~a" e)
                     nil)))

             ,gf))))))


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

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

Input:
(static-let* nil
  (progn))

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

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

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

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

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


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

Problem: Macro call that should be transformed by .>

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

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

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

Input: (alter-table 'lol-gen::some-name)

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


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

Problem: Macro call that should be transformed by ROTATEF

Input: (rotatef nil :key nil)

Output: (defmacro ROTATEF ...)


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

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

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

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


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

Problem: Macro call that should be transformed by FM?

Input: (fm? nil)

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


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

Issue: Macro call that should be transformed by NAND

Input: (nand nil)

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

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

Input: (make-name-transformer nil)

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


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

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

Input: (defun nil (progn))

Output: (defmacro DEFUN ...)


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

Problem: Macro call that should be transformed by CURRENT-DECODER

Input: (current-decoder 'lol-gen::some-name)

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


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

Issue: Macro call that should be transformed by JBIND

Input:
(jbind nil
    nil)

Output:
(defmacro jbind (destructuring-pattern form &body body)
  "Match the FORM against DESTRUCTURING-PATTERN.
The pattern might be:
- A symbol, in which case the current chosen form is bound to it. If
  the symbol is _, simply skip the form.
- A literal form:
  - String or number: compare with `equal'.
  - Keywords :TRUE, :FALSE, and :NULL, matching T, NIL, and :NULL
    respectively.
- If the pattern is a property list of string+pattern pairs, match the
  string+pattern pairs inside it to the provided JSON object and
  resolve them recursively.
- If the pattern is a list of symbols (VAR &optional VAR-P), these are
  bound to the respective values of `jget'. It is a good way to make
  `jbind' to be more lenient to missing keys, because the default
  behavior is to error on missing data.
- If the pattern is an inline vector, match it against a JSON array
  with at least as many elements as provided in the vector. Match
  every form in the vector against the element with the same index.

If the DESTRUCTURING-PATTERN doesn't match the object, throw
`value-mismatch'.

Underlying `jget' can throw errors for the exceptionally malformed
inputs. See `jget' documentation for the types of errors it throws.

Example:
\(\"hello\" hello \"a\" _ \"b\" b
 \"array\" #(first second third _))

matches a JSON object
{\"hello\": 3, \"a\": 8, \"b\": 3, \"c\": null, \"array\": [1, 2, 3, 4]}

and binds
- HELLO to 3
- B to 3
- FIRST to 1
- SECOND to 2
- THIRD to 3

It also checks that \"a\" key is present in the object and there's a
fourth element in the nested array.

See more examples in njson tests."
  (let ((form-sym (gensym "BIND-FORM"))
        (bindings (list)))
    (labels ((parse-pattern (pattern &optional (current-path (list)))
               (etypecase pattern
                 ((or (member :true :false :null) string real)
                  (push (cons pattern (copy-list current-path))
                        bindings))
                 ((cons symbol *)
                  (push (cons pattern (copy-list current-path))
                        bindings))
                 (list
                  (loop for (key subpattern) on pattern by #'cddr
                        do (parse-pattern subpattern (append current-path (list key))))
                  (push (cons nil (copy-list current-path))
                        bindings))
                 ((and symbol (not keyword))
                  (push (cons (if (equal "_" (symbol-name pattern))
                                  (gensym "_PATTERN")
                                  pattern)
                              (copy-list current-path))
                        bindings))
                 (array
		  (loop for elem across pattern
                        for index from 0
                        do (parse-pattern elem (append current-path (list index))))
		  (push (cons #() (copy-list current-path))
			bindings)))))
      (check-type destructuring-pattern (or list (and array (not string))
                                            (and symbol (not keyword)))
                  "proper jbind destructuring pattern: list, array, or symbol")
      (parse-pattern destructuring-pattern)
      (let ((let-forms (loop for (binding . key) in bindings
                             do (check-type binding (or array real symbol
                                                        ;; For (VAR VAR-P) forms
                                                        (cons symbol (or (cons symbol null)
                                                                         null))))
                             if (typep binding '(or array real null
                                                 (member :true :false :null)))
                               collect `(,(gensym) (check-value ,binding (vector ,@key) ,form-sym))
                             else if (and (symbolp binding)
                                          (uiop:emptyp key))
                                    collect `(,binding ,form-sym)
                             else if (listp binding)
                                    append (destructuring-bind (var &optional (var-p nil var-p-provided))
                                               binding
                                             (append
                                              `((,var (jget (vector ,@key) ,form-sym)))
                                              (when var-p-provided
                                                `((,var-p (nth-value 1 (jget (vector ,@key) ,form-sym)))))))
                             else
                               collect `(,binding (check-value t (vector ,@key) ,form-sym)))))
        `(let* ((,form-sym ,form)
                ,@let-forms)
           (declare (ignorable ,form-sym ,@(mapcar #'first let-forms)))
           ,@body))))


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

Problem: Macro call that should be transformed by DEF-C-UNCHANGED-TEST

Input: (def-c-unchanged-test 'lol-gen::some-name)

Output:
(defmacro def-c-unchanged-test ((class slotname) &body test)
  `(defmethod c-unchanged-test ((self ,class) (slotname (eql ',slotname)))
     ,@test))


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

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

Input:
(cond->>
  nil
  (progn))

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


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

Issue: Macro call that should be transformed by SPECIAL-SYMBOL-REPROGV

Input:
(special-symbol-reprogv nil
    nil)

Output: (defmacro SPECIAL-SYMBOL-REPROGV ...)


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

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

Input: (update nil (progn))

Output:
(defmacro update (place value-form)
  (etypecase place
    (symbol `(setf ,place ,value-form))
    (list
     (let ((result (gensym "RESULT"))
           (var (gensym "VAR")))
       (lambda-fiddle:with-destructured-lambda-list (:required req :optional opt :rest rest :body body :key key) place
         (let ((rest (or rest body)))
           `(let ((,result ,value-form))
              ;; Convert required into test and POP
              ,@(loop for var in req
                      do (assert (and (not (null var)) (symbolp var)))
                      collect `(if ,result
                                   (setf ,var (pop ,result))
                                   (error "Not enough arguments to satisfy lambda-list ~a." ',place)))
              ;; Convert &OPTIONAL into POP and default.
              ,@(loop for o in opt
                      for (var default) = (enlist o)
                      do (assert (and (not (null var)) (symbolp var)))
                      collect `(setf ,var (or (pop ,result) ,default)))
              ;; If we don't have &REST or &KEY, error if there are some elements left.
              ,@(when (and (not rest) (not (find '&key place)))
                  `((when ,result (error "Too many elements supplied to satisfy lambda-list ~a." ',place))))
              ;; Convert &REST by just setting it to the remainder.
              ,@(when rest `((setf ,rest ,result)))
              ;; Convert &KEY into GETF and default.
              ,@(loop for k in key
                      for (var default) = (enlist k)
                      do (assert (and (not (null var)) (symbolp var)))
                      collect `(setf ,var (or (getf ,result ,(intern (string var) :keyword)) ,default)))
              ;; If we have a non-empty &KEY list and don't have &ALLOW-OTHER-KEYS, check the keys.
              ,@(when (and key (not (find '&allow-other-keys place)))
                  `((loop for ,var in ,result by #'cddr
                          do (unless (find ,var ',(loop for k in key collect (intern (string k) :keyword)))
                               (error "Keyword argument ~s not found in lambda-list ~a."
                                      ,var ',place))))))))))))


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

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

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

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


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

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

Input:
(ensure-transaction-with-isolation-level nil
  :key
  nil)

Output:
(defmacro ensure-transaction-with-isolation-level (isolation-level &body body)
  "Executes body within a with-transaction form if and only if no transaction is
already in progress. This adds the ability to specify an isolation level other
than the current default"
  `(call-with-ensured-transaction (lambda () ,@body) ,isolation-level))


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

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

Input: (with-unique-names nil)

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


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

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

Input: (and-it nil nil)

Output:
(defmacro and-it (&rest args)
  "Like AND. IT is bound to the value of the previous AND form."
  (cond ((null args) t)
        ((null (cdr args)) (car args))
        (t `(when-it ,(car args) (and-it ,@(cdr args))))))


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

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

Input: (xhtml nil (progn))

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


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

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

Input: (continue-whopper nil nil)

Output: (defmacro CONTINUE-WHOPPER ...)


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

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

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

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


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

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

Input: (with-connection nil)

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


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

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

Input: (defmethod* nil :key nil)

Output: (defmacro DEFMETHOD* ...)


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

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

Input: (<- nil (progn))

Output:
(defmacro <- (place fn)
    "Apply FN in-place to PLACE."
    `(setf ,place (call ,fn ,place)))


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

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

Input:
(bind-custom-vars nil
  nil)

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


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

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

Input:
(with-custom-decoder-level nil
  :key
  nil)

Output:
(defmacro with-custom-decoder-level ((&rest customizations) &body body)
  "Execute BODY in a dynamic environment such that, when nested
structures are decoded, the outermost level is decoded with the given
custom handlers (CUSTOMIZATIONS) whereas inner levels are decoded in
the usual way."
  `(let ((current-decoder
          (current-decoder
           ,@(loop for (key value) on customizations by #'cddr
                if (eq key :internal-decoder)
                  do (error "~S ~S customization is meaningless in ~
                             the context of WITH-CUSTOM-DECODER-LEVEL."
                            key value)
                else collect key))))
     (bind-custom-vars (:internal-decoder current-decoder ,@customizations)
       ,@body)))


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

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

Input: (with-dot nil)

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


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

Problem: Macro call that should be transformed by F_%

Output: (defmacro F_% ...)


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

Problem: Macro call that should be transformed by REMOVEF

Input: (removef nil (progn))

Output: (defmacro REMOVEF ...)


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

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

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

Output:
(defmacro c-abs (value &body body)
  `(make-c-drifter-absolute
    :code ',body
    :value-state :valid
    :value ,value
    :rule (c-lambda ,@body)))


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

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

Input:
(with-explicit-encoder
  nil)

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


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

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

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

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


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

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

Input: (iterate nil nil)

Output: (defmacro ITERATE ...)


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

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

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

Output:
(defmacro with-unique-names (names &body body)
  `(let ,(mapcar (lambda (sym)
                   `(,sym (gensym ,(symbol-name sym))))
                  names)
     ,@body))


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

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

Input: (aand nil)

Output:
(defmacro aand (first &rest rest)
  "Like AND, except binds the first argument to IT (via LET) for the
scope of the rest of the arguments."
  `(anaphoric and ,first ,@rest))


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

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

Input:
(ensure nil
  :key
  nil)

Output:
(defmacro ensure (place &body newval
                        &environment env)
  "Essentially (or place (setf place newval)).

PLACE is treated as unbound if it returns `nil', signals
`unbound-slot', or signals `unbound-variable'.

Note that ENSURE is `setf'-able, so you can do things like
     (incf (ensure x 0))

Cf. `ensure2'."
  (multiple-value-bind (vars vals stores setter getter)
      (get-setf-expansion place env)
    `(let* ,(mapcar #'list vars vals)
       (or (ignore-some-conditions (unbound-slot unbound-variable)
             ,getter)
           (multiple-value-bind ,stores
               (progn ,@newval)
             (when ,(first stores)
               ,setter))))))


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

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

Input: (fm-other?! nil)

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


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

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

Input:
(with-keys nil
    :key
  nil)

Output:
(defmacro with-keys ((&rest kv-pairs) ht &body body)
  "Like WITH-ACCESSORS but for pairs in hash-table HT."
  (once-only (ht)
    `(let (,@(mapcar #`(list (car %) `(gethash ,(second %) ,ht))
                     kv-pairs))
       ,@body)))


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

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

Input: (aand nil)

Output: (defmacro AAND ...)


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

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

Input:
(defmacro* nil
    :key
  nil)

Output: (defmacro DEFMACRO* ...)


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

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

Input: (etypecase nil)

Output: (defmacro ETYPECASE ...)


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

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

Input: (isnt nil :key nil)

Output:
(defmacro isnt (got expected &rest args)
  (with-gensyms (duration result new-args desc)
    (once-only (expected)
      `(let* ((,new-args (list ,@args))
              (,desc (parse-description-and-test ,new-args)))
         (with-catching-errors (:description ,desc :expected ,expected)
           (with-duration ((,duration ,result) ,got)
             (test ,result ,expected ,new-args
                   :notp t
                   :duration ,duration)))))))


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

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

Input: (declaim nil)

Output: (defmacro DECLAIM ...)


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

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

Input: (->> nil)

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


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

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

Input:
(all-of nil
  :key
  nil)

Output: (defmacro ALL-OF ...)


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

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

Input: (between nil :key nil)

Output:
(defmacro between (a parser b &key (id nil))
  "A main parser flanked by two other ones. Only the value of the main parser is
kept. Good for parsing backets, parentheses, etc."
  (declare (ignore id))
  `(*> ,a (<* ,parser ,b)))


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(on-duplicate-key-update)

What needs to change: Macro call that should be transformed by ON-DUPLICATE-KEY-UPDATE

Input: (on-duplicate-key-update)

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


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

Problem: Macro call that should be transformed by MATCH

Input: (match nil)

Output:
(defmacro match (arg &body clauses)
  "Matches ARG with CLAUSES. CLAUSES is a list of the form of (PATTERN
. BODY) where PATTERN is a pattern specifier and BODY is an implicit
progn. If ARG matches some PATTERN, `match` then evaluates
the corresponding BODY and returns the evaluated value.  If no pattern matches,
then returns NIL.

Evaluating a form (FAIL) in the clause body causes the latest pattern
matching to fail. For example,

    (match 1
      (x (if (eql x 1)
             (fail)
             x))
      (_ 'ok))

returns OK, because the form (FAIL) in the first clause is
evaluated.

If BODY starts with the symbols WHEN or UNLESS, then the next form
will be used to introduce (FAIL). That is,

    (match list ((list x) when (oddp x) x))
    (match list ((list x) unless (evenp x) x))

will be translated to

    (match list ((list x) (if (oddp x) x (fail))))
    (match list ((list x) (if (evenp x) (fail) x)))

Examples:

    (match 1 (1 1))
    => 1
    (match 1 (2 2))
    => 2
    (match 1 (x x))
    => 1
    (match (list 1 2 3)
      (list x y z) (+ x y z))
    => 6"
  (compile-match-1 arg clauses nil))


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

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

Input: (with-interleaving)

Output:
(defmacro with-interleaving (&body body)
  (let* ((root (copy-list (pop body)))
         (current root))
    (dolist (form body root)
      (let ((form (copy-list form)))
        (when form
          (setf (cdr (last current)) (cons form NIL))
          (setf current form))))))


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

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

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

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


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

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

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

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


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

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

Input: (or nil nil)

Output: (defmacro OR ...)


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

Problem: Macro call that should be transformed by SUMMING

Input:
(summing
  nil
  :key
  nil)

Output:
(defmacro summing (&body body)
  "Within BODY, bind `sum' to a function that gathers numbers to sum.

If the first form in BODY is a literal number, it is used instead of 0
as the initial sum.

To see the running sum, call `sum' with no arguments.

Return the total."
  ;; TODO This should be numerically stable, at least if the zero is a
  ;; float.
  (let ((zero (if (numberp (first body)) (pop body) 0)))
    (with-gensyms (running-total x x-supplied?)
      (with-current-package-symbols (sum)
        `(let ((,running-total ,zero))
           (declare (number ,running-total))
           (flet ((,sum (&optional (,x 0 ,x-supplied?))
                    (if ,x-supplied?
                        (incf ,running-total ,x)
                        ,running-total)))
             (declare (ignorable (function ,sum)))
             ,@body)
           (the number ,running-total))))))


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

Issue: Macro call that should be transformed by FAIL

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

Output:
(defmacro fail (&rest message-args)
  "Simply generate a FAIL."
  `(process-failure ',message-args
                    ,@message-args))


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

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

Input: (dict-of nil :key nil)

Output: (defmacro DICT-OF ...)


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

Write a macro that addresses: Macro call that should be transformed by PRINTING-UNREADABLY

Input: (printing-unreadably nil nil)

Output:
(defmacro printing-unreadably (fields-list class-std-form
                               &key (type t) (identity t))
  "Automatically generates the unreadable printing boiler plate to print classes and its fields (from FIELDS-LIST)."
  (let ((g!stream (gensym "STREAM"))
        (name (cadr class-std-form)))
    `(progn ,class-std-form
            (defmethod print-object ((,name ,name) ,g!stream)
              (print-unreadable-object (,name ,g!stream
                                        :type ,type
                                        :identity ,identity)
                (format ,g!stream
                        ,(format nil "~{~a: ~~s~^,~^ ~}" fields-list)
                        ,@(mapcar (lambda (a1)
                                    `(,a1 ,name))
                                  fields-list)))))))


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

Issue: Macro call that should be transformed by CMATCH

Input: (cmatch nil)

Output:
(defmacro cmatch (arg &body clauses)
  "Same as MATCH, except a continuable MATCH-ERROR will be raised if none of the
clauses match."
  (once-only (arg)
    (let ((else `(cerror "Continue."
                         'match-error
                         :values (list ,arg)
                         :patterns ',(mapcar (lambda (c) (list (car c))) clauses))))
      (compile-match-1 arg clauses else))))


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

Problem: Macro call that should be transformed by WITH-COMPILATION-UNIT

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

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


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

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

Input: (c?)

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


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

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

Input: (for nil)

Output:
(defmacro for (&environment env bindings &body body)
  (let ((*environment* env))
    (multiple-value-bind (bind-init bind-forms bind-exit bind-post) (convert-bindings bindings)
      (multiple-value-bind (clause-init body-forms clause-exit) (convert-clauses body)
        `(with-interleaving
           ,@bind-init
           ,@clause-init
           (with-for-block ()
             (with-for-tagbody
                 (progn ,@bind-forms
                        ,@body-forms
                        ,@bind-post)
               (return-for
                ,@clause-exit
                ,@bind-exit))))))))


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

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

Input:
(with-foreign-strings nil
  (progn))

Output:
(defmacro with-foreign-strings (bindings &body body)
  "See WITH-FOREIGN-STRING's documentation."
  (if bindings
      `(with-foreign-string ,(first bindings)
         (with-foreign-strings ,(rest bindings)
           ,@body))
      `(progn ,@body)))


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

Problem: Macro call that should be transformed by WITHOUT-C-DEPENDENCY

Input:
(without-c-dependency
  nil)

Output:
(defmacro without-c-dependency (&body body)
  ` (let (*depender*)
      ,@body))


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

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

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

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


Instruction:
Write a Common Lisp macro to handle this code pattern:
(on-duplicate-key-update nil)

Problem: Macro call that should be transformed by ON-DUPLICATE-KEY-UPDATE

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

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


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

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

Input: (do-sequences nil)

Output:
(defmacro do-sequences (name/seqs &body forms &environment env)
  "Iterate over the elements of one or more sequences.

   Iteration is performed using the iterator interface, and over
   multiple sequences simultaneously.

   The macro arguments can be in one of the following two forms:

    1. (NAME (&REST SEQS) &BODY BODY)

    2. ((&REST SEQS) &BODY BODY)

   NAME is a symbol serving as the name of the BLOCK from which the
   forms in BODY can return, using (RETURN-FROM NAME ...). If not
   given defaults to NIL.

   Each element of SEQS is a list of the form (VAR SEQUENCE . ARGS),
   where VAR is the variable to which the element of the sequence,
   SEQUENCE, is bound, at each iteration, and ARGS are arguments
   passed to the ITERATOR function, after the sequence.

   BODY is a list of forms evaluated at each iteration. RETURN-FROM to
   the block named NAME may be used to terminate the iteration early
   and return a value from the DO-SEQUENCES form. NIL is returned if
   there is no explicit RETURN."

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

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

         ,name
         ,seqs
         ,@forms))))


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

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

Input:
(drelet nil
  nil)

Output: (defmacro DRELET ...)


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

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

Input: (define-method-combination nil nil)

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


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

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

Input:
(local-output
  nil
  (progn))

Output: (defmacro LOCAL-OUTPUT ...)


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

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

Input: (some-<>> nil)

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


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

Pattern to recognize: Macro call that should be transformed by WITH-SHADOWED-CUSTOM-VARS

Input:
(with-shadowed-custom-vars
  nil
  (progn))

Output:
(defmacro with-shadowed-custom-vars (&body body)
  `(let ,(loop for (var) in *custom-vars*
            collect `(,var (if (boundp ',var) ,var)))
     ,@body))


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

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

Input: (pcase nil (progn))

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

   Example usage:

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


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

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

Input: (with-cc nil)

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


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

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

Input:
(lambda-bind nil
  nil)

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

This lets you funcall and destructure simultaneously. For example

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

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


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

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

Input: (nor nil (progn))

Output:
(defmacro nor (&rest forms)
  "Equivalent to (not (or ...)).

From Arc."
  (if (null forms) t
      (if (null (rest forms))
          `(not ,(first forms))
          `(if ,(first forms)
               nil
               (nor ,@(rest forms))))))


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

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

Input: (ok nil (progn))

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


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

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

Input: (make-window-or-instance nil :key nil)

Output: (defmacro MAKE-WINDOW-OR-INSTANCE ...)


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

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

Input: (<*> nil)

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


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

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

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

Output:
(defmacro with-unique-names (names &body body)
  `(let ,(mapcar (lambda (sym)
                   `(,sym (gensym ,(symbol-name sym))))
                  names)
     ,@body))


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

Issue: Macro call that should be transformed by METACLASS

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

Output: (defmacro METACLASS ...)


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

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

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

Output:
(defmacro with-foreign-strings (bindings &body body)
  "See WITH-FOREIGN-STRING's documentation."
  (if bindings
      `(with-foreign-string ,(first bindings)
         (with-foreign-strings ,(rest bindings)
           ,@body))
      `(progn ,@body)))


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

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

Input: (and nil nil)

Output: (defmacro AND ...)


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

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

Input: (is-print nil nil)

Output:
(defmacro is-print (got expected &optional desc)
  (with-gensyms (output duration duration-inner)
    (once-only (expected desc)
      `(with-catching-errors (:description ,desc :expected ,expected)
         (let* (,duration
                (,output (with-output-to-string (*standard-output*)
                           (with-duration ((,duration-inner ,output) ,got)
                             (declare (ignore ,output))
                             (setq ,duration ,duration-inner)))))
           (test ,output ,expected ,desc
                 :duration ,duration
                 :got-form ',got
                 :test-fn #'string=
                 :report-expected-label "output"))))))


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

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

Input: (abbr nil :key nil)

Output:
(defmacro abbr (short long &optional lambda-list)
  "Abbreviate LONG macro or function name as SHORT.
   If LAMBDA-LIST is present, also copy appropriate SETF-expander."
  `(eval-always
     ;; Lispworks signals error while abbreviating to keywords
     ;; SBCL has package locks when accessing built-in functionality
     ;; other similar things are probably possible in other implementations
     (handler-bind ((error (lambda (e)
                             (let ((r (find-restart 'continue e)))
                               (when r
                                 (warn 'rutils-style-warning
                                       :format-control
                                       "Skipped error during abbreviation: ~A"
                                       :format-arguments (list e))
                                 (invoke-restart r))))))
       (cond
         ((macro-function ',long)
          (setf (macro-function ',short) (macro-function ',long))
          #+ccl (setf (ccl:arglist ',short) (ccl:arglist ',long)))
         ((special-operator-p ',long)
          (error "Can't abbreviate a special-operator ~a" ',long))
         ((fboundp ',long)
          (setf (fdefinition ',short) (fdefinition ',long))
          #+ccl (setf (ccl:arglist ',short) (ccl:arglist ',long))
          ,(when lambda-list
            `(define-setf-expander ,short ,lambda-list
               (values ,@(multiple-value-bind
                          (dummies vals store store-form access-form)
                          (get-setf-expansion
                           (cons long (remove-if (lambda (sym)
                                                   (member sym '(&optional &key)))
                                                 lambda-list)))
                          (let ((expansion-vals (mapcar (lambda (x) `(quote ,x))
                                                        (list dummies
                                                              vals
                                                              store
                                                              store-form
                                                              access-form))))
                            (setf (second expansion-vals)
                                  (cons 'list vals))
                            expansion-vals))))))
         (t
          (error "Can't abbreviate ~a" ',long)))
       (setf (documentation ',short 'function) (documentation ',long 'function))
       ',short)))


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

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

Input: (raw nil (progn))

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


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

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

Input:
(econd-let nil
  :key
  nil)

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:
(with-unique-names nil
  :key
  nil)

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

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

Output:
(defmacro with-unique-names (names &body body)
  `(let ,(mapcar (lambda (sym)
                   `(,sym (gensym ,(symbol-name sym))))
                  names)
     ,@body))


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

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

Input: (collect-sum nil)

Output: (defmacro COLLECT-SUM ...)


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

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

Input: (or nil (progn))

Output: (defmacro OR ...)


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

Issue: Macro call that should be transformed by WHEN

Input: (when nil)

Output: (defmacro WHEN ...)


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

Issue: Macro call that should be transformed by APPENDF

Input: (appendf nil (progn))

Output: (defmacro APPENDF ...)


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

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

Input: (trcx nil)

Output:
(defmacro trcx (tgt-form &rest os)
  (if (eql tgt-form 'nil)
      '(progn)
    `(without-c-dependency
         (call-trc t ,(format nil "TX> ~(~s~)" tgt-form)
           ,@(loop for obj in (or os (list tgt-form))
                   nconcing (list (intern (format nil "~a" obj) :keyword) obj))))))


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

Problem: Macro call that should be transformed by BCOND

Input:
(bcond
  nil)

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

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

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

Output:
(defmacro signals (condition-spec
                   &body body)
  "Generates a pass if BODY signals a condition of type
CONDITION. BODY is evaluated in a block named NIL, CONDITION is
not evaluated."
  (let ((block-name (gensym)))
    (destructuring-bind (condition &optional reason-control &rest reason-args)
        (ensure-list condition-spec)
      `(block ,block-name
         (handler-bind ((,condition (lambda (c)
                                      (declare (ignore c))
                                      ;; ok, body threw condition
                                      (add-result 'test-passed
                                                  :test-expr ',condition)
                                      (return-from ,block-name t))))
           (block nil
             ,@body))
         (process-failure
           ',condition
           ,@(if reason-control
                 `(,reason-control ,@reason-args)
                 `("Failed to signal a ~S" ',condition)))
         (return-from ,block-name nil)))))


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

Issue: Macro call that should be transformed by BDD-TYPECASE

Input: (bdd-typecase nil)

Output: (defmacro BDD-TYPECASE ...)


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

Problem: Macro call that should be transformed by LETREC

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

Output:
(defmacro letrec ((&rest bindings) &body body)
  "Recursive LET.
The idea is that functions created in BINDINGS can close over one
another, and themselves.

Note that `letrec' only binds variables: it can define recursive
functions, but can't bind them as functions. (But see `fbindrec'.)"
  `(letrec-with psetq ,bindings
     ,@body))


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

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

Input: (setf nil nil)

Output: (defmacro SETF ...)


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

Write a macro that addresses: Macro call that should be transformed by PUSH-END

Input: (push-end nil nil)

Output:
(defmacro push-end (item place &environment env)
  "Destructively push ITEM to the end of PLACE.
Like `push', but affects the last item rather than the first.

You may want to use `enq' on a `queue' instead.

From LispWorks."
  (multiple-value-bind (dummies vals temps setter getter)
      (get-setf-expansion place env)
    (when (rest temps) (error "Invalid place for push-end"))
    (let ((temp (car temps)))
      `(let* (,@(mapcar #'list dummies vals)
              (,temp ,getter))
         (setf ,temp (nconc1 ,temp ,item))
         ,setter))))


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

Pattern to recognize: Macro call that should be transformed by WITH-READ-ONLY-VARS

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

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

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

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


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

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

Input: (the-part 'lol-gen::some-name)

Output: (defmacro THE-PART ...)


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

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

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

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

Input:
(ecase-of nil
    :key
  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:
Write a Common Lisp macro to handle this code pattern:
(fn* nil)

Problem: Macro call that should be transformed by FN*

Input: (fn* nil)

Output:
(defmacro fn* (form &environment env)
  (fn*-internals form env))


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

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

Input:
(awhen nil
  nil)

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:
Define a macro that eliminates this repetitive pattern:
(live
  'lol-gen::some-name)

Issue: Macro call that should be transformed by LIVE

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

Output:
(defmacro live (&body forms)
  "Define a live block consisting of FORMS.

The FORMS are evaluated once when the LIVE form is first evaluated,
after which they are evaluated again whenever the values of the cells
referenced by them change. Cells may be referenced either directly in
FORMS or by a function called during the evaluation of FORMS.

Returns a function which when called, stops the live block. Once
stopped the live block will no longer be called when the values of the
referenced cells change."

  (let ((spec (make-instance 'watch-function-spec :body forms)))
    (generate-watch-function spec)))


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

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

Input:
(defalias nil
  :key
  nil)

Output:
(defmacro defalias (alias &body (def &optional docstring)
                    &environment env)
  "Define a value as a top-level function.

     (defalias string-gensym (compose #'gensym #'string))

Like (setf (fdefinition ALIAS) DEF), but with a place to put
documentation and some niceties to placate the compiler.

Note that a function defined with `defalias' is declared `notinline'.
This is a matter of semantics: before we can assign to the function,
we must make it assignable (which is what `notinline' means).

Name from Emacs Lisp."
  `(progn
     (declaim (notinline ,alias))
     ,(multiple-value-bind (env decls lambda)
          (let-over-lambda def env)
        ;; If we can expand DEF into a lambda (possibly with some
        ;; variable bindings around it) then splice that lambda in
        ;; directly as the body of the function. (This is the same
        ;; function we use to resolve lambdas in `fbind'.)
        (if lambda
            (ematch lambda
              ((list* (and _ (eql 'lambda)) args body)
               `(let ,env
                  (declare ,@decls)
                  (defun ,alias ,args
                    ,@(unsplice docstring)
                    ,@body))))
            (with-unique-names (temp)
              `(let ((,temp (ensure-function ,def)))
                 (declare (type function ,temp))
                 ;; Give the function a temporary definition at
                 ;; compile time so the compiler doesn't complain
                 ;; about its being undefined.
                 (defun ,alias (&rest args)
                   (apply ,temp args))
                 (setf (fdefinition ',alias) ,temp)
                 ,@(unsplice
                    (and docstring
                         `(setf (documentation ',alias 'function) ,docstring)))))))))


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

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

Input: (define-module nil)

Output:
(defmacro define-module (name &body options)
  (let ((name (string name))
        (package (gensym "PACKAGE")))
    `(eval-when (:compile-toplevel :load-toplevel :execute)
       (let ((,package (or (find-package ,name)
                           (make-package ,name :use ()))))
         (modularize :package ,package :name ,name)
         (expand-module ,name ',options)
         ,package))))


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

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

Input: (defmethod nil)

Output: (defmacro DEFMETHOD ...)


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

Problem: Macro call that should be transformed by ADOWHILE

Input:
(adowhile nil
  :key
  nil)

Output: (defmacro ADOWHILE ...)


Instruction:
Generate a defmacro form that transforms code like this:
(export-only-always nil nil)

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

Input: (export-only-always nil nil)

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


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

Write a macro that addresses: Macro call that should be transformed by DEFINE-ACCUMULATION-BINDING

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

Output:
(defmacro define-accumulation-binding (name (var &rest args) &body body)
  `(define-form-binding ,name (,var ,@args)
     ,@(form-fiddle:lambda-declarations `(lambda () ,@body))
     (values
      (progn ,@(form-fiddle:lambda-forms `(lambda () ,@body)))
      (delist var))))


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

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

Input:
(c-abs nil
  nil)

Output:
(defmacro c-abs (value &body body)
  `(make-c-drifter-absolute
    :code ',body
    :value-state :valid
    :value ,value
    :rule (c-lambda ,@body)))


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

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

Input: (nreversef nil)

Output: (defmacro NREVERSEF ...)


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

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

Input: (yield-all nil)

Output:
(defmacro yield-all (generator)
  "Walks through generator, re-yielding all of the items in it. Only meant for use inside of a defgenerator or with-yield block."
  (let ((x (gensym)))
    `(do-generator (,x ,generator)
       (yield ,x))))


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

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

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

Output:
(defmacro cell-let ((&rest bindings) &body body &environment env)
  "Define cells that are visible only to the forms in BODY.

BINDINGS is a list of cell bindings to establish, similar to
LET*. Each item in BINDINGS is a list of the form

.. code-block::

   (NAME VALUE-FORM)

where NAME is the symbol identifying the cell and VALUE-FORM is the
value form of the cell. The cell can then be referenced within the
forms in BODY by the symbol NAME.

The cells defined in BINDINGS lexcially shadow those in the
environment defined with DEFCELL or by an enclosing CELL-LET
form. Like LET* and unlike LET, each cell definition may reference the
cells defined earlier in the same CELL-LET.

The forms in BODY are evaluated in an implicit PROGN. The value
returned by the last form is returned by the CELL-LET form."

  (flet ((make-cell-binding (binding form)
           (destructuring-bind (name &optional initform)
               (ensure-list binding)

             (if (constantp initform env)
                 `(mutable-cell-let% (,name ,initform) ,form)
                 `(computed-cell-let% (,name ,initform) ,form)))))

    (->> `(progn ,@body)
         (reduce #'make-cell-binding bindings :from-end t :initial-value))))


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

Issue: Macro call that should be transformed by DO-GENERATOR

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

Output:
(defmacro do-generator ((var &rest vars-and-generator) &body body)
  "Steps through the specified generator, binding the value it returns to var, then executing the body for each step. If multiple variables are specified and the generator returns multiple values, the extra values will be bound to the extra variables."
  (let ((g (gensym)))
    `(let ((,g ,(car (last vars-and-generator))))
       (loop
	  do (if-generator ((,var ,@(butlast vars-and-generator)) ,g)
			   (progn
			     ,@body)
			   (return))))))


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

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

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

Output:
(defmacro c-in (value)
  `(make-cell
    :inputp t
    :value-state :valid
    :value ,value))


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

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

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

Output: (defmacro EXPORT-CLASS ...)


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

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

Input:
(destructuring-ecase-of nil
    (progn))

Output:
(defmacro destructuring-ecase-of (type expr &body body)
  "Like `destructuring-ecase', from Alexandria, but with exhaustivness
checking.

TYPE is a designator for a type, which should be defined as `(member
...)'. At compile time, the macro checks that, taken together, the
symbol at the head of each of the destructuring lists in BODY form an
exhaustive partition of TYPE, and warns if it is not so."
  (expand-destructuring-case-of type expr body 'ecase-of))


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

What needs to change: Macro call that should be transformed by DEF-METADATA-KIND

Input:
(def-metadata-kind nil
    nil)

Output:
(defmacro def-metadata-kind (name (&key conc-name (binds-to :value))
                             &body slot-names)
  (warn 'v-deprecated
        :old 'def-metadata-kind
        :new 'define-metadata-kind)
  `(define-metadata-kind ,name (:conc-name ,conc-name :binds-to ,binds-to)
     ,@slot-names))


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

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

Input: (nreversef nil)

Output: (defmacro NREVERSEF ...)


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

Issue: Macro call that should be transformed by DEFINE-GLOBAL-PARAMETER

Input: (define-global-parameter nil :key nil)

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


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

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

Input: (destructuring-bind () :key nil)

Output: (defmacro DESTRUCTURING-BIND ...)


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

What needs to change: Macro call that should be transformed by DECLARE-DEPRECATED-OPERATORS

Input: (declare-deprecated-operators)

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


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

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

Input:
(do-iter-values nil
  :key
  nil)

Output:
(defmacro do-iter-values ((&rest iters) &body forms)
  "Iterate over the remaining elements of a sequence pointed to by static iterators.

   Evaluate FORMS at each iteration, for each remaining element, until
   one of the iterators reaches the end of the sequence.

   NOTE: May only be used inside a WITH-ITERATORS form.

   ITERS:

     List of bindings. Each element is of the form (PATTERN ITER),
     interpreted as if to WITH-ITER-VALUE, where PATTERN is a binding
     pattern, for the binding to the sequence element value, and ITER
     is a static iterator identifier symbol, introduced in a parent
     WITH-ITERATORS form.

   FORMS

     List of forms evaluated for each remaining element in the
     sequences pointed to by the static iterators.

     At each evaluation the next element of each sequence, pointed by
     each ITER in ITERS, is bound to the variable(s) specified by the
     corresponding PATTERN. After which the iterators are advanced to
     the next elements.

   If one of the iterators has reached the end of its sequence, a
   non-local jump outside the enclosing WITH-ITERATORS form is
   performed, i.e. any forms following this form, within the enclosing
   WITH-ITERATORS form, will not be evaluated."

  (with-gensyms (start)
    `(tagbody
        ,start
        (with-iter-values ,iters ,@forms)
        (go ,start))))


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

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

Input: (define-setf-expander nil (progn))

Output: (defmacro DEFINE-SETF-EXPANDER ...)


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

Problem: Macro call that should be transformed by C?

Input:
(c?
  nil
  :key
  nil)

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


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

Issue: Macro call that should be transformed by F_N

Input:
(f_n
  nil
  :key
  nil)

Output: (defmacro F_N ...)


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

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

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

Output: (defmacro ->> ...)


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

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

Input: (lambda-match)

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


Instruction:
Define a macro that eliminates this repetitive pattern:
(if-not nil :key nil)

Issue: Macro call that should be transformed by IF-NOT

Input: (if-not nil :key nil)

Output:
(defmacro if-not (test then &optional else)
  "If TEST evaluates to NIL, evaluate THEN and return its values,
otherwise evaluate ELSE and return its values. ELSE defaults to NIL."
  `(if (not ,test)
       ,then
       ,else))


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

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

Input: (summing-to nil (progn))

Output: (defmacro SUMMING-TO ...)


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

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

Input:
(ensure nil
  nil)

Output:
(defmacro ensure (place &body newval
                        &environment env)
  "Essentially (or place (setf place newval)).

PLACE is treated as unbound if it returns `nil', signals
`unbound-slot', or signals `unbound-variable'.

Note that ENSURE is `setf'-able, so you can do things like
     (incf (ensure x 0))

Cf. `ensure2'."
  (multiple-value-bind (vars vals stores setter getter)
      (get-setf-expansion place env)
    `(let* ,(mapcar #'list vars vals)
       (or (ignore-some-conditions (unbound-slot unbound-variable)
             ,getter)
           (multiple-value-bind ,stores
               (progn ,@newval)
             (when ,(first stores)
               ,setter))))))


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

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

Input: (finc nil)

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


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

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

Input:
(define-screamer-package nil
  nil)

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

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


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

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

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

Output: (defmacro CASE ...)


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

Problem: Macro call that should be transformed by ITERATE

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

Output: (defmacro ITERATE ...)


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

Problem: Macro call that should be transformed by DEFVARIANT

Input:
(defvariant nil
  (progn))

Output: (defmacro DEFVARIANT ...)


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

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

Input: (isnt-values 'lol-gen::some-name)

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


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

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

Input:
(-> nil
  :key
  nil)

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


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

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

Input: (is-false nil :key nil)

Output:
(defmacro is-false (condition &rest reason-args)
  "Generates a pass if CONDITION returns false, generates a
  failure otherwise. Like IS-TRUE, and unlike IS, IS-FALSE does
  not inspect CONDITION to determine what reason to give it case
  of test failure"
  (with-gensyms (value)
    `(let ((,value ,condition))
       (if ,value
           (process-failure ',condition
                            ,@(or reason-args
                                  `("~S returned the value ~S, which is true" ',condition ,value)))
           (add-result 'test-passed :test-expr ',condition)))))