j14i/cl-macros huggingface dataset:
Generate a defmacro form that transforms code like this:
(collecting 'some-name)

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

Macro definition:
(defmacro COLLECTING ...)

Macroexpansion:
(with-collector-output (output)
  (dolist (quote (alexandria:ensure-list some-name))
    (restart-case (output (progn))
      (skip nil "Skip this element"))))
Generate a defmacro form that transforms code like this:
(with-capped-stack () (make-instance 'environment :condition condition))

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

Macro definition:
(defmacro with-capped-stack (() &body body)
  `(stack-capper (lambda () ,@body)))

Macroexpansion:
(stack-capper (lambda nil (make-instance (quote environment) :condition condition)))
Write a Common Lisp macro to handle this code pattern:
(-> :g () 1)

Problem: Macro call that should be transformed by ->

Macro definition:
(defmacro -> (invariant &body args)
  "See flow:atomically"
  `(atomically ,invariant ,@args))

Macroexpansion:
(atomically :g nil 1)
Write a Common Lisp macro to handle this code pattern:
(with-html-string (:body (:h* "This is a top level heading") (:p "...") (:section (:p "...") (:h* "This is a second-level heading") (:p "...") (:h* "This is another second-level heading") (:p "...") (:section (:h* "This is a third-level heading") (:p "...")))))

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

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

Macroexpansion:
(with-output-to-string (*html*) (with-html (:body (:h* "This is a top level heading") (:p "...") (:section (:p "...") (:h* "This is a second-level heading") (:p "...") (:h* "This is another second-level heading") (:p "...") (:section (:h* "This is a third-level heading") (:p "..."))))))
Create a Common Lisp macro for the following transformation. Before code:
(deferror "57P03" cannot-connect-now operator-intervention)

What needs to change: 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 cannot-connect-now (operator-intervention) nil) (setf (gethash "57P03" *error-table*) (quote cannot-connect-now)))
Create a Common Lisp macro for the following transformation. Before code:
(is-type 1 'string)

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

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

Macroexpansion:
(let ((#:desc179 nil) (#:expected-type180 (quote string))) (with-catching-errors (:description #:desc179 :expected #:expected-type180) (with-duration ((#:duration177 #:result178) 1) (test #:result178 #:expected-type180 #:desc179 :duration #:duration177 :got-form (quote 1) :test-fn (function typep) :report-expected-label "be a type of"))))
You are a Common Lisp macro expert. Given this code pattern:
(define-element-maker :group "g" '())

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 :group)) attributes) (declare (ignore element)) (unless (evenp (length attributes)) (warn "attribute list may be missing data: ~A" attributes)) (let ((missing (set-difference (quote nil) attributes))) (when missing (error (quote missing-attributes) :message (format nil "~A missing attributes: ~{~A~^ ~}" :group missing))))) (defmethod make-svg-element ((element (eql :group)) attributes) (when *check-required-attributes* (assert-required-attributes element attributes)) (make-instance (quote svg-element) :name "g" :attributes attributes)))
You are a Common Lisp macro expert. Given this code pattern:
(multiple-value-prog2 (values 1 1 1) (values 2 20 200) (values 3 3 3))

Write a macro that addresses: Macro call that should be transformed by multiple-value-prog2

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

Macroexpansion:
(progn (values 1 1 1) (multiple-value-prog1 (values 2 20 200) (values 3 3 3)))
Create a Common Lisp macro for the following transformation. Before code:
(assoc-cdr :token--endpoint disc)

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

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

Macroexpansion:
(cdr (assoc :token--endpoint disc :test (function eql)))
Define a macro that eliminates this repetitive pattern:
(define-modf-rewrite first (expr) `(car ,(second expr)))

Issue: 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 first) *modf-rewrites*) (lambda (expr) (sb-int:quasiquote (car #S(sb-impl::comma :expr (second expr) :kind 0))))))
Create a Common Lisp macro for the following transformation. Before code:
(ψ 'some-name)

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

Macro definition:
(defmacro Ψ ...)

Macroexpansion:
(mapcar (λ) 'some-name)
You are a Common Lisp macro expert. Given this code pattern:
(define-modf-method pathname-directory 1 (new-val path) (make-pathname :directory new-val :defaults path))

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

Macro definition:
(defmacro define-modf-method (name nth-arg (new-val &rest args) &body body)
  "Define a new modf method.  It inverts NAME forms by modifying the NTH-ARG
term of the arguments of the place form in the MODF macro.  This method can
specialize on any of ARGS."
  ;; Side effect in a macro, I know.  How can you do this via EVAL-WHEN if I
  ;; want it to run even if not a toplevel macro?
  (setf (gethash name *modf-nth-arg*)
        nth-arg)
  `(progn
     (eval-when (:compile-toplevel :load-toplevel :execute)
       (setf (gethash ',name *modf-nth-arg*)
             ,nth-arg))
     (defmethod ,(intern (modf-name name) :modf) (,new-val ,@args)
       ,@body)))

Macroexpansion:
(progn (eval-when (:compile-toplevel :load-toplevel :execute) (setf (gethash (quote pathname-directory) *modf-nth-arg*) 1)) (defmethod |BUILDER:COMMON-LISP:PATHNAME-DIRECTORY| (new-val path) (make-pathname :directory new-val :defaults path)))
Create a Common Lisp macro for the following transformation. Before code:
(defpackage nil)

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

Macro definition:
(defmacro DEFPACKAGE ...)

Macroexpansion:
(common-lisp:defpackage nil
  (:use :adhoc :closer-mop :cl)
  (:shadowing-import-from :closer-mop
                          #:defmethod
                          #:standard-generic-function
                          #:defgeneric
                          #:standard-method
                          #:standard-class)
  (:shadowing-import-from :adhoc #:defpackage #:variable #:the))
You are a Common Lisp macro expert. Given this code pattern:
(defclause (collect expr &optional into var at (place 'end) result-type (type 'list)) "Collect into a list" (return-collection-code :variable var :expression expr :one-element t :start-operation 'cons :end-operation '(subst (var expr) (list expr)) :place place :result-type type))

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

Macro definition:
(defmacro defclause (clause-template &body body)
  (define-clause 'defun clause-template body nil))

Macroexpansion:
(eval-when (:compile-toplevel :load-toplevel :execute) (defun clause-collect-18 (&key ((:collect expr)) ((:into var)) ((:at place) (quote end)) ((:result-type type) (quote list))) "Collect into a list" (return-collection-code :variable var :expression expr :one-element t :start-operation (quote cons) :end-operation (quote (subst (var expr) (list expr))) :place place :result-type type)) (install-clause-info (quote (collect)) (quote (collect &optional :into :at :result-type)) (quote clause-collect-18) "Collect into a list" nil) (quote (collect expr &optional into var at (place (quote end)) result-type (type (quote list)))))
Write a Common Lisp macro to handle this code pattern:
(when (second item) `(declaration-value (make-node ,(second item))))

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 (second item) (sb-int:quasiquote (declaration-value (make-node #S(sb-impl::comma :expr (second item) :kind 0)))))
Create a Common Lisp macro for the following transformation. Before code:
(ct-let nil
  :key
  nil)

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

Macro definition:
(defmacro CT-LET ...)

Macroexpansion:
(cond
 (*within-captured-dynenv*
  (let ()
    (let ((#:new-var-space161
           (reduce
            (lambda (#:accum162 #:item163)
              (destructuring-bind
                  (#:name164 . #:value165)
                  #:item163
                (update-alist #:name164 #:value165 #:accum162)))
            (list) :initial-value *var-space*)))
      `(symbol-macrolet ((var-space ,#:new-var-space161))
         ,(let ((*var-space* #:new-var-space161))
            :key
            nil)))))
 (t
  (error
   "No macrodynamic environment has been captured to establish CT-LET bindings.")))
Create a Common Lisp macro for the following transformation. Before code:
(destructuring-case nil)

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

Macro definition:
(defmacro DESTRUCTURING-CASE ...)

Macroexpansion:
(destructuring-case-alt nil)
Create a Common Lisp macro for the following transformation. Before code:
(defmacro nil ())

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

Macro definition:
(defmacro DEFMACRO ...)

Macroexpansion:
(progn
 (eval-when (:compile-toplevel)
   (sb-c::%compiler-defmacro :macro-function 'nil))
 (eval-when (:compile-toplevel :load-toplevel :execute)
   (sb-c::%defmacro 'nil
                    (sb-int:named-lambda (macro-function nil)
                        (#:expr #:env)
                      (declare (sb-c::lambda-list nil))
                      (declare (ignore #:env))
                      (sb-int:named-ds-bind (:macro nil . defmacro)
                          nil
                          (cdr #:expr)
                        (declare (sb-c::constant-value))))
                    (sb-c:source-location))))
Define a macro that eliminates this repetitive pattern:
(pop-preprocessor-directive-token token-list directive-symbol :errorp nil)

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

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

Macroexpansion:
(let ((#:head_263 (check-and-pop-pp-directive-token-1 token-list directive-symbol nil))) (if (eq +whitespace-marker+ #:head_263) (check-and-pop-pp-directive-token-1 token-list directive-symbol nil) #:head_263))
You are a Common Lisp macro expert. Given this code pattern:
(continue-whopper nil nil)

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

Macro definition:
(defmacro CONTINUE-WHOPPER ...)

Macroexpansion:
(call-next-method-fn self class-env inst-env mcs%caller mcs%next-methods
                     (list nil nil))
Write a Common Lisp macro to handle this code pattern:
(with-local-readtable
  nil
  nil)

Problem: Macro call that should be transformed by WITH-LOCAL-READTABLE

Macro definition:
(defmacro WITH-LOCAL-READTABLE ...)

Macroexpansion:
(bind ((*readtable* (copy-readtable *readtable*)))
  nil
  nil)
Create a Common Lisp macro for the following transformation. Before code:
(with-color (:cyan :stream stream) (format/indent reporter stream "● ~D test~:*~P skipped" skipped-count))

What needs to change: 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 :cyan :gray) (eq :cyan :grey) (eq :cyan +gray+) (eq :cyan +grey+)) (with-gray stream (format/indent reporter stream "● ~D test~:*~P skipped" skipped-count)) (cl-ansi-text:with-color (:cyan :stream stream) (format/indent reporter stream "● ~D test~:*~P skipped" skipped-count))) (progn (format/indent reporter stream "● ~D test~:*~P skipped" skipped-count)))
Define a macro that eliminates this repetitive pattern:
(define-modf-rewrite sixth (expr) `(cadr (cddddr ,(second expr))))

Issue: 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 sixth) *modf-rewrites*) (lambda (expr) (sb-int:quasiquote (cadr (cddddr #S(sb-impl::comma :expr (second expr) :kind 0)))))))
Write a Common Lisp macro to handle this code pattern:
(defclass/a dbd-sqlite3-query (dbi-query) ((store :initarg :store :initform t :accessor sqlite3-use-store)))

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-sqlite3-query (dbi-query) ((store :initarg :store :initform t :accessor sqlite3-use-store))) (deftype <dbd-sqlite3-query> nil (quote dbd-sqlite3-query)) (setf (find-class (quote <dbd-sqlite3-query>)) (find-class (quote dbd-sqlite3-query))))
Generate a defmacro form that transforms code like this:
(bind (((:struct metabang-bind-test-1- (my-a a) c) (make-metabang-bind-test-1 :a 1 :b 2 :c 3))) (list c my-a))

Pattern to recognize: 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-190| (make-metabang-bind-test-1 :a 1 :b 2 :c 3)) (my-a (metabang-bind-test-1-a #:|values-190|)) (c (metabang-bind-test-1-c #:|values-190|))) (declare (ignorable #:|values-190|)) (progn (list c my-a)))
You are a Common Lisp macro expert. Given this code pattern:
(js nil (progn))

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

Macro definition:
(defmacro JS ...)

Macroexpansion:
(ps
  nil
  (progn))
Generate a defmacro form that transforms code like this:
(with-yield-binds (format nil "~A ~{~A~^ ~}" (sql-statement-name (car (composed-statement-statements statement))) (loop for (type original-scoped-clauses) on grouped-clauses by #'cddr collect (let ((scoped-clauses original-scoped-clauses)) (when (and (eq type 'fields-clause) (some (lambda (clause) (and (null (select-statement-table-name (scoped-clause-statement clause))) (some (lambda (field) (string= "*" (typecase field (as-op (sql-symbol-name (as-op-right field))) (sql-symbol (sql-symbol-name field))))) (sql-splicing-list-elements (fields-clause-statement (scoped-clause-clause clause)))))) scoped-clauses)) (setf scoped-clauses (list (make-scoped-clause (make-clause :fields :*) (make-statement :select))))) (setf scoped-clauses (delete-duplicates scoped-clauses :key #'scoped-clause-clause :test #'equalp :from-end t)) (reduce (if has-join-clause-p (lambda (a b) (scoped-merging-yield a b :with-table-names t)) #'scoped-merging-yield) scoped-clauses :initial-value nil)))))

Pattern to recognize: 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 ~{~A~^ ~}" (sql-statement-name (car (composed-statement-statements statement))) (loop for (type original-scoped-clauses) on grouped-clauses by (function cddr) collect (let ((scoped-clauses original-scoped-clauses)) (when (and (eq type (quote fields-clause)) (some (lambda (clause) (and (null (select-statement-table-name (scoped-clause-statement clause))) (some (lambda (field) (string= "*" (typecase field (as-op (sql-symbol-name (as-op-right field))) (sql-symbol (sql-symbol-name field))))) (sql-splicing-list-elements (fields-clause-statement (scoped-clause-clause clause)))))) scoped-clauses)) (setf scoped-clauses (list (make-scoped-clause (make-clause :fields :*) (make-statement :select))))) (setf scoped-clauses (delete-duplicates scoped-clauses :key (function scoped-clause-clause) :test (function equalp) :from-end t)) (reduce (if has-join-clause-p (lambda (a b) (scoped-merging-yield a b :with-table-names t)) (function scoped-merging-yield)) scoped-clauses :initial-value nil))))) (loop for bind in (reverse *bind-values*) append bind)))
Generate a defmacro form that transforms code like this:
(c-assert (member self (kids (fm-parent self))))

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

Macro definition:
(defmacro c-assert (assertion &optional places fmt$ &rest fmt-args)
  (declare (ignorable assertion places fmt$ fmt-args))
   #+(or)`(progn) 
  `(unless *stop*
     (unless ,assertion
       ,(if fmt$
            `(c-break ,fmt$ ,@fmt-args)
          `(c-break "failed assertion: ~a" ',assertion)))))

Macroexpansion:
(unless *stop* (unless (member self (kids (fm-parent self))) (c-break "failed assertion: ~a" (quote (member self (kids (fm-parent self)))))))
Create a Common Lisp macro for the following transformation. Before code:
(with-html-string (:div (:textarea "123")))

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

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

Macroexpansion:
(with-output-to-string (*html*) (with-html (:div (:textarea "123"))))
You are a Common Lisp macro expert. Given this code pattern:
(with-yield (do-generator (x (list->generator data)) (yield x)))

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

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

Macroexpansion:
(let (#:g141 #:g142) (with-call/cc (labels ((yield (&rest values) (setf #:g142 values) (let/cc k (setf #:g141 k)))) (do-generator (x (list->generator data)) (yield x)) (setf #:g141 nil))) (gen-lambda nil (cond ((null #:g141) (quote generator-stop)) (t (let ((current #:g142)) (funcall #:g141 nil) (apply (function values) (funcall values-handler current)))))))