j14i/cl-macros huggingface dataset:
You are a Common Lisp macro expert. Given this code pattern:
(with-*test-dribble* nil (explain! (run 'is1)))

Write a macro that addresses: Macro call that should be transformed by with-*test-dribble*

Macro definition:
(defmacro with-*test-dribble* (stream &body body)
  `(let ((*test-dribble* ,stream))
     (declare (special *test-dribble*))
     ,@body))

Macroexpansion:
(let ((*test-dribble* nil)) (declare (special *test-dribble*)) (explain! (run (quote is1))))
Generate a defmacro form that transforms code like this:
(mvlet* nil
  (progn))

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

Macro definition:
(defmacro MVLET* ...)

Macroexpansion:
(progn (progn))
Write a Common Lisp macro to handle this code pattern:
(matrix-etypecase 'some-name)

Problem: Macro call that should be transformed by MATRIX-ETYPECASE

Macro definition:
(defmacro MATRIX-ETYPECASE ...)

Macroexpansion:
(let ((#:g246 quote))
  (etypecase #:g246))
Define a macro that eliminates this repetitive pattern:
(o> (progn (decf test-calls-left) (< *flow-value* iterations)) (-> nil (value) (1+ value)))

Issue: Macro call that should be transformed by o>

Macro definition:
(defmacro o> (condition &body body)
  "See flow:repeatedly"
  `(repeatedly ,condition
     ,@body))

Macroexpansion:
(repeatedly (progn (decf test-calls-left) (< *flow-value* iterations)) (-> nil (value) (1+ value)))
Define a macro that eliminates this repetitive pattern:
(builder (:backtrace :result-on-error (lambda (condition) (if (typep condition 'test-error) '(503 (:content-type "text/plain") ("Service Temporary Unavailable")) '(500 (:content-type "text/plain") ("Internal Server Error"))))) (lambda (env) (if (string= (getf env :path-info) "/503") (error 'test-error) (error "Error occured"))))

Issue: 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 (#:app194) (funcall (find-middleware :backtrace) #:app194 :result-on-error (lambda (condition) (if (typep condition (quote test-error)) (quote (503 (:content-type "text/plain") ("Service Temporary Unavailable"))) (quote (500 (:content-type "text/plain") ("Internal Server Error"))))))))) :initial-value (to-app (lambda (env) (if (string= (getf env :path-info) "/503") (error (quote test-error)) (error "Error occured")))) :from-end t)
Generate a defmacro form that transforms code like this:
(c-assert fm)

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 fm (c-break "failed assertion: ~a" (quote fm))))
Define a macro that eliminates this repetitive pattern:
(define-hook-type number->number (function (number) number) "Hook taking a number and returning a number.")

Issue: 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-number->number (hook) ((handler-type :initform (quote (function (number) number)) :allocation :class)) (:metaclass sb-mop:funcallable-standard-class) (:documentation "Hook taking a number and returning a number."))
You are a Common Lisp macro expert. Given this code pattern:
(multiple-value-bind (form expanded) (macroexpand-1 form *env*) (cond (expanded (e form)) (t (typecase form (null nil) (list (let ((next (compiler-macroexpand-1 form))) (if (eq form next) (handle form) (e next)))) (t `',form)))))

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

Macro definition:
(defmacro m (form &environment *env*)
  (e form))

Macroexpansion:
(multiple-value-call (function (lambda (&optional form expanded &rest #:ignore) (declare (ignore #:ignore)) (cond (expanded (e form)) (t (typecase form (null nil) (list (let ((next (compiler-macroexpand-1 form))) (if (eq form next) (handle form) (e next)))) (t (sb-int:quasiquote (quote #S(sb-impl::comma :expr form :kind 0))))))))) (macroexpand-1 form *env*))
Create a Common Lisp macro for the following transformation. Before code:
(fmap f (funcall p1 next))

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

Macro definition:
(defmacro fmap (f thing)
  "Apply a pure function to the inner contents of some parsing operation, if the
parsing itself was successful."
  `(multiple-value-bind (res next) ,thing
     (if (failure? res)
         (fail next)
         (values (funcall ,f res) next))))

Macroexpansion:
(multiple-value-bind (res next) (funcall p1 next) (if (failure? res) (fail next) (values (funcall f res) next)))
Write a Common Lisp macro to handle this code pattern:
(define-op (:case 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 (case-op (:include conjunctive-op (name "CASE")) (:constructor make-case-op (&rest expressions))))
Define a macro that eliminates this repetitive pattern:
(define-error invalid-context-symbols () (symbols) "Sorry but the following symbols are not valid as a context specifiers: ~{~s~^ ~}" symbols)

Issue: 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 invalid-context-symbols (:error-type varjo-error :prefix "Varjo") (symbols) "Sorry but the following symbols are not valid as a context specifiers: ~{~s~^ ~}" symbols)
You are a Common Lisp macro expert. Given this code pattern:
(define-test emergency-dependency :depends-on (:not bad-dependency) (true "ALARM!!"))

Write a macro that addresses: 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 emergency-dependency) (find-package #A((9) base-char . "PARACHUTE"))) (ensure-test (quote test) :name (quote emergency-dependency) :home (find-package #A((9) base-char . "PARACHUTE")) :tests (list (lambda nil (true "ALARM!!"))) :parent (quote nil) (quote :depends-on) (quote (:not bad-dependency)))) (quote emergency-dependency))
Write a Common Lisp macro to handle this code pattern:
(define-op (:in infix-list-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 (in-op (:include infix-list-op (name "IN")) (:constructor make-in-op (left right))))
You are a Common Lisp macro expert. Given this code pattern:
(defclause (counting expr &optional into var result-type (type 'fixnum)) "Increment a variable if expression is non-nil" (return-reduction-code :identity 0 :operation '(subst (var expr) (1+ var)) :expression nil :test expr :variable var :type type :accum-kind :increment))

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-counting-9 (&key ((:counting expr)) ((:into var)) ((:result-type type) (quote fixnum))) "Increment a variable if expression is non-nil" (return-reduction-code :identity 0 :operation (quote (subst (var expr) (1+ var))) :expression nil :test expr :variable var :type type :accum-kind :increment)) (install-clause-info (quote (counting)) (quote (counting &optional :into :result-type)) (quote clause-counting-9) "Increment a variable if expression is non-nil" nil) (quote (counting expr &optional into var result-type (type (quote fixnum)))))
Generate a defmacro form that transforms code like this:
(integer-writer 4)

Pattern to recognize: Macro call that should be transformed by integer-writer

Macro definition:
(defmacro integer-writer (bytes)
  "Create a function to write integers to a binary stream."
  (let ((bits (* 8 bytes)))
    `(progn
       (declaim (inline ,(integer-writer-name bytes t)
                        ,(integer-writer-name bytes nil)))
       (defun ,(integer-writer-name bytes nil) (socket value)
         (declare (type stream socket)
                  (type (unsigned-byte ,bits) value)
                  #.*optimize*)
         ,@(if (= bytes 1)
               `((write-byte value socket))
               (loop :for byte :from (1- bytes) :downto 0
                     :collect `(write-byte (ldb (byte 8 ,(* byte 8)) value)
                                           socket)))
         (values))
       (defun ,(integer-writer-name bytes t) (socket value)
         (declare (type stream socket)
                  (type (signed-byte ,bits) value)
                  #.*optimize*)
         ,@(if (= bytes 1)
               `((write-byte (ldb (byte 8 0) value) socket))
               (loop :for byte :from (1- bytes) :downto 0
                     :collect `(write-byte (ldb (byte 8 ,(* byte 8)) value)
                                           socket)))
         (values)))))

Macroexpansion:
(progn (declaim (inline write-int4 write-uint4)) (defun write-uint4 (socket value) (declare (type stream socket) (type (unsigned-byte 32) value) (optimize (speed 3) (safety 0) (space 1) (debug 1) (compilation-speed 0))) (write-byte (ldb (byte 8 24) value) socket) (write-byte (ldb (byte 8 16) value) socket) (write-byte (ldb (byte 8 8) value) socket) (write-byte (ldb (byte 8 0) value) socket) (values)) (defun write-int4 (socket value) (declare (type stream socket) (type (signed-byte 32) value) (optimize (speed 3) (safety 0) (space 1) (debug 1) (compilation-speed 0))) (write-byte (ldb (byte 8 24) value) socket) (write-byte (ldb (byte 8 16) value) socket) (write-byte (ldb (byte 8 8) value) socket) (write-byte (ldb (byte 8 0) value) socket) (values)))
Define a macro that eliminates this repetitive pattern:
(c-assert (member old-kid (kids fm-parent)) () "~&oldkid ~s not amongst kids of its fm-parent ~s" old-kid fm-parent)

Issue: 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 old-kid (kids fm-parent)) (c-break "~&oldkid ~s not amongst kids of its fm-parent ~s" old-kid fm-parent)))
Define a macro that eliminates this repetitive pattern:
(c? (* 2 (width self)))

Issue: Macro call that should be transformed by c?

Macro definition:
(defmacro c? (&body body)
  `(make-c-dependent
    :code ',body
    :value-state :unevaluated
    :rule (c-lambda ,@body)))

Macroexpansion:
(make-c-dependent :code (quote ((* 2 (width self)))) :value-state :unevaluated :rule (c-lambda (* 2 (width self))))
Write a Common Lisp macro to handle this code pattern:
(define-modf-rewrite cddadr (expr) `(cdr (cdadr ,(second expr))))

Problem: 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 cddadr) *modf-rewrites*) (lambda (expr) (sb-int:quasiquote (cdr (cdadr #S(sb-impl::comma :expr (second expr) :kind 0)))))))
Create a Common Lisp macro for the following transformation. Before code:
(define-modf-rewrite cdadr (expr) `(cdr (cadr ,(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 cdadr) *modf-rewrites*) (lambda (expr) (sb-int:quasiquote (cdr (cadr #S(sb-impl::comma :expr (second expr) :kind 0)))))))
You are a Common Lisp macro expert. Given this code pattern:
(class/std stub slot1 slot2 slot3 slot4 slot5)

Write a macro that addresses: 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 stub nil ((slot1 slot2 slot3 slot4 slot5)))
Create a Common Lisp macro for the following transformation. Before code:
(with-cache ("foo" :expire 2 :store storage) 2)

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 ((#:key257 "foo") (#:store258 storage) (#:expire259 2)) (multiple-value-bind (#:value260 #:exists-p261) (getcache #:key257 #:store258) (if #:exists-p261 #:value260 (let ((#:value260 (progn 2))) (setcache #:key257 #:value260 #:store258 :expire #:expire259) #:value260))))
You are a Common Lisp macro expert. Given this code pattern:
(set-data pt (rect y x))

Write a macro that addresses: Macro call that should be transformed by set-data

Macro definition:
(defmacro set-data (obj (name &rest new-values))
  "Mutate the fields of the ADT value OBJ whose constructor is NAME
and whose updated values are NEW-VALUES based on order. If the symbol
'_' is used as a value, that field is not updated. Trailing '_' may be
omitted."
  (let ((once (gensym "ONCE")))
    `(let ((,once ,obj))
       (psetf
        ,@(loop :for i :from 0
                :for x :in new-values
                :when (not (wild? x))
                  :append (list `(,(field name i) ,once)
                                x))))))

Macroexpansion:
(let ((#:once145 pt)) (psetf (rect%0 #:once145) y (rect%1 #:once145) x))
Generate a defmacro form that transforms code like this:
(defcategory :info (or :info :notice))

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

Macro definition:
(defmacro defcategory (category &optional expands-as set)
  `(defcategory-fn ',category ',expands-as ,set))

Macroexpansion:
(defcategory-fn (quote :info) (quote (or :info :notice)) nil)