j14i/cl-macros huggingface dataset:
You are a Common Lisp macro expert. Given this code pattern:
(defannotation metaclass (metaclass class-definition-form) (:arity 2) (progn-form-replace-last (lambda (class-definition-form) (if (get-class-option :metaclass class-definition-form) (error ":metaclass is not empty") (append class-definition-form `((:metaclass ,metaclass))))) class-definition-form))

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

Macro definition:
(defmacro defannotation (name lambda-list options &body body)
  `(progn
     (set-annotation-options ',name ',options)
     (defmacro ,name ,lambda-list ,@body)))

Macroexpansion:
(progn (set-annotation-options (quote metaclass) (quote (:arity 2))) (defmacro metaclass (metaclass class-definition-form) (progn-form-replace-last (lambda (class-definition-form) (if (get-class-option :metaclass class-definition-form) (error ":metaclass is not empty") (append class-definition-form (sb-int:quasiquote ((:metaclass #S(sb-impl::comma :expr metaclass :kind 0))))))) class-definition-form)))
Write a Common Lisp macro to handle this code pattern:
(with-flow-let-macro (flow-list flow) (flow-lambda-macro (flow-context) `(dispatch-serially ,flow-context ,flow-list)))

Problem: Macro call that should be transformed by with-flow-let-macro

Macro definition:
(defmacro with-flow-let-macro ((var flow) &body body)
  `(with-gensyms (,var)
     `(let ((,,var (list ,@,flow)))
        ,,@body)))

Macroexpansion:
(with-gensyms (flow-list) (sb-int:quasiquote (let ((#S(sb-impl::comma :expr flow-list :kind 0) (list #S(sb-impl::comma :expr flow :kind 2)))) #S(sb-impl::comma :expr (flow-lambda-macro (flow-context) (sb-int:quasiquote (dispatch-serially #S(sb-impl::comma :expr flow-context :kind 0) #S(sb-impl::comma :expr flow-list :kind 0)))) :kind 0))))
Generate a defmacro form that transforms code like this:
(with-input-from-file (file-stream pathname :external-format external-format) (read-stream-content-into-string file-stream :buffer-size buffer-size))

Pattern to recognize: Macro call that should be transformed by with-input-from-file

Macro definition:
(defmacro with-input-from-file ((stream-name file-name &rest args
                                             &key (direction nil direction-p)
                                             &allow-other-keys)
                                &body body)
  "Evaluate BODY with STREAM-NAME to an input stream on the file
FILE-NAME. ARGS is sent as is to the call to OPEN except EXTERNAL-FORMAT,
which is only sent to WITH-OPEN-FILE when it's not NIL."
  (declare (ignore direction))
  (when direction-p
    (error "Can't specify :DIRECTION for WITH-INPUT-FROM-FILE."))
  `(with-open-file* (,stream-name ,file-name :direction :input ,@args)
     ,@body))

Macroexpansion:
(with-open-file* (file-stream pathname :direction :input :external-format external-format) (read-stream-content-into-string file-stream :buffer-size buffer-size))
You are a Common Lisp macro expert. Given this code pattern:
(with-ps-gensyms 'some-name)

Write a macro that addresses: Macro call that should be transformed by WITH-PS-GENSYMS

Macro definition:
(defmacro WITH-PS-GENSYMS ...)

Macroexpansion:
(let* ((quote (ps-gensym #A((5) base-char . "QUOTE")))
       (some-name (ps-gensym "SOME-NAME"))))
Create a Common Lisp macro for the following transformation. Before code:
(dynamic-reprogv nil
    :key
  nil)

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

Macro definition:
(defmacro DYNAMIC-REPROGV ...)

Macroexpansion:
(dynamic-wind
  :proceed
  #:proceed204
  (let* ((#:computed-symbols202 nil)
         (#:computed-bindings203 (compute-bindings #:computed-symbols202 :key)))
    (progv #:computed-symbols202 #:computed-bindings203 (#:proceed204 nil))))
Generate a defmacro form that transforms code like this:
(f_
  nil
  nil)

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

Macro definition:
(defmacro F_ ...)

Macroexpansion:
(lambda (_) nil nil)
Generate a defmacro form that transforms code like this:
(with-html-string (:tag :name "xy" "Hello"))

Pattern to recognize: 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 (:tag :name "xy" "Hello")))
Generate a defmacro form that transforms code like this:
(bind ((#(a b c) #(1 2 3))) (list a b c))

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-166| #(1 2 3)) (a (aref #:|values-166| 0)) (b (aref #:|values-166| 1)) (c (aref #:|values-166| 2))) (declare (ignorable #:|values-166|)) (progn (list a b c)))
Create a Common Lisp macro for the following transformation. Before code:
(the nil :key nil)

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

Macro definition:
(defmacro THE ...)

Macroexpansion:
(send self nil :key nil)
Generate a defmacro form that transforms code like this:
(m 'some-name)

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

Macro definition:
(defmacro M ...)

Macroexpansion:
(lambda (&rest #:|macro-lambda-list124|)
  (destructuring-bind (quote some-name) #:|macro-lambda-list124|))
Define a macro that eliminates this repetitive pattern:
(match nil
  (progn))

Issue: Macro call that should be transformed by MATCH

Macro definition:
(defmacro MATCH ...)

Macroexpansion:
(match* (nil)
  ((progn)))
Generate a defmacro form that transforms code like this:
(c-assert entry)

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 entry (c-break "failed assertion: ~a" (quote entry))))
You are a Common Lisp macro expert. Given this code pattern:
(producing nil nil)

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

Macro definition:
(defmacro PRODUCING ...)

Macroexpansion:
(non-opt-producing nil
    nil)
Create a Common Lisp macro for the following transformation. Before code:
(cardinality-case nil)

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

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

Macroexpansion:
(let ((#:cardinality127 nil))
  (typecase #:cardinality127))
Write a Common Lisp macro to handle this code pattern:
(maybe-do-not-silence-errors (handler-case (call-next-method) (error (err) (setf (value result) (if (typep result 'multiple-value-result) (list err) err)) (setf (status result) :failed))))

Problem: Macro call that should be transformed by maybe-do-not-silence-errors

Macro definition:
(defmacro maybe-do-not-silence-errors (&body body)
  `(if *silence-plain-compilation-errors-p*
       ,@body
       (let ((ok nil))
         (unwind-protect
              (multiple-value-prog1
                  (call-next-method)
                (setf ok t))
           (unless ok (setf (status result) :failed))))))

Macroexpansion:
(if *silence-plain-compilation-errors-p* (handler-case (call-next-method) (error (err) (setf (value result) (if (typep result (quote multiple-value-result)) (list err) err)) (setf (status result) :failed))) (let ((ok nil)) (unwind-protect (multiple-value-prog1 (call-next-method) (setf ok t)) (unless ok (setf (status result) :failed)))))
Create a Common Lisp macro for the following transformation. Before code:
(define-hook-type any (function (&rest t)) "Hook accepting any arguments and returning anything.")

What needs to change: 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-any (hook) ((handler-type :initform (quote (function (&rest t))) :allocation :class)) (:metaclass sb-mop:funcallable-standard-class) (:documentation "Hook accepting any arguments and returning anything."))
Write a Common Lisp macro to handle this code pattern:
(n-spaces *indent*)

Problem: Macro call that should be transformed by n-spaces

Macro definition:
(defmacro n-spaces (n)
  "A string with N spaces - used by indentation."
  `(make-array ,n
               :element-type 'base-char
               :displaced-to +spaces+
               :displaced-index-offset 0))

Macroexpansion:
(make-array *indent* :element-type (quote base-char) :displaced-to +spaces+ :displaced-index-offset 0)
Generate a defmacro form that transforms code like this:
(ematch0 parsed1 ((list slot pattern) (let (effslot reader) (cond ((setf effslot (find-effective-slot slot type)) `((slot-value ,it ',(c2mop:slot-definition-name effslot)) ,pattern)) ((setf reader (find-reader slot type)) `((,reader ,it) ,pattern)) (t (error "Failed to deduce the way to access the slot ~s" slot))))))

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

Macro definition:
(defmacro ematch0 (what &body clauses)
  `(match0 ,what
     ,@clauses
     (_ (error "level0 match error!"))))

Macroexpansion:
(match0 parsed1 ((list slot pattern) (let (effslot reader) (cond ((setf effslot (find-effective-slot slot type)) (sb-int:quasiquote ((slot-value #S(sb-impl::comma :expr it :kind 0) (quote #S(sb-impl::comma :expr (sb-mop:slot-definition-name effslot) :kind 0))) #S(sb-impl::comma :expr pattern :kind 0)))) ((setf reader (find-reader slot type)) (sb-int:quasiquote ((#S(sb-impl::comma :expr reader :kind 0) #S(sb-impl::comma :expr it :kind 0)) #S(sb-impl::comma :expr pattern :kind 0)))) (t (error "Failed to deduce the way to access the slot ~s" slot))))) (_ (error "level0 match error!")))
Write a Common Lisp macro to handle this code pattern:
(defmethod* nil (progn))

Problem: Macro call that should be transformed by DEFMETHOD*

Macro definition:
(defmacro DEFMETHOD* ...)

Macroexpansion:
(let* ((#:nil127 (ensure-generic*-function 'nil))
       (temp-method (defmethod #:nil126 (progn)))
       (actual-gf
        (ensure-generic*-function 'nil :lambda-list
                                  (sb-mop:generic-function-lambda-list
                                   (symbol-function '#:nil126))
                                  :special-variables 'nil))
       (actual-method
        (add-method* #:nil127
                     (make-instance 'method* :special-variables (list)
                                    :qualifiers 'nil :specializers
                                    (sb-mop:method-specializers temp-method)
                                    :lambda-list
                                    (sb-mop:method-lambda-list temp-method)
                                    :documentation
                                    (documentation temp-method t) :function
                                    (sb-mop:method-function temp-method)))))
  (declare (ignorable #:nil127)
           (ignore actual-gf))
  (setf (documentation actual-method t) (documentation temp-method t))
  actual-method)
Define a macro that eliminates this repetitive pattern:
(with-wcs-math-error-handling (ret (hypot x y)) (check-wcs-math-result))

Issue: Macro call that should be transformed by with-wcs-math-error-handling

Macro definition:
(defmacro with-wcs-math-error-handling
    ((var-or-var-list
      (function x &optional (y nil y-supplied-p))
      &rest keyargs
      &key underflow-value)
     &body body)
  (declare (ignorable underflow-value))
  (let ((x_ (gensym)) (y_ (gensym)) (args_ (gensym))
        (var-list (ensure-list var-or-var-list)))
    `(let* ((,x_ ,x)
            (,y_ ,y)
            (,args_ (list ,x_ ,@(if y-supplied-p `(,y_)))))
       (declare (ignorable ,y_)
                (type list ,args_)
                (dynamic-extent ,args_))
       (catch 'return-from-with-wcs-math-error-handling
         (multiple-value-bind ,var-list
             (call-with-wcs-math-error-handler ',function ,args_
                                               ,@keyargs)
           (flet ((check-wcs-math-result
                      (&optional (ret ,(first var-list))
                                 (arg-list ,args_))
                    (check-wcs-math-result ret arg-list)))
             ,@body))))))

Macroexpansion:
(let* ((#:g236 x) (#:g237 y) (#:g238 (list #:g236 #:g237))) (declare (ignorable #:g237) (type list #:g238) (dynamic-extent #:g238)) (catch (quote return-from-with-wcs-math-error-handling) (multiple-value-bind (ret) (call-with-wcs-math-error-handler (quote hypot) #:g238) (flet ((check-wcs-math-result (&optional (ret ret) (arg-list #:g238)) (check-wcs-math-result ret arg-list))) (check-wcs-math-result)))))
Write a Common Lisp macro to handle this code pattern:
(defgenerator take-as-generator (n generator &key (fail-if-short t)) "This function has the same meaning as TAKE but returns a generator instead of a list. Eg: (generator->list (take-as-generator 10 (list->generator '(1 2 3)))) -> Signals a condition (generator->list (take-as-generator 10 (list->generator '(1 2 3)) :fail-if-short nil)) -> (1 2 3) (generator->list (take-as-generator 3 (repeat 1))) -> (1 1 1)" (declare (type (integer 1) n)) (let ((count 0)) (do-generator (g generator) (yield g) (incf count) (when (= count n) (yield 'generator-stop)))) (when fail-if-short (error 'insufficient-items :format-control "Insufficient items in generator")))

Problem: Macro call that should be transformed by defgenerator

Macro definition:
(defmacro defgenerator (name arguments &body body)
  (multiple-value-bind (remaining-forms declarations doc-string)
      (alexandria:parse-body body :documentation t)
    `(defun ,name ,arguments
       ,doc-string
       ,@declarations
       (with-yield
	 ,@remaining-forms))))

Macroexpansion:
(defun take-as-generator (n generator &key (fail-if-short t)) "This function has the same meaning as TAKE but returns a generator instead of a list. Eg: (generator->list (take-as-generator 10 (list->generator '(1 2 3)))) -> Signals a condition (generator->list (take-as-generator 10 (list->generator '(1 2 3)) :fail-if-short nil)) -> (1 2 3) (generator->list (take-as-generator 3 (repeat 1))) -> (1 1 1)" (declare (type (integer 1) n)) (with-yield (let ((count 0)) (do-generator (g generator) (yield g) (incf count) (when (= count n) (yield (quote generator-stop))))) (when fail-if-short (error (quote insufficient-items) :format-control "Insufficient items in generator"))))
You are a Common Lisp macro expert. Given this code pattern:
(compile-$flavor-$methods)

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))
Define a macro that eliminates this repetitive pattern:
(fail (error "An expected failure."))

Issue: Macro call that should be transformed by fail

Macro definition:
(defmacro fail (form &optional (type 'error) description &rest format-args)
  `(eval-in-context
    *context*
    (make-instance 'comparison-result
                   :expression '(fail ,form ,type)
                   :value-form '(capture-error ,form)
                   :body (lambda () (capture-error ,form ,(maybe-unquote type)))
                   :expected ',(maybe-unquote type)
                   :comparison 'typep
                   ,@(when description
                       `(:description (format NIL ,description ,@format-args))))))

Macroexpansion:
(eval-in-context *context* (make-instance (quote comparison-result) :expression (quote (fail (error "An expected failure.") error)) :value-form (quote (capture-error (error "An expected failure."))) :body (lambda nil (capture-error (error "An expected failure.") error)) :expected (quote error) :comparison (quote typep)))
Write a Common Lisp macro to handle this code pattern:
(disable-version-syntax)

Problem: Macro call that should be transformed by disable-version-syntax

Macro definition:
(defmacro disable-version-syntax ()
  "Restore readtable which was active before last call to
ENABLE-VERSION-SYNTAX. If there was no such call, the standard
readtable is used."
  `(eval-when (:compile-toplevel :load-toplevel :execute)
     (%disable-version-syntax)))

Macroexpansion:
(eval-when (:compile-toplevel :load-toplevel :execute) (%disable-version-syntax))
Write a Common Lisp macro to handle this code pattern:
(sctypecase (car x) (symbol (setf it 'symbol)) (bit (setf it 'bit)))

Problem: Macro call that should be transformed by sctypecase

Macro definition:
(defmacro sctypecase (keyform &body cases)
  "Like CTYPECASE, except binds the keyform to IT (via SYMBOL-MACROLET) for
the scope of the cases. IT can be set with SETF."
  `(symbolic ctypecase ,keyform ,@cases))

Macroexpansion:
(symbolic ctypecase (car x) (symbol (setf it (quote symbol))) (bit (setf it (quote bit))))
Generate a defmacro form that transforms code like this:
(psetq nil (progn))

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

Macro definition:
(defmacro PSETQ ...)

Macroexpansion:
(progn (setq nil (progn)) nil)
Create a Common Lisp macro for the following transformation. Before code:
(psetf nil nil)

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

Macro definition:
(defmacro PSETF ...)

Macroexpansion:
(progn (setf nil nil) nil)
Create a Common Lisp macro for the following transformation. Before code:
(define-fixture-capture function (symbol) (when (and (fboundp symbol) (not (macro-function symbol)) (not (locked-package-p (symbol-package symbol)))) (values (fdefinition symbol) T)))

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

Macro definition:
(defmacro define-fixture-capture (name args &body body)
  `(progn (setf (gethash ',name *fixture-captures*)
                (lambda ,args ,@body))
          ',name))

Macroexpansion:
(progn (setf (gethash (quote function) *fixture-captures*) (lambda (symbol) (when (and (fboundp symbol) (not (macro-function symbol)) (not (locked-package-p (symbol-package symbol)))) (values (fdefinition symbol) t)))) (quote function))
Generate a defmacro form that transforms code like this:
(defobject-amendment nil)

Pattern to recognize: Macro call that should be transformed by DEFOBJECT-AMENDMENT

Macro definition:
(defmacro DEFOBJECT-AMENDMENT ...)

Macroexpansion:
(defobject nil
    (standard-object))
Write a Common Lisp macro to handle this code pattern:
(gather-next nil (progn))

Problem: Macro call that should be transformed by GATHER-NEXT

Macro definition:
(defmacro GATHER-NEXT ...)

Macroexpansion:
(common-lisp:funcall nil (progn) nil)
Write a Common Lisp macro to handle this code pattern:
(with-wrap-attempt () name (let* ((return-type (ensure-type return-type "function ~S (nee ~S) with return type ~S" name c-symbol return-type)) (fun (make-instance 'foreign-function :name name :c-symbol c-symbol :type return-type :variadic-p variadic-p))) (setf (foreign-record-fields fun) (loop for param in params collect (make-instance 'foreign-field :name (car param) :type (ensure-type (cadr param) "function ~S (nee ~S) due to parameter ~S of type ~S" name c-symbol (car param) (cadr param))))) (setf (gethash name *foreign-functions*) fun)))

Problem: Macro call that should be transformed by with-wrap-attempt

Macro definition:
(defmacro with-wrap-attempt ((&optional format-control &rest format-args) wrappable-name &body body)
  `(call-with-wrap-attempt ,wrappable-name (lambda () ,@body) ,format-control (list ,@format-args)))

Macroexpansion:
(call-with-wrap-attempt name (lambda nil (let* ((return-type (ensure-type return-type "function ~S (nee ~S) with return type ~S" name c-symbol return-type)) (fun (make-instance (quote foreign-function) :name name :c-symbol c-symbol :type return-type :variadic-p variadic-p))) (setf (foreign-record-fields fun) (loop for param in params collect (make-instance (quote foreign-field) :name (car param) :type (ensure-type (cadr param) "function ~S (nee ~S) due to parameter ~S of type ~S" name c-symbol (car param) (cadr param))))) (setf (gethash name *foreign-functions*) fun))) nil (list))
You are a Common Lisp macro expert. Given this code pattern:
(nlet nil
    nil)

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

Macro definition:
(defmacro NLET ...)

Macroexpansion:
(let* ())
Create a Common Lisp macro for the following transformation. Before code:
(with-unique-names (value coerced-value) `((,name (,value) (let ((,coerced-value (coerce ,value ',type))) (declare (type ,type ,coerced-value)) (when (or ,firstp (> ,coerced-value ,var)) (setq ,var ,coerced-value ,firstp nil))))))

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

Macro definition:
(defmacro with-unique-names (names &body body)
  `(let ,(mapcar (lambda (sym)
                   `(,sym (gensym ,(symbol-name sym))))
                  names)
     ,@body))

Macroexpansion:
(let ((value (gensym #A((5) base-char . "VALUE"))) (coerced-value (gensym #A((14) base-char . "COERCED-VALUE-")))) (quasiquote ((#S(sb-impl::comma :expr name :kind 0) (#S(sb-impl::comma :expr value :kind 0)) (let ((#S(sb-impl::comma :expr coerced-value :kind 0) (coerce #S(sb-impl::comma :expr value :kind 0) (quote #S(sb-impl::comma :expr type :kind 0))))) (declare (type #S(sb-impl::comma :expr type :kind 0) #S(sb-impl::comma :expr coerced-value :kind 0))) (when (or #S(sb-impl::comma :expr firstp :kind 0) (> #S(sb-impl::comma :expr coerced-value :kind 0) #S(sb-impl::comma :expr var :kind 0))) (setq #S(sb-impl::comma :expr var :kind 0) #S(sb-impl::comma :expr coerced-value :kind 0) #S(sb-impl::comma :expr firstp :kind 0) nil)))))))
Generate a defmacro form that transforms code like this:
(with-local-readtable
  nil
  (progn))

Pattern to recognize: Macro call that should be transformed by WITH-LOCAL-READTABLE

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

Macroexpansion:
(bind ((*readtable* (copy-readtable *readtable*)))
  nil
  (progn))