j14i/cl-macros huggingface dataset:
Generate a defmacro form that transforms code like this:
(check-cursor-attached cluffer:erase-item (cursor))

Pattern to recognize: Macro call that should be transformed by check-cursor-attached

Macro definition:
(defmacro check-cursor-attached (name arguments)
  (let ((args (substitute '(cursor cluffer:cursor) 'cursor arguments)))
    `(defmethod ,name :before ,args
       (declare (ignore ,@(set-difference (remove 'cursor arguments)
                                          lambda-list-keywords)))
       (unless (cluffer:cursor-attached-p cursor)
         (error 'cluffer:cursor-detached)))))

Macroexpansion:
(defmethod cluffer:erase-item :before ((cursor cluffer:cursor)) (declare (ignore)) (unless (cluffer:cursor-attached-p cursor) (error (quote cluffer:cursor-detached))))
Generate a defmacro form that transforms code like this:
(define-hook (:boot uiop) () (unless uiop/image::*image-restored-p* (setf uiop/image::*image-restored-p* :in-progress) (uiop/image:call-image-restore-hook) (setf uiop/image::*image-restored-p* T)))

Pattern to recognize: Macro call that should be transformed by define-hook

Macro definition:
(defmacro define-hook ((type name &optional (priority 0)) args &body body)
  (ecase type (:pre-load) (:load) (:build) (:deploy) (:boot) (:quit))
  (check-type name symbol)
  `(let ((,name (or (hook ,type ',name)
                    (make-instance 'hook :name ',name :type ,type))))
     (setf (hook-priority ,name) ,priority)
     (setf (hook-function ,name) (flet ((,name (&key ,@args &allow-other-keys)
                                          ,@body))
                                   #',name))
     (setf (hook ,type ',name) ,name)
     (setf (docstring ,name) ,(if (stringp (car body)) (car body)))
     ',name))

Macroexpansion:
(let ((uiop (or (hook :boot (quote uiop)) (make-instance (quote hook) :name (quote uiop) :type :boot)))) (setf (hook-priority uiop) 0) (setf (hook-function uiop) (flet ((uiop (&key &allow-other-keys) (unless uiop/image::*image-restored-p* (setf uiop/image::*image-restored-p* :in-progress) (uiop/image:call-image-restore-hook) (setf uiop/image::*image-restored-p* t)))) (function uiop))) (setf (hook :boot (quote uiop)) uiop) (setf (docstring uiop) nil) (quote uiop))
Create a Common Lisp macro for the following transformation. Before code:
(define-fixture-restore macro (symbol value) (setf (macro-function symbol) value))

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

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

Macroexpansion:
(progn (setf (gethash (quote macro) *fixture-restores*) (lambda (symbol value) (setf (macro-function symbol) value))) (quote macro))
Define a macro that eliminates this repetitive pattern:
(some->
  nil
  :key
  nil)

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

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

Macroexpansion:
(let* ((#:var173 nil)
       (#:var174
        (if #:var173
            (:key #:var173)
            nil))
       (#:var175
        (if #:var174
            (nil #:var174)
            nil)))
  #:var175)
Write a Common Lisp macro to handle this code pattern:
(defsynonym multiply :mult)

Problem: 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 multiply) (quote synonym)) (quote :mult)))
Define a macro that eliminates this repetitive pattern:
(defjsmacro nil (progn))

Issue: Macro call that should be transformed by DEFJSMACRO

Macro definition:
(defmacro DEFJSMACRO ...)

Macroexpansion:
(defpsmacro nil
    (progn))
You are a Common Lisp macro expert. Given this code pattern:
(assert-values ("deleted bar") (foo 'nothing) (foo+1 'nothing) (bar 'nothing) (bar-1 'nothing) (baz 'nothing))

Write a macro that addresses: Macro call that should be transformed by assert-values

Macro definition:
(defmacro assert-values ((desc) &body objects-and-values)
  `(progn
     (trc ,desc)
     ,@(loop for (obj val) in objects-and-values
	    collect `(assert (eql (value ,obj) ,val)))))

Macroexpansion:
(progn (trc "deleted bar") (assert (eql (value foo) (quote nothing))) (assert (eql (value foo+1) (quote nothing))) (assert (eql (value bar) (quote nothing))) (assert (eql (value bar-1) (quote nothing))) (assert (eql (value baz) (quote nothing))))
Write a Common Lisp macro to handle this code pattern:
(enable-quasi-quoted-string-to-binary-emitting-form-syntax nil)

Problem: Macro call that should be transformed by ENABLE-QUASI-QUOTED-STRING-TO-BINARY-EMITTING-FORM-SYNTAX

Macro definition:
(defmacro ENABLE-QUASI-QUOTED-STRING-TO-BINARY-EMITTING-FORM-SYNTAX ...)

Macroexpansion:
(eval-when (:compile-toplevel :execute)
  (setf *readtable* (copy-readtable *readtable*))
  (set-quasi-quoted-string-to-binary-emitting-form-syntax-in-readtable nil
                                                                       :with-inline-emitting
                                                                       nil
                                                                       :declarations
                                                                       'nil
                                                                       :start-character
                                                                       nil
                                                                       :end-character
                                                                       nil
                                                                       :unquote-character
                                                                       #\COMMA
                                                                       :splice-character
                                                                       #\COMMERCIAL_AT
                                                                       :destructive-splice-character
                                                                       #\FULL_STOP
                                                                       :dispatched-quasi-quote-name
                                                                       "str"
                                                                       :encoding
                                                                       *default-character-encoding*)
  (values))
Create a Common Lisp macro for the following transformation. Before code:
(defun/1 fgetc (fd) (handler-case (char-code (read-char (fd-stream fd))) (end-of-file () (setf (feof fd) 1) EOF) (error () (setf (ferror fd) EIO) EOF)))

What needs to change: Macro call that should be transformed by defun/1

Macro definition:
(defmacro defun/1 (name arglist &body body)
  "Lisp-1 defun; makes function pointers work."
  `(progn
     (defun ,name ,arglist
       (declare (optimize (speed 0) (debug 3)
                          ;; FIXME: Why do minor warnings result in load errors?
                          #+sbcl (sb-ext:inhibit-warnings 3)))
        
       ,@body)
     (defparameter ,name (vacietis.c:mkptr& (symbol-function ',name)))))

Macroexpansion:
(progn (defun fgetc (fd) (declare (optimize (speed 0) (debug 3) (sb-ext:inhibit-warnings 3))) (handler-case (char-code (read-char (fd-stream fd))) (end-of-file nil (setf (feof fd) 1) eof) (error nil (setf (ferror fd) eio) eof))) (defparameter fgetc (vacietis.c:mkptr& (symbol-function (quote fgetc)))))
You are a Common Lisp macro expert. Given this code pattern:
(max-of 'some-name)

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

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

Macroexpansion:
(lc ('some-name) maximize)
You are a Common Lisp macro expert. Given this code pattern:
(rte-ecase nil)

Write a macro that addresses: Macro call that should be transformed by RTE-ECASE

Macro definition:
(defmacro RTE-ECASE ...)

Macroexpansion:
(let ((#:rte171 nil))
  (rte-ecase #:rte171
    ((:* t) (error "The sequence ~A fell through the RTE-ECASE" #:rte171))))
Generate a defmacro form that transforms code like this:
(class/std new-stub var1 var2 var3 var4 :with :std :unbound)

Pattern to recognize: 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 new-stub nil ((var1 var2 var3 var4 :with :std :unbound)))
Write a Common Lisp macro to handle this code pattern:
(deferror "40P01" deadlock-detected transaction-rollback)

Problem: 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 deadlock-detected (transaction-rollback) nil) (setf (gethash "40P01" *error-table*) (quote deadlock-detected)))
Generate a defmacro form that transforms code like this:
(signal-syntax-error* (1- (lexer-pos lexer)) "Character '~A' may not follow '(?<' (because ~a = NIL)" next-char '*allow-named-registers*)

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

Macro definition:
(defmacro signal-syntax-error* (pos format-control &rest format-arguments)
  `(error 'ppcre-syntax-error
          :pos ,pos
          :format-control ,format-control
          :format-arguments (list ,@format-arguments)))

Macroexpansion:
(error (quote ppcre-syntax-error) :pos (1- (lexer-pos lexer)) :format-control "Character '~A' may not follow '(?<' (because ~a = NIL)" :format-arguments (list next-char (quote *allow-named-registers*)))
Write a Common Lisp macro to handle this code pattern:
(fn 'some-name)

Problem: Macro call that should be transformed by FN

Macro definition:
(defmacro FN ...)

Macroexpansion:
(lambda () 'some-name)
You are a Common Lisp macro expert. Given this code pattern:
(with-symbol-access
  nil
  nil)

Write a macro that addresses: Macro call that should be transformed by WITH-SYMBOL-ACCESS

Macro definition:
(defmacro WITH-SYMBOL-ACCESS ...)

Macroexpansion:
(let ((*symbol-access* t))
  nil
  nil)
Create a Common Lisp macro for the following transformation. Before code:
(def$flavor nil :key nil)

What needs to change: Macro call that should be transformed by DEF$FLAVOR

Macro definition:
(defmacro DEF$FLAVOR ...)

Macroexpansion:
(progn
 (eval-when (:compile-toplevel)
   (defvar nil)
   (setq nil
           (funcall (mcs-slot-value flavor-class (index-of-basicnew-fn))
                    flavor-class :name 'nil :supers
                    (if 'nil
                        (list)
                        (list standard-object))
                    :own-slots ':key :req-inst-vars 'nil)))
 (eval-when (:load-toplevel)
   (defvar nil)
   (setq nil
           (send-fast
            (funcall (mcs-slot-value flavor-class (index-of-basicnew-fn))
                     flavor-class :name 'nil :supers
                     (if 'nil
                         (list)
                         (list standard-object))
                     :own-slots ':key :req-inst-vars 'nil)
            :init)))
 (eval-when (:execute)
   (defvar nil)
   (let ((new-class
          (funcall (mcs-slot-value flavor-class (index-of-basicnew-fn))
                   flavor-class :name 'nil :supers
                   (if 'nil
                       (list)
                       (list standard-object))
                   :own-slots ':key :req-inst-vars 'nil)))
     (if (flavorp 'nil)
         (redefine-class nil new-class)
         (setq nil (send-fast new-class :init))))))
Create a Common Lisp macro for the following transformation. Before code:
(with-wrap-attempt ("accessors for structure ~S" foreign-record) foreign-record (let ((*package* (find-package package)) (foreign-record (etypecase foreign-record (foreign-record foreign-record) ((or symbol cons) (require-type-no-context foreign-record))))) (unless (and (typep foreign-record 'foreign-alias) (struct-or-union-p (foreign-type-name foreign-record))) (let* ((*accessor-forms*) (*accessor-seen-types*) (*accessor-params* (list (foreign-type-name foreign-record))) (*accessor-record-name* (foreign-type-name foreign-record)) (actual-foreign-record (basic-foreign-type foreign-record))) (when (typep actual-foreign-record 'foreign-record) (%make-accessors actual-foreign-record :prefix *accessor-record-name*) `(progn ,@(nreverse *accessor-forms*)))))))

What needs to change: 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 foreign-record (lambda nil (let ((*package* (find-package package)) (foreign-record (etypecase foreign-record (foreign-record foreign-record) ((or symbol cons) (require-type-no-context foreign-record))))) (unless (and (typep foreign-record (quote foreign-alias)) (struct-or-union-p (foreign-type-name foreign-record))) (let* ((*accessor-forms*) (*accessor-seen-types*) (*accessor-params* (list (foreign-type-name foreign-record))) (*accessor-record-name* (foreign-type-name foreign-record)) (actual-foreign-record (basic-foreign-type foreign-record))) (when (typep actual-foreign-record (quote foreign-record)) (%make-accessors actual-foreign-record :prefix *accessor-record-name*) (sb-int:quasiquote (progn #S(sb-impl::comma :expr (nreverse *accessor-forms*) :kind 2)))))))) "accessors for structure ~S" (list foreign-record))
Generate a defmacro form that transforms code like this:
(define 'some-name)

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

Macro definition:
(defmacro DEFINE ...)

Macroexpansion:
(eval-when (:load-toplevel :execute)
  (check-if-bound ''some-name)
  (setf (get ''some-name 'read-macro)
          (lambda (#:stream149) (let ((*standard-input* #:stream149)))))
  ''some-name)
Write a Common Lisp macro to handle this code pattern:
(mvlet* ((fn (caar bindings)) (body decls (parse-body body)) (local others (partition-declarations `((function ,fn)) decls env))) `(fbind (,(first bindings)) ,@local (fbind* ,(rest bindings) ,@others ,@body)))

Problem: 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:
(let* ((fn (caar bindings))) (mvlet* ((body decls (parse-body body)) (local others (partition-declarations (sb-int:quasiquote ((function #S(sb-impl::comma :expr fn :kind 0)))) decls env))) (sb-int:quasiquote (fbind (#S(sb-impl::comma :expr (first bindings) :kind 0)) #S(sb-impl::comma :expr local :kind 2) (fbind* #S(sb-impl::comma :expr (rest bindings) :kind 0) #S(sb-impl::comma :expr others :kind 2) #S(sb-impl::comma :expr body :kind 2))))))
Generate a defmacro form that transforms code like this:
(with-disable-handler-restart ((first handler-entry)) (with-hook-restart (list (apply (first handler-entry) args))))

Pattern to recognize: Macro call that should be transformed by with-disable-handler-restart

Macro definition:
(defmacro with-disable-handler-restart ((handler) &body body)
  "This is intended to wrap all handler executions."
  `(restart-case
       (progn ,@body)
     (disable-handler ()
       :report
       (lambda (stream)
         (format stream "Disable handler ~a which causes the error." ,handler))
       (disable-hook *hook* ,handler))))

Macroexpansion:
(restart-case (progn (with-hook-restart (list (apply (first handler-entry) args)))) (disable-handler nil :report (lambda (stream) (format stream "Disable handler ~a which causes the error." (first handler-entry))) (disable-hook *hook* (first handler-entry))))
Write a Common Lisp macro to handle this code pattern:
(with-html-string (:body (:h* "This is a top level heading") (:p "...") (let ((*html-path* (append *html-path* '(:section)))) (:h* "This is a second-level tricked by *HTML-PATH*") (:p "..."))))

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

Macro definition:
(defmacro with-html (&body body &environment env)
  "Interpret BODY as HTML. Consult README.txt for the syntax."
  `(let ((*html* (ensure-html-stream *html*)))
     ,(if (and (null (cdr body)) (atom (car body)))
          (car body)
          `(progn ,@(parse-html body env)))))

Macroexpansion:
(with-output-to-string (*html*) (with-html (:body (:h* "This is a top level heading") (:p "...") (let ((*html-path* (append *html-path* (quote (:section))))) (:h* "This is a second-level tricked by *HTML-PATH*") (:p "...")))))
Create a Common Lisp macro for the following transformation. Before code:
(gen-lambda-with-sticky-stop () (let ((res (funcall source-func))) (if (funcall predicate res) res (sticky-stop))))

What needs to change: Macro call that should be transformed by gen-lambda-with-sticky-stop

Macro definition:
(defmacro gen-lambda-with-sticky-stop (&rest rest)
  `(make-instance 
    'basic-generator 
    :function (sticky-stop-lambda ,@rest)))

Macroexpansion:
(make-instance (quote basic-generator) :function (sticky-stop-lambda nil (let ((res (funcall source-func))) (if (funcall predicate res) res (sticky-stop)))))
You are a Common Lisp macro expert. Given this code pattern:
(macroexpand-convention (form) (if (consp form) (expand-export-constructors-using-head (first form) form) form))

Write a macro that addresses: Macro call that should be transformed by macroexpand-convention

Macro definition:
(defmacro macroexpand-convention ((original-form) &body body)
  "Executes BODY as like `progn' and return the result as the first
value.  As the second value, returns a boolean whether the result is
not same with ORIGINAL-FORM or not.
This macro is designed to follow the `macroexpand' convention."
  `(multiple-value-bind (result expanded-p)
       (progn ,@body)
     (values result
             (or expanded-p
                 (not (eq result ,original-form))))))

Macroexpansion:
(multiple-value-bind (result expanded-p) (progn (if (consp form) (expand-export-constructors-using-head (first form) form) form)) (values result (or expanded-p (not (eq result form)))))
Write a Common Lisp macro to handle this code pattern:
(define-bug loop-flow-analysis-failure (:error-type varjo-critical-error) () "Varjo's flow analyzer has been unable to resolve the variable flow in this loop within a reasonable ammount of time. This counts as a compiler bug so please report it on github")

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

Macro definition:
(defmacro define-bug (name (&key (error-type 'varjo-error) (prefix "Varjo Bug"))
                            (&rest args) error-string &body body)
  `(defcondition ,name (:error-type ,error-type :prefix ,prefix) ,args
       ,error-string ,@body))

Macroexpansion:
(defcondition loop-flow-analysis-failure (:error-type varjo-critical-error :prefix "Varjo Bug") nil "Varjo's flow analyzer has been unable to resolve the variable flow in this loop within a reasonable ammount of time. This counts as a compiler bug so please report it on github")
Create a Common Lisp macro for the following transformation. Before code:
(*> +skip-space+ +slash+)

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

Macro definition:
(defmacro *> (parser &rest parsers)
  "Combination of parsers yielding the result of the rightmost one."
  (let ((offset (gensym "*>-OFFSET")))
    `(lambda (,offset)
       ,(reduce (lambda (i p)
                  (let ((res  (gensym "*>-RES"))
                        (next (gensym "*>-NEXT")))
                    `(multiple-value-bind (,res ,next) ,i
                       (if (ok? ,res)
                           (funcall ,p ,next)
                           (fail ,next)))))
                parsers
                :initial-value `(funcall ,parser ,offset)))))

Macroexpansion:
(lambda (#:*>-offset259) (multiple-value-bind (#:*>-res260 #:*>-next261) (funcall +skip-space+ #:*>-offset259) (if (ok? #:*>-res260) (funcall +slash+ #:*>-next261) (fail #:*>-next261))))
You are a Common Lisp macro expert. Given this code pattern:
(none-of nil)

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

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

Macroexpansion:
(lc (nil) never)
You are a Common Lisp macro expert. Given this code pattern:
(with-csv-input-stream (in-stream stream-or-string) (read-with-dispatch-table csv-reader in-stream) (coerce (rows csv-reader) 'list))

Write a macro that addresses: Macro call that should be transformed by with-csv-input-stream

Macro definition:
(defmacro with-csv-input-stream ((name inp) &body body)
  (alexandria:with-unique-names (opened?)
    `(multiple-value-bind (,name ,opened?) (%in-stream ,inp)
      (flet ((body () ,@body))
        (unwind-protect (body)
          (when (and ,name ,opened?)
            (close ,name)))))))

Macroexpansion:
(multiple-value-bind (in-stream #:opened?199) (%in-stream stream-or-string) (flet ((body nil (read-with-dispatch-table csv-reader in-stream) (coerce (rows csv-reader) (quote list)))) (unwind-protect (body) (when (and in-stream #:opened?199) (close in-stream)))))