j14i/cl-macros huggingface dataset:
Define a macro that eliminates this repetitive pattern:
(defrule nil)

Issue: Macro call that should be transformed by DEFRULE

Macro definition:
(defmacro DEFRULE ...)

Macroexpansion:
(setf (gethash #A((3) base-char . "NIL") cl-rules.core::*rules*)
        '#S(cl-rules.core::rule
            :name #A((3) base-char . "NIL")
            :conditions nil
            :actions nil))
Write a Common Lisp macro to handle this code pattern:
(define-hook-type void (function ()) "Empty hook type with no arguments.")

Problem: Macro call that should be transformed by define-hook-type

Macro definition:
(defmacro define-hook-type (name type &optional documentation)
  "Define hook class.
Type must be something like:

  (function (string) (values integer t))

The `handler-type' of the defined hook class has `:class' allocation
type, so that all hooks of such class have the same `handler-type'."
  (let* ((name (string name))
         (hook-class-name (intern (serapeum:concat "HOOK-" name))))
    `(defclass ,hook-class-name (hook)
       ((handler-type :initform ',type :allocation :class))
       (:metaclass closer-mop:funcallable-standard-class)
       ,@(when documentation
           `((:documentation ,documentation))))))

Macroexpansion:
(defclass hook-void (hook) ((handler-type :initform (quote (function nil)) :allocation :class)) (:metaclass sb-mop:funcallable-standard-class) (:documentation "Empty hook type with no arguments."))
Create a Common Lisp macro for the following transformation. Before code:
(collect nil (progn))

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

Macro definition:
(defmacro COLLECT ...)

Macroexpansion:
(common-lisp:let* ((#:generator-601 (generator (progn)))
                   #:items-594
                   #:seq-595
                   (#:limit-596
                    (common-lisp:multiple-value-bind (x y)
                        (decode-seq-type (list 'quote nil))
                      (declare (ignore x))
                      y))
                   (#:lst-597 nil))
  (declare (type generator #:generator-601)
           (type (null-or nonnegative-integer) #:limit-596)
           (type list #:lst-597))
  (tagbody
   #:ll-602
    (setq #:items-594 (next-in #:generator-601 (go end)))
    (setq #:lst-597 (cons #:items-594 #:lst-597))
    (go #:ll-602)
   end)
  (common-lisp:let ((num (length #:lst-597)))
    (declare (type nonnegative-integer num))
    (setq #:seq-595 (make-sequence nil (or #:limit-596 num)))
    (do ((i (1- num) (1- i)))
        ((minusp i))
      (setf (elt #:seq-595 i) (pop #:lst-597))))
  #:seq-595)
Generate a defmacro form that transforms code like this:
(define-script-symbol-macro 'some-name)

Pattern to recognize: Macro call that should be transformed by DEFINE-SCRIPT-SYMBOL-MACRO

Macro definition:
(defmacro DEFINE-SCRIPT-SYMBOL-MACRO ...)

Macroexpansion:
(define-ps-symbol-macro 'some-name)
Generate a defmacro form that transforms code like this:
(signal-syntax-error "Backreference to register ~A which has not been defined." max-back-ref)

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 "Backreference to register ~A which has not been defined." max-back-ref)
You are a Common Lisp macro expert. Given this code pattern:
(defvar-unbound *readtable-copy* "Bound to the current readtable if it has to be temporarily modified.")

Write a macro that addresses: Macro call that should be transformed by defvar-unbound

Macro definition:
(defmacro defvar-unbound (variable-name documentation)
  "Like DEFVAR, but the variable will be unbound rather than getting
an initial value.  This is useful for variables which should have no
global value but might have a dynamically bound value."
  ;; stolen from comp.lang.lisp article <k7727i3s.fsf@comcast.net> by
  ;; "prunesquallor@comcast.net"
  `(eval-when (:load-toplevel :compile-toplevel :execute)
    (defvar ,variable-name)
    (setf (documentation ',variable-name 'variable)
            ,documentation)))

Macroexpansion:
(eval-when (:load-toplevel :compile-toplevel :execute) (defvar *readtable-copy*) (setf (documentation (quote *readtable-copy*) (quote variable)) "Bound to the current readtable if it has to be temporarily modified."))
Write a Common Lisp macro to handle this code pattern:
(c?-with-stored (v :foo store 'nothing) (bwhen (val (value v)) (1+ val)))

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

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

Macroexpansion:
(c? (bwhen-c-stored (v :foo store (quote nothing)) (bwhen (val (value v)) (1+ val))))
Write a Common Lisp macro to handle this code pattern:
(define-cfun c-malloc)

Problem: Macro call that should be transformed by define-cfun

Macro definition:
(defmacro define-cfun (name-or-function &optional (package *package*))
  (when-let ((fun (find-function name-or-function)))
    (with-wrap-attempt ("function ~S" name-or-function) name-or-function
      (with-slots (name type c-symbol fields) fun
        (let* ((fun-name (intern (symbol-name name) package))
               (param-names (mapcar #'foreign-type-name fields))
               (param-syms (mapcar (lambda (x) (gensym (symbol-name x))) param-names))
               (make-function-p (not (foreign-function-variadic-p fun)))
               (maybe-cbv-return
                 (when (cbv-return-p fun)
                   (list 'return-value))))
          (with-gensyms (!fun !fields rest)
            (let ((form
                    (if make-function-p
                        `(defun ,fun-name (,@maybe-cbv-return
                                           ,@param-names ,@(when (foreign-function-variadic-p fun) `(&rest ,rest)))
                           ,@(when maybe-cbv-return `((declare (ignorable ,@maybe-cbv-return))))
                           ,(let ((!fun (find-function name-or-function)))
                              (with-slots ((!fields fields)) !fun
                                (foreign-to-ffi
                                 (and (car !fields) (foreign-type (car !fields)))
                                 param-syms
                                 param-names
                                 !fields
                                 (make-foreign-funcall !fun (and maybe-cbv-return 'return-value)
                                                       param-syms (when (foreign-function-variadic-p fun) rest))))))
                        `(defmacro ,fun-name (,@maybe-cbv-return
                                              ,@param-names ,@(when (foreign-function-variadic-p fun) `(&rest ,rest)))
                           ,@(when maybe-cbv-return `((declare (ignorable ,@maybe-cbv-return))))
                           (let ((,!fun (find-function ',name-or-function)))
                             (with-slots ((,!fields fields)) ,!fun
                               (foreign-to-ffi
                                (and (car ,!fields) (foreign-type (car ,!fields)))
                                ',param-syms
                                (list ,@param-names)
                                ,!fields
                                (make-foreign-funcall ,!fun ,(and maybe-cbv-return 'return-value)
                                                      ',param-syms ,(when (foreign-function-variadic-p fun) rest)))))))))
              `(progn
                 ,@(when (foreign-function-cbv-p fun)
                     (list (funcall *build-libffi-definition* fun)))
                 ,form))))))))

Macroexpansion:
(progn (defun c-malloc (size) (let ((#:size193 size)) (declare (ignorable #:size193)) (cffi-sys:%foreign-funcall "malloc" (:unsigned-long-long #:size193 :pointer) :convention :cdecl))))
Generate a defmacro form that transforms code like this:
(defsynonym while :while)

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

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

Macroexpansion:
(eval-always (setf (get (quote while) (quote synonym)) (quote :while)))
Generate a defmacro form that transforms code like this:
(mvlet* ((x y (floor 20 6)) (z a (values x 5))) (+ x y z a))

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

Macro definition:
(defmacro mvlet* ((&rest bindings) &body body &environment env)
  "Expand a series of nested `multiple-value-bind' forms.

`mvlet*' is similar in intent to Scheme’s `let-values', but with a
different and less parenthesis-intensive syntax. Each binding is a
list of

    (var var*... expr)

A simple example should suffice to show both the implementation and
the motivation:

    (defun uptime (seconds)
      (mvlet* ((minutes seconds (truncate seconds 60))
               (hours minutes (truncate minutes 60))
               (days hours (truncate hours 24)))
        (declare ((integer 0 *) days hours minutes seconds))
        (fmt \"~d day~:p, ~d hour~:p, ~d minute~:p, ~d second~:p\"
             days hours minutes seconds)))

Note that declarations work just like `let*'."
  (cond ((null bindings)
         `(locally ,@body))
        ((every #'simple-binding-p bindings)
         `(let* ,bindings ,@body))
        (t (multiple-value-bind (body decls)
               (parse-body body)
             (let* ((bindings (canonicalize-bindings bindings))
                    (mvbinds (member-if-not #'simple-binding-p bindings))
                    (simple-binds (ldiff bindings mvbinds)))
               (if simple-binds
                   (multiple-value-bind (local other)
                       (partition-declarations (mapcar #'car simple-binds) decls env)
                     `(let* ,simple-binds
                        ,@local
                        (mvlet* ,mvbinds
                          ,@other
                          ,@body)))
                   (let* ((vars (butlast (car bindings)))
                          (expr (lastcar (car bindings))))
                     (multiple-value-bind (local other)
                         (partition-declarations vars decls env)
                       `(multiple-value-bind ,vars
                            ,expr
                          ,@local
                          (mvlet* ,(cdr bindings)
                            ,@other
                            ,@body))))))))))

Macroexpansion:
(multiple-value-bind (x y) (floor 20 6) (mvlet* ((z a (values x 5))) (+ x y z a)))
Generate a defmacro form that transforms code like this:
(do-generators ((g (some-numbers)) (:list l data)) (yield (+ l g)))

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

Macro definition:
(defmacro do-generator ((var &rest vars-and-generator) &body body)
  "Steps through the specified generator, binding the value it returns to var, then executing the body for each step. If multiple variables are specified and the generator returns multiple values, the extra values will be bound to the extra variables."
  (let ((g (gensym)))
    `(let ((,g ,(car (last vars-and-generator))))
       (loop 
	  do (if-generator ((,var ,@(butlast vars-and-generator)) ,g)
			   (progn
			     ,@body)
			   (return))))))

Macroexpansion:
(let ((#:g172 (multi-gen (some-numbers) (list->generator data)))) (loop do (destructuring-bind (#:g174 . #:g173) (multiple-value-list (next-generator-value #:g172)) (unless #:g174 (return)) (let ((g (elt (elt #:g173 0) 0)) (l (elt (elt #:g173 1) 0))) (yield (+ l g))))))
Generate a defmacro form that transforms code like this:
(define-script-symbol-macro nil
  :key
  nil)

Pattern to recognize: Macro call that should be transformed by DEFINE-SCRIPT-SYMBOL-MACRO

Macro definition:
(defmacro DEFINE-SCRIPT-SYMBOL-MACRO ...)

Macroexpansion:
(define-ps-symbol-macro nil :key nil)
Define a macro that eliminates this repetitive pattern:
(action (:after node-variable node bound-variables) (when (and (eq name (node-variable-value node)) (not (member name bound-variables :test #'eq)) (member target bound-variables :test #'eq)) (setf unsafe? t)) (values))

Issue: 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 (and (eq name (node-variable-value node)) (not (member name bound-variables :test (function eq))) (member target bound-variables :test (function eq))) (setf unsafe? t)) (values)))
Define a macro that eliminates this repetitive pattern:
(some-> nil (progn))

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

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

Macroexpansion:
(let* ((#:g143 nil))
  (if (null #:g143)
      nil
      (-> #:g143 (progn))))
Define a macro that eliminates this repetitive pattern:
(when export `(export '(,name ,@slot-list)))

Issue: 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 export (sb-int:quasiquote (export (quote (#S(sb-impl::comma :expr name :kind 0) #S(sb-impl::comma :expr slot-list :kind 2))))))
Define a macro that eliminates this repetitive pattern:
(lambda* nil
  :key
  nil)

Issue: Macro call that should be transformed by LAMBDA*

Macro definition:
(defmacro LAMBDA* ...)

Macroexpansion:
(lambda () (the t (block nil :key nil)))
Create a Common Lisp macro for the following transformation. Before code:
(do+ (for x (from 0)) (generating y (across #(0 1))) (collect (list x y)) (when (oddp x) (is (= (update y) y))))

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

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

Macroexpansion:
(do+/internal nil (for x (from 0)) (generating y (across #(0 1))) (collect (list x y)) (when (oddp x) (is (= (update y) y))))
You are a Common Lisp macro expert. Given this code pattern:
(define-template nil nil)

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

Macro definition:
(defmacro DEFINE-TEMPLATE ...)

Macroexpansion:
(defmacro define-nil (&optional (#:name126))
  (flet ((template-unfulfillable ()
           (error 'template-unfulfillable :template 'nil :arguments (list))))
    (declare (ignorable (function template-unfulfillable)))
    (let ((body (progn)) (name (or #:name126 (compose-name #\SOLIDUS 'nil))))
      `(progn
        (declaim
         (ftype
          (function
           ,(loop with types = (declared-variable-types body)
                  for arg in (quote nil)
                  collect (or (second (assoc arg types)) (quote t)))
           ,(declared-return-type body))
          ,name)
         ,@(when (find (quote inline) (declarations body)) `((inline ,name))))
        (defun ,name ,'nil
          (declare (optimize speed (safety 0) (debug 0) (compilation-speed 0))
                   ,@(remove (quote inline) (declarations body)))
          ,@(remove-if #'declaration-p body))))))
Generate a defmacro form that transforms code like this:
(with-mocks () (register-mock 'foo) (let ((sym (gensym))) (foo sym) (is (equal `((foo ,sym)) (invocations)))))

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

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

Macroexpansion:
(call-with-mocks (lambda nil (register-mock (quote foo)) (let ((sym (gensym))) (foo sym) (is (equal (sb-int:quasiquote ((foo #S(sb-impl::comma :expr sym :kind 0)))) (invocations))))) :recordp t)
Create a Common Lisp macro for the following transformation. Before code:
(lambda () (progn))

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

Macro definition:
(defmacro LAMBDA ...)

Macroexpansion:
#'(lambda () (progn))
Create a Common Lisp macro for the following transformation. Before code:
(define-error switch-type-error () (form) "Currently the clause forms of a switch must all be either ints, uints, floats or doubles:~%Code:~%~a" form)

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 switch-type-error (:error-type varjo-error :prefix "Varjo") (form) "Currently the clause forms of a switch must all be either ints, uints, floats or doubles:~%Code:~%~a" form)
Create a Common Lisp macro for the following transformation. Before code:
(with-cache ("foo" :store storage) (error "MUST NOT BE ERROR"))

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

Macro definition:
(defmacro with-cache ((key &key store expire) &body body)
  "If a cache indicated by KEY exists, this just returns the cache
value without evaluating BODY. Otherwise, this evaluates BODY and
stores the evaluated value into STORE with KEY and EXPIRE. KEY is a
form that an evaluated value indicates the cache key.

Example:

    (defun f (x)
      (with-cache (x *store*)
        (very-complex-computation x)))"
  (once-only (key store expire)
    (with-gensyms (value exists-p)
      `(multiple-value-bind (,value ,exists-p)
           (getcache ,key ,store)
         (if ,exists-p
             ,value
             (let ((,value (progn ,@body)))
               (setcache ,key ,value ,store :expire ,expire)
               ,value))))))

Macroexpansion:
(let ((#:key237 "foo") (#:store238 storage) (#:expire239 nil)) (multiple-value-bind (#:value240 #:exists-p241) (getcache #:key237 #:store238) (if #:exists-p241 #:value240 (let ((#:value240 (progn (error "MUST NOT BE ERROR")))) (setcache #:key237 #:value240 #:store238 :expire #:expire239) #:value240))))
Define a macro that eliminates this repetitive pattern:
(action (:after node-bind node) (multiple-value-bind (new-node new-changed?) (maybe-collapse-bind node) (when new-changed? (setf changed? t) new-node)))

Issue: 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-bind) (lambda (node) (declare (type node-bind node)) (multiple-value-bind (new-node new-changed?) (maybe-collapse-bind node) (when new-changed? (setf changed? t) new-node))))
You are a Common Lisp macro expert. Given this code pattern:
(with-yield-binds (format nil "~{~A~^, ~}" (mapcar (lambda (element) (if (sql-statement-p element) (format nil "(~A)" (yield element)) (yield element))) (sql-list-elements list))))

Write a macro that addresses: 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 (lambda (element) (if (sql-statement-p element) (format nil "(~A)" (yield element)) (yield element))) (sql-list-elements list)))) (loop for bind in (reverse *bind-values*) append bind)))
Write a Common Lisp macro to handle this code pattern:
(like "truth" "^true")

Problem: Macro call that should be transformed by like

Macro definition:
(defmacro like (got regex &optional desc)
  (with-gensyms (duration result)
    (once-only (regex desc)
      `(with-catching-errors (:description ,desc :expected ,regex)
         (with-duration ((,duration ,result) ,got)
           (test ,result ,regex ,desc
                 :duration ,duration
                 :test-fn (lambda (x y) (not (null (ppcre:scan y x))))
                 :report-expected-label "be like"))))))

Macroexpansion:
(let ((#:regex211 "^true") (#:desc212 nil)) (with-catching-errors (:description #:desc212 :expected #:regex211) (with-duration ((#:duration209 #:result210) "truth") (test #:result210 #:regex211 #:desc212 :duration #:duration209 :test-fn (lambda (x y) (not (null (cl-ppcre:scan y x)))) :report-expected-label "be like"))))
You are a Common Lisp macro expert. Given this code pattern:
(defclause (until expr) "Exit loop if test is non-nil" (setq *loop-end-used?* t) (return-code :body `((if ,(walk-expr expr) (go ,*loop-end*)))))

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-until-15 (&key ((:until expr))) "Exit loop if test is non-nil" (setq *loop-end-used?* t) (return-code :body (sb-int:quasiquote ((if #S(sb-impl::comma :expr (walk-expr expr) :kind 0) (go #S(sb-impl::comma :expr *loop-end* :kind 0))))))) (install-clause-info (quote (until)) (quote (until)) (quote clause-until-15) "Exit loop if test is non-nil" nil) (quote (until expr)))