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

Issue: Macro call that should be transformed by <*

Input: (<* nil nil)

Output:
(defmacro <* (parser &rest parsers)
  "Combination of parsers yielding the result of the leftmost one."
  (let ((offset (gensym "<*-OFFSET")))
    `(lambda (,offset)
       ,(reduce (lambda (i p)
                  (let ((res0 (gensym "<*-RES"))
                        (next (gensym "<*-NEXT")))
                    `(multiple-value-bind (,res0 ,next) ,i
                       (if (ok? ,res0)
                           (multiple-value-bind (res next) (funcall ,p ,next)
                             (if (ok? res)
                                 (values ,res0 next)
                                 (fail next)))
                           (fail ,next)))))
                parsers
                :initial-value `(funcall ,parser ,offset)))))


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

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

Input: (nor nil :key nil)

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

Issue: Macro call that should be transformed by ISNT

Input: (isnt nil 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:
Write a Common Lisp macro to handle this code pattern:
(when-let nil
  (progn))

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

Input:
(when-let nil
  (progn))

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

BINDINGS must be either single binding of the form:

 (variable initial-form)

or a list of bindings of the form:

 ((variable-1 initial-form-1)
  (variable-2 initial-form-2)
  ...
  (variable-n initial-form-n))

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

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


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

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

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

Output: (defmacro DRELETF* ...)


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

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

Input:
(defmacro/ps nil
    :key
  nil)

Output: (defmacro DEFMACRO/PS ...)


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

Problem: Macro call that should be transformed by WHEN-MATCH

Input:
(when-match common-lisp:nil
    (common-lisp:progn))

Output:
(defmacro when-match (pattern arg &body body)
  "Equivalent to (match ARG (PATTERN BODY...))."
  `(match ,arg (,pattern ,.body)))


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

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

Input: (if-it nil (progn))

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


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

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

Input:
(without-recursion nil
  (progn))

