j14i/cl-macros huggingface dataset:
Generate a defmacro form that transforms code like this:
(with-color (:red :stream stream) (format/indent reporter stream "× ~D of ~D test~:*~P failed" failed-count count))

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 :red :gray) (eq :red :grey) (eq :red +gray+) (eq :red +grey+)) (with-gray stream (format/indent reporter stream "× ~D of ~D test~:*~P failed" failed-count count)) (cl-ansi-text:with-color (:red :stream stream) (format/indent reporter stream "× ~D of ~D test~:*~P failed" failed-count count))) (progn (format/indent reporter stream "× ~D of ~D test~:*~P failed" failed-count count)))
Create a Common Lisp macro for the following transformation. Before code:
(collect-max nil nil)

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

Macro definition:
(defmacro COLLECT-MAX ...)

Macroexpansion:
(common-lisp:let* ((#:generator-353 (generator nil))
                   #:items-343
                   (#:generator-351 (generator nil))
                   #:numbers-342
                   (#:number-345 nil)
                   #:result-346)
  (declare (type generator #:generator-353)
           (type generator #:generator-351)
           (type (null-or t) #:result-346))
  (tagbody
   #:ll-354
    (setq #:items-343 (next-in #:generator-353 (go end)))
    (setq #:numbers-342 (next-in #:generator-351 (go end)))
    (if (or (null #:number-345) (< #:number-345 #:numbers-342))
        (setq #:number-345 #:numbers-342
              #:result-346 #:items-343))
    (go #:ll-354)
   end)
  (if (null #:number-345)
      (setq #:result-346 nil))
  #:result-346)
You are a Common Lisp macro expert. Given this code pattern:
(defun-speedy make-random-string (&optional (length 12)) (declare (type fixnum length)) (let ((result (make-string length))) (declare (type simple-string result)) (dotimes (i length result) (setf (aref result i) (ecase (random 5) ((0 1) (code-char (+ #.(char-code #\a) (random 26)))) ((2 3) (code-char (+ #.(char-code #\A) (random 26)))) ((4) (code-char (+ #.(char-code #\0) (random 10)))))))))

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

Macro definition:
(defmacro defun-speedy (name lambda-list &body body)
  `(progn
     (declaim (notinline ,name))
     (defun ,name ,lambda-list
       ,*speedy-declaration*
       ,@body)))

Macroexpansion:
(progn (declaim (notinline make-random-string)) (defun make-random-string (&optional (length 12)) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0))) (declare (type fixnum length)) (let ((result (make-string length))) (declare (type simple-string result)) (dotimes (i length result) (setf (aref result i) (ecase (random 5) ((0 1) (code-char (+ 97 (random 26)))) ((2 3) (code-char (+ 65 (random 26)))) ((4) (code-char (+ 48 (random 10))))))))))
Define a macro that eliminates this repetitive pattern:
(subtest "Subtest" (diag "in subtest") (is #\a #\a) (like "truth" "^true"))

Issue: Macro call that should be transformed by subtest

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

Macroexpansion:
(%subtest "Subtest" (lambda nil (diag "in subtest") (is #\LATIN_SMALL_LETTER_A #\LATIN_SMALL_LETTER_A) (like "truth" "^true")))
You are a Common Lisp macro expert. Given this code pattern:
(with-symbol-access
  'some-name)

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

Macro definition:
(defmacro WITH-SYMBOL-ACCESS ...)

Macroexpansion:
(let ((*symbol-access* t))
  'some-name)
Generate a defmacro form that transforms code like this:
(dynamic-relet* nil
  nil)

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

Macro definition:
(defmacro DYNAMIC-RELET* ...)

Macroexpansion:
(progn nil)
Write a Common Lisp macro to handle this code pattern:
(defclass/a dbd-null-query (cl-dbi:dbi-query) ())

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

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

Macroexpansion:
(progn (defclass dbd-null-query (dbi.driver:dbi-query) nil) (deftype <dbd-null-query> nil (quote dbd-null-query)) (setf (find-class (quote <dbd-null-query>)) (find-class (quote dbd-null-query))))
Write a Common Lisp macro to handle this code pattern:
(when (and (node-slot type) (not (eql info 'cast-expression)) (not (eql info 'funcall)) (not (eql info 'declaration-item))) (format stream " "))

Problem: Macro call that should be transformed by when

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

Macroexpansion:
(if (and (node-slot type) (not (eql info (quote cast-expression))) (not (eql info (quote funcall))) (not (eql info (quote declaration-item)))) (format stream " "))
Write a Common Lisp macro to handle this code pattern:
(iterate nil nil)

Problem: Macro call that should be transformed by ITERATE

Macro definition:
(defmacro ITERATE ...)

Macroexpansion:
(progn (tagbody #:ll-249 ((lambda () nil)) (go #:ll-249)) nil)
Generate a defmacro form that transforms code like this:
(class/std employee name id salary)

Pattern to recognize: Macro call that should be transformed by class/std

Macro definition:
(defmacro class/std (name &body defaulted-slots)
  "The most concise shortcut macro to DEFCLASS.

  (class/std example slot1 slot2 slot3)

  expands to:

  (DEFCLASS/STD EXAMPLE ()
    ((SLOT1 SLOT2 SLOT3)))

  which expands to:

  (DEFCLASS EXAMPLE ()
    ((SLOT1 :ACCESSOR SLOT1 :INITARG :SLOT1 :INITFORM NIL)
    (SLOT2 :ACCESSOR SLOT2 :INITARG :SLOT2 :INITFORM NIL)
    (SLOT3 :ACCESSOR SLOT3 :INITARG :SLOT3 :INITFORM NIL)))
"
  `(defclass/std ,name ()
     ((,@defaulted-slots))))

Macroexpansion:
(defclass/std employee nil ((name id salary)))
Generate a defmacro form that transforms code like this:
(action (:after node-lisp node bound-variables) (when (and (member target bound-variables :test #'eq) (loop :for (_ . coalton-var) :in (node-lisp-vars node) :thereis (and (eq name coalton-var) (not (member name bound-variables :test #'eq))))) (setf unsafe? t)) (values))

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

Macro definition:
(defmacro action ((when type &rest args) &body body)
  "Construct an action block, turning `body` into a lambda function
accepting `args` if `args` are provided. If there are no `args`, then
`body` is assumed to be a function object and is used directly with
`when` and `type` to create an `action` instance. Otherwise, the first
argument in `args` is declared to be a node of type `type`, and the
`args` and `body` are used to generate a lambda function."
  (check-type when keyword)
  (check-type type symbol)
  (assert (subtypep type 'node))
  (assert (or (not (endp args)) (= 1 (length body))))
  (if (endp args)
      `(make-action ',when ',type ,@body)
      `(make-action ',when ',type
                    (lambda (,@args)
                      (declare (type ,type ,(first args)))
                      ,@body))))

Macroexpansion:
(make-action (quote :after) (quote node-lisp) (lambda (node bound-variables) (declare (type node-lisp node)) (when (and (member target bound-variables :test (function eq)) (loop :for (_ . coalton-var) :in (node-lisp-vars node) :thereis (and (eq name coalton-var) (not (member name bound-variables :test (function eq)))))) (setf unsafe? t)) (values)))
Create a Common Lisp macro for the following transformation. Before code:
(define-error merge-env-parent-mismatch () (env-a env-b) "Attempting to merge two environments with different parent environments ~s~%~s~%~s" (cons (v-parent-env env-a) (v-parent-env env-b)) env-a env-b)

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

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

Macroexpansion:
(defcondition merge-env-parent-mismatch (:error-type varjo-error :prefix "Varjo") (env-a env-b) "Attempting to merge two environments with different parent environments ~s~%~s~%~s" (cons (v-parent-env env-a) (v-parent-env env-b)) env-a env-b)
Define a macro that eliminates this repetitive pattern:
(->*
  'some-name)

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

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

Macroexpansion:
'some-name
Write a Common Lisp macro to handle this code pattern:
(bind (((:plist a (b _) (c _ 2) (dd d)) '(:b "B" :a "A" :d "D"))) (list a b c dd))

Problem: 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-164| (quote (:b "B" :a "A" :d "D"))) (a (getf #:|values-164| :a)) (b (getf #:|values-164| :b)) (c (getf #:|values-164| :c 2)) (dd (getf #:|values-164| :d))) (declare (ignorable #:|values-164|)) (progn (list a b c dd)))
Generate a defmacro form that transforms code like this:
(with-active-layers* nil
  nil)

Pattern to recognize: Macro call that should be transformed by WITH-ACTIVE-LAYERS*

Macro definition:
(defmacro WITH-ACTIVE-LAYERS* ...)

Macroexpansion:
(progn nil)
Write a Common Lisp macro to handle this code pattern:
(builder (:session :store (make-dbi-store :connector (lambda () *conn*))) (lambda (env) (unless (gethash :user (getf env :lack.session)) (setf (gethash :user (getf env :lack.session)) "深町英太郎")) (unless (gethash :counter (getf env :lack.session)) (setf (gethash :counter (getf env :lack.session)) 0)) `(200 (:content-type "text/plain") (,(format nil "Hello, ~A! You've been here for ~Ath times!" (gethash :user (getf env :lack.session)) (incf (gethash :counter (getf env :lack.session))))))))

Problem: Macro call that should be transformed by builder

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

Macroexpansion:
(reduce (function funcall) (remove-if (function null) (list (lambda (#:app234) (funcall (find-middleware :session) #:app234 :store (make-dbi-store :connector (lambda nil *conn*)))))) :initial-value (to-app (lambda (env) (unless (gethash :user (getf env :lack.session)) (setf (gethash :user (getf env :lack.session)) "深町英太郎")) (unless (gethash :counter (getf env :lack.session)) (setf (gethash :counter (getf env :lack.session)) 0)) (sb-int:quasiquote (200 (:content-type "text/plain") (#S(sb-impl::comma :expr (format nil "Hello, ~A! You've been here for ~Ath times!" (gethash :user (getf env :lack.session)) (incf (gethash :counter (getf env :lack.session)))) :kind 0)))))) :from-end t)
Create a Common Lisp macro for the following transformation. Before code:
(define-test failing (true (< 8 5)) (fail 'happy) (true (= 5 (read-from-string "OH-SHIT"))))

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

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

Macroexpansion:
(let ((*package* (find-package #A((9) base-char . "PARACHUTE")))) (setf (find-test (quote failing) (find-package #A((9) base-char . "PARACHUTE"))) (ensure-test (quote test) :name (quote failing) :home (find-package #A((9) base-char . "PARACHUTE")) :tests (list (lambda nil (true (< 8 5))) (lambda nil (fail (quote happy))) (lambda nil (true (= 5 (read-from-string "OH-SHIT"))))) :parent (quote nil))) (quote failing))
You are a Common Lisp macro expert. Given this code pattern:
(newq nil :key nil)

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

Macro definition:
(defmacro NEWQ ...)

Macroexpansion:
(new 'nil :key nil)
Define a macro that eliminates this repetitive pattern:
(cond->> nil)

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

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

Macroexpansion:
(let* ((#:|cond135| nil))
  #:|cond135|)
You are a Common Lisp macro expert. Given this code pattern:
(collect-first nil (progn))

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

Macro definition:
(defmacro COLLECT-FIRST ...)

Macroexpansion:
(common-lisp:let* ((#:generator-632 (generator nil))
                   #:items-626
                   (#:item-628 (progn)))
  (declare (type generator #:generator-632)
           (type (null-or t) #:item-628))
  (tagbody
   #:ll-633
    (setq #:items-626 (next-in #:generator-632 (go end)))
    (setq #:item-628 #:items-626)
   end)
  #:item-628)
Create a Common Lisp macro for the following transformation. Before code:
(when-let (previous *log-manager*) (dolist (messenger (log-manager-messengers previous)) (stop-messenger messenger)))

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

Macro definition:
(defmacro when-let (binding &body body)
  (destructuring-bind (var val) binding
    `(let ((,var ,val))
       (when ,var
	 ,@body))))

Macroexpansion:
(let ((previous *log-manager*)) (when previous (dolist (messenger (log-manager-messengers previous)) (stop-messenger messenger))))
Create a Common Lisp macro for the following transformation. Before code:
(defun/1 fmod (x y) (mod x y))

What needs to change: Macro call that should be transformed by defun/1

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

Macroexpansion:
(progn (defun fmod (x y) (declare (optimize (speed 0) (debug 3) (sb-ext:inhibit-warnings 3))) (mod x y)) (defparameter fmod (vacietis.c:mkptr& (symbol-function (quote fmod)))))
You are a Common Lisp macro expert. Given this code pattern:
(define-condition/a dbi-integrity-error (dbi-database-error) () (:documentation "Exception raised when the relational integrity of the database is affected, e.g. a foreign key check fails."))

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

Macro definition:
(defmacro define-condition/a (name parent-types slots &body options)
  `(progn
     (define-condition ,name ,parent-types ,slots ,@options)
     (deftype ,(intern (format nil "<~A>" (symbol-name name))) () ',name)
     (setf (find-class ',(intern (format nil "<~A>" (symbol-name name))))
           (find-class ',name))))

Macroexpansion:
(progn (define-condition dbi-integrity-error (dbi-database-error) nil (:documentation "Exception raised when the relational integrity of the database is affected, e.g. a foreign key check fails.")) (deftype <dbi-integrity-error> nil (quote dbi-integrity-error)) (setf (find-class (quote <dbi-integrity-error>)) (find-class (quote dbi-integrity-error))))
Write a Common Lisp macro to handle this code pattern:
(product-of nil
  (progn))

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

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

Macroexpansion:
(lc (nil (progn)) multiply)
You are a Common Lisp macro expert. Given this code pattern:
(define-element-maker :line "line" '(:x1 :y1 :x2 :y2))

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

Macro definition:
(defmacro define-element-maker (element name required-attributes)
  `(progn
     (defmethod assert-required-attributes ((element (eql ,element)) attributes)
       (declare (ignore element))
       (unless (evenp (length attributes))
         (warn "attribute list may be missing data: ~A" attributes))
       (let ((missing (set-difference ,required-attributes attributes)))
	 (when missing
	   (error 'missing-attributes :message (format nil "~A missing attributes: ~{~A~^ ~}" ,element missing)))))
     (defmethod make-svg-element ((element (eql ,element)) attributes)
       (when *check-required-attributes*
         (assert-required-attributes element attributes))
       (make-instance 'svg-element :name ,name :attributes attributes))))

Macroexpansion:
(progn (defmethod assert-required-attributes ((element (eql :line)) attributes) (declare (ignore element)) (unless (evenp (length attributes)) (warn "attribute list may be missing data: ~A" attributes)) (let ((missing (set-difference (quote (:x1 :y1 :x2 :y2)) attributes))) (when missing (error (quote missing-attributes) :message (format nil "~A missing attributes: ~{~A~^ ~}" :line missing))))) (defmethod make-svg-element ((element (eql :line)) attributes) (when *check-required-attributes* (assert-required-attributes element attributes)) (make-instance (quote svg-element) :name "line" :attributes attributes)))
Generate a defmacro form that transforms code like this:
(make-$instance nil (progn))

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

Macro definition:
(defmacro MAKE-$INSTANCE ...)

Macroexpansion:
(let ((class (symbol-value nil)))
  (funcall (mcs-slot-value class (index-of-basicnew-fn)) class (progn)))
Define a macro that eliminates this repetitive pattern:
(fn nil)

Issue: Macro call that should be transformed by FN

Macro definition:
(defmacro FN ...)

Macroexpansion:
(lambda () nil)
Generate a defmacro form that transforms code like this:
(define-modf-rewrite cddar (expr) `(cdr (cdar ,(second expr))))

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

Macro definition:
(defmacro define-modf-rewrite (name (expr) &body body)
  "Define a new rewrite rule.  If a form starting with NAME is encountered, call
the defined function to return a form that we can deal with (i.e. one defined
via DEFINE-MODF-EXPANDER, DEFINE-MODF-FUNCTION, and DEFINE-MODF-METHOD)."
  `(eval-when (:compile-toplevel :load-toplevel :execute)
     (setf (gethash ',name *modf-rewrites*)
           (lambda (,expr)
             ,@body))))

Macroexpansion:
(eval-when (:compile-toplevel :load-toplevel :execute) (setf (gethash (quote cddar) *modf-rewrites*) (lambda (expr) (sb-int:quasiquote (cdr (cdar #S(sb-impl::comma :expr (second expr) :kind 0)))))))
Generate a defmacro form that transforms code like this:
(cond->>
  nil
  (progn))

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

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

Macroexpansion:
(let* ((#:var164 nil)
       (#:var165
        (if progn
            (->>
              #:var164)
            #:var164)))
  #:var165)
Generate a defmacro form that transforms code like this:
(some-<> nil :key nil)

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

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

Macroexpansion:
(let* ((#:g123 nil)
       (#:g123
        (if (null #:g123)
            nil
            (:key #:g123))))
  (if (null #:g123)
      nil
      (-> #:g123 nil)))
Create a Common Lisp macro for the following transformation. Before code:
(ignore-errors 'some-name)

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

Macro definition:
(defmacro IGNORE-ERRORS ...)

Macroexpansion:
(handler-case (progn 'some-name) (error (condition) (values nil condition)))