j14i/cl-macros huggingface dataset:
Generate a defmacro form that transforms code like this:
(with-color ((cond ((failed-report-p report) :red) ((skipped-report-p report) :cyan) (T :gray)) :stream stream) (format stream (if (error-report-p report) "x" ".")))

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

Macro definition:
(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)))))

Macroexpansion:
(if *enable-colors* (if (or (eq (cond ((failed-report-p report) :red) ((skipped-report-p report) :cyan) (t :gray)) :gray) (eq (cond ((failed-report-p report) :red) ((skipped-report-p report) :cyan) (t :gray)) :grey) (eq (cond ((failed-report-p report) :red) ((skipped-report-p report) :cyan) (t :gray)) +gray+) (eq (cond ((failed-report-p report) :red) ((skipped-report-p report) :cyan) (t :gray)) +grey+)) (with-gray stream (format stream (if (error-report-p report) "x" "."))) (cl-ansi-text:with-color ((cond ((failed-report-p report) :red) ((skipped-report-p report) :cyan) (t :gray)) :stream stream) (format stream (if (error-report-p report) "x" ".")))) (progn (format stream (if (error-report-p report) "x" "."))))
Create a Common Lisp macro for the following transformation. Before code:
(with-yield-binds (format nil "(~{~A~^ ~})" (mapcar #'yield (sql-expression-list-elements list))))

What needs to change: Macro call that should be transformed by with-yield-binds

Macro definition:
(defmacro with-yield-binds (&body body)
  `(let ((*bind-values* nil)
         (*use-global-bind-values* t))
     (values
      (progn ,@body)
      (loop for bind in (reverse *bind-values*)
            append bind))))

Macroexpansion:
(let ((*bind-values* nil) (*use-global-bind-values* t)) (values (progn (format nil "(~{~A~^ ~})" (mapcar (function yield) (sql-expression-list-elements list)))) (loop for bind in (reverse *bind-values*) append bind)))
Write a Common Lisp macro to handle this code pattern:
(mvlet nil
  (progn))

Problem: Macro call that should be transformed by MVLET

Macro definition:
(defmacro MVLET ...)

Macroexpansion:
(progn (progn))
Generate a defmacro form that transforms code like this:
(define-direct-clause repeat (n) (let ((limit (gensym "LIMIT")) (counter (gensym "COUNTER"))) (values `(let ((,limit ,n) (,counter 0))) `(when (<= ,limit (incf ,counter)) (end-for)))))

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

Macro definition:
(defmacro define-direct-clause (name args &body body)
  (let ((env (or (lambda-fiddle:environment-lambda-var args) (gensym "ENVIRONMENT"))))
    `(progn (setf (clause ',name)
                  (lambda ,(lambda-fiddle:remove-environment-part args)
                    (let ((,env *environment*))
                      (declare (ignorable ,env))
                      ,@body)))
            ',name)))

Macroexpansion:
(progn (setf (clause (quote repeat)) (lambda (n) (let ((#:environment183 *environment*)) (declare (ignorable #:environment183)) (let ((limit (gensym "LIMIT")) (counter (gensym "COUNTER"))) (values (sb-int:quasiquote (let ((#S(sb-impl::comma :expr limit :kind 0) #S(sb-impl::comma :expr n :kind 0)) (#S(sb-impl::comma :expr counter :kind 0) 0)))) (sb-int:quasiquote (when (<= #S(sb-impl::comma :expr limit :kind 0) (incf #S(sb-impl::comma :expr counter :kind 0))) (end-for)))))))) (quote repeat))
Define a macro that eliminates this repetitive pattern:
(bind (((:structure metabang-bind-test-1- (my-a a) c) (make-metabang-bind-test-1 :a 1 :b 2 :c 3))) (list c my-a))

Issue: Macro call that should be transformed by bind

Macro definition:
(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))))

Macroexpansion:
(let* ((#:|values-191| (make-metabang-bind-test-1 :a 1 :b 2 :c 3)) (my-a (metabang-bind-test-1-a #:|values-191|)) (c (metabang-bind-test-1-c #:|values-191|))) (declare (ignorable #:|values-191|)) (progn (list c my-a)))
Write a Common Lisp macro to handle this code pattern:
(deferror "22021" invalid-byte-sequence data-exception)

Problem: Macro call that should be transformed by deferror

Macro definition:
(defmacro deferror (code typename &optional (superclass 'database-error))
  `(progn (define-condition ,typename (,superclass) ())
          (setf (gethash ,code *error-table*) ',typename)))

Macroexpansion:
(progn (define-condition invalid-byte-sequence (data-exception) nil) (setf (gethash "22021" *error-table*) (quote invalid-byte-sequence)))
Define a macro that eliminates this repetitive pattern:
(with-prepared-query query (conn "SELECT last_insert_id() AS last_insert_id") (or (first (dbi:fetch (dbi:execute query) :format :values)) 0))

Issue: Macro call that should be transformed by with-prepared-query

Macro definition:
(defmacro with-prepared-query (query (conn sql &key use-prepare-cached) &body body)
  `(call-with-prepared-query ,conn ,sql (lambda (,query) ,@body) :use-prepare-cached ,use-prepare-cached))

Macroexpansion:
(call-with-prepared-query conn "SELECT last_insert_id() AS last_insert_id" (lambda (query) (or (first (dbi.driver:fetch (dbi.driver:execute query) :format :values)) 0)) :use-prepare-cached nil)
Write a Common Lisp macro to handle this code pattern:
(->> (v) (flow-gen v))

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

Macro definition:
(defmacro ->> (lambda-list &body body)
  "See flow:dynamically"
  `(dynamically ,lambda-list
     ,@body))

Macroexpansion:
(dynamically (v) (flow-gen v))
Define a macro that eliminates this repetitive pattern:
(defvar nil nil)

Issue: Macro call that should be transformed by DEFVAR

Macro definition:
(defmacro DEFVAR ...)

Macroexpansion:
(progn
 (eval-when (:compile-toplevel) (sb-impl::%compiler-defvar 'nil))
 (sb-impl::%defvar 'nil (sb-c:source-location) 'nil))
Define a macro that eliminates this repetitive pattern:
(define-bug name-clash (:error-type varjo-critical-error) (lisp glsl) "The glsl name ~s was generated for the lisp-name ~s However this name was already taken. This is Varjo bug, please raise an issue on github. Sorry for the inconvenience" glsl lisp)

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

Macro definition:
(defmacro define-bug (name (&key (error-type 'varjo-error) (prefix "Varjo Bug"))
                            (&rest args) error-string &body body)
  `(defcondition ,name (:error-type ,error-type :prefix ,prefix) ,args
       ,error-string ,@body))

Macroexpansion:
(defcondition name-clash (:error-type varjo-critical-error :prefix "Varjo Bug") (lisp glsl) "The glsl name ~s was generated for the lisp-name ~s However this name was already taken. This is Varjo bug, please raise an issue on github. Sorry for the inconvenience" glsl lisp)
Generate a defmacro form that transforms code like this:
(mvlet nil)

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

Macro definition:
(defmacro MVLET ...)

Macroexpansion:
(progn)
Generate a defmacro form that transforms code like this:
(with-preprocessor-state-slots (state) (push if-section-obj if-section-stack) (when (and (null if-section-skip-reason) (not eval-result)) (setf if-section-skip-reason if-section-obj)))

Pattern to recognize: Macro call that should be transformed by with-preprocessor-state-slots

Macro definition:
(defmacro with-preprocessor-state-slots ((state) &body body)
  `(with-accessors ((file-pathname pp-state-file-pathname)
                    (token-list pp-state-token-list)
                    (result-list pp-state-result-list)
                    (line-number pp-state-line-number)
                    (tokens-in-line pp-state-tokens-in-line)
                    (macro-alist pp-state-macro-alist)
                    (if-section-stack pp-state-if-section-stack)
                    (if-section-skip-reason pp-state-if-section-skip-reason)
                    (include-stack pp-state-include-stack))
       ,state
     ,@body))

Macroexpansion:
(with-accessors ((file-pathname pp-state-file-pathname) (token-list pp-state-token-list) (result-list pp-state-result-list) (line-number pp-state-line-number) (tokens-in-line pp-state-tokens-in-line) (macro-alist pp-state-macro-alist) (if-section-stack pp-state-if-section-stack) (if-section-skip-reason pp-state-if-section-skip-reason) (include-stack pp-state-include-stack)) state (push if-section-obj if-section-stack) (when (and (null if-section-skip-reason) (not eval-result)) (setf if-section-skip-reason if-section-obj)))
Create a Common Lisp macro for the following transformation. Before code:
(ensure-gethash x table 13)

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

Macro definition:
(defmacro ensure-gethash (key hash-table &optional default)
  "Like GETHASH, but if KEY is not found in the HASH-TABLE saves the DEFAULT
under key before returning it. Secondary return value is true if key was
already in the table."
  (once-only (key hash-table)
    (with-unique-names (value presentp)
      `(multiple-value-bind (,value ,presentp) (gethash ,key ,hash-table)
         (if ,presentp
             (values ,value ,presentp)
             (values (setf (gethash ,key ,hash-table) ,default) nil))))))

Macroexpansion:
(let ((#:n-key-163 x) (#:n-hash-table-164 table)) (multiple-value-bind (#:value165 #:foundp166) (gethash #:n-key-163 #:n-hash-table-164) (if #:foundp166 (values #:value165 t) (values (setf (gethash #:n-key-163 #:n-hash-table-164) 13) nil))))
Write a Common Lisp macro to handle this code pattern:
(define-mustache-character #\^ (make-instance 'section-start-tag :text arg-text :end end :falsey t))

Problem: Macro call that should be transformed by define

Macro definition:
(defmacro define (name template)
  "Define a named renderer of string TEMPLATE."
  `(setf (symbol-function ',name)
         (compile-template ,template)))

Macroexpansion:
(set-mustache-character #\CIRCUMFLEX_ACCENT (lambda (raw-text arg-text escapep start end) (declare (ignorable raw-text arg-text escapep start end) (type simple-string raw-text arg-text) (boolean escapep) (offset start end)) (make-instance (quote section-start-tag) :text arg-text :end end :falsey t)))
Generate a defmacro form that transforms code like this:
(define-c-syntax-reader-for-each-case-mode c-reader-level-1)

Pattern to recognize: Macro call that should be transformed by define-c-syntax-reader-for-each-case-mode

Macro definition:
(defmacro define-c-syntax-reader-for-each-case-mode (base-readtable-name)
  (check-type base-readtable-name symbol)
  (loop with case-modes = '(:upcase :downcase :preserve :invert)
        for mode in case-modes
        as name = (format-symbol :with-c-syntax.core "~A-~A" base-readtable-name mode)
        collect `(defreadtable ,name
                   (:merge ,base-readtable-name)
                   (:case ,mode))
          into bodies
        finally
           (return `(progn ,@bodies))))

Macroexpansion:
(progn (defreadtable c-reader-level-1-upcase (:merge c-reader-level-1) (:case :upcase)) (defreadtable c-reader-level-1-downcase (:merge c-reader-level-1) (:case :downcase)) (defreadtable c-reader-level-1-preserve (:merge c-reader-level-1) (:case :preserve)) (defreadtable c-reader-level-1-invert (:merge c-reader-level-1) (:case :invert)))
Write a Common Lisp macro to handle this code pattern:
(flet* nil
  nil)

Problem: Macro call that should be transformed by FLET*

Macro definition:
(defmacro FLET* ...)

Macroexpansion:
(flet ()
  nil)
Create a Common Lisp macro for the following transformation. Before code:
(defclause list-tails (&whole form list &key (by '(function cdr)) &environment env) "Loops over the successive tails of a list, checking for the end of the list as if by ATOM. Can perform destructuring." (if (symbolp *iteration-variable*) (let ((g (gensym))) (list (make-simple-iteration :var *iteration-variable* :init list :step `(funcall ,by ,*iteration-variable*)) (make-simple-iteration :var g :init nil :step nil :precondition `(not (atom ,*iteration-variable*))))) (expand-with-simple-destructuring form env)))

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

Macro definition:
(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*)))

Macroexpansion:
(progn (defmacro list-tails (&whole form list &key (by (quote (function cdr))) &environment env) "Loops over the successive tails of a list, checking for the end of the list as if by ATOM. Can perform destructuring." (if (symbolp *iteration-variable*) (let ((g (gensym))) (list (make-simple-iteration :var *iteration-variable* :init list :step (sb-int:quasiquote (funcall #S(sb-impl::comma :expr by :kind 0) #S(sb-impl::comma :expr *iteration-variable* :kind 0)))) (make-simple-iteration :var g :init nil :step nil :precondition (sb-int:quasiquote (not (atom #S(sb-impl::comma :expr *iteration-variable* :kind 0))))))) (expand-with-simple-destructuring form env))) (pushnew (quote list-tails) *clauses*))
Generate a defmacro form that transforms code like this:
(match list ((list x) (if (oddp x) x (fail))))

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

Macro definition:
(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))

Macroexpansion:
(%or (%if (consp list) (let ((#:g144 (car list)) (#:g145 (cdr list))) (declare (ignorable #:g144 #:g145)) (%if (%equals #:g145 nil) (%or (let ((x #:g144)) (if (oddp x) x (fail))) (fail)) (fail))) (fail)) nil)
Write a Common Lisp macro to handle this code pattern:
(->> nil)

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

Macro definition:
(defmacro ->> ...)

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

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

Macro definition:
(defmacro DICT-OF ...)

Macroexpansion:
(let ((#:dict128 (make-hash-table :test 'equal)))
  (do-for ((progn))
    (multiple-value-call
        (lambda (#:k129 #:v130) (setf (gethash #:k129 #:dict128) #:v130))
      nil))
  #:dict128)
Create a Common Lisp macro for the following transformation. Before code:
(with-properties nil
    :key
  nil)

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

Macro definition:
(defmacro WITH-PROPERTIES ...)

Macroexpansion:
(let ((#:g135 :key))
  (symbol-macrolet ()
    nil))
Create a Common Lisp macro for the following transformation. Before code:
(defprotocol nil)

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

Macro definition:
(defmacro DEFPROTOCOL ...)

Macroexpansion:
(progn
 (progn
  (eval-when (:compile-toplevel :load-toplevel :execute)
    (%build-protocol-object (%ensure-protocol-compilation-note 'nil) 'nil)
    (defun nil-p (object)
      #A((29) base-char . "test if object implements NIL")
      (implements-protocol? object (ensure-protocol 'nil)))
    (deftype nil () nil '(satisfies nil-p)))
  (let ((#:g131 (ensure-protocol 'nil)))
    (%build-protocol-object #:g131 'nil)
    (setf (protocol-includes-generic-pun #:g131) nil
          (protocol-includes-method-pun #:g131) nil))))
You are a Common Lisp macro expert. Given this code pattern:
(define-custom-var (:object-key *object-key-handler*) (constantly t) "Designator for a function of 1 string argument (decoded member key of Object).")

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

Macro definition:
(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))))

Macroexpansion:
(eval-when (:compile-toplevel :load-toplevel :execute) (progn (pushnew (quote (*object-key-handler* . :object-key)) *custom-vars* :test (function equal)) (defvar *object-key-handler* (constantly t) "Designator for a function of 1 string argument (decoded member key of Object).")))
Generate a defmacro form that transforms code like this:
(dlet* nil)

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

Macro definition:
(defmacro DLET* ...)

Macroexpansion:
(dynamic-let* nil)
Create a Common Lisp macro for the following transformation. Before code:
(do-all-namespaces 'some-name)

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

Macro definition:
(defmacro DO-ALL-NAMESPACES ...)

Macroexpansion:
(do-namespace (namespace _ quote some-name))
Create a Common Lisp macro for the following transformation. Before code:
(if-let ((x 1) (y nil)) :oops (and (not y) x))

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

Macro definition:
(defmacro if-let (bindings &body (then-form &optional else-form))
    "Creates new variable bindings, and conditionally executes either
THEN-FORM or ELSE-FORM. ELSE-FORM defaults to NIL.

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, the THEN-FORM is executed with the
bindings in effect, otherwise the ELSE-FORM is executed with the bindings in
effect."
    (let* ((binding-list (if (and (consp bindings) (symbolp (car bindings)))
                             (list bindings)
                             bindings))
         (variables (mapcar #'car binding-list)))
    `(let ,binding-list
       (if (and ,@variables)
           ,then-form
           ,else-form))))

Macroexpansion:
(let ((x 1) (y nil)) (if (and x y) :oops (and (not y) x)))
You are a Common Lisp macro expert. Given this code pattern:
(subtest "Outer testcase with multiline description." (is 'blah 'blah "Blah with multiline description!") (subtest "Inner testcase with multiline description." (is 'foo 'foo "Foo with multiline description!")))

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

Macro definition:
(defmacro subtest (desc &body body)
  `(%subtest ,desc (lambda () ,@body)))

Macroexpansion:
(%subtest "Outer testcase with multiline description." (lambda nil (is (quote blah) (quote blah) "Blah with multiline description!") (subtest "Inner testcase with multiline description." (is (quote foo) (quote foo) "Foo with multiline description!"))))
You are a Common Lisp macro expert. Given this code pattern:
(define-op (:union conjunctive-op))

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

Macro definition:
(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)))

Macroexpansion:
(defstruct (union-op (:include conjunctive-op (name "UNION")) (:constructor make-union-op (&rest expressions))))