Output:
(defmacro without-recursion ((&key) &body body)
  "If BODY calls itself, at any depth, signal a (continuable) error of
type `recursion-forbidden'."
  (with-unique-names (recursion-id)
    `(progn
       (when (member ',recursion-id *recursions*)
         (cerror "Recurse anyway."
                 'recursion-forbidden
                 :form ',body))
       (let ((*recursions* (cons ',recursion-id *recursions*)))
         (declare (dynamic-extent *recursions*))
         ,@body))))


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

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

Input: (jor nil :key nil)

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


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

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

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

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


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

Issue: Macro call that should be transformed by GLOBAL

Input:
(global
  nil
  nil)

Output: (defmacro GLOBAL ...)


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

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

Input:
(when-it nil
  nil)

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


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

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

Input:
(defproxymethod nil
    :key
    nil)

Output:
(defmacro defproxymethod (qualifier class proxy-node &body body)
  "define a method for a proxy node"
  (if (eql :self qualifier)
      `(progn
	 (setf (gethash (find-class ',(gethash proxy-node *proxy-node*))
			*ignore-node*) t)
	 (defmethod traverser
	     (,class
	      (item ,(gethash proxy-node *proxy-node*)) level)
	   (declare (ignorable level))
	   (with-slots (values subnodes parent) item ,@body)
	   (call-next-method)))
      `(defmethod traverser ,qualifier
	 (,class
	  (item ,(gethash proxy-node *proxy-node*)) level)
	 (declare (ignorable level))
	 (with-slots (values subnodes parent) item ,@body))))


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

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

Input:
(select nil
  :key
  nil)

Output:
(defmacro select (fields &body clauses)
  `(make-statement :select
                   ,(match fields
                      ((or (list* (type keyword) _)
                           (list* (list* (type keyword) _) _))
                       `(make-clause :fields
                                     ,@(mapcar #'expand-op fields)))
                      ((type keyword) `(fields ,fields))
                      ((or (type symbol)
                           (list* (type symbol) _))
                       `(convert-if-fields-clause ,fields))
                      (otherwise fields))
                   ,@clauses))


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

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

Input:
(c?_
  nil)

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


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(static-load-time-value nil (progn))

What needs to change: Macro call that should be transformed by STATIC-LOAD-TIME-VALUE

Input: (static-load-time-value nil (progn))

Output:
(defmacro static-load-time-value
    (form &optional (read-only-p nil read-only-p-supplied?))
  "Like `load-time-value', but signals an error if it cannot preserve identity.

On close reading of the standard, in a function that is evaluated but
not compiled, it is permissible for implementations to repeatedly
execute a `load-time-value' form, and in fact some implementations do
this \(including, at the time of writing, ABCL, CLISP, Allegro and
LispWorks).

When `static-load-time-value' is compiled, it behaves exactly like
`load-time-value'. Otherwise it conducts a run-time check to ensure
that `load-time-value' preserves identity."
  ;; Thanks to Jean-Philippe Paradis and Michał Herda for helping to
  ;; diagnose and treat the problem here.
  (if *compile-file-truename*
      `(load-time-value ,form
                        ,@(and read-only-p-supplied? (list read-only-p)))
      `(progn
         (flet ((fn () (load-time-value (random most-positive-fixnum))))
           (declare (dynamic-extent #'fn) (ignorable #'fn)
                    #+LispWorks (notinline fn))
           ;; Do the actual test out of line.
           (test-load-time-value #'fn ',form ',read-only-p))
         (load-time-value ,form
                          ,@(and read-only-p-supplied? (list read-only-p))))))


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

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

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

Output: (defmacro COLLECT-NCONC ...)


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

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

Input: (gather-next nil (progn))

Output: (defmacro GATHER-NEXT ...)


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

Issue: Macro call that should be transformed by LAMBDA

Input: (lambda ())

Output: (defmacro LAMBDA ...)


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

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

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

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


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

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

Input: (wnotrc nil)

Output:
(defmacro wnotrc ((&optional (min 1) (max 50) &rest banner) &body body )
  (declare (ignore min max banner))
  `(progn ,@body))


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

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

Input: (match nil nil)

Output: (defmacro MATCH ...)


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

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

Input: (esc nil (progn))

Output:
(defmacro esc (&rest forms)
  `(list
    ,@(loop for form in forms
            collect (%escape-string-form form))))


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

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

Input: (of-type nil :key nil)

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


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

Problem: Macro call that should be transformed by DLET*

Input:
(dlet* nil
  nil)

Output: (defmacro DLET* ...)


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

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

Input: (with-compilation-unit nil)

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


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

Write a macro that addresses: Macro call that should be transformed by POP-ASSOC

Input: (pop-assoc nil (progn))

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

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


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

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

Input: (fm-count-named nil nil)

Output:
(defmacro fm-count-named (family md-name &key (global-search t))
    `(length (fm-find-all ,family ,md-name
                 :must-find nil
                 :global-search ,global-search)))


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

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

Input: (custom-decoder nil)

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


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

Problem: Macro call that should be transformed by HTML5

Input: (html5 nil nil)

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


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

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

Input:
(do-for nil
  (progn))

Output: (defmacro DO-FOR ...)


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
;; Conditional logic with different variable bindings per branch
;; requires deeply nested lets inside each cond clause
(cond ((> x 0)
       (let ((order :ascending)
             (bound (sqrt x)))
         (process order bound)))
      ((< x 0)
       (let ((order :descending)
             (bound (sqrt (- x))))
         (process order bound)))
      (t
       (let ((order :zero)
             (bound 0))
         (process order bound))))

;; Repetitive: same body structure, different bindings per branch

Write a macro that addresses: Cond with per-branch variable bindings leads to duplicated body code — want shared body with branch-specific bindings

Input:
;; Conditional logic with different variable bindings per branch
;; requires deeply nested lets inside each cond clause
(cond ((> x 0)
       (let ((order :ascending)
             (bound (sqrt x)))
         (process order bound)))
      ((< x 0)
       (let ((order :descending)
             (bound (sqrt (- x))))
         (process order bound)))
      (t
       (let ((order :zero)
             (bound 0))
         (process order bound))))

;; Repetitive: same body structure, different bindings per branch

Output:
(defmacro condlet (clauses &body body)
  (let ((bodfn (gensym))
        (vars (mapcar #'(lambda (v) (cons v (gensym)))
                      (remove-duplicates
                        (mapcar #'car
                                (mappend #'cdr clauses))))))
    `(labels ((,bodfn ,(mapcar #'car vars)
                 ,@body))
       (cond ,@(mapcar #'(lambda (cl)
                           (condlet-clause vars cl bodfn))
                       clauses)))))


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

Problem: Macro call that should be transformed by *LET

Input: (*let nil)

Output: (defmacro *LET ...)


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

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

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

Output: (defmacro AS->* ...)


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

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

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

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

Problem: Macro call that should be transformed by COND

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

Output: (defmacro COND ...)


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

Issue: Macro call that should be transformed by HTML

Input: (html nil :key nil)

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


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(with-decoder-simple-list-semantics
  nil)

What needs to change: Macro call that should be transformed by WITH-DECODER-SIMPLE-LIST-SEMANTICS

Input:
(with-decoder-simple-list-semantics
  nil)

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


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

Problem: Macro call that should be transformed by SET=

Input: (set= nil :key nil)

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


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

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

Input:
(some-> nil
  :key
  nil)

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


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

Write a macro that addresses: Macro call that should be transformed by DEFCLAUSE-DRIVER

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

Output:
(defmacro defclause-driver (clause-template &body body)
  "Macro for for defining (with DEFUN) iterators, which may also be used
as generators."
  (define-clause 'defun clause-template body t))


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

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

Input:
(eval-always
  nil
  nil)

Output:
(defmacro eval-always (&body body)
  "Shorthand for
        (eval-when (:compile-toplevel :load-toplevel :execute) ...)"
  `(eval-when (:compile-toplevel :load-toplevel :execute)
     ,@body))


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

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

Input:
(lambda-ematch
  common-lisp:nil
  :key
  common-lisp:nil)

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


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

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

Input: (finish nil :key nil)

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


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(enable-quasi-quoted-string-to-binary-emitting-form-syntax 'lol-gen::some-name)

Write a macro that addresses: Macro call that should be transformed by ENABLE-QUASI-QUOTED-STRING-TO-BINARY-EMITTING-FORM-SYNTAX

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

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


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

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

Input: (char-case nil)

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

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

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

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


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

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

Input:
(defwalker-handler nil
  nil)

Output: (defmacro DEFWALKER-HANDLER ...)


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

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

Input:
(json-bind nil
    (progn))

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

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

Input: (with-collectors nil)

Output: (defmacro WITH-COLLECTORS ...)


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

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

Input:
(op
  nil
  (progn))

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

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

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

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

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

You can also use positional arguments directly:

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

Argument lists can be sparse:

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

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

     (funcall (op 1)) => 1

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

     (funcall (op _) 1) => 1

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

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

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

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


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

Issue: Macro call that should be transformed by NEXT-IN

Input: (next-in nil nil)

Output: (defmacro NEXT-IN ...)


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

Issue: Macro call that should be transformed by CTYPECASE-LET

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

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


Instruction:
Generate a defmacro form that transforms code like this:
(enable-quasi-quoted-bivalent-to-binary-emitting-form-syntax nil)

Pattern to recognize: Macro call that should be transformed by ENABLE-QUASI-QUOTED-BIVALENT-TO-BINARY-EMITTING-FORM-SYNTAX

Input: (enable-quasi-quoted-bivalent-to-binary-emitting-form-syntax nil)

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


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

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

Input:
(dynamic-extent common-lisp:nil
  :key
  common-lisp:nil)

Output: (defmacro DYNAMIC-EXTENT ...)


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

Issue: Macro call that should be transformed by LETREC*

Input:
(letrec* nil
  (progn))

Output:
(defmacro letrec* ((&rest bindings) &body body)
  "Like LETREC, but the bindings are evaluated in order.
See Waddell et al., *Fixing Letrec* for motivation.

Cf. `fbindrec*'."
  `(letrec-with setq ,bindings
     ,@body))


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

Write a macro that addresses: Macro call that should be transformed by DELETE-FROM

Input:
(delete-from nil
  nil)

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


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

Issue: Macro call that should be transformed by F_%

Input:
(f_%
  'lol-gen::some-name)

Output: (defmacro F_% ...)


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

Problem: Macro call that should be transformed by ->

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

Output:
(defmacro -> (value &rest forms)
  "Smart threading macro that dispatches based on clause types returned by forms.

   This macro enables immutable query composition by threading clauses through
   query-state objects. Creates a single copy at the beginning, then destructively
   adds clauses for efficiency. Supports both v1 select-statements and composer query-states.

   Forms that evaluate to NIL are skipped, enabling conditional composition:
     (-> (from :users)
         (when active-only (where (:= :active 1)))
         (when sort-by-name (order-by :name)))

   Examples:
     ;; With composer clause
     (-> (from :users)
         (where (:= :active 1))
         (order-by :name))

     ;; With v1 select-statement (backward compatible)
     (-> (select (:id :name) (from :users))
         (where (:= :active 1))
         (order-by :name))

     ;; Conditional composition
     (-> (from :users)
         (when include-inactive (where (:= :active 0)))
         (when sort-by-date (order-by :created_at)))"
  (a:with-gensyms (threaded-var clause-var)
    `(let* ((,threaded-var ,value)
            ;; Convert to query-state and copy once at the beginning
            (,threaded-var
              (typecase ,threaded-var
                (query-state-base (copy-query-state-immutable ,threaded-var))
                (stmt:select-statement (select-statement-to-query-state ,threaded-var))
                (stmt:insert-into-statement (insert-statement-to-query-state ,threaded-var))
                (stmt:update-statement (update-statement-to-query-state ,threaded-var))
                (stmt:delete-from-statement (delete-statement-to-query-state ,threaded-var))
                (otherwise (add-clause (make-select-query-state) ,threaded-var)))))
       ;; Now destructively add clauses (no more copying), skipping NILs
       ,@(loop for form in forms
               collect `(let ((,clause-var ,(if (listp form)
                                                ;; For list forms, call the function with its arguments (no threading)
                                                `(,(car form) ,@(cdr form))
                                                ;; For symbol forms, call the function with no arguments
                                                `(,form))))
                          (when ,clause-var
                            (add-clause ,threaded-var ,clause-var))))
       ,threaded-var)))


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

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

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

Output:
(defmacro skip (desc &body tests)
  `(with-forced-status (:skipped ,@(if (listp desc) desc (list desc)))
     ,@tests))


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

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

Input:
(fbind* nil
  (progn))

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


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

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

Input:
(f0
  nil
  (progn))

Output: (defmacro F0 ...)


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

Issue: Macro call that should be transformed by INSTEAD

Input: (instead nil (progn))

Output:
(defmacro instead (item parser)
  "Run some parser, but substitute its inner value with some `item' if parsing was
  successful."
  `(<$ ,item ,parser))


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

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

Input: (and-bind nil (progn))

Output: (defmacro AND-BIND ...)


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

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

Input:
(eif-let nil
  (progn))

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


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

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

Input: (eko nil)

Output:
(defmacro eko ((&rest trcargs) &rest body)
  (let ((result (gensym)))
     `(let ((,result ,@body))
        ,(if (stringp (car trcargs))
             `(trc ,(car trcargs) :=> ,result ,@(cdr trcargs))
           `(trc ,(car trcargs) ,(cadr trcargs) :=> ,result ,@(cddr trcargs)))
         ,result)))


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

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

Input:
(->*
  nil
  (progn))

Output: (defmacro ->* ...)


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

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

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

Output:
(defmacro do-select ((dao select &optional index) &body body)
  (with-gensyms (main main-body select-fn cursor i)
    `(block nil
       (labels ((,main-body (,dao ,(or index i))
                  ,@(and (not index)
                         `((declare (ignore ,i))))
                  ,@body)
                (,select-fn () ,select)
                (,main ()
                  (case (dbi:connection-driver-type *connection*)
                    (:postgres
                     (let ((,cursor (let ((*want-cursor* t))
                                      (,select-fn))))
                       (loop ,@(and index `(for ,i from 0))
                             for ,dao = (fetch-dao-from-cursor ,cursor)
                             while ,dao
                             do (,main-body ,dao ,i))))
                    (otherwise
                     (loop ,@(and index `(for ,i from 0))
                           for ,dao in (,select-fn)
                           do (,main-body ,dao ,i))))))
         (if (dbi:in-transaction *connection*)
             (,main)
             (dbi:with-transaction *connection*
               (,main)))))))


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

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

Input:
(fn nil
    nil)

Output: (defmacro FN ...)


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

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

Input:
(match-of nil
    (progn))

Output:
(defmacro match-of (union expr &body clauses &environment env)
  "Do pattern matching on an algebraic data type.

UNION should be an algebraic data type.

Each clause in CLAUSES has a pattern as its first element.

If the pattern is a symbol, it matches a unit type.

If the pattern is a list, it matches a constructor.

If the pattern is an underscore, it introduces a default or
fallthrough clause.

If the pattern is a list that starts with `or', it is a disjunction of
other patterns."
  (check-match-exhaustive union clauses env)
  `(ematch ,expr
     ,@(loop for (pattern . body) in clauses
             collect `(,(nth-value 1 (pattern-type pattern union))
                       ,@body))))


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

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

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

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


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

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

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

Output: (defmacro TO ...)


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

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

Input: (esc nil nil)

Output:
(defmacro esc (&rest forms)
  `(list
    ,@(loop for form in forms
            collect (%escape-string-form form))))


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

Issue: Macro call that should be transformed by CMATCH

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

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


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

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

Input:
(match nil
  (progn))

Output: (defmacro MATCH ...)


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

Issue: Macro call that should be transformed by AND

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

Output: (defmacro AND ...)


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

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

Input:
(lambda-match*
  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:
Define a macro that eliminates this repetitive pattern:
(with-foreign-strings nil
  nil)

Issue: Macro call that should be transformed by WITH-FOREIGN-STRINGS

Input:
(with-foreign-strings nil
  nil)

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

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

Input: (cond-let nil)

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

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

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


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

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

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

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:
(-<>
  'lol-gen::some-name)

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

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

Output: (defmacro -<> ...)


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

Issue: Macro call that should be transformed by ODIG

Input: (odig nil)

Output: (defmacro ODIG ...)


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

Issue: Macro call that should be transformed by AWHEN

Input:
(awhen nil
  nil)

Output: (defmacro AWHEN ...)


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

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

Input:
(doquery nil
    (progn))

Output:
(defmacro doquery (query (&rest names) &body body)
  "Execute the given query (a string or a list starting with a keyword),
iterating over the rows in the result. The body will be executed with the values
in the row bound to the symbols given in names. To iterate over a
parameterised query, one can specify a list whose car is the query, and whose
cdr contains the arguments. For example:

(doquery (:select 'name 'score :from 'scores) (n s)
  (incf (gethash n *scores*) s))

(doquery ((:select 'name :from 'scores :where (:> 'score '$1)) 100) (name)
  (print name))"
  (let* ((fields (gensym))
         (query-name (gensym))
         args
         (reader-expr
           `(row-reader (,fields)
              (unless (= ,(length names) (length ,fields))
                (error "Number of field names does not match number of selected fields in query ~A."
                       ,query-name))
              (loop :while (next-row)
                    :do (let ,(loop :for i :from 0
                                    :for name :in names
                                    :collect `(,name (next-field (elt ,fields ,i))))
                          ,@body)))))
    (when (and (consp query) (not (keywordp (first query))))
      (setf args (cdr query) query (car query)))
    (if args
        `(let ((,query-name ,(real-query query)))
           (prepare-query *database* "" ,query-name (list ,@args))
           (exec-prepared *database* "" (list ,@args) ,reader-expr))
        `(let ((,query-name ,(real-query query)))
           (exec-query *database* ,query-name ,reader-expr)))))


Instruction:
Define a macro that eliminates this repetitive pattern:
(with-decoder-simple-list-semantics
  'lol-gen::some-name)

Issue: Macro call that should be transformed by WITH-DECODER-SIMPLE-LIST-SEMANTICS

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

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


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

Issue: Macro call that should be transformed by RESOLVE

Input:
(resolve
  nil
  (progn))

Output: (defmacro RESOLVE ...)


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

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

Input: (-> nil :key nil)

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

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

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


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

Problem: Macro call that should be transformed by DEF-FIXTURE

Input:
(def-fixture nil
    nil)

Output:
(defmacro def-fixture (name (&rest args) &body body)
  "Defines a fixture named NAME. A fixture is very much like a
macro but is used only for simple templating. A fixture created
with DEF-FIXTURE is a macro which can use the special macrolet
&BODY to specify where the body should go.

See Also: WITH-FIXTURE
"
  `(eval-when (:compile-toplevel :load-toplevel :execute)
     (setf (get-fixture ',name) (cons ',args ',body))
     ',name))


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

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

Input: (set-plist-val! nil :key nil)

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


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

Problem: Macro call that should be transformed by FILTERF

Input: (filterf nil nil)

Output: (defmacro FILTERF ...)


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

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

Input:
(with-string-dispatch nil
    nil)

Output:
(defmacro with-string-dispatch ((&rest types) var &body body)
  "Like `with-subtype-dispatch' with an overall type of `string'."
  `(with-subtype-dispatch string
       ;; Always specialize for (simple-array character (*)).
       ((simple-array character (*))
        (simple-array base-char (*))
        ,@types)
       ,var
     ,@body))


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

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

Input: (rem-bops nil)

Output: (defmacro REM-BOPS ...)


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

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

Input: (cond-> nil :key nil)

Output: (defmacro COND-> ...)


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

Problem: Macro call that should be transformed by DEFMD

Input: (defmd nil nil)

Output:
(defmacro defmd (class superclasses &rest mdspec)
  `(defmodel ,class (,@superclasses model)
     ,@(let (definitargs class-options slots)
         (loop with skip
             for (spec next) on mdspec
             if skip
             do (setf skip nil)
             else do (etypecase spec
                       (cons
                        (cond
                         ((keywordp (car spec))
                          (assert (find (car spec) '(:documentation :metaclass)))
                          (push spec class-options))
                         ((find (cadr spec) '(:initarg :type :ps :persistable :cell :initform :allocation :reader :writer :accessor :documentation))
                          (push (apply 'defmd-canonicalize-slot spec) slots))
                         (t ;; shortform (slotname initform &rest slotdef-key-values)
                          (push (apply 'defmd-canonicalize-slot
                                  (list* (car spec) :initform (cadr spec) (cddr spec))) slots))))
                       (keyword
                        (setf definitargs (append definitargs (list spec next)))
                        (setf skip t))
                       (symbol (push (list spec :initform nil
                                       :initarg (intern (symbol-name spec) :keyword)
                                       :accessor spec) slots)))
             finally
               (return (list* (nreverse slots)
                         (delete nil
                           (list* `(:default-initargs ,@definitargs)
                             (nreverse class-options)))))))))


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

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

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

Output:
(defmacro when-let ((var test) &body body)
  "Like WHEN. VAR will be bound to TEST."
  `(let ((,var ,test))
     (when ,var
       ,@body)))


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

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

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

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


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

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

Input:
(none-of nil
  (progn))

Output: (defmacro NONE-OF ...)


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

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

Input: (fm-mapc nil nil)

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


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

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

Input: (current-decoder nil :key nil)

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


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

Problem: Macro call that should be transformed by ~>

Input: (~> nil)

Output:
(defmacro ~> (needle &rest holes)
  "Threading macro from Clojure (by way of Racket).

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

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


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

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

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

Output: (defmacro MINIMIZING ...)


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

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

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

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

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

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

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


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

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

Input:
(ps-once-only nil
  nil)

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


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

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

Input:
(c?n
  nil
  nil)

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


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

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

Input:
(cond-<>
  nil
  nil)

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


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

Issue: Macro call that should be transformed by SORT-VALUES

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

Output:
(defmacro sort-values (pred &rest values)
  "Sort VALUES with PRED and return as multiple values.

Equivalent to

    (values-list (sort (list VALUES...) pred))

But with less consing, and potentially faster."
  ;; Remember to evaluate `pred' no matter what.
  (with-gensyms (gpred)
    `(let ((,gpred (ensure-function ,pred)))
       (declare (ignorable ,gpred)
                (function ,gpred)
                (optimize (safety 1) (debug 0) (compilation-speed 0)))
       ,(match values
          ((list) `(values))
          ((list x) `(values ,x))
          ;; The strategy here is to use a sorting network if the
          ;; inputs are few, and a stack-allocated vector if the
          ;; inputs are many.
          (otherwise
           (if (<= (length values) 8)
               `(sort-values/network ,gpred ,@values)
               `(sort-values/temp-vector ,gpred ,@values)))))))


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

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

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

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


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

Problem: Macro call that should be transformed by DEFINE-VALUE-SYMBOL-MACRO-BINDING

Input:
(define-value-symbol-macro-binding nil
    (progn))

Output:
(defmacro define-value-symbol-macro-binding (name (var &rest args) &body body)
  (let ((vars (lambda-fiddle:extract-lambda-vars (lambda-fiddle:remove-aux-part args))))
    (emit-binding-definition name var args body :extra-vars vars :symbol-macro-p T)))


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

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

Input:
(with-synapse nil
    (progn))

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


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

Problem: Macro call that should be transformed by MAKE*

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

Output: (defmacro MAKE* ...)


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

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

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

Output: (defmacro ANY-OF ...)


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

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

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

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

Input: (-<> nil :key nil)

Output: (defmacro -<> ...)


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

Problem: Macro call that should be transformed by LIVE

Input:
(live
  nil
  (progn))

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

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

Input: (query nil :key nil)

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

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

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


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

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

Input:
(-<>>
  nil
  nil)

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


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

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

Input: (collect-max nil)

Output: (defmacro COLLECT-MAX ...)


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

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

Input:
(labels* nil
  nil)

Output: (defmacro LABELS* ...)


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

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

Input:
(char-case nil
  nil)

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

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

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

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


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

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

Input: (who-ps-html nil :key nil)

Output: (defmacro WHO-PS-HTML ...)


Instruction:
Define a macro that eliminates this repetitive pattern:
;; Regex matching with captures requires manual multiple-value-bind
(multiple-value-bind (matchp captures)
    (cl-ppcre:scan-to-strings "_(\\w+)@(\\w+)\\.com_" email)
  (if matchp
      (let ((user (aref captures 0))
            (domain (aref captures 1)))
        (format t "~a at ~a~%" user domain))
      :invalid))

;; Verbose: bind result, extract captures by index, branch - repetitive

Issue: Regex matching with named captures requires verbose destructuring — want $1, $2, ... anaphors bound to capture groups

Input:
;; Regex matching with captures requires manual multiple-value-bind
(multiple-value-bind (matchp captures)
    (cl-ppcre:scan-to-strings "_(\\w+)@(\\w+)\\.com_" email)
  (if matchp
      (let ((user (aref captures 0))
            (domain (aref captures 1)))
        (format t "~a at ~a~%" user domain))
      :invalid))

;; Verbose: bind result, extract captures by index, branch - repetitive

Output:
#+cl-ppcre
(defun dollar-symbol-p (s)
  (and (symbolp s)
       (> (length (symbol-name s)) 1)
       (string= (symbol-name s)
                "$"
                :start1 0
                :end1 1)
       (ignore-errors (parse-integer (subseq (symbol-name s) 1)))))

(defmacro! if-match ((match-regex str) then &optional else)
  (let* ((dollars (remove-duplicates
                   (remove-if-not #'dollar-symbol-p
                                  (flatten then))))
         (top (or (car (sort (mapcar #'dollar-symbol-p dollars) #'>))
                  0)))
    `(multiple-value-bind (,g!matches ,g!captures) (,match-regex ,str)
       (declare (ignorable ,g!matches ,g!captures))
       (let ((,g!captures-len (length ,g!captures)))
         (declare (ignorable ,g!captures-len))
         (symbol-macrolet ,(mapcar #`(,(symb "$" a1)
                                       (if (< ,g!captures-len ,a1)
                                           (error "Too few matchs: ~a unbound." ,(mkstr "$" a1))
                                           (aref ,g!captures ,(1- a1))))
                                   (loop for i from 1 to top collect i))
           (if ,g!matches
               ,then
               ,else))))))


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

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

Input:
(cond-let nil
  (progn))

Output:
(defmacro cond-let (var &body body)
  "Like COND. VAR will be bound to the passed COND test."
  `(let (,var)
     (cond
       ,@(mapcar #``((setf ,var ,(car %)) ,(cadr %))
                 ;; uses the fact, that SETF returns the value set
                 body))))


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

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

Input: (collect-max nil :key nil)

Output: (defmacro COLLECT-MAX ...)


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

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

Input: (removef nil nil)

Output: (defmacro REMOVEF ...)


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

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

Input: (xor nil (progn))

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


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

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

Input: (none-of nil)

Output: (defmacro NONE-OF ...)


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

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

Input: (ps-html nil nil)

Output: (defmacro PS-HTML ...)


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

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

Input: (set-handler nil :key nil)

Output: (defmacro SET-HANDLER ...)


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

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

Input: (rotatef nil nil)

Output: (defmacro ROTATEF ...)


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

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

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

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

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

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


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

Issue: Macro call that should be transformed by CMATCH*

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

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


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

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

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

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


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

Problem: Macro call that should be transformed by XHTML

Input: (xhtml nil nil)

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


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

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

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

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


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

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

Input:
(eval-always
  nil
  (progn))

Output:
(defmacro eval-always (&body body)
  "Wrap BODY in eval-when with all keys (compile, load and execute) mentioned."
  `(eval-when (:compile-toplevel :load-toplevel :execute)
     ,@body))


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

Problem: Macro call that should be transformed by AIF

Input: (aif nil :key nil)

Output: (defmacro AIF ...)


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

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

Input: (fm-otherx nil)

Output:
(defmacro fm-otherx (md-name &key (starting 'self) skip-tree)
   (if (eql starting 'self)
      `(or (fm-find-one ,starting ,(if (consp md-name)
                                      `(list ',(car md-name) ,(cadr md-name))
                                      `',md-name)
             :must-find t
             :skip-tree ,skip-tree
             :global-search t))
      `(fm-find-one ,starting ,(if (consp md-name)
                                  `(list ',(car md-name) ,(cadr md-name))
                                  `',md-name)
         :must-find t
         :skip-tree ,skip-tree
         :global-search t)))


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

Problem: Macro call that should be transformed by RESOLVE

Input: (resolve)

Output: (defmacro RESOLVE ...)


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

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

Input:
(mvlet* nil
  (progn))

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

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

    (var var*... expr)

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

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

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


Instruction:
Write a Common Lisp macro to handle this code pattern:
(on-conflict-do-nothing)

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

Input: (on-conflict-do-nothing)

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


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

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

Input:
(alter-table nil
  (progn))

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


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

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

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

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


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

Issue: Macro call that should be transformed by DEFPSMACRO

Input:
(defpsmacro nil
    nil)

Output: (defmacro DEFPSMACRO ...)


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

Issue: Macro call that should be transformed by SKIP

Input:
(skip nil
  (progn))

Output:
(defmacro skip (desc &body tests)
  `(with-forced-status (:skipped ,@(if (listp desc) desc (list desc)))
     ,@tests))


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

Problem: Macro call that should be transformed by MATCH2

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

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


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

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

Input: (eko nil :key nil)

Output:
(defmacro eko ((&rest trcargs) &rest body)
  (let ((result (gensym)))
     `(let ((,result ,@body))
        ,(if (stringp (car trcargs))
             `(trc ,(car trcargs) :=> ,result ,@(cdr trcargs))
           `(trc ,(car trcargs) ,(cadr trcargs) :=> ,result ,@(cddr trcargs)))
         ,result)))


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

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

Input:
(finishes
  nil
  (progn))

Output:
(defmacro finishes (&body body)
  "Generates a pass if BODY executes to normal completion. In
other words if body does signal, return-from or throw this test
fails."
  `(unwind-protect-case () (progn ,@body)
     (:normal (add-result 'test-passed :test-expr ',body))
     (:abort (process-failure ',body "Test didn't finish"))))


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

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

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

Output: (defmacro COND-> ...)


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

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

Input: (when nil)

Output: (defmacro WHEN ...)


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

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

Input: (push nil nil)

Output: (defmacro PUSH ...)


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

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

Input: (u^ nil)

Output:
(defmacro u^ (type)
  `(upper self ,type))


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

Issue: Macro call that should be transformed by ACCASE

Input:
(accase nil
  :key
  nil)

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

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

Input:
(defiter nil
    (progn))

Output: (defmacro DEFITER ...)


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

Issue: Macro call that should be transformed by DEFTYPE

Input: (deftype nil (progn))

Output: (defmacro DEFTYPE ...)


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

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

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

Output: (defmacro EXPORT-SLOTS ...)


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

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

Input: (cardinality-case nil)

Output: (defmacro CARDINALITY-CASE ...)


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

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

Input:
(with-standard-input-syntax
  'lol-gen::some-name)

Output:
(defmacro with-standard-input-syntax (&body body)
  "Like `with-standard-io-syntax', but only bind the variables that
control the reader, not the printer.

This may be preferable to using `with-standard-io-syntax' when loading
data, as it will not effect how errors are printed, thus preserving
debugging information."
  (with-thunk ((body :name with-standard-input-syntax))
    `(call/standard-input-syntax ,body)))


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

Issue: Macro call that should be transformed by ACOND

Input:
(acond
  nil
  (progn))

Output: (defmacro ACOND ...)


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

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

Input:
(for-all* nil
  (progn))

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

Works like FOR-ALL but variables are defined sequentially - subsequent
generator bindings may use value of a previous generator.

Example:

  (for-all* ((a (gen-integer))
             (b (gen-integer :min a :max (+ a 20)))
    (is (<= a b)))"
  (with-gensyms (test-lambda-args)
    `(perform-random-testing
      nil
      (lambda (,test-lambda-args)
        (declare (ignore ,test-lambda-args))
        (dbind-rec ,bindings
          (if (and ,@(delete-if #'null (mapcar #'third bindings)))
              (progn ,@body)
              (throw 'run-once
                (list :guard-conditions-failed))))))))


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

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

Input: (with-yield)

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


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

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

Input:
(letrec nil
  :key
  nil)

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

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

Input: (modf-eval 'lol-gen::some-name)

Output:
(defmacro modf-eval (&rest args)
  `(progn ,@args))


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

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

Input: (make-instance* nil nil)

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

Conveniences:

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

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

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

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

Examples:

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

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

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

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

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

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

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

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


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

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

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

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


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

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

Input:
(define-macro nil
    :key
    nil)

Output: (defmacro DEFINE-MACRO ...)


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

Problem: Macro call that should be transformed by F-PLUSP

Input: (f-plusp nil :key nil)

Output:
(defmacro f-plusp (key &rest body)
  `(with-synapse ,key (prior-fire-value)
     (let ((new-basis (progn ,@body)))
       (values new-basis (if (xor prior-fire-value (plusp new-basis))
                             (progn
                               (setf prior-fire-value (plusp new-basis))
                               :propagate)
                           :no-propagate)))))


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

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

Input: (case nil (progn))

Output: (defmacro CASE ...)


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

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

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

Output:
(defmacro and-let* ((&rest clauses) &body body &environment env)
  "Scheme's guarded LET* (SRFI-2).

Each clause should have one of the following forms:

- `identifier', in which case IDENTIFIER's value is tested.

- `(expression)', in which case the value of EXPRESSION is tested.

- `(identifier expression)' in which case EXPRESSION is evaluated,
    and, if its value is not false, IDENTIFIER is bound to that value
    for the remainder of the clauses and the optional body.

Note that, of course, the semantics are slightly different in Common
Lisp than in Scheme, because our AND short-circuits on null, not
false.

Also, this version makes the bindings immutable."
  (multiple-value-bind (body decls)
      (parse-body body)
    (labels ((expand (clauses body)
               (unsplice
                (ematch clauses
                  (() (if body `(progn ,@body) nil))
                  ((list* (and var (type symbol)) clauses)
                   `(and ,var ,@(expand clauses body)))
                  ((list* (list var expr) clauses)
                   (let ((temp (gensym (string var))))
                     (multiple-value-bind (local-decls other-decls)
                         (partition-declarations (list var) decls env)
                       ;; The use of the temporary here is so we still
                       ;; get style warnings if the variable is
                       ;; unused.
                       `(let* ((,temp ,expr)
                               (,var ,temp))
                          ,@local-decls
                          (and ,temp
                               ,@(expand clauses
                                         (append other-decls body)))))))
                  ((list* (list expr) clauses)
                   `(and ,expr ,@(expand clauses body)))))))
      (car (expand clauses body)))))