j14i/cl-macros huggingface dataset:
Define a macro that eliminates this repetitive pattern:
(fail-compile (defun foo () (frob)) style-warning)

Issue: Macro call that should be transformed by fail-compile

Macro definition:
(defmacro fail-compile (form &optional (type 'error) description &rest format-args)
  `(eval-in-context
    *context*
    (make-instance 'comparison-result
                   :expression '(fail-expansion ,form)
                   :value-form '(nth-value 3 (try-compile ',form ',type))
                   :body (lambda () (nth-value 3 (try-compile ',form ',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-expansion (defun foo nil (frob)))) :value-form (quote (nth-value 3 (try-compile (quote (defun foo nil (frob))) (quote style-warning)))) :body (lambda nil (nth-value 3 (try-compile (quote (defun foo nil (frob))) (quote style-warning)))) :expected (quote style-warning) :comparison (quote typep)))
You are a Common Lisp macro expert. Given this code pattern:
(defun/1 fwrite (mem element_size count fd) (handler-case (let ((start (memptr-ptr mem))) (write-sequence (memptr-mem mem) (fd-stream fd) :start start :end (+ start (* element_size count))) count) (error () (setf (ferror fd) EIO) 0)))

Write a macro that addresses: 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 fwrite (mem element_size count fd) (declare (optimize (speed 0) (debug 3) (sb-ext:inhibit-warnings 3))) (handler-case (let ((start (memptr-ptr mem))) (write-sequence (memptr-mem mem) (fd-stream fd) :start start :end (+ start (* element_size count))) count) (error nil (setf (ferror fd) eio) 0))) (defparameter fwrite (vacietis.c:mkptr& (symbol-function (quote fwrite)))))
Write a Common Lisp macro to handle this code pattern:
(drelet nil
  nil)

Problem: Macro call that should be transformed by DRELET

Macro definition:
(defmacro DRELET ...)

Macroexpansion:
(dynamic-relet nil
  nil)
Create a Common Lisp macro for the following transformation. Before code:
(define-alias-binding repeat repeating)

What needs to change: Macro call that should be transformed by define-alias-binding

Macro definition:
(defmacro define-alias-binding (name referenced-binding-name)
  `(progn (setf (binding ',name) ',referenced-binding-name)
          ',name))

Macroexpansion:
(progn (setf (binding (quote repeat)) (quote repeating)) (quote repeat))
Define a macro that eliminates this repetitive pattern:
(with-yield (iterate (for (x) in-generator (some-numbers)) (yield (1+ x))))

Issue: Macro call that should be transformed by with-yield

Macro definition:
(defmacro with-yield (&body body)
  (let ((point (gensym))
        (current (gensym)))
    `(let (,point ,current)
       (with-call/cc
	 (labels ((yield (&rest values)
		    (setf ,current values)
		    (let/cc k
		      (setf ,point k))))
	   ,@body
	   (setf ,point nil)))
       (gen-lambda ()
	 (cond ((null ,point)
		'generator-stop)
	       (t
		(let ((current ,current))
		  (funcall ,point nil)
		  ;values-handler: see gen-lambda
		  (apply #'values (funcall values-handler current)))))))))

Macroexpansion:
(let (#:g151 #:g152) (with-call/cc (labels ((yield (&rest values) (setf #:g152 values) (let/cc k (setf #:g151 k)))) (iterate (for (x) in-generator (some-numbers)) (yield (1+ x))) (setf #:g151 nil))) (gen-lambda nil (cond ((null #:g151) (quote generator-stop)) (t (let ((current #:g152)) (funcall #:g151 nil) (apply (function values) (funcall values-handler current)))))))
Generate a defmacro form that transforms code like this:
(pass)

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

Macro definition:
(defmacro pass (&rest message-args)
  "Simply generate a PASS."
  `(add-result 'test-passed
               :test-expr ',message-args
               ,@(when message-args
                   `(:reason (format nil ,@message-args)))))

Macroexpansion:
(add-result (quote test-passed) :test-expr (quote nil))
Generate a defmacro form that transforms code like this:
(auto-permute-typecase nil
  nil)

Pattern to recognize: Macro call that should be transformed by AUTO-PERMUTE-TYPECASE

Macro definition:
(defmacro AUTO-PERMUTE-TYPECASE ...)

Macroexpansion:
(typecase nil ())
Define a macro that eliminates this repetitive pattern:
(*> (take 3) (take 2))

Issue: 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 (#:*>-offset209) (multiple-value-bind (#:*>-res210 #:*>-next211) (funcall (take 3) #:*>-offset209) (if (ok? #:*>-res210) (funcall (take 2) #:*>-next211) (fail #:*>-next211))))
You are a Common Lisp macro expert. Given this code pattern:
(atypecase 1.0 (integer (+ 2 it)) (float (1- it)))

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

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

Macroexpansion:
(anaphoric typecase 1.0 (integer (+ 2 it)) (float (1- it)))
Write a Common Lisp macro to handle this code pattern:
(with-preprocessor-state-slots (state) (when if-section-skip-reason (return-from process-preprocessing-directive nil)) (multiple-value-bind (header-name header-type) (parse-header-name directive-token-list directive-symbol t macro-alist state) (let* ((pathname (ecase header-type (:q-char-sequence (find-include-header-file header-name)) (:h-char-sequence (find-include-<header>-file header-name)))) (included-tokens (tokenize-included-source-file pathname state))) (push-include-state state) (pop-next-newline token-list) (setf token-list (nconc included-tokens token-list)))))

Problem: Macro call that should be transformed by with-preprocessor-state-slots

Macro definition:
(defmacro with-preprocessor-state-slots ((state) &body body)
  `(with-accessors ((file-pathname pp-state-file-pathname)
                    (token-list pp-state-token-list)
                    (result-list pp-state-result-list)
                    (line-number pp-state-line-number)
                    (tokens-in-line pp-state-tokens-in-line)
                    (macro-alist pp-state-macro-alist)
                    (if-section-stack pp-state-if-section-stack)
                    (if-section-skip-reason pp-state-if-section-skip-reason)
                    (include-stack pp-state-include-stack))
       ,state
     ,@body))

Macroexpansion:
(with-accessors ((file-pathname pp-state-file-pathname) (token-list pp-state-token-list) (result-list pp-state-result-list) (line-number pp-state-line-number) (tokens-in-line pp-state-tokens-in-line) (macro-alist pp-state-macro-alist) (if-section-stack pp-state-if-section-stack) (if-section-skip-reason pp-state-if-section-skip-reason) (include-stack pp-state-include-stack)) state (when if-section-skip-reason (return-from process-preprocessing-directive nil)) (multiple-value-bind (header-name header-type) (parse-header-name directive-token-list directive-symbol t macro-alist state) (let* ((pathname (ecase header-type (:q-char-sequence (find-include-header-file header-name)) (:h-char-sequence (find-include-<header>-file header-name)))) (included-tokens (tokenize-included-source-file pathname state))) (push-include-state state) (pop-next-newline token-list) (setf token-list (nconc included-tokens token-list)))))
Create a Common Lisp macro for the following transformation. Before code:
(defclass/a dbd-postgres (dbi-driver) ())

What needs to change: Macro call that should be transformed by defclass/a

Macro definition:
(defmacro defclass/a (name superclasses slots &rest class-options)
  `(progn
     (defclass ,name ,superclasses ,slots ,@class-options)
     (deftype ,(intern (format nil "<~A>" (symbol-name name))) () ',name)
     (setf (find-class ',(intern (format nil "<~A>" (symbol-name name))))
           (find-class ',name))))

Macroexpansion:
(progn (defclass dbd-postgres (dbi-driver) nil) (deftype <dbd-postgres> nil (quote dbd-postgres)) (setf (find-class (quote <dbd-postgres>)) (find-class (quote dbd-postgres))))
Write a Common Lisp macro to handle this code pattern:
(with-access nil
    :key
  nil)

Problem: Macro call that should be transformed by WITH-ACCESS

Macro definition:
(defmacro with-access ((&rest keys) val-form &body body)
  "Similar to with-accessors except using the access functions"
  (let* ((gval (gensym "val"))
     (forms
      (iter (for k in keys)
        (for (k-to k-from) = (if (listp k) k (list k k)))
        (collect `(,k-to (access ,gval ',k-from))))))
    `(let ((,gval ,val-form))
       (declare (ignorable ,gval))
       (symbol-macrolet (,@forms)
     ,@body
     ))))

Macroexpansion:
(let ((#:|val243| :key))
  (declare (ignorable #:|val243|))
  (symbol-macrolet ()
    nil))
Define a macro that eliminates this repetitive pattern:
;; Building a closure with mutable behavior requires manual forwarding
(let ((counter 0)
      (impl (lambda (n) (incf counter n))))
  (lambda (&rest args)
    (apply impl args)))

;; To change behavior: build an entirely new closure

Issue: Need mutable closure behavior changeable at runtime, with implicit 'this' pointing to current implementation

Macro definition:
(defmacro alet (letargs &rest body)
  `(let ((this) ,@letargs)
     (setq this ,@(last body))
     ,@(butlast body)
     (lambda (&rest params)
       (apply this params))))

Macroexpansion:
;; (alet ((acc 0))
;;   (format t "Initialized~%")
;;   (lambda (n) (incf acc n)))
;;
;; Returns a forwarding closure where 'this' can be swapped.
;; The lambda inside can (setq this #'new-fn) to hotpatch.
You are a Common Lisp macro expert. Given this code pattern:
(dreletf* nil)

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

Macro definition:
(defmacro DRELETF* ...)

Macroexpansion:
(progn)
Define a macro that eliminates this repetitive pattern:
(class-stealth-mixins 'some-name)

Issue: Macro call that should be transformed by CLASS-STEALTH-MIXINS

Macro definition:
(defmacro CLASS-STEALTH-MIXINS ...)

Macroexpansion:
(gethash 'some-name *stealth-mixins*)
Define a macro that eliminates this repetitive pattern:
(with-prepared-query query (conn "SELECT last_insert_rowid() AS last_insert_id") (or (first (dbi:fetch (dbi:execute query) :format :values)) 0))

Issue: Macro call that should be transformed by with-prepared-query

Macro definition:
(defmacro with-prepared-query (query (conn sql &key use-prepare-cached) &body body)
  `(call-with-prepared-query ,conn ,sql (lambda (,query) ,@body) :use-prepare-cached ,use-prepare-cached))

Macroexpansion:
(call-with-prepared-query conn "SELECT last_insert_rowid() AS last_insert_id" (lambda (query) (or (first (dbi.driver:fetch (dbi.driver:execute query) :format :values)) 0)) :use-prepare-cached nil)
Generate a defmacro form that transforms code like this:
($map-reduce "foo" m r :query ($> "l" -9))

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

Macro definition:
(defmacro $ (&rest args)
  `(kv ,@args))

Macroexpansion:
(db.find "$cmd" (kv (kv "mapreduce" "foo") (kv "map" (or (jsdef m) (quote m))) (kv "reduce" (or (jsdef r) (quote r))) (when nil (kv "finalize" (jsdef nil))) (kv "out" (if nil nil (concatenate (quote string) "mr." "foo"))) (kv "verbose" t) (kv "limit" 0) (kv "keeptemp" nil) (kv "query" ($> "l" -9))))
Generate a defmacro form that transforms code like this:
(with-effective-qualifier generic-function qualifier `(%lay-method-base-for-dispatch ,generic-function ,qualifier ,type-list ,descriptive-lambda-list (dispatch ,generic-function ,qualifier ,specialized-lambda-list) ,@body))

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

Macro definition:
(defmacro with-effective-qualifier (gf-name qualifier &body body)
  "take generic function and a symbol bound to a qualifier and mask that symbol with the effective qualifier.

The effective qualifier is the default qualifier for the given generic function should there be one defined by
a define-hook-generic form."
  `(let ((,qualifier
          (effective-qualifier ,gf-name ,qualifier)))
     ,@body))

Macroexpansion:
(let ((qualifier (effective-qualifier generic-function qualifier))) (sb-int:quasiquote (%lay-method-base-for-dispatch #S(sb-impl::comma :expr generic-function :kind 0) #S(sb-impl::comma :expr qualifier :kind 0) #S(sb-impl::comma :expr type-list :kind 0) #S(sb-impl::comma :expr descriptive-lambda-list :kind 0) (dispatch #S(sb-impl::comma :expr generic-function :kind 0) #S(sb-impl::comma :expr qualifier :kind 0) #S(sb-impl::comma :expr specialized-lambda-list :kind 0)) #S(sb-impl::comma :expr body :kind 2))))
You are a Common Lisp macro expert. Given this code pattern:
(-<>>
  nil
  nil)

Write a macro that addresses: Macro call that should be transformed by -<>>

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

Macroexpansion:
(let* ((#:var120 nil) (#:var121 (nil #:var120)))
  #:var121)
Create a Common Lisp macro for the following transformation. Before code:
(define-modf-rewrite second (expr) `(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 second) *modf-rewrites*) (lambda (expr) (sb-int:quasiquote (cadr #S(sb-impl::comma :expr (second expr) :kind 0))))))
Generate a defmacro form that transforms code like this:
(make-obsolete mustache-type version "0.10.0")

Pattern to recognize: Macro call that should be transformed by make-obsolete

Macro definition:
(defmacro make-obsolete (obsolete-name current-name when)
  `(defun ,obsolete-name (&rest args)
     ,(documentation current-name 'function)
     (warn 'deprecation-warning
           :name ',obsolete-name :replacement ',current-name :since ,when)
     (apply ',current-name args)))

Macroexpansion:
(defun mustache-type (&rest args) #A((31) base-char . "Return the CL-MUSTACHE version.") (warn (quote deprecation-warning) :name (quote mustache-type) :replacement (quote version) :since "0.10.0") (apply (quote version) args))
Generate a defmacro form that transforms code like this:
(define-error flow-id-must-be-specified-co (:error-type varjo-critical-error) () "code objects must be given a flow id when created")

Pattern to recognize: 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 flow-id-must-be-specified-co (:error-type varjo-critical-error :prefix "Varjo") nil "code objects must be given a flow id when created")
You are a Common Lisp macro expert. Given this code pattern:
(infix)

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

Macro definition:
(defmacro INFIX ...)

Macroexpansion:
nil
Generate a defmacro form that transforms code like this:
(with-additional-indent (reporter stream "✓ ") (let ((description (possible-report-description report)) (duration (slot-value report 'duration))) (when description (with-color (:gray :stream stream) (format/indent reporter stream description))) (when duration (format stream " ") (print-duration stream duration (slot-value report 'slow-threshold)))) (terpri stream))

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

Macro definition:
(defmacro with-additional-indent ((reporter stream control-string &rest format-arguments) &body body)
  (declare (ignorable reporter stream control-string))
  (let* ((need-new-line (ppcre:scan "^~&" control-string))
         (string (apply #'format nil control-string format-arguments))
         (increment (length string)))
    `(with-slots (indent-space) reporter
       (let* ((first-line-indent (indent indent-space))
              (*additional-indent* ,(if need-new-line
                                        increment
                                        `(+ *additional-indent*
                                            ,increment))))
         (declare (ignorable first-line-indent))
         ,(if need-new-line
              `(progn (fresh-line stream)
                      (write-string first-line-indent ,stream)
                      ;; because we just started a new line, we
                      ;; should use format/indent to write string
                      ;; taking into account a main indentation level
                      (format/indent ,reporter ,stream ,string))
              ;; otherwise, just output our prefix
              `(write-string ,string ,stream))
       
       
         ,@body))))

Macroexpansion:
(with-slots (indent-space) reporter (let* ((first-line-indent (indent indent-space)) (*additional-indent* (+ *additional-indent* 2))) (declare (ignorable first-line-indent)) (write-string "✓ " stream) (let ((description (possible-report-description report)) (duration (slot-value report (quote duration)))) (when description (with-color (:gray :stream stream) (format/indent reporter stream description))) (when duration (format stream " ") (print-duration stream duration (slot-value report (quote slow-threshold))))) (terpri stream)))
Create a Common Lisp macro for the following transformation. Before code:
(with-cached-reader-conditionals
  nil)

What needs to change: Macro call that should be transformed by WITH-CACHED-READER-CONDITIONALS

Macro definition:
(defmacro WITH-CACHED-READER-CONDITIONALS ...)

Macroexpansion:
(call-with-cached-reader-conditionals (lambda () nil))
Generate a defmacro form that transforms code like this:
(with-prepared-query query (conn (format nil "SELECT pg_get_serial_sequence('~A', '~A')" table-name column)) (let ((seq (first (dbi:fetch (dbi:execute query) :format :values)))) (if (eq seq :null) nil seq)))

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

Macro definition:
(defmacro with-prepared-query (query (conn sql &key use-prepare-cached) &body body)
  `(call-with-prepared-query ,conn ,sql (lambda (,query) ,@body) :use-prepare-cached ,use-prepare-cached))

Macroexpansion:
(call-with-prepared-query conn (format nil "SELECT pg_get_serial_sequence('~A', '~A')" table-name column) (lambda (query) (let ((seq (first (dbi.driver:fetch (dbi.driver:execute query) :format :values)))) (if (eq seq :null) nil seq))) :use-prepare-cached nil)
Create a Common Lisp macro for the following transformation. Before code:
(fail-compile (defun foo () (frob)) style-warning)

What needs to change: 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-expansion (defun foo nil (frob)))) :value-form (quote (nth-value 3 (try-compile (quote (defun foo nil (frob))) (quote style-warning)))) :body (lambda nil (nth-value 3 (try-compile (quote (defun foo nil (frob))) (quote style-warning)))) :expected (quote style-warning) :comparison (quote typep)))
Write a Common Lisp macro to handle this code pattern:
(defsynonym :minimize :min)

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 :minimize) (quote synonym)) (quote :min)))
Write a Common Lisp macro to handle this code pattern:
(define-binary-op-mapping-definer define-binary-ops `(progn (declaim (inline ,op)) (defun ,op (x y) (,cl x y))))

Problem: Macro call that should be transformed by define-binary-op-mapping-definer

Macro definition:
(defmacro define-binary-op-mapping-definer (name &body body)
  `(defmacro ,name (&rest map)
     `(progn ,@(loop for (vacietis cl) on map by #'cddr collect
                    (let ((op (find-symbol (symbol-name vacietis) '#:vacietis.c)))
                      ,@body)))))

Macroexpansion:
(defmacro define-binary-ops (&rest map) (sb-int:quasiquote (progn #S(sb-impl::comma :expr (loop for (vacietis cl) on map by (function cddr) collect (let ((op (find-symbol (symbol-name vacietis) (quote #:vacietis.c)))) (sb-int:quasiquote (progn (declaim (inline #S(sb-impl::comma :expr op :kind 0))) (defun #S(sb-impl::comma :expr op :kind 0) (x y) (#S(sb-impl::comma :expr cl :kind 0) x y)))))) :kind 2))))
Generate a defmacro form that transforms code like this:
(let+ 'some-name)

Pattern to recognize: Macro call that should be transformed by LET+

Macro definition:
(defmacro LET+ ...)

Macroexpansion:
(let ((quote))
  (let ((some-name))))
Define a macro that eliminates this repetitive pattern:
(assoc-cdr :first-name uinfo)

Issue: Macro call that should be transformed by assoc-cdr

Macro definition:
(defmacro assoc-cdr (key alist &optional (test '#'eql))
  `(cdr (assoc ,key ,alist :test ,test)))

Macroexpansion:
(cdr (assoc :first-name uinfo :test (function eql)))
You are a Common Lisp macro expert. Given this code pattern:
(ps-once-only nil
  nil)

Write a macro that addresses: Macro call that should be transformed by PS-ONCE-ONLY

Macro definition:
(defmacro PS-ONCE-ONLY ...)

Macroexpansion:
(let* ()
  `(let* ()
     ,(let* ()
        nil)))
You are a Common Lisp macro expert. Given this code pattern:
(define-bug invalid-special-function-arg-spec (:error-type varjo-critical-error) (name spec) "The special function named ~s has an invalid argument spec: ~a Please report this bug on github" name spec)

Write a macro that addresses: 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 invalid-special-function-arg-spec (:error-type varjo-critical-error :prefix "Varjo Bug") (name spec) "The special function named ~s has an invalid argument spec: ~a Please report this bug on github" name spec)