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

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

Input: (is (<= a b))

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

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

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

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

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

(let ((#:e134 a) (#:a135 b)) (if (progn (<= #:e134 #:a135)) (add-result (quote test-passed) :test-expr (quote (<= a b))) (process-failure (quote (<= a b)) "~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%" (quote b) #:a135 (quote <=) #:e134)))


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

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

Input: (define _IOFBF 1)

Output:
(defmacro define (name value &rest docstring)
  "Like a #define but also visible to Lisp code."
  `(progn
     (eval-when (:compile-toplevel :load-toplevel :execute)
       (defvar ,(pp-defines *package*) (make-hash-table))
       (setf (gethash ',name ,(pp-defines *package*)) ,(prin1-to-string value)))
     (defparameter ,name ,value ,@docstring)))

(progn (eval-when (:compile-toplevel :load-toplevel :execute) (defvar *preprocessor-defines* (make-hash-table)) (setf (gethash (quote _iofbf) *preprocessor-defines*) #A((1) base-char . "1"))) (defparameter _iofbf 1))


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(binding-forms (get 'bind :binding-forms))

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

Input: (binding-forms (get 'bind :binding-forms))

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

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

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

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

(binding-forms (get (quote bind) :binding-forms))


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

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

Input: (aif it it)

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


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

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

Input:
(dletf* nil
  (progn))

Output: (defmacro DLETF* ...)


Instruction:
Define a macro that eliminates this repetitive pattern:
(*> +skip-all-space+ +skip-comments+)

Issue: Macro call that should be transformed by *>

Input: (*> +skip-all-space+ +skip-comments+)

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

(lambda (#:*>-offset251) (multiple-value-bind (#:*>-res252 #:*>-next253) (funcall +skip-all-space+ #:*>-offset251) (if (ok? #:*>-res252) (funcall +skip-comments+ #:*>-next253) (fail #:*>-next253))))


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


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

Issue: Macro call that should be transformed by DEFUN

Input: (defun nil (progn))

Output: (defmacro DEFUN ...)

(progn
 (eval-when (:compile-toplevel) (sb-c:%compiler-defun 'nil t nil nil))
 (sb-impl::%defun 'nil
                  (sb-int:named-lambda nil
                      (progn)
                    (block nil))))


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(lret ((out (make-array shape :element-type element-type))) (replace* (%flatten out) (%flatten array)))

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

Input: (lret ((out (make-array shape :element-type element-type))) (replace* (%flatten out) (%flatten array)))

Output:
(defmacro lret ((&rest bindings) &body body)
  "Return the initial value of the last binding in BINDINGS. The idea
is to create something, initialize it, and then return it.

    (lret ((x 1)
           (y (make-array 1)))
      (setf (aref y 0) x))
    => #(1)

Note that the value returned is the value initially bound. Subsequent
assignments are ignored.

    (lret ((x 1))
      (setf x 2))
    => 1

Furthermore, on Lisps that support it, the variable may be made
read-only, making assignment a compiler-time error.

`lret' may seem trivial, but it fufills the highest purpose a macro
can: it eliminates a whole class of bugs (initializing an object, but
forgetting to return it).

Cf. `aprog1' in Anaphora."
  `(lret-aux let ,bindings
     ,@body))

(lret-aux let ((out (make-array shape :element-type element-type))) (replace* (%flatten out) (%flatten array)))


Instruction:
Write a Common Lisp macro to handle this code pattern:
(defclass/a dbd-null (cl-dbi:dbi-driver) ())

Problem: Macro call that should be transformed by defclass/a

Input: (defclass/a dbd-null (cl-dbi:dbi-driver) ())

Output:
(defmacro defclass/a (name superclasses slots &rest class-options)
  `(progn
     (defclass ,name ,superclasses ,slots ,@class-options)
     (deftype ,(intern (format nil "<~A>" (symbol-name name))) () ',name)
     (setf (find-class ',(intern (format nil "<~A>" (symbol-name name))))
           (find-class ',name))))

(progn (defclass dbd-null (dbi.driver:dbi-driver) nil) (deftype <dbd-null> nil (quote dbd-null)) (setf (find-class (quote <dbd-null>)) (find-class (quote dbd-null))))


Instruction:
Generate a defmacro form that transforms code like this:
(letrec* (x) x)

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

Input: (letrec* (x) x)

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

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

Input:
(min-of nil
  nil)

Output: (defmacro MIN-OF ...)


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(define-find-c-readtable-name-methods c-reader-level-0 0)

Write a macro that addresses: Macro call that should be transformed by define-find-c-readtable-name-methods

Input: (define-find-c-readtable-name-methods c-reader-level-0 0)

Output:
(defmacro define-find-c-readtable-name-methods (base-readtable-name level)
  (check-type base-readtable-name symbol)
  (check-type level integer)
  (loop with case-modes = '(nil :upcase :downcase :preserve :invert)
        for mode in case-modes
        as name = (format-symbol :with-c-syntax.core "~A~@[-~A~]"
                                 base-readtable-name mode)
        collect `(defmethod find-c-readtable-name
                     ((level (eql ,level)) (readtable-case (eql ,mode)))
                   ',name)
          into bodies
        finally
           (return `(progn ,@bodies))))

(progn (defmethod find-c-readtable-name ((level (eql 0)) (readtable-case (eql nil))) (quote c-reader-level-0)) (defmethod find-c-readtable-name ((level (eql 0)) (readtable-case (eql :upcase))) (quote c-reader-level-0-upcase)) (defmethod find-c-readtable-name ((level (eql 0)) (readtable-case (eql :downcase))) (quote c-reader-level-0-downcase)) (defmethod find-c-readtable-name ((level (eql 0)) (readtable-case (eql :preserve))) (quote c-reader-level-0-preserve)) (defmethod find-c-readtable-name ((level (eql 0)) (readtable-case (eql :invert))) (quote c-reader-level-0-invert)))


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(def-unary-op vacietis.c:~ lognot)

What needs to change: Macro call that should be transformed by def-unary-op

Input: (def-unary-op vacietis.c:~ lognot)

Output:
(defmacro def-unary-op (c lisp)
  (let ((x (gensym)))
   `(defmacro ,c (,x)
      `(,',lisp ,,x))))

(defmacro vacietis.c:~ (#:g225) (sb-int:quasiquote (#S(sb-impl::comma :expr (quote lognot) :kind 0) #S(sb-impl::comma :expr #:g225 :kind 0))))


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

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

Input:
(product-of nil
  :key
  nil)

Output: (defmacro PRODUCT-OF ...)


Instruction:
Define a macro that eliminates this repetitive pattern:
(assoc-cdr "oauth_token" parameters #'equal)

Issue: Macro call that should be transformed by assoc-cdr

Input: (assoc-cdr "oauth_token" parameters #'equal)

Output:
(defmacro assoc-cdr (key alist &optional (test '#'eql))
  `(cdr (assoc ,key ,alist :test ,test)))

(cdr (assoc "oauth_token" parameters :test (function equal)))


Instruction:
Define a macro that eliminates this repetitive pattern:
(defun/1 modf (x ptr) (multiple-value-bind (whole part) (fround x) (setf (deref* ptr) whole) part))

Issue: Macro call that should be transformed by defun/1

Input: (defun/1 modf (x ptr) (multiple-value-bind (whole part) (fround x) (setf (deref* ptr) whole) part))

Output:
(defmacro defun/1 (name arglist &body body)
  "Lisp-1 defun; makes function pointers work."
  `(progn
     (defun ,name ,arglist
       (declare (optimize (speed 0) (debug 3)
                          ;; FIXME: Why do minor warnings result in load errors?
                          #+sbcl (sb-ext:inhibit-warnings 3)))

       ,@body)
     (defparameter ,name (vacietis.c:mkptr& (symbol-function ',name)))))

(progn (defun modf (x ptr) (declare (optimize (speed 0) (debug 3) (sb-ext:inhibit-warnings 3))) (multiple-value-bind (whole part) (fround x) (setf (deref* ptr) whole) part)) (defparameter modf (vacietis.c:mkptr& (symbol-function (quote modf)))))


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

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

Input: (defmessage nil (progn))

Output: (defmacro DEFMESSAGE ...)

(progn
 (eval-when (:compile-toplevel) (proclaim `(ftype function ,'nil)))
 (aprog1 (ensure-message 'nil :lambda-list '(progn))))


Instruction:
Define a macro that eliminates this repetitive pattern:
(defun/1 va_copy (dest src) (setf (deref* dest) (deref* src)))

Issue: Macro call that should be transformed by defun/1

Input: (defun/1 va_copy (dest src) (setf (deref* dest) (deref* src)))

Output:
(defmacro defun/1 (name arglist &body body)
  "Lisp-1 defun; makes function pointers work."
  `(progn
     (defun ,name ,arglist
       (declare (optimize (speed 0) (debug 3)
                          ;; FIXME: Why do minor warnings result in load errors?
                          #+sbcl (sb-ext:inhibit-warnings 3)))

       ,@body)
     (defparameter ,name (vacietis.c:mkptr& (symbol-function ',name)))))

(progn (defun va_copy (dest src) (declare (optimize (speed 0) (debug 3) (sb-ext:inhibit-warnings 3))) (setf (deref* dest) (deref* src))) (defparameter va_copy (vacietis.c:mkptr& (symbol-function (quote va_copy)))))


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(define-left-arrow-accessors nil)

Write a macro that addresses: Macro call that should be transformed by DEFINE-LEFT-ARROW-ACCESSORS

Input: (define-left-arrow-accessors nil)

Output: (defmacro DEFINE-LEFT-ARROW-ACCESSORS ...)


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(when (first in-decl) (setf (first in-decl-item) t))

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

Input: (when (first in-decl) (setf (first in-decl-item) t))

Output:
(defmacro when (test &body forms)
  `(if ,test
	   ,(cl:if (cadr forms)
			   `(progn ,@forms)
			   (car forms))))

(if (first in-decl) (setf (first in-decl-item) t))


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(lambda-ignoring-_ (dspecs _t) (finalize-decl-specs dspecs) `(,dspecs nil))

What needs to change: Macro call that should be transformed by lambda-ignoring-_

Input: (lambda-ignoring-_ (dspecs _t) (finalize-decl-specs dspecs) `(,dspecs nil))

Output:
(defmacro lambda-ignoring-_ (lambda-list &body body)
  "Works like `cl:lambda' macro except automatically `declare's
 `ignore' for parameters beginning with '_' character."
  (let ((ignored-parameters
          (collect-_-symbol-in-lambda-list lambda-list)))
    (unless ignored-parameters
      (warn "No ignored parameters in: ~A" lambda-list))
    (multiple-value-bind (body decls doc)
        (parse-body body :documentation t)
      `(lambda ,lambda-list
         ,@ (if doc `(,doc))
         (declare (ignore ,@ignored-parameters))
         ,@decls
         ,@body))))

(lambda (dspecs _t) (declare (ignore _t)) (finalize-decl-specs dspecs) (sb-int:quasiquote (#S(sb-impl::comma :expr dspecs :kind 0) nil)))


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(define-generic generic ((a a) (b b) &key (c nil)) (+ a b) (:method ((a x) (b z) &key c) c))

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

Input: (define-generic generic ((a a) (b b) &key (c nil)) (+ a b) (:method ((a x) (b z) &key c) c))

Output:
(defmacro define-generic (name (&rest arglist) &body body)
  "Convenience macro to define generics as if they were methods.
ARGLIST can be a method arglist, in which case it's parsed into
generic function arglist by removing method-specific args.

BODY can be a list of `defgeneric' options (processed as-is, even
:method ones) intermixed with other Lisp forms:
- If there's a docstring as the first form, it's processed into
  :documentation option of `defgeneric'.
- If there are non-option forms, they are put together into a separate
  :method option under ARGLIST.
- If there's a `declare' form:
  - If it's generic-friendly (optimize for speed or space), then it's
    put into both generic body and :method body (if any).
  - Otherwise it's only put into :method (creating it if necessary).
- If there's an `:export-generic-name-p' boolean option, export (T) or
  don't export (NIL) the generic symbol.

Example:

\(define-generic add ((a integer) (b integer) &key coerce-to-fixnum &allow-other-keys)
  \"Adds A and B, coercing them to fixnum if the sum is too big.\"
  (if coerce-to-fixnum
      (coerce (+ a b) 'fixnum)
      (+ a b))
  (:method ((a string) (b integer))
   (error \"Cannot use `add' on strings!\")))
=>
\(defgeneric add (a b &key &allow-other-keys)
  (:method ((a integer) (b integer) &key coerce-to-fixnum &allow-other-keys)
   (if coerce-to-fixnum
      (coerce (+ a b) 'fixnum)
      (+ a b)))
  (:method ((a string) (b integer))
   (error \"Cannot use `add' on strings!\"))
  (:documentation \"Adds A and B, coercing them to fixnum if the sum is too big.\"))"
  (multiple-value-bind (body declarations documentation)
      (uiop:parse-body body :documentation t)
    (when (and (= 1 (length body))
               (stringp (first body)))
      (style-warn "Body of DEFINE-GENERIC contains a single string:
~s.
It's interpreted as a method body by default.

If you meant this string to be a generic docstring, and not a method
body, add an explicit NIL or some other body form:
(define-generic name (arg1 arg2)
  \"Docstring\"
  'body-form)

If you meant it as a body form, do nothing, or provide explicit
documentation or any other option:
(define-generic name (arg1 arg2)
  \"Docstring\"
  (:documentation \"Real docstring\"))" (first body)))
    (let* ((generic-declarations (remove-if (lambda (d)
                                              (or (> (length d) 2)
                                                  (not (eq 'optimize (first (second d))))
                                                  (notevery (lambda (o)
                                                              (let ((feature (first (uiop:ensure-list o))))
                                                                (or (eq feature 'speed)
                                                                    (eq feature 'space))))
                                                            (rest (second d)))))
                                            declarations))
           (options (remove-if-not (lambda (form)
                                     (keywordp (first (uiop:ensure-list form))))
                                   body))
           (method-body (remove-if (lambda (f) (member f options :test #'equal)) body))
           (export-generic-name-p (find :export-generic-name-p options :key #'first))
           (options (remove export-generic-name-p options :test #'equal))
           (export-p (if export-generic-name-p
                         (second export-generic-name-p)
                         *export-generic-name-p*))
           (generalized-arglist (generalize-arglist arglist)))
      (when (and (not (equal generalized-arglist arglist))
                 (every #'null (list method-body options)))
        (style-warn "Specialized arglist used without method body in define-generic: ~a" arglist))
      `(prog1
           (defgeneric ,name ,generalized-arglist
             ,@generic-declarations
             ,@(when (or method-body
                         (not (equal generic-declarations
                                     declarations)))
                 `((:method ,arglist
                     ,@declarations
                     ,@method-body)))
             ,@options
             ,@(when documentation
                 `((:documentation ,documentation))))
         ;; FIXME: Maybe only export if package of generic function name
         ;; matches *PACKAGE*?
         ,@(when export-p
             `((eval-when (:compile-toplevel :load-toplevel :execute)
                 (export ',name ,(package-name *package*)))))
         ,@(let ((documentation (or documentation
                                    (second (first (member :documentation options :key #'first))))))
             (when documentation
               `((setf (documentation ',name 'function) ,documentation)
                 (setf (documentation (fdefinition ',name) 'function) ,documentation))))))))

(prog1 (defgeneric generic (a b &key c) (:method ((a a) (b b) &key (c nil)) (+ a b)) (:method ((a x) (b z) &key c) c)))


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

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

Input: (is-values (values 1 2 nil 3) '(1 2 nil 3))

Output:
(defmacro is (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
                   :duration ,duration)))))))

(is (multiple-value-list (values 1 2 nil 3)) (quote (1 2 nil 3)))


Instruction:
Define a macro that eliminates this repetitive pattern:
(with-foreign-pointer-as-string (s 100) (sprintf s "%.0f" :double (* pi 100d0)))

Issue: Macro call that should be transformed by with-foreign-pointer

Input: (with-foreign-pointer-as-string (s 100) (sprintf s "%.0f" :double (* pi 100d0)))

Output:
(defmacro with-foreign-pointer ((var size &optional size-var) &body body)
  "Bind 'var to 'size bytes of foreign memory during 'body.  The
  pointer in 'var is invalid beyond the dynamic extent of 'body, and
  may be stack-allocated if supported by the implementation.  If
  'size-var is supplied, it will be bound to 'size during 'body."
  (unless size-var
    (setf size-var (gensym (symbol-name '#:size))))
  ;; If the size is constant we can stack-allocate.
  (cond ((constantp size)
         (let ((alien-var (gensym (symbol-name '#:alien))))
           `(with-alien ((,alien-var (array (unsigned 8) ,(eval size))))
             (let ((,size-var ,size)
                   (,var (alien-sap ,alien-var)))
               (declare (ignorable ,size-var))
               ,@body))))
        (t
         `(let ((,size-var ,size))
            (alien:with-bytes (,var ,size-var)
              ,@body)))))

(with-foreign-pointer-as-string (s 100) (sprintf s "%.0f" :double (* pi 100.0d0)))


Instruction:
Write a Common Lisp macro to handle this code pattern:
(ignore-errors)

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

Input: (ignore-errors)

Output: (defmacro IGNORE-ERRORS ...)

(handler-case (progn) (error (condition) (values nil condition)))


Instruction:
Write a Common Lisp macro to handle this code pattern:
(defcategory :notice (or :notice :warning))

Problem: Macro call that should be transformed by defcategory

Input: (defcategory :notice (or :notice :warning))

Output:
(defmacro defcategory (category &optional expands-as set)
  `(defcategory-fn ',category ',expands-as ,set))

(defcategory-fn (quote :notice) (quote (or :notice :warning)) nil)


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

Problem: Macro call that should be transformed by DEFINE-TEMPLATED-DISPATCH

Input:
(define-templated-dispatch nil
    nil)

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


Instruction:
Write a Common Lisp macro to handle this code pattern:
(with-additional-indent (reporter stream "~& ") (with-color (:white :stream stream) (format/indent reporter stream (slot-value report 'description))) (terpri stream))

Problem: Macro call that should be transformed by with-additional-indent

Input: (with-additional-indent (reporter stream "~& ") (with-color (:white :stream stream) (format/indent reporter stream (slot-value report 'description))) (terpri stream))

Output:
(defmacro with-additional-indent ((reporter stream control-string &rest format-arguments) &body body)
  (declare (ignorable reporter stream control-string))
  (let* ((need-new-line (ppcre:scan "^~&" control-string))
         (string (apply #'format nil control-string format-arguments))
         (increment (length string)))
    `(with-slots (indent-space) reporter
       (let* ((first-line-indent (indent indent-space))
              (*additional-indent* ,(if need-new-line
                                        increment
                                        `(+ *additional-indent*
                                            ,increment))))
         (declare (ignorable first-line-indent))
         ,(if need-new-line
              `(progn (fresh-line stream)
                      (write-string first-line-indent ,stream)
                      ;; because we just started a new line, we
                      ;; should use format/indent to write string
                      ;; taking into account a main indentation level
                      (format/indent ,reporter ,stream ,string))
              ;; otherwise, just output our prefix
              `(write-string ,string ,stream))

         ,@body))))

(with-slots (indent-space) reporter (let* ((first-line-indent (indent indent-space)) (*additional-indent* 1)) (declare (ignorable first-line-indent)) (progn (fresh-line stream) (write-string first-line-indent stream) (format/indent reporter stream #A((1) base-char . " "))) (with-color (:white :stream stream) (format/indent reporter stream (slot-value report (quote description)))) (terpri stream)))


Instruction:
Write a Common Lisp macro to handle this code pattern:
($ "$min" ($ "value-1" 600))

Problem: Macro call that should be transformed by $

Input: ($ "$min" ($ "value-1" 600))

Output:
(defmacro $ (&rest args)
  `(kv ,@args))


Instruction:
Define a macro that eliminates this repetitive pattern:
(defclause while (condition) "Same as (until (not <condition>))." (make-termination :condition `(not ,condition)))

Issue: Macro call that should be transformed by defclause

Input: (defclause while (condition) "Same as (until (not <condition>))." (make-termination :condition `(not ,condition)))

Output:
(defmacro defclause (name arglist &body body)
  "Same as cl:defmacro, but additionally records <name> in *clauses* as a known clause macro."
  `(progn
     (defmacro ,name ,arglist ,@body)
     (pushnew ',name *clauses*)))

(progn (defmacro while (condition) "Same as (until (not <condition>))." (make-termination :condition (sb-int:quasiquote (not #S(sb-impl::comma :expr condition :kind 0))))) (pushnew (quote while) *clauses*))


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(builder :backtrace (lambda (env) (declare (ignore env)) (error 'test-error)))

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

Input: (builder :backtrace (lambda (env) (declare (ignore env)) (error 'test-error)))

Output:
(defmacro builder (&rest app-or-middlewares)
  (let ((middlewares (butlast app-or-middlewares)))
    `(reduce #'funcall
             (remove-if
              #'null
              (list
               ,@(loop for mw in middlewares
                       when mw
                         collect (convert-to-middleware-form mw))))
             :initial-value (to-app ,(car (last app-or-middlewares)))
             :from-end t)))

(reduce (function funcall) (remove-if (function null) (list (find-middleware :backtrace))) :initial-value (to-app (lambda (env) (declare (ignore env)) (error (quote test-error)))) :from-end t)


Instruction:
Write a Common Lisp macro to handle this code pattern:
(when-let* ((x t) (y (consp x)) (z (error "OOPS"))) t)

Problem: Macro call that should be transformed by when-let*

Input: (when-let* ((x t) (y (consp x)) (z (error "OOPS"))) t)

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

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

Each INITIAL-FORM is executed in turn, and the variable bound to the
corresponding value. INITIAL-FORM expressions can refer to variables
previously bound by the WHEN-LET*.

Execution of WHEN-LET* stops immediately if any INITIAL-FORM evaluates to NIL.
If all INITIAL-FORMs evaluate to true, then BODY is executed as an implicit
PROGN."
  (let ((binding-list (if (and (consp bindings) (symbolp (car bindings)))
                          (list bindings)
                          bindings)))
    (labels ((bind (bindings body)
               (if bindings
                   `(let (,(car bindings))
                      (when ,(caar bindings)
                        ,(bind (cdr bindings) body)))
                   `(progn ,@body))))
      (bind binding-list body))))

(let ((x t)) (when x (let ((y (consp x))) (when y (let ((z (error "OOPS"))) (when z (progn t)))))))


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

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

Input: (match nil (progn))

Output: (defmacro MATCH ...)

(block #:match127
  (let (progn)
    (when (and (setft progn nil)) (return-from #:match127 nil))))


Instruction:
Define a macro that eliminates this repetitive pattern:
($ ($ "$min" ($ "value-1" 600)) ($ "$max" ($ "value-1" 610)) ($ "query" ($ nil nil)))

Issue: Macro call that should be transformed by $

Input: ($ ($ "$min" ($ "value-1" 600)) ($ "$max" ($ "value-1" 610)) ($ "query" ($ nil nil)))

Output:
(defmacro $ (&rest args)
  `(kv ,@args))


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

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

Input:
(with-properties nil
    (progn))

Output: (defmacro WITH-PROPERTIES ...)

(let ((#:g134 (progn)))
  (symbol-macrolet ()))


Instruction:
Write a Common Lisp macro to handle this code pattern:
(ps-to-stream 'some-name)

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

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

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

(let ((*parenscript-stream* 'some-name))
  (write-string "" *parenscript-stream*))


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(when-let* (x y) (1+ x))

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

Input: (when-let* (x y) (1+ x))

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

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

Each INITIAL-FORM is executed in turn, and the variable bound to the
corresponding value. INITIAL-FORM expressions can refer to variables
previously bound by the WHEN-LET*.

Execution of WHEN-LET* stops immediately if any INITIAL-FORM evaluates to NIL.
If all INITIAL-FORMs evaluate to true, then BODY is executed as an implicit
PROGN."
  (let ((binding-list (if (and (consp bindings) (symbolp (car bindings)))
                          (list bindings)
                          bindings)))
    (labels ((bind (bindings body)
               (if bindings
                   `(let (,(car bindings))
                      (when ,(caar bindings)
                        ,(bind (cdr bindings) body)))
                   `(progn ,@body))))
      (bind binding-list body))))


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

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

Input:
(define-class nil
    :key
    nil)

Output: (defmacro DEFINE-CLASS ...)


Instruction:
Define a macro that eliminates this repetitive pattern:
(define-generic generic (a b &key c) (declare (ignorable a b c)) (+ a b c))

Issue: Macro call that should be transformed by define-generic

Input: (define-generic generic (a b &key c) (declare (ignorable a b c)) (+ a b c))

Output:
(defmacro define-generic (name (&rest arglist) &body body)
  "Convenience macro to define generics as if they were methods.
ARGLIST can be a method arglist, in which case it's parsed into
generic function arglist by removing method-specific args.

BODY can be a list of `defgeneric' options (processed as-is, even
:method ones) intermixed with other Lisp forms:
- If there's a docstring as the first form, it's processed into
  :documentation option of `defgeneric'.
- If there are non-option forms, they are put together into a separate
  :method option under ARGLIST.
- If there's a `declare' form:
  - If it's generic-friendly (optimize for speed or space), then it's
    put into both generic body and :method body (if any).
  - Otherwise it's only put into :method (creating it if necessary).
- If there's an `:export-generic-name-p' boolean option, export (T) or
  don't export (NIL) the generic symbol.

Example:

\(define-generic add ((a integer) (b integer) &key coerce-to-fixnum &allow-other-keys)
  \"Adds A and B, coercing them to fixnum if the sum is too big.\"
  (if coerce-to-fixnum
      (coerce (+ a b) 'fixnum)
      (+ a b))
  (:method ((a string) (b integer))
   (error \"Cannot use `add' on strings!\")))
=>
\(defgeneric add (a b &key &allow-other-keys)
  (:method ((a integer) (b integer) &key coerce-to-fixnum &allow-other-keys)
   (if coerce-to-fixnum
      (coerce (+ a b) 'fixnum)
      (+ a b)))
  (:method ((a string) (b integer))
   (error \"Cannot use `add' on strings!\"))
  (:documentation \"Adds A and B, coercing them to fixnum if the sum is too big.\"))"
  (multiple-value-bind (body declarations documentation)
      (uiop:parse-body body :documentation t)
    (when (and (= 1 (length body))
               (stringp (first body)))
      (style-warn "Body of DEFINE-GENERIC contains a single string:
~s.
It's interpreted as a method body by default.

If you meant this string to be a generic docstring, and not a method
body, add an explicit NIL or some other body form:
(define-generic name (arg1 arg2)
  \"Docstring\"
  'body-form)

If you meant it as a body form, do nothing, or provide explicit
documentation or any other option:
(define-generic name (arg1 arg2)
  \"Docstring\"
  (:documentation \"Real docstring\"))" (first body)))
    (let* ((generic-declarations (remove-if (lambda (d)
                                              (or (> (length d) 2)
                                                  (not (eq 'optimize (first (second d))))
                                                  (notevery (lambda (o)
                                                              (let ((feature (first (uiop:ensure-list o))))
                                                                (or (eq feature 'speed)
                                                                    (eq feature 'space))))
                                                            (rest (second d)))))
                                            declarations))
           (options (remove-if-not (lambda (form)
                                     (keywordp (first (uiop:ensure-list form))))
                                   body))
           (method-body (remove-if (lambda (f) (member f options :test #'equal)) body))
           (export-generic-name-p (find :export-generic-name-p options :key #'first))
           (options (remove export-generic-name-p options :test #'equal))
           (export-p (if export-generic-name-p
                         (second export-generic-name-p)
                         *export-generic-name-p*))
           (generalized-arglist (generalize-arglist arglist)))
      (when (and (not (equal generalized-arglist arglist))
                 (every #'null (list method-body options)))
        (style-warn "Specialized arglist used without method body in define-generic: ~a" arglist))
      `(prog1
           (defgeneric ,name ,generalized-arglist
             ,@generic-declarations
             ,@(when (or method-body
                         (not (equal generic-declarations
                                     declarations)))
                 `((:method ,arglist
                     ,@declarations
                     ,@method-body)))
             ,@options
             ,@(when documentation
                 `((:documentation ,documentation))))
         ;; FIXME: Maybe only export if package of generic function name
         ;; matches *PACKAGE*?
         ,@(when export-p
             `((eval-when (:compile-toplevel :load-toplevel :execute)
                 (export ',name ,(package-name *package*)))))
         ,@(let ((documentation (or documentation
                                    (second (first (member :documentation options :key #'first))))))
             (when documentation
               `((setf (documentation ',name 'function) ,documentation)
                 (setf (documentation (fdefinition ',name) 'function) ,documentation))))))))

(prog1 (defgeneric generic (a b &key c) (:method (a b &key c) (declare (ignorable a b c)) (+ a b c))))


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

Problem: Macro call that should be transformed by F0

Input:
(f0
  nil
  nil)

Output: (defmacro F0 ...)


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

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

Input: (define-op (:> infix-op))

Output:
(defmacro define-op ((op-name struct-type &key sql-op-name include-slots (package (find-package '#:sxql/operator))) &body body)
  (check-type op-name symbol)
  (let ((struct-name (intern (concatenate 'string (symbol-name op-name) #.(string :-op)) package)))
    `(defstruct (,struct-name (:include ,struct-type
                               (name ,(or sql-op-name
                                          (with-output-to-string (s)
                                            (loop for c across (symbol-name op-name)
                                                  if (char= c #\-)
                                                    do (write-char #\Space s)
                                                  else
                                                    do (write-char c s)))))
                               ,@include-slots)
                              (:constructor ,(intern (concatenate 'string
                                                                  #.(string :make-)
                                                                  (symbol-name op-name)
                                                                  #.(string :-op))
                                                     package)
                                  ,(ecase struct-type
                                     ((unary-op
                                       unary-splicing-op
                                       unary-postfix-op) '(var))
                                     ((infix-op
                                       infix-splicing-op
                                       infix-list-op) '(left right))
                                     (conjunctive-op '(&rest expressions)))))
       ,@body)))

(defstruct (>-op (:include infix-op (name ">")) (:constructor make->-op (left right))))


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

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

Input: (unless nil (progn))

Output: (defmacro UNLESS ...)


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

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

Input: (mapping)

Output: (defmacro MAPPING ...)


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

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

Input:
(list-of nil
  (progn))

Output: (defmacro LIST-OF ...)


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

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

Input:
(define-shared-method nil
    nil)

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

(define-incongruent-method incongruent-methods.methods::nil
    nil)


Instruction:
Define a macro that eliminates this repetitive pattern:
(define-simple-definition-resolver global (designator) (eq :global (sb-cltl2:variable-information designator)))

Issue: Macro call that should be transformed by define-simple-definition-resolver

Input: (define-simple-definition-resolver global (designator) (eq :global (sb-cltl2:variable-information designator)))

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

(define-definition-resolver global (global #:package147) (when (ignore-errors (let ((designator global)) (eq :global (sb-cltl2:variable-information designator)))) (list (make-instance (quote global) :designator global :package #:package147))))


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(match ARG (PATTERN THEN) (otherwise ELSE))

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

Input: (match ARG (PATTERN THEN) (otherwise ELSE))

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

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

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

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

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

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

will be translated to

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

Examples:

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

(%or (%or (let ((pattern arg)) then) else (fail)) nil)


Instruction:
Write a Common Lisp macro to handle this code pattern:
(macroexpand-convention (form) (if (consp form) (expand-export-slots-using-head (first form) form) form))

Problem: Macro call that should be transformed by macroexpand-convention

Input: (macroexpand-convention (form) (if (consp form) (expand-export-slots-using-head (first form) form) form))

Output:
(defmacro macroexpand-convention ((original-form) &body body)
  "Executes BODY as like `progn' and return the result as the first
value.  As the second value, returns a boolean whether the result is
not same with ORIGINAL-FORM or not.
This macro is designed to follow the `macroexpand' convention."
  `(multiple-value-bind (result expanded-p)
       (progn ,@body)
     (values result
             (or expanded-p
                 (not (eq result ,original-form))))))

(multiple-value-bind (result expanded-p) (progn (if (consp form) (expand-export-slots-using-head (first form) form) form)) (values result (or expanded-p (not (eq result form)))))


Instruction:
Generate a defmacro form that transforms code like this:
(define-column-type string (&optional length) (if length `(:varchar ,length) :text))

Pattern to recognize: Macro call that should be transformed by define-column-type

Input: (define-column-type string (&optional length) (if length `(:varchar ,length) :text))

Output:
(defmacro define-column-type (type-symbol lambda-list &body body)
  (let ((type (gensym "TYPE"))
        (args (gensym "ARGS")))
    `(defmethod cltype-to-dbtype ((,type (eql ',type-symbol)) &rest ,args)
       (declare (ignore ,type))
       (destructuring-bind ,lambda-list ,args
         ,@body))))

(defmethod cltype-to-dbtype ((#:type222 (eql (quote string))) &rest #:args223) (declare (ignore #:type222)) (destructuring-bind (&optional length) #:args223 (if length (sb-int:quasiquote (:varchar #S(sb-impl::comma :expr length :kind 0))) :text)))


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(define-simple-documentation-lookup special-operator cl:function)

Write a macro that addresses: Macro call that should be transformed by define-simple-documentation-lookup

Input: (define-simple-documentation-lookup special-operator cl:function)

Output:
(defmacro define-simple-documentation-lookup (class documentation-type)
  `(defmethod documentation ((,class ,class))
     ,(if (eql documentation-type T)
          `(cl:documentation (object ,class) 'T)
          `(cl:documentation (designator ,class) ',documentation-type))))

(defmethod documentation ((special-operator special-operator)) (common-lisp:documentation (designator special-operator) (quote common-lisp:function)))


Instruction:
Write a Common Lisp macro to handle this code pattern:
(when (typep (car evaluated) 'node) (setf asts (append asts evaluated)))

Problem: Macro call that should be transformed by when

Input: (when (typep (car evaluated) 'node) (setf asts (append asts evaluated)))

Output:
(defmacro when (test &body forms)
  `(if ,test
	   ,(cl:if (cadr forms)
			   `(progn ,@forms)
			   (car forms))))

(if (typep (car evaluated) (quote node)) (setf asts (append asts evaluated)))


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(ensure-getf options :type type)

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

Input: (ensure-getf options :type type)

Output:
(defmacro ensure-getf (place key &optional default)
  (once-only (key default)
    `(setf (getf ,place ,key) (getf ,place ,key ,default))))

(let ((#:key169 :type) (#:default170 type)) (setf (getf options #:key169) (getf options #:key169 #:default170)))


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(define-simple-type-map type cl:type)

Write a macro that addresses: Macro call that should be transformed by define-simple-type-map

Input: (define-simple-type-map type cl:type)

Output:
(defmacro define-simple-type-map (class type)
  `(defmethod type ((,class ,class))
     ',type))

(defmethod type ((type type)) (quote common-lisp:type))


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
;; Sorting multiple places requires manual compare-and-swap
(when (> b a) (rotatef a b))
(when (> c a) (rotatef a c))
(when (> c b) (rotatef b c))
;; This is a sorting network but manually written - error-prone
;; For more than 3 elements, the network is complex

Write a macro that addresses: Sorting multiple values in-place requires compare-and-swap networks — want automatic sorting network generation

Input:
;; Sorting multiple places requires manual compare-and-swap
(when (> b a) (rotatef a b))
(when (> c a) (rotatef a c))
(when (> c b) (rotatef b c))
;; This is a sorting network but manually written - error-prone
;; For more than 3 elements, the network is complex

Output:
(defun build-batcher-sn (n)
  (let* (network
         (tee (ceiling (log n 2)))
         (p (ash 1 (- tee 1))))
    (loop while (> p 0) do
      (let ((q (ash 1 (- tee 1)))
            (r 0)
            (d p))
        (loop while (> d 0) do
          (loop for i from 0 to (- n d 1) do
            (if (= (logand i p) r)
              (push (list i (+ i d))
                    network)))
          (setf d (- q p)
                q (ash q -1)
                r p)))
      (setf p (ash p -1)))
    (nreverse network)))

(defmacro! sortf (comparator &rest places)
  (if places
    `(tagbody
       ,@(mapcar
           #`(let ((,g!a #1=,(nth (car a1) places))
                   (,g!b #2=,(nth (cadr a1) places)))
               (if (,comparator ,g!b ,g!a)
                 (setf #1# ,g!b
                       #2# ,g!a)))
           (build-batcher-sn (length places))))))

;; (sortf string< a b c d e)
;; Generates a Batcher sorting network of compare-and-swap operations
;; Each pair is: (let ((#:ga (nth 0 places)) (#:gb (nth 3 places)))
;;                (if (string< #:gb #:ga) (setf #1# #:gb #2# #:ga)))
;; All within a tagbody for compiler optimization


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

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

Input: (the nil (progn))

Output: (defmacro THE ...)


Instruction:
Write a Common Lisp macro to handle this code pattern:
(bind (((:struct metabang-bind-test-1- a c) (make-metabang-bind-test-1 :a 1 :b 2 :c 3))) (list a c))

Problem: Macro call that should be transformed by bind

Input: (bind (((:struct metabang-bind-test-1- a c) (make-metabang-bind-test-1 :a 1 :b 2 :c 3))) (list a c))

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

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

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

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

(let* ((#:|values-188| (make-metabang-bind-test-1 :a 1 :b 2 :c 3)) (a (metabang-bind-test-1-a #:|values-188|)) (c (metabang-bind-test-1-c #:|values-188|))) (declare (ignorable #:|values-188|)) (progn (list a c)))


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

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

Output: (defmacro ENABLE-QUASIQUOTE-2.0 ...)

(eval-when (:compile-toplevel :load-toplevel :execute) (%enable-quasiquote-2.0))


Instruction:
Generate a defmacro form that transforms code like this:
(*> +array-open+ +skip-space-and-comments+)

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

Input: (*> +array-open+ +skip-space-and-comments+)

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

(lambda (#:*>-offset236) (multiple-value-bind (#:*>-res237 #:*>-next238) (funcall +array-open+ #:*>-offset236) (if (ok? #:*>-res237) (funcall +skip-space-and-comments+ #:*>-next238) (fail #:*>-next238))))


Instruction:
Define a macro that eliminates this repetitive pattern:
(special-symbol-progv nil
    nil)

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

Input:
(special-symbol-progv nil
    nil)

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

(let (#:symbol-list176)
  (tagbody
   #:retry177
    (setq #:symbol-list176 nil)
    (unless (every #'special-symbol-p #:symbol-list176)
      (cerror "Retry to rebind the place(s)."
              "Attempt at rebinding one or more non-special places: ~S" 'nil)
      (go #:retry177)))
  (dynamic-progv #:symbol-list176
      nil))


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

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

Input:
(with-yield
  'some-name)

Output: (defmacro WITH-YIELD ...)

(isolate-cont
  (enable-yield
    nil
    'some-name))


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

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

Input:
(labels* nil
  (progn))

Output: (defmacro LABELS* ...)


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(when (typep (node-slot name) 'identifier) (format stream "~~"))

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

Input: (when (typep (node-slot name) 'identifier) (format stream "~~"))

Output:
(defmacro when (test &body forms)
  `(if ,test
	   ,(cl:if (cadr forms)
			   `(progn ,@forms)
			   (car forms))))

(if (typep (node-slot name) (quote identifier)) (format stream "~~"))


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

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

Input: (var nil (progn))

Output: (defmacro VAR ...)


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

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

Input: (defparam nil nil)

Output: (defmacro DEFPARAM ...)

(setf (gethash #A((3) base-char . "NIL") cl-rules.core::*parameters*) nil)


Instruction:
Generate a defmacro form that transforms code like this:
(rte-case 'some-name)

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

Input: (rte-case 'some-name)

Output: (defmacro RTE-CASE ...)

(let ((#:rte170 'some-name))
  (typecase #:rte170
    ((not sequence) nil)
    (t
     (funcall
      (lambda (#:rte170)
        (declare (optimize (speed 3) (debug 0) (safety 0)))
        (block check
          (typecase #:rte170
            (list nil)
            (simple-vector
             (let ((i 0) (len (length #:rte170)))
               (declare (type (and unsigned-byte fixnum) i len)
                        (ignorable len))
               nil))
            (vector
             (let ((i 0) (len (length #:rte170)))
               (declare (type (and fixnum unsigned-byte) i len)
                        (ignorable len))
               nil))
            (sequence
             (let ((i 0) (len (sb-sequence:length #:rte170)))
               (declare (type (and fixnum unsigned-byte) i len)
                        (ignorable len))
               nil))
            (t nil))))
      #:rte170))))


Instruction:
Write a Common Lisp macro to handle this code pattern:
(with-html-string (:p (:button "Log in") (:a :href "#" "Forgot?")))

Problem: Macro call that should be transformed by with-html

Input: (with-html-string (:p (:button "Log in") (:a :href "#" "Forgot?")))

Output:
(defmacro with-html (&body body &environment env)
  "Interpret BODY as HTML. Consult README.txt for the syntax."
  `(let ((*html* (ensure-html-stream *html*)))
     ,(if (and (null (cdr body)) (atom (car body)))
          (car body)
          `(progn ,@(parse-html body env)))))

(with-output-to-string (*html*) (with-html (:p (:button "Log in") (:a :href "#" "Forgot?"))))


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(path (move-to 100 400) (line-to-r 50 -25) (arc-to-r 25 25 -30 0 1 50 -25) (line-to-r 50 -25) (arc-to-r 25 50 -30 0 1 50 -25) (line-to-r 50 -25) (arc-to-r 25 75 -30 0 1 50 -25) (line-to-r 50 -25) (arc-to-r 25 100 -30 0 1 50 -25) (line-to-r 50 -25) (vertical-to-r 50))

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

Input: (path (move-to 100 400) (line-to-r 50 -25) (arc-to-r 25 25 -30 0 1 50 -25) (line-to-r 50 -25) (arc-to-r 25 50 -30 0 1 50 -25) (line-to-r 50 -25) (arc-to-r 25 75 -30 0 1 50 -25) (line-to-r 50 -25) (arc-to-r 25 100 -30 0 1 50 -25) (line-to-r 50 -25) (vertical-to-r 50))

Output:
(defmacro path (&body cmds)
  (let ((path (gensym "path")))
    `(let ((,path (make-path)))
       (with-path ,path
         ,@cmds)
       ,path)))


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

Problem: Macro call that should be transformed by $

Input: ($ 'some-name)

Output: (defmacro $ ...)


Instruction:
Write a Common Lisp macro to handle this code pattern:
(aand (+ 1 1) (+ 1 it))

Problem: Macro call that should be transformed by aand

Input: (aand (+ 1 1) (+ 1 it))

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


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

Problem: Macro call that should be transformed by DEFITER

Input:
(defiter nil
    :key
  nil)

Output: (defmacro DEFITER ...)

(defun nil :key
  (make-instance 'iterator :coro
                 (lambda-coro
                   nil)))


Instruction:
Generate a defmacro form that transforms code like this:
(when-let* ((x 2) (y x)) (+ x y))

Pattern to recognize: Macro call that should be transformed by when-let*

Input: (when-let* ((x 2) (y x)) (+ x y))

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

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

Each INITIAL-FORM is executed in turn, and the variable bound to the
corresponding value. INITIAL-FORM expressions can refer to variables
previously bound by the WHEN-LET*.

Execution of WHEN-LET* stops immediately if any INITIAL-FORM evaluates to NIL.
If all INITIAL-FORMs evaluate to true, then BODY is executed as an implicit
PROGN."
  (let ((binding-list (if (and (consp bindings) (symbolp (car bindings)))
                          (list bindings)
                          bindings)))
    (labels ((bind (bindings body)
               (if bindings
                   `(let (,(car bindings))
                      (when ,(caar bindings)
                        ,(bind (cdr bindings) body)))
                   `(progn ,@body))))
      (bind binding-list body))))

(let ((x 2)) (when x (let ((y x)) (when y (progn (+ x y))))))


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(do+ (for (k v) (hash-entries-of ht)) (collect (cons k v)))

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

Input: (do+ (for (k v) (hash-entries-of ht)) (collect (cons k v)))

Output:
(defmacro do+ (&body body)
  "High-level, extensible iteration construct. Refer to the manual for syntax and semantics."
  `(do+/internal nil ,@body))

(do+/internal nil (for (k v) (hash-entries-of ht)) (collect (cons k v)))


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

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

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

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

(cond (*within-captured-dynenv* (progn :key nil))
      (t
       (error
        "No macrodynamic environment has been captured to establish CT-LET* bindings.")))


Instruction:
Define a macro that eliminates this repetitive pattern:
(def-neo4j-fun get-relationship-properties (relationship-id) :get (:uri-spec (format nil "relationship/~A/properties" relationship-id)) (:status-handlers (200 (decode-neo4j-json-output body)) (204 nil) (404 (error 'relationship-not-found-error :uri uri))))

Issue: Macro call that should be transformed by def-neo4j-fun

Input: (def-neo4j-fun get-relationship-properties (relationship-id) :get (:uri-spec (format nil "relationship/~A/properties" relationship-id)) (:status-handlers (200 (decode-neo4j-json-output body)) (204 nil) (404 (error 'relationship-not-found-error :uri uri))))

Output:
(defmacro def-neo4j-fun (name lambda-list method &rest args)
  `(progn
     (defun ,name (&key ,@lambda-list)
       (let ((uri ,(cadr (assoc :uri-spec args)))
             (json (encode-neo4j-json-payload ,@(aif (assoc :encode args)
                                                     (cdr it)
                                                     (list '() :string)))))
         (make-neo4j-request ,method uri json
                             (list ,@(mapcar (lambda (handler)
                                               `(list ,(car handler) (lambda (body uri json)
                                                                  ,(cadr handler))))
                                             (cdr (assoc :status-handlers args)))))))))

(progn (defun get-relationship-properties (&key relationship-id) (let ((uri (format nil "relationship/~A/properties" relationship-id)) (json (encode-neo4j-json-payload nil :string))) (make-neo4j-request :get uri json (list (list 200 (lambda (body uri json) (decode-neo4j-json-output body))) (list 204 (lambda (body uri json) nil)) (list 404 (lambda (body uri json) (error (quote relationship-not-found-error) :uri uri))))))))


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(when (eql counter 0) (return))

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

Input: (when (eql counter 0) (return))

Output:
(defmacro when (test &body forms)
  `(if ,test
	   ,(cl:if (cadr forms)
			   `(progn ,@forms)
			   (car forms))))


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(defgenerator ifilter-false (predicate generator) "Emits only those items in generator that are false by predicate. The generator equivalent of remove-if" (do-generator (g generator) (unless (funcall predicate g) (yield g))))

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

Input: (defgenerator ifilter-false (predicate generator) "Emits only those items in generator that are false by predicate. The generator equivalent of remove-if" (do-generator (g generator) (unless (funcall predicate g) (yield g))))

Output:
(defmacro defgenerator (name arguments &body body)
  (multiple-value-bind (remaining-forms declarations doc-string)
      (alexandria:parse-body body :documentation t)
    `(defun ,name ,arguments
       ,doc-string
       ,@declarations
       (with-yield
	 ,@remaining-forms))))

(defun ifilter-false (predicate generator) "Emits only those items in generator that are false by predicate. The generator equivalent of remove-if" (with-yield (do-generator (g generator) (unless (funcall predicate g) (yield g)))))


Instruction:
Generate a defmacro form that transforms code like this:
(def-neo4j-fun remove-from-index ((type :node) name key value object-id) :delete (:uri-spec (format nil "index/~A/~A/~@[~A/~]~@[~A/~]~A" (string-downcase (symbol-name type)) name key (urlencode value) object-id)) (:status-handlers (204 (values t body)) (404 (error 'index-entry-not-found-error :uri uri))))

Pattern to recognize: Macro call that should be transformed by def-neo4j-fun

Input: (def-neo4j-fun remove-from-index ((type :node) name key value object-id) :delete (:uri-spec (format nil "index/~A/~A/~@[~A/~]~@[~A/~]~A" (string-downcase (symbol-name type)) name key (urlencode value) object-id)) (:status-handlers (204 (values t body)) (404 (error 'index-entry-not-found-error :uri uri))))

Output:
(defmacro def-neo4j-fun (name lambda-list method &rest args)
  `(progn
     (defun ,name (&key ,@lambda-list)
       (let ((uri ,(cadr (assoc :uri-spec args)))
             (json (encode-neo4j-json-payload ,@(aif (assoc :encode args)
                                                     (cdr it)
                                                     (list '() :string)))))
         (make-neo4j-request ,method uri json
                             (list ,@(mapcar (lambda (handler)
                                               `(list ,(car handler) (lambda (body uri json)
                                                                  ,(cadr handler))))
                                             (cdr (assoc :status-handlers args)))))))))

(progn (defun remove-from-index (&key (type :node) name key value object-id) (let ((uri (format nil "index/~A/~A/~@[~A/~]~@[~A/~]~A" (string-downcase (symbol-name type)) name key (urlencode value) object-id)) (json (encode-neo4j-json-payload nil :string))) (make-neo4j-request :delete uri json (list (list 204 (lambda (body uri json) (values t body))) (list 404 (lambda (body uri json) (error (quote index-entry-not-found-error) :uri uri))))))))


Instruction:
Define a macro that eliminates this repetitive pattern:
(do-sequences! ((item1 seq1 :start start1 :end end1) (item2 seq2 :start start2 :end end2)) (setf item1 item2))

Issue: Macro call that should be transformed by do-sequences

Input: (do-sequences! ((item1 seq1 :start start1 :end end1) (item2 seq2 :start start2 :end end2)) (setf item1 item2))

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

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

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

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

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

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

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

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

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

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

         ,name
         ,seqs
         ,@forms))))

(do-sequences!-fast% nil ((item1 seq1 :start start1 :end end1) (item2 seq2 :start start2 :end end2)) (setf item1 item2))


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(orf (formatted-message-text self) (format-message self))

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

Input: (orf (formatted-message-text self) (format-message self))

Output:
(defmacro orf (location form &environment env)
  (multiple-value-bind (vars values new setter getter)
      (get-setf-expansion location env)
    (when (cdr new)
      (error "Can't work with setf-expansion for ~s - ~d values from setter ~s"
             location (length new) new))
    (let ((current (car new)))
      `(let* (,@(mapcar 'list vars values)
              (,current ,getter))
         (or ,current
             (progn (setf ,current ,form)
               ,setter))))))

(let* ((#:self132 self) (#:new131 (formatted-message-text #:self132))) (or #:new131 (progn (setf #:new131 (format-message self)) (funcall (function (setf formatted-message-text)) #:new131 #:self132))))


Instruction:
Generate a defmacro form that transforms code like this:
(with-special-initargs* 'some-name)

Pattern to recognize: Macro call that should be transformed by WITH-SPECIAL-INITARGS*

Input: (with-special-initargs* 'some-name)

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

(with-special-initargs (quote)
  (with-special-initargs* (some-name)))


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

Issue: Macro call that should be transformed by MATCH

Input: (match nil nil)

Output: (defmacro MATCH ...)

(block #:match125 (when (and (not nil)) (return-from #:match125 nil)))


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(define-custom-var (:end-of-array *end-of-array-handler*) (constantly nil) "Designator for a function of no arguments (called at encountering a closing bracket for an Array).")

Write a macro that addresses: Macro call that should be transformed by define-custom-var

Input: (define-custom-var (:end-of-array *end-of-array-handler*) (constantly nil) "Designator for a function of no arguments (called at encountering a closing bracket for an Array).")

Output:
(defmacro define-custom-var ((key name) &rest other-args)
  `(eval-when (:compile-toplevel :load-toplevel :execute)
     (progn (pushnew '(,name . ,key) *custom-vars* :test #'equal)
            (defvar ,name ,@other-args))))

(eval-when (:compile-toplevel :load-toplevel :execute) (progn (pushnew (quote (*end-of-array-handler* . :end-of-array)) *custom-vars* :test (function equal)) (defvar *end-of-array-handler* (constantly nil) "Designator for a function of no arguments (called at encountering a closing bracket for an Array).")))


Instruction:
Generate a defmacro form that transforms code like this:
(when-let* ((x t) (y (consp x)) (z (error "OOPS"))) t)

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

Input: (when-let* ((x t) (y (consp x)) (z (error "OOPS"))) t)

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

(let ((x t)) (when x (let ((y (consp x))) (when y (let ((z (error "OOPS"))) (when z (progn t)))))))


Instruction:
Define a macro that eliminates this repetitive pattern:
(c?-with-stored (v :bar store 'nothing) (bwhen (val (value v)) val))

Issue: Macro call that should be transformed by c?-with-stored

Input: (c?-with-stored (v :bar store 'nothing) (bwhen (val (value v)) val))

Output:
(defmacro c?-with-stored ((var key store &optional default) &body body)
  `(c? (bwhen-c-stored (,var ,key ,store ,default)
	 ,@body)))

(c? (bwhen-c-stored (v :bar store (quote nothing)) (bwhen (val (value v)) val)))


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(c? (c-assert (listp (kid-values self))) (mapsort (^sort-map) (the-kids (mapcar (lambda (kid-value) (trc "making kid" kid-value) (or (find kid-value .cache :key (kv-key self) :test (kv-key-test self)) (trc nil "family-values forced to make new kid" self .cache kid-value) (funcall (kid-factory self) self kid-value))) (^kid-values)))))

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

Input: (c? (c-assert (listp (kid-values self))) (mapsort (^sort-map) (the-kids (mapcar (lambda (kid-value) (trc "making kid" kid-value) (or (find kid-value .cache :key (kv-key self) :test (kv-key-test self)) (trc nil "family-values forced to make new kid" self .cache kid-value) (funcall (kid-factory self) self kid-value))) (^kid-values)))))

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

(make-c-dependent :code (quote ((c-assert (listp (kid-values self))) (mapsort (^sort-map) (the-kids (mapcar (lambda (kid-value) (trc "making kid" kid-value) (or (find kid-value .cache :key (kv-key self) :test (kv-key-test self)) (trc nil "family-values forced to make new kid" self .cache kid-value) (funcall (kid-factory self) self kid-value))) (^kid-values)))))) :value-state :unevaluated :rule (c-lambda (c-assert (listp (kid-values self))) (mapsort (^sort-map) (the-kids (mapcar (lambda (kid-value) (trc "making kid" kid-value) (or (find kid-value .cache :key (kv-key self) :test (kv-key-test self)) (trc nil "family-values forced to make new kid" self .cache kid-value) (funcall (kid-factory self) self kid-value))) (^kid-values))))))


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

Problem: Macro call that should be transformed by DEFINE-SYNTAX

Input: (define-syntax common-lisp:nil common-lisp:nil)

Output: (defmacro DEFINE-SYNTAX ...)

(common-lisp:defmacro common-lisp:nil
                      (
                       common-lisp:&rest
                       |https://github.com/g000001/mbe#internals|::__syntax-rules-arg__)
  (common-lisp:let ((|https://github.com/g000001/mbe#internals|::__syntax-rules-arg__
                     (common-lisp:cons 'common-lisp:nil
                                       |https://github.com/g000001/mbe#internals|::__syntax-rules-arg__))
                    (|https://github.com/g000001/mbe#internals|::__syntax-rules-keywords__
                     '(common-lisp:nil)))
    (common-lisp:cond
     (common-lisp:t
      (common-lisp:error "~a: no matching clause" 'common-lisp:nil)))))


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

Issue: Macro call that should be transformed by SETF

Input: (setf)

Output: (defmacro SETF ...)


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

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

Input:
(any-of nil
  nil)

Output: (defmacro ANY-OF ...)


Instruction:
Generate a defmacro form that transforms code like this:
(isnt "1" 1)

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

Input: (isnt "1" 1)

Output:
(defmacro is (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
                   :duration ,duration)))))))

(let ((#:expected161 1)) (let* ((#:new-args159 (list)) (#:desc160 (parse-description-and-test #:new-args159))) (with-catching-errors (:description #:desc160 :expected #:expected161) (with-duration ((#:duration157 #:result158) "1") (test #:result158 #:expected161 #:new-args159 :notp t :duration #:duration157)))))


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(with-mocks () (register-mock 'foo) (is (null (multiple-value-list (foo)))))

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

Input: (with-mocks () (register-mock 'foo) (is (null (multiple-value-list (foo)))))

Output:
(defmacro with-mocks ((&key (recordp T)) &body body)
  "Execute BODY in a new mocking context.  Invocations will be recorded
if RECORDP is set (default true)."
  `(call-with-mocks
    (lambda () ,@body)
    :recordp ,recordp))

(call-with-mocks (lambda nil (register-mock (quote foo)) (is (null (multiple-value-list (foo))))) :recordp t)


Instruction:
Generate a defmacro form that transforms code like this:
(with-color (:yellow :stream stream) (format/indent reporter stream "△ Looks like you planned ~D test~:*~P but ran ~A.~%" plan count))

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

Input: (with-color (:yellow :stream stream) (format/indent reporter stream "△ Looks like you planned ~D test~:*~P but ran ~A.~%" plan count))

Output:
(defmacro with-color ((color &rest args) &body body)
  (cond
    ((or (eq color :gray)
         (eq color :grey))
     `(if *enable-colors*
          (with-gray ,(or (getf args :stream) t) ,@body)
          (progn ,@body)))
    (T `(if *enable-colors*
            (if (or (eq ,color :gray)
                    (eq ,color :grey)
                    (eq ,color cl-colors:+gray+)
                    (eq ,color cl-colors:+grey+))
                (with-gray ,(or (getf args :stream) t) ,@body)
                (cl-ansi-text:with-color (,color ,@args) ,@body))
            (progn ,@body)))))

(if *enable-colors* (if (or (eq :yellow :gray) (eq :yellow :grey) (eq :yellow +gray+) (eq :yellow +grey+)) (with-gray stream (format/indent reporter stream "△ Looks like you planned ~D test~:*~P but ran ~A.~%" plan count)) (cl-ansi-text:with-color (:yellow :stream stream) (format/indent reporter stream "△ Looks like you planned ~D test~:*~P but ran ~A.~%" plan count))) (progn (format/indent reporter stream "△ Looks like you planned ~D test~:*~P but ran ~A.~%" plan count)))


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
(enable-quasi-quoted-binary-syntax)

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

Input: (enable-quasi-quoted-binary-syntax)

Output: (defmacro ENABLE-QUASI-QUOTED-BINARY-SYNTAX ...)

(eval-when (:compile-toplevel :execute)
  (setf *readtable* (copy-readtable *readtable*))
  (set-quasi-quoted-binary-syntax-in-readtable :start-character nil
                                               :end-character nil
                                               :unquote-character #\COMMA
                                               :splice-character
                                               #\COMMERCIAL_AT
                                               :destructive-splice-character
                                               #\FULL_STOP
                                               :dispatched-quasi-quote-name
                                               "bin" :transformation-pipeline
                                               nil)
  (values))


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

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

Input: (defsynonym :minimizing :min)

Output:
(defmacro defsynonym (symbol synonym)
  "Set SYNONYM for a SYMBOL. "
  `(eval-always
     (setf (get ',symbol 'synonym) ',synonym)))

(eval-always (setf (get (quote :minimizing) (quote synonym)) (quote :min)))


Instruction:
Define a macro that eliminates this repetitive pattern:
(with-html-string (:a :href "#" :data-instant nil))

Issue: Macro call that should be transformed by with-html

Input: (with-html-string (:a :href "#" :data-instant nil))

Output:
(defmacro with-html (&body body &environment env)
  "Interpret BODY as HTML. Consult README.txt for the syntax."
  `(let ((*html* (ensure-html-stream *html*)))
     ,(if (and (null (cdr body)) (atom (car body)))
          (car body)
          `(progn ,@(parse-html body env)))))

(with-output-to-string (*html*) (with-html (:a :href "#" :data-instant nil)))


Instruction:
Generate a defmacro form that transforms code like this:
(let-syntax 'some-name)

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

Input: (let-syntax 'some-name)

Output: (defmacro LET-SYNTAX ...)

(letrec-syntax (common-lisp:quote) (let-syntax (some-name)))


Instruction:
You are a Common Lisp macro expert. Given this code pattern:
($op* op l)

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

Input: ($op* op l)

Output:
(defmacro $op (op &rest args)
  (cond ((consp (car args)) `(map-reduce-op ,op ($exp+ ,@args)))
	(t                   `($op* ,op ,@args))))


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

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

Input: (define-global-parameter nil nil)

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

(progn
 (store-in-symbol-plist nil nil .value-key.)
 (sb-ext:defglobal nil (get 'nil +value-key+))
 (eval-when (:compile-toplevel :load-toplevel :execute)
   (setf nil (get 'nil +value-key+)))
 (remprop 'nil +value-key+)
 'nil)


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

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

Input:
(with-access nil
    nil)

Output:
(defmacro with-access ((&rest keys) val-form &body body)
  "Similar to with-accessors except using the access functions"
  (let* ((gval (gensym "val"))
     (forms
      (iter (for k in keys)
        (for (k-to k-from) = (if (listp k) k (list k k)))
        (collect `(,k-to (access ,gval ',k-from))))))
    `(let ((,gval ,val-form))
       (declare (ignorable ,gval))
       (symbol-macrolet (,@forms)
     ,@body
     ))))

(let ((#:|val241| nil))
  (declare (ignorable #:|val241|))
  (symbol-macrolet ()))


Instruction:
Generate a defmacro form that transforms code like this:
($> "l" -9)

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

Input: ($> "l" -9)

Output:
(defmacro $ (&rest args)
  `(kv ,@args))


Instruction:
Define a macro that eliminates this repetitive pattern:
(define-value-binding in (var list &key (by NIL by-p)) (declare (type list list)) `(cond (,list ,(if by-p `(progn (update ,var (car ,list)) (setf ,list (funcall ,by ,list))) `(update ,var (pop ,list)))) (T (end-for))))

Issue: Macro call that should be transformed by define-value-binding

Input: (define-value-binding in (var list &key (by NIL by-p)) (declare (type list list)) `(cond (,list ,(if by-p `(progn (update ,var (car ,list)) (setf ,list (funcall ,by ,list))) `(update ,var (pop ,list)))) (T (end-for))))

Output:
(defmacro define-value-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)))

(define-direct-binding in (var list &key (by nil by-p)) (let ((#:list134 (gensym #A((4) base-char . "LIST"))) (#:by135 (gensym #A((2) base-char . "BY")))) (values* (sb-int:quasiquote (with-interleaving (let* #S(sb-impl::comma :expr (list* (list #:list134 list) (list #:by135 by) (loop for #:var133 in (lambda-fiddle:extract-lambda-vars (enlist var)) collect (list #:var133 nil))) :kind 0) (declare (ignorable #S(sb-impl::comma :expr #:list134 :kind 0) #S(sb-impl::comma :expr #:by135 :kind 0))) #S(sb-impl::comma :expr (sb-int:quasiquote (declare (type #S(sb-impl::comma :expr (quote list) :kind 0) #S(sb-impl::comma :expr #:list134 :kind 0)))) :kind 0)) #S(sb-impl::comma :expr nil :kind 0))) (let ((list #:list134) (by #:by135)) (declare (ignorable list by)) (sb-int:quasiquote (cond (#S(sb-impl::comma :expr list :kind 0) #S(sb-impl::comma :expr (if by-p (sb-int:quasiquote (progn (update #S(sb-impl::comma :expr var :kind 0) (car #S(sb-impl::comma :expr list :kind 0))) (setf #S(sb-impl::comma :expr list :kind 0) (funcall #S(sb-impl::comma :expr by :kind 0) #S(sb-impl::comma :expr list :kind 0))))) (sb-int:quasiquote (update #S(sb-impl::comma :expr var :kind 0) (pop #S(sb-impl::comma :expr list :kind 0))))) :kind 0)) (t (end-for))))))))


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

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

Input: (collect-nth nil :key nil)

Output: (defmacro COLLECT-NTH ...)

(common-lisp:let* ((#:generator-420 (generator :key))
                   #:items-412
                   (#:counter-414 nil)
                   (#:item-415 nil))
  (declare (type generator #:generator-420)
           (type (null-or fixnum) #:counter-414)
           (type (null-or t) #:item-415))
  (tagbody
   #:ll-421
    (setq #:items-412 (next-in #:generator-420 (go end)))
    (when (zerop #:counter-414) (setq #:item-415 #:items-412) (go end))
    (decf #:counter-414)
    (go #:ll-421)
   end)
  #:item-415)


Instruction:
Define a macro that eliminates this repetitive pattern:
(pop-preprocessor-directive-token token-list :|_Pragma|)

Issue: Macro call that should be transformed by pop-preprocessor-directive-token

Input: (pop-preprocessor-directive-token token-list :|_Pragma|)

Output:
(defmacro pop-preprocessor-directive-token (token-list directive-name &key (errorp t))
  "Pops the next token in TOKEN-LIST ignoring `+whitespace-marker+'"
  (with-gensyms (head_)
    `(let ((,head_
             (check-and-pop-pp-directive-token-1 ,token-list ,directive-name ,errorp)))
       (if (eq +whitespace-marker+ ,head_)
           (check-and-pop-pp-directive-token-1 ,token-list ,directive-name ,errorp)
           ,head_))))

(let ((#:head_268 (check-and-pop-pp-directive-token-1 token-list :|_Pragma| t))) (if (eq +whitespace-marker+ #:head_268) (check-and-pop-pp-directive-token-1 token-list :|_Pragma| t) #:head_268))


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

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

Input: (loop 'some-name)

Output: (defmacro LOOP ...)

(block nil (tagbody #:g191 (progn 'some-name) (go #:g191)))


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(define-errno-symbol EILSEQ)

What needs to change: Macro call that should be transformed by define-errno-symbol

Input: (define-errno-symbol EILSEQ)

Output:
(defmacro define-errno-symbol (name)
  `(defparameter ,name
     (find-errno-symbol (string ',name))))

(defparameter eilseq (find-errno-symbol (string (quote eilseq))))


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

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

Input: (destructuring-case 'some-name)

Output: (defmacro DESTRUCTURING-CASE ...)


Instruction:
Generate a defmacro form that transforms code like this:
(define-test bad-dependency :depends-on (failing) (is = 5 5))

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

Input: (define-test bad-dependency :depends-on (failing) (is = 5 5))

Output:
(defmacro define-test (name &body arguments-and-body)
  (destructuring-bind (nparent name) (if (listp name) name (list NIL name))
    (form-fiddle:with-body-options (body options parent home (test-class 'test) (compile-at :compile-time) defun) arguments-and-body
      (let ((body (remove 'define-test body :key (lambda (a) (when (listp a) (car a))) :test #'eql))
            (defs (remove 'define-test body :key (lambda (a) (when (listp a) (car a))) :test-not #'eql))
            (home-form (or home `(find-package ,(package-name *package*)))))
        (when (and parent nparent)
          (error "Cannot specify parent through name and through a keyword argument at the same time!"))
        `(let ((*package* (find-package ,(package-name *package*)))) ; Make sure package stays consistent throughout initialisation.
           (setf (find-test ',name ,home-form)
                 (ensure-test ',test-class
                              :name ',name
                              :home ,home-form
                              :tests (list ,@(loop for form in body
                                                   collect (ecase compile-at
                                                             (:compile-time `(lambda () ,form))
                                                             (:execute `(lambda () (call-compile ',form))))))
                              :parent ',(or parent nparent)
                              ,@(loop for option in options
                                      collect `',option)))
           ,@(loop for (def subname . body) in defs
                   collect `(,def (,name ,subname)
                              :home ,home
                              ,@body))
           ,@(when defun
               `((defun ,(if (stringp name) (read-symbol name) name) (&rest test-args)
                   (apply #'test (find-test ',name ,home-form) test-args))))
           ',name)))))

(let ((*package* (find-package #A((9) base-char . "PARACHUTE")))) (setf (find-test (quote bad-dependency) (find-package #A((9) base-char . "PARACHUTE"))) (ensure-test (quote test) :name (quote bad-dependency) :home (find-package #A((9) base-char . "PARACHUTE")) :tests (list (lambda nil (is = 5 5))) :parent (quote nil) (quote :depends-on) (quote (failing)))) (quote bad-dependency))


Instruction:
Create a Common Lisp macro for the following transformation. Before code:
(signal-syntax-error* open-paren-pos "Opening paren has no matching closing paren.")

What needs to change: Macro call that should be transformed by signal-syntax-error*

Input: (signal-syntax-error* open-paren-pos "Opening paren has no matching closing paren.")

Output:
(defmacro signal-syntax-error* (pos format-control &rest format-arguments)
  `(error 'ppcre-syntax-error
          :pos ,pos
          :format-control ,format-control
          :format-arguments (list ,@format-arguments)))

(error (quote ppcre-syntax-error) :pos open-paren-pos :format-control "Opening paren has no matching closing paren." :format-arguments (list))


Instruction:
Generate a defmacro form that transforms code like this:
(dflet ((list ())) (is (eql 42 (list))))

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

Input: (dflet ((list ())) (is (eql 42 (list))))

Output:
(defmacro dflet ((&rest definitions) &body body)
  "Like FLET, but dynamically sets the FDEFINITIONS during the duration of
the BODY."
  `(progf
       ',(mapcar #'car definitions)
       (list
        ,.(mapcar (lambda (definition)
                    `(lambda ,(cadr definition)
                       ,@(cddr definition)))
                  definitions))
     ,@body))

(progf (quote (list)) (list (lambda nil)) (is (eql 42 (list))))


Instruction:
Write a Common Lisp macro to handle this code pattern:
(define-option-expander nicknames (package &rest nicknames) (loop for nick in nicknames do (add-package-nickname package nick)))

Problem: Macro call that should be transformed by define-option-expander

Input: (define-option-expander nicknames (package &rest nicknames) (loop for nick in nicknames do (add-package-nickname package nick)))

Output:
(defmacro define-option-expander (name (package &rest arguments) &body body)
  (let ((args (gensym "ARGS")))
    `(defmethod expand-option ((,(gensym "TYPE") (eql ,(intern (string name) "KEYWORD"))) ,package ,args)
       (destructuring-bind ,arguments ,args
         ,@body))))

(defmethod expand-option ((#:type122 (eql :nicknames)) package #:args121) (destructuring-bind (&rest nicknames) #:args121 (loop for nick in nicknames do (add-package-nickname package nick))))


Instruction:
Write a Common Lisp macro to handle this code pattern:
(with-connection (let ((user (retrieve-one :user :by :name := "nitro_idiot"))) (is-type user 'trivial-types:property-list)) (let ((user (retrieve-one :user :by :name := "nitro_idiot" :as 'hash-table))) (is-type user 'hash-table)) (let* ((*default-row-type* 'hash-table) (user (retrieve-one :user :by :name := "nitro_idiot"))) (is-type user 'hash-table)) (let* ((*default-row-type* 'hash-table) (user (retrieve-one :user :by :name := "nitro_idiot" :as 'trivial-types:association-list))) (is-type user 'trivial-types:association-list)))

Problem: Macro call that should be transformed by with-connection

Input: (with-connection (let ((user (retrieve-one :user :by :name := "nitro_idiot"))) (is-type user 'trivial-types:property-list)) (let ((user (retrieve-one :user :by :name := "nitro_idiot" :as 'hash-table))) (is-type user 'hash-table)) (let* ((*default-row-type* 'hash-table) (user (retrieve-one :user :by :name := "nitro_idiot"))) (is-type user 'hash-table)) (let* ((*default-row-type* 'hash-table) (user (retrieve-one :user :by :name := "nitro_idiot" :as 'trivial-types:association-list))) (is-type user 'trivial-types:association-list)))

Output:
(defmacro with-connection (&body body)
  `(let ((*connection* (connect-cached :sqlite3 :database-name *db-path*)))
     ,@body))

(let ((let (connect ((user (retrieve-one :user :by :name := "nitro_idiot"))) (is-type user (quote trivial-types:property-list))))) (unwind-protect (progn (let ((user (retrieve-one :user :by :name := "nitro_idiot" :as (quote hash-table)))) (is-type user (quote hash-table))) (let* ((*default-row-type* (quote hash-table)) (user (retrieve-one :user :by :name := "nitro_idiot"))) (is-type user (quote hash-table))) (let* ((*default-row-type* (quote hash-table)) (user (retrieve-one :user :by :name := "nitro_idiot" :as (quote trivial-types:association-list)))) (is-type user (quote trivial-types:association-list)))) (disconnect let)))