j14i/cl-macros huggingface dataset:
Generate a defmacro form that transforms code like this:
(do-sequences! ((place seq :start start :end end) (new new)) (setf place new))

Pattern to recognize: Macro call that should be transformed by do-sequences

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

Macroexpansion:
(do-sequences!-fast% nil ((place seq :start start :end end) (new new)) (setf place new))
Define a macro that eliminates this repetitive pattern:
(->
  nil
  (progn))

Issue: Macro call that should be transformed by ->

Macro definition:
(defmacro -> ...)

Macroexpansion:
(let* ((#:var150 nil) (#:var151 (progn #:var150)))
  #:var151)
Create a Common Lisp macro for the following transformation. Before code:
(define-condition/a dbi-already-rolled-back-error (dbi-error) () (:documentation "This exception occur when there is a programming error and you are trying to rollback a transaction twice."))

What needs to change: 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-already-rolled-back-error (dbi-error) nil (:documentation "This exception occur when there is a programming error and you are trying to rollback a transaction twice.")) (deftype <dbi-already-rolled-back-error> nil (quote dbi-already-rolled-back-error)) (setf (find-class (quote <dbi-already-rolled-back-error>)) (find-class (quote dbi-already-rolled-back-error))))
You are a Common Lisp macro expert. Given this code pattern:
;; Common pattern: read a value, apply a function, store back
(let ((old (car place)))
  (setf (car place) (1+ old)))

;; Or with a more complex place:
(let ((old (getf plist :count)))
  (setf (getf plist :count) (* old 2)))

;; Every operation needs manual read-modify-write boilerplate

Write a macro that addresses: Read-modify-write on places requires manual let + access + setf — want a single operator that applies any function to a place

Macro definition:
(defmacro _f (op place &rest args)
  (multiple-value-bind (vars forms var set access)
                       (get-setf-method place)
    `(let* (,@(mapcar #'list vars forms)
            (,(car var) (,op ,access ,@args)))
       ,set)))

Macroexpansion:
;; (_f 1+ (car place))
;; (_f #'* (getf plist :count) 2)
;;
;; _f applies the function to the place's current value (and any extra args)
;; and stores the result back. Works with ANY setf-able place.
;;
;; (_f 1+ x)      ≡ (incf x) but generalized
;; (_f #'cons x y) ≡ (push y x)
;;
;; Uses get-setf-method for full setf integration.
Generate a defmacro form that transforms code like this:
(defclass test-parent () ((a :accessor a-of :initarg :a)))

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

Macro definition:
(defmacro defclass (name direct-superclasses direct-slots &rest options)
  "Define Modf expansions for class slot accessor and reader methods."
  ;; We need the names of all methods that access data in the object and what
  ;; slot they are associated with.
  `(progn
     (cl:defclass ,name ,direct-superclasses ,direct-slots ,@options)
     ,@(iter :outer
         (for slot in direct-slots)
         (let ((slot-name (if (atom slot) slot (first slot))))
           (iter (for accessor in (remove-if-not
                                   (lambda (x) (member
                                           (first x)
                                           '(:accessor :reader)))
                                   (group-by (rest slot) 2)))
             (in :outer
                 (collecting
                  `(define-modf-method ,(second accessor) 1
                       (new-val (obj ,name))
                     (modf (slot-value obj ',slot-name) new-val)))))))))

Macroexpansion:
(progn (eval-when (:compile-toplevel) (sb-kernel::%compiler-defclass (quote test-parent) (quote (a-of)) (quote ((setf a-of))) (quote (a)))) (let nil (sb-pcl::load-defclass (quote test-parent) (quote standard-class) (quote nil) (list (list* :name (quote a) :readers (quote (a-of)) :writers (quote ((setf a-of))) :initargs (quote (:a)) (quote sb-pcl::source) #S(sb-c:definition-source-location :namestring nil :indices 0) (quote nil))) (list :direct-default-initargs nil) (quote (a-of)) (quote ((setf a-of))) (quote (a)) (sb-c:source-location))))
Generate a defmacro form that transforms code like this:
(defpixel-inch-accessors height :height dot-vertex-mixin)

Pattern to recognize: Macro call that should be transformed by defpixel-inch-accessors

Macro definition:
(defmacro defpixel-inch-accessors (name attr type)
  (let ((actual-name (form-symbol name "-IN-PIXELS")))
    `(progn
       (eval-always (export ',actual-name))
      (defmethod ,actual-name ((thing ,type))
        "Return the attribute in pixels assuming 72 dpi"
        (when (dot-attribute-value ,attr thing)
          (* 72 (dot-attribute-value ,attr thing))))
      (defmethod (setf ,actual-name) (value (thing ,type))
        "Set the attribute in pixels assuming 72 dpi"
        (setf (dot-attribute-value ,attr thing)
	      (coerce (/ value 72) 'double-float))))))

Macroexpansion:
(progn (eval-always (export (quote height-in-pixels))) (defmethod height-in-pixels ((thing dot-vertex-mixin)) "Return the attribute in pixels assuming 72 dpi" (when (dot-attribute-value :height thing) (* 72 (dot-attribute-value :height thing)))) (defmethod (setf height-in-pixels) (value (thing dot-vertex-mixin)) "Set the attribute in pixels assuming 72 dpi" (setf (dot-attribute-value :height thing) (coerce (/ value 72) (quote double-float)))))
Create a Common Lisp macro for the following transformation. Before code:
(deferror "42712" duplicate-alias syntax-error-or-access-violation)

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 duplicate-alias (syntax-error-or-access-violation) nil) (setf (gethash "42712" *error-table*) (quote duplicate-alias)))
Generate a defmacro form that transforms code like this:
(signal-syntax-error "LAST-POS stack of LEXER ~A is empty." lexer)

Pattern to recognize: Macro call that should be transformed by signal-syntax-error

Macro definition:
(defmacro signal-syntax-error (format-control &rest format-arguments)
  `(signal-syntax-error* nil ,format-control ,@format-arguments))

Macroexpansion:
(signal-syntax-error* nil "LAST-POS stack of LEXER ~A is empty." lexer)
Generate a defmacro form that transforms code like this:
(action (:after node-variable node bound-variables) (when (tracked-variable-p node bound-variables) (setf escaped? 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-variable) (lambda (node bound-variables) (declare (type node-variable node)) (when (tracked-variable-p node bound-variables) (setf escaped? t)) (values)))
Create a Common Lisp macro for the following transformation. Before code:
(action (:after node-direct-application node) (when (eq name (node-rator-name node)) (application-with-rator node rator)))

What needs to change: 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-direct-application) (lambda (node) (declare (type node-direct-application node)) (when (eq name (node-rator-name node)) (application-with-rator node rator))))
Create a Common Lisp macro for the following transformation. Before code:
(alambda (x) (if (zerop x) x (self (1- x))))

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

Macro definition:
(defmacro alambda (lambda-list &body body)
  "Like LAMBDA, except that SELF is bound to the resulting function (via LABELS)
within BODY."
  `(labels ((self ,lambda-list ,@body))
     #'self))

Macroexpansion:
(labels ((self (x) (if (zerop x) x (self (1- x))))) (function self))
You are a Common Lisp macro expert. Given this code pattern:
(compile-$flavor-$methods nil)

Write a macro that addresses: Macro call that should be transformed by COMPILE-$FLAVOR-$METHODS

Macro definition:
(defmacro COMPILE-$FLAVOR-$METHODS ...)

Macroexpansion:
(eval-when (:load-toplevel) (combine-class-methods nil))
Create a Common Lisp macro for the following transformation. Before code:
(define-modf-rewrite cdddr (expr) `(cdr (cddr ,(second expr))))

What needs to change: 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 cdddr) *modf-rewrites*) (lambda (expr) (sb-int:quasiquote (cdr (cddr #S(sb-impl::comma :expr (second expr) :kind 0)))))))
Write a Common Lisp macro to handle this code pattern:
(define-op (:and conjunctive-op))

Problem: 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 (and-op (:include conjunctive-op (name "AND")) (:constructor make-and-op (&rest expressions))))
You are a Common Lisp macro expert. Given this code pattern:
(repeatedly (> counter 0) (serially (atomically nil () (decf counter))) (concurrently () (atomically nil () (symbol-name 'this)) (atomically nil () (symbol-name 'is)) (atomically nil () (symbol-name 'meh))))

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

Macro definition:
(defmacro repeatedly (live-test-form &body flow)
  "Short-circuit the flow specified inside the block and executes it repeatedly
in loop until LIVE-TEST-FORM evaluates to NIL. Result from the last iteration
will be passed to the next block. Non-consing."
  (with-gensyms (test-fu)
    (with-flow-let-macro (flow-list flow)
      (flow-lambda-macro (flow-context)
        `(flet ((,test-fu () ,live-test-form))
           (dispatch-repeatedly ,flow-context #',test-fu ,flow-list))))))

Macroexpansion:
(let ((#:flow-list160 (list (serially (atomically nil nil (decf counter))) (concurrently nil (atomically nil nil (symbol-name (quote this))) (atomically nil nil (symbol-name (quote is))) (atomically nil nil (symbol-name (quote meh))))))) (%flow-lambda (#:flow-context161) (flet ((#:test-fu159 nil (> counter 0))) (dispatch-repeatedly #:flow-context161 (function #:test-fu159) #:flow-list160))))
Create a Common Lisp macro for the following transformation. Before code:
(special-symbol-reprogv nil
    nil)

What needs to change: Macro call that should be transformed by SPECIAL-SYMBOL-REPROGV

Macro definition:
(defmacro SPECIAL-SYMBOL-REPROGV ...)

Macroexpansion:
(let (#:symbol-list205)
  (tagbody
   #:retry206
    (setq #:symbol-list205 nil)
    (unless (every #'special-symbol-p #:symbol-list205)
      (cerror "Retry to rebind the place(s)."
              "Attempt at rebinding one or more non-special places: ~S" 'nil)
      (go #:retry206)))
  (dynamic-reprogv #:symbol-list205
      nil))
Define a macro that eliminates this repetitive pattern:
(define-modf-function gethash 2 (new-val key hash-table) (let ((new-hash (alexandria:copy-hash-table hash-table))) (setf (gethash key new-hash) new-val) new-hash))

Issue: Macro call that should be transformed by define-modf-function

Macro definition:
(defmacro define-modf-function (name nth-arg (new-val &rest args) &body body)
  "Define a new modf function.  It inverts NAME forms by modifying the NTH-ARG
term of the arguments of the place form in the MODF macro."
  ;; 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))
     (defun ,(intern (modf-name name) :modf) (,new-val ,@args)
       ,@body)))

Macroexpansion:
(progn (eval-when (:compile-toplevel :load-toplevel :execute) (setf (gethash (quote gethash) *modf-nth-arg*) 2)) (defun |BUILDER:COMMON-LISP:GETHASH| (new-val key hash-table) (let ((new-hash (alexandria:copy-hash-table hash-table))) (setf (gethash key new-hash) new-val) new-hash)))
Create a Common Lisp macro for the following transformation. Before code:
(deferror "23502" not-null-violation integrity-violation)

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 not-null-violation (integrity-violation) nil) (setf (gethash "23502" *error-table*) (quote not-null-violation)))
Create a Common Lisp macro for the following transformation. Before code:
(-<> nil (progn))

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

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

Macroexpansion:
(-> nil (progn))
Define a macro that eliminates this repetitive pattern:
(signal-reader-error "Expected { after \\N")

Issue: Macro call that should be transformed by signal-reader-error

Macro definition:
(defmacro signal-reader-error (format-control &rest format-arguments)
  "Like ERROR but signals a SIMPLE-READER-ERROR for the stream
*STREAM*."
  `(error 'simple-reader-error
          :stream *stream*
          :format-control ,format-control
          :format-arguments (list ,@format-arguments)))

Macroexpansion:
(error (quote simple-reader-error) :stream *stream* :format-control "Expected { after \\N" :format-arguments (list))
You are a Common Lisp macro expert. Given this code pattern:
(c-assert (c-model c))

Write a macro that addresses: 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 (c-model c) (c-break "failed assertion: ~a" (quote (c-model c)))))
Generate a defmacro form that transforms code like this:
(draw scene (:rect :x 490 :y 490 :height 200 :width 200) :fill (xlink-href rg2))

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

Macro definition:
(defmacro draw (scene (shape &rest params) &rest opts)
  (let ((element (gensym)))
    `(let ((,element (funcall #'make-svg-element ,shape (append (list ,@params) (list ,@opts)))))
       (add-element ,scene ,element)
       ,element)))

Macroexpansion:
(let ((#:g151 (funcall (function make-svg-element) :rect (append (list :x 490 :y 490 :height 200 :width 200) (list :fill (xlink-href rg2)))))) (add-element scene #:g151) #:g151)
Write a Common Lisp macro to handle this code pattern:
(acase (incf x) (0 :no) (1 (list :yes it)) (2 :nono))

Problem: Macro call that should be transformed by acase

Macro definition:
(defmacro acase (keyform &body cases)
  "Like CASE, except binds the result of the keyform to IT (via LET) for the
scope of the cases."
  `(anaphoric case ,keyform ,@cases))

Macroexpansion:
(anaphoric case (incf x) (0 :no) (1 (list :yes it)) (2 :nono))
Define a macro that eliminates this repetitive pattern:
(ct-flet nil
  (progn))

Issue: Macro call that should be transformed by CT-FLET

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

Macroexpansion:
(cond (*within-captured-dynenv* (progn (progn)))
      (t
       (error
        "No macrodynamic environment has been captured to establish CT-FLET bindings.")))
You are a Common Lisp macro expert. Given this code pattern:
(vect-of nil :key nil)

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

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

Macroexpansion:
(let ((#:vect140 (make-array 10 :adjustable t :fill-pointer 0)))
  (do-for (:key nil)
    (vector-push-extend nil #:vect140))
  #:vect140)
Generate a defmacro form that transforms code like this:
(draw scene (:rect :x 10 :y 10 :height 200 :width 200) :fill (xlink-href lg1))

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

Macro definition:
(defmacro draw (scene (shape &rest params) &rest opts)
  (let ((element (gensym)))
    `(let ((,element (funcall #'make-svg-element ,shape (append (list ,@params) (list ,@opts)))))
       (add-element ,scene ,element)
       ,element)))

Macroexpansion:
(let ((#:g149 (funcall (function make-svg-element) :rect (append (list :x 10 :y 10 :height 200 :width 200) (list :fill (xlink-href lg1)))))) (add-element scene #:g149) #:g149)
Define a macro that eliminates this repetitive pattern:
(defmacro-driver (for var in-package pkg &optional external-only (ext nil)) "Symbols accessible in a package" `(,(if generate 'generate 'for) (,var) in-packages ,pkg having-access ,(if ext '(:external) '(:external :internal :inherited))))

Issue: Macro call that should be transformed by defmacro-driver

Macro definition:
(defmacro defmacro-driver (clause-template &body body)
  "Create iterators which may also be used as generators"
  (define-clause 'defmacro clause-template body t))

Macroexpansion:
(eval-when (:compile-toplevel :load-toplevel :execute) (defmacro clause-for-in-package-1 (&key ((:for var)) ((:in-package pkg)) ((:external-only ext) nil) generate) "Symbols accessible in a package" (sb-int:quasiquote (#S(sb-impl::comma :expr (if generate (quote generate) (quote for)) :kind 0) (#S(sb-impl::comma :expr var :kind 0)) in-packages #S(sb-impl::comma :expr pkg :kind 0) having-access #S(sb-impl::comma :expr (if ext (quote (:external)) (quote (:external :internal :inherited))) :kind 0)))) (install-clause-info (quote (for :in-package)) (quote (for :in-package &optional :external-only)) (quote clause-for-in-package-1) "Symbols accessible in a package" t) (quote (for var in-package pkg &optional external-only (ext nil))))
Define a macro that eliminates this repetitive pattern:
(iter
  nil
  :key
  nil)

Issue: Macro call that should be transformed by ITER

Macro definition:
(defmacro ITER ...)

Macroexpansion:
(let* ()
  (block nil
    (block nil
      (tagbody
        (progn)
       loop-top-nil
        (progn :key nil)
        (progn)
        (go loop-top-nil)
        (progn))
      nil)))