j14i/cl-macros huggingface dataset:
Define a macro that eliminates this repetitive pattern:
(with-shadowed-custom-vars (let ((*json-identifier-name-to-lisp* #'simplified-camel-case-to-lisp)) (dotimes (x count) (let ((discard-soon (with-fp-overflow-handler (invoke-restart 'placeholder :infty) (with-no-char-handler (invoke-restart 'substitute-char #\?) (decode-json-from-string json-string))))) (funcall #'identity discard-soon)))))

Issue: Macro call that should be transformed by with-shadowed-custom-vars

Macro definition:
(defmacro with-shadowed-custom-vars (&body body)
  `(let ,(loop for (var) in *custom-vars*
            collect `(,var (if (boundp ',var) ,var)))
     ,@body))

Macroexpansion:
(let ((*aggregate-scope-variables* (if (boundp (quote *aggregate-scope-variables*)) *aggregate-scope-variables*)) (*string-scope-variables* (if (boundp (quote *string-scope-variables*)) *string-scope-variables*)) (*array-scope-variables* (if (boundp (quote *array-scope-variables*)) *array-scope-variables*)) (*object-scope-variables* (if (boundp (quote *object-scope-variables*)) *object-scope-variables*)) (*internal-decoder* (if (boundp (quote *internal-decoder*)) *internal-decoder*)) (*end-of-object-handler* (if (boundp (quote *end-of-object-handler*)) *end-of-object-handler*)) (*object-value-handler* (if (boundp (quote *object-value-handler*)) *object-value-handler*)) (*object-key-handler* (if (boundp (quote *object-key-handler*)) *object-key-handler*)) (*beginning-of-object-handler* (if (boundp (quote *beginning-of-object-handler*)) *beginning-of-object-handler*)) (*json-array-type* (if (boundp (quote *json-array-type*)) *json-array-type*)) (*end-of-array-handler* (if (boundp (quote *end-of-array-handler*)) *end-of-array-handler*)) (*array-member-handler* (if (boundp (quote *array-member-handler*)) *array-member-handler*)) (*beginning-of-array-handler* (if (boundp (quote *beginning-of-array-handler*)) *beginning-of-array-handler*)) (*end-of-string-handler* (if (boundp (quote *end-of-string-handler*)) *end-of-string-handler*)) (*string-char-handler* (if (boundp (quote *string-char-handler*)) *string-char-handler*)) (*beginning-of-string-handler* (if (boundp (quote *beginning-of-string-handler*)) *beginning-of-string-handler*)) (*boolean-handler* (if (boundp (quote *boolean-handler*)) *boolean-handler*)) (*real-handler* (if (boundp (quote *real-handler*)) *real-handler*)) (*integer-handler* (if (boundp (quote *integer-handler*)) *integer-handler*))) (let ((*json-identifier-name-to-lisp* (function simplified-camel-case-to-lisp))) (dotimes (x count) (let ((discard-soon (with-fp-overflow-handler (invoke-restart (quote placeholder) :infty) (with-no-char-handler (invoke-restart (quote substitute-char) #\QUESTION_MARK) (decode-json-from-string json-string))))) (funcall (function identity) discard-soon)))))
Create a Common Lisp macro for the following transformation. Before code:
(who-ps-html 'some-name)

What needs to change: Macro call that should be transformed by WHO-PS-HTML

Macro definition:
(defmacro WHO-PS-HTML ...)

Macroexpansion:
(stringify "someName")
Define a macro that eliminates this repetitive pattern:
(deferror "42P03" duplicate-cursor syntax-error-or-access-violation)

Issue: 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 duplicate-cursor (syntax-error-or-access-violation) nil) (setf (gethash "42P03" *error-table*) (quote duplicate-cursor)))
You are a Common Lisp macro expert. Given this code pattern:
(mvlet* ((simple decls (partn simple decls)) (complex decls (partn complex decls)) (lambda decls (partn lambda decls))) (values simple complex lambda decls))

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

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

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

    (var var*... expr)

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

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

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

Macroexpansion:
(multiple-value-bind (simple decls) (partn simple decls) (mvlet* ((complex decls (partn complex decls)) (lambda decls (partn lambda decls))) (values simple complex lambda decls)))
You are a Common Lisp macro expert. Given this code pattern:
(with-yield-binds (format nil "ON CONFLICT ~:[~;ON CONSTRAINT ~]~A DO UPDATE ~A~@[ ~A~]" (eq (type-of (on-conflict-do-update-clause-conflict-target clause)) 'sql-symbol) (yield (on-conflict-do-update-clause-conflict-target clause)) (yield (on-conflict-do-update-clause-update-set clause)) (and (on-conflict-do-update-clause-where-condition clause) (yield (on-conflict-do-update-clause-where-condition clause)))))

Write a macro that addresses: Macro call that should be transformed by with-yield-binds

Macro definition:
(defmacro with-yield-binds (&body body)
  `(let ((*bind-values* nil)
         (*use-global-bind-values* t))
     (values
      (progn ,@body)
      (loop for bind in (reverse *bind-values*)
            append bind))))

Macroexpansion:
(let ((*bind-values* nil) (*use-global-bind-values* t)) (values (progn (format nil "ON CONFLICT ~:[~;ON CONSTRAINT ~]~A DO UPDATE ~A~@[ ~A~]" (eq (type-of (on-conflict-do-update-clause-conflict-target clause)) (quote sql-symbol)) (yield (on-conflict-do-update-clause-conflict-target clause)) (yield (on-conflict-do-update-clause-update-set clause)) (and (on-conflict-do-update-clause-where-condition clause) (yield (on-conflict-do-update-clause-where-condition clause))))) (loop for bind in (reverse *bind-values*) append bind)))
Define a macro that eliminates this repetitive pattern:
(->*)

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

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

Macroexpansion:
nil
Write a Common Lisp macro to handle this code pattern:
(dynenv-macrolet nil
  nil)

Problem: Macro call that should be transformed by DYNENV-MACROLET

Macro definition:
(defmacro DYNENV-MACROLET ...)

Macroexpansion:
(macrolet ()
  nil)
Create a Common Lisp macro for the following transformation. Before code:
(define-error out-var-name-taken () (out-var-name) "The variable name '~a' is already taken and so cannot be used~%for an out variable" out-var-name)

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

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

Macroexpansion:
(defcondition out-var-name-taken (:error-type varjo-error :prefix "Varjo") (out-var-name) "The variable name '~a' is already taken and so cannot be used~%for an out variable" out-var-name)
Create a Common Lisp macro for the following transformation. Before code:
(define-print-object/std foo2)

What needs to change: Macro call that should be transformed by define-print-object/std

Macro definition:
(defmacro define-print-object/std (class)
  "Define a print-object method for objects of class CLASS.

  Print all slots with their values. Prints \"UNBOUND\", as a string, when slots are unbound.

  Usage:

  (defclass/std test () ((a b)))

  (print-object/std test)

  The macro expands to:

  (DEFMETHOD PRINT-OBJECT ((OBJ TEST) STREAM)
    (PRINT-UNREADABLE-OBJECT (OBJ STREAM :TYPE T :IDENTITY T)
        (FORMAT STREAM \"~{~a~^ ~}\" (COLLECT-OBJECT-SLOTS OBJ))))
"
  `(defmethod print-object ((obj ,class) stream)
     (print-unreadable-object (obj stream :type t :identity t)
       (format stream "~{~a~^ ~}"
               (collect-object-slots obj)))))

Macroexpansion:
(defmethod print-object ((obj foo2) stream) (print-unreadable-object (obj stream :type t :identity t) (format stream "~{~a~^ ~}" (collect-object-slots obj))))
You are a Common Lisp macro expert. Given this code pattern:
(define-value-symbol-macro-binding updating ((var (current iterator)) iterable &rest iterator-args &aux (iterator (apply #'make-iterator iterable iterator-args))) `(if (has-more ,iterator) (next ,iterator) (end-for)))

Write a macro that addresses: Macro call that should be transformed by define-value-symbol-macro-binding

Macro definition:
(defmacro define-value-symbol-macro-binding (name (var &rest args) &body body)
  (let ((vars (lambda-fiddle:extract-lambda-vars (lambda-fiddle:remove-aux-part args))))
    (emit-binding-definition name var args body :extra-vars vars :symbol-macro-p T)))

Macroexpansion:
(define-direct-binding updating (var iterable &rest iterator-args) (let ((#:iterator182 (gensym #A((8) base-char . "ITERATOR"))) (#:iterable180 (gensym #A((8) base-char . "ITERABLE"))) (#:iterator-args181 (gensym #A((13) base-char . "ITERATOR-ARGS")))) (values* (sb-int:quasiquote (with-interleaving (let* #S(sb-impl::comma :expr (list* (list #:iterable180 iterable) (list #:iterator-args181 (list* (quote list) iterator-args)) (list #:iterator182 (list (quote apply) (list (quote function) (quote make-iterator)) #:iterable180 #:iterator-args181)) nil) :kind 0) (declare (ignorable #S(sb-impl::comma :expr #:iterator182 :kind 0) #S(sb-impl::comma :expr #:iterable180 :kind 0) #S(sb-impl::comma :expr #:iterator-args181 :kind 0)))) #S(sb-impl::comma :expr (sb-int:quasiquote (symbol-macrolet #S(sb-impl::comma :expr (loop for #:var179 in (lambda-fiddle:extract-lambda-vars (enlist var)) collect (list #:var179 (list (quote current) #:iterator182))) :kind 0))) :kind 0))) (let ((iterator #:iterator182) (iterable #:iterable180) (iterator-args #:iterator-args181)) (declare (ignorable iterator iterable iterator-args)) (sb-int:quasiquote (if (has-more #S(sb-impl::comma :expr iterator :kind 0)) (next #S(sb-impl::comma :expr iterator :kind 0)) (end-for)))))))
Generate a defmacro form that transforms code like this:
(with-collectors nil
  (progn))

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

Macro definition:
(defmacro WITH-COLLECTORS ...)

Macroexpansion:
(progn (progn))
You are a Common Lisp macro expert. Given this code pattern:
(with-flow-let-macro (flow-list flow) (flow-lambda-macro (flow-context) `(flet ((,test-fu () ,live-test-form)) (dispatch-repeatedly ,flow-context #',test-fu ,flow-list))))

Write a macro that addresses: 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 (flet ((#S(sb-impl::comma :expr test-fu :kind 0) nil #S(sb-impl::comma :expr live-test-form :kind 0))) (dispatch-repeatedly #S(sb-impl::comma :expr flow-context :kind 0) (function #S(sb-impl::comma :expr test-fu :kind 0)) #S(sb-impl::comma :expr flow-list :kind 0))))) :kind 0))))
You are a Common Lisp macro expert. Given this code pattern:
(accase (car x) (:x (setf it :foo)))

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

Macro definition:
(defmacro accase (keyform &body cases)
  "Like CCASE, except binds the result of the keyform to IT (via LET) for the
scope of the cases. Unlike CCASE, the keyform/place doesn't receive new values
possibly stored with STORE-VALUE restart; the new value is received by IT."
  `(anaphoric ccase ,keyform ,@cases))

Macroexpansion:
(anaphoric ccase (car x) (:x (setf it :foo)))
Generate a defmacro form that transforms code like this:
(with-color (:red :stream stream) (with-additional-indent (reporter stream "× ") (when (slot-value report 'description) (format/indent reporter stream "~A~%" (slot-value report 'description))) (format/indent reporter stream "Raised an error ~A (expected: ~S)" (slot-value report 'got) (slot-value report 'expected))))

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

Macro definition:
(defmacro with-color ((color &rest args) &body body)
  (cond
    ((or (eq color :gray)
         (eq color :grey))
     `(if *enable-colors*
          (with-gray ,(or (getf args :stream) t) ,@body)
          (progn ,@body)))
    (T `(if *enable-colors*
            (if (or (eq ,color :gray)
                    (eq ,color :grey)
                    (eq ,color cl-colors:+gray+)
                    (eq ,color cl-colors:+grey+))
                (with-gray ,(or (getf args :stream) t) ,@body)
                (cl-ansi-text:with-color (,color ,@args) ,@body))
            (progn ,@body)))))

Macroexpansion:
(if *enable-colors* (if (or (eq :red :gray) (eq :red :grey) (eq :red +gray+) (eq :red +grey+)) (with-gray stream (with-additional-indent (reporter stream "× ") (when (slot-value report (quote description)) (format/indent reporter stream "~A~%" (slot-value report (quote description)))) (format/indent reporter stream "Raised an error ~A (expected: ~S)" (slot-value report (quote got)) (slot-value report (quote expected))))) (cl-ansi-text:with-color (:red :stream stream) (with-additional-indent (reporter stream "× ") (when (slot-value report (quote description)) (format/indent reporter stream "~A~%" (slot-value report (quote description)))) (format/indent reporter stream "Raised an error ~A (expected: ~S)" (slot-value report (quote got)) (slot-value report (quote expected)))))) (progn (with-additional-indent (reporter stream "× ") (when (slot-value report (quote description)) (format/indent reporter stream "~A~%" (slot-value report (quote description)))) (format/indent reporter stream "Raised an error ~A (expected: ~S)" (slot-value report (quote got)) (slot-value report (quote expected))))))
Define a macro that eliminates this repetitive pattern:
(all-of nil
  nil)

Issue: Macro call that should be transformed by ALL-OF

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

Macroexpansion:
(lc (nil nil) always)
Generate a defmacro form that transforms code like this:
(*> #'any #'any #'eof)

Pattern to recognize: 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 (#:*>-offset164) (multiple-value-bind (#:*>-res167 #:*>-next168) (multiple-value-bind (#:*>-res165 #:*>-next166) (funcall (function any) #:*>-offset164) (if (ok? #:*>-res165) (funcall (function any) #:*>-next166) (fail #:*>-next166))) (if (ok? #:*>-res167) (funcall (function eof) #:*>-next168) (fail #:*>-next168))))
You are a Common Lisp macro expert. Given this code pattern:
(unwind-protect-case () (return-from foof 42) (:normal (push :normal result3)) (:abort (push :abort result3)) (:always (push :always result3)))

Write a macro that addresses: Macro call that should be transformed by unwind-protect-case

Macro definition:
(defmacro unwind-protect-case ((&optional abort-flag) protected-form &body clauses)
  "Like CL:UNWIND-PROTECT, but you can specify the circumstances that
the cleanup CLAUSES are run.

  clauses ::= (:NORMAL form*)* | (:ABORT form*)* | (:ALWAYS form*)*

Clauses can be given in any order, and more than one clause can be
given for each circumstance. The clauses whose denoted circumstance
occured, are executed in the order the clauses appear.

ABORT-FLAG is the name of a variable that will be bound to T in
CLAUSES if the PROTECTED-FORM aborted preemptively, and to NIL
otherwise.

Examples:

  (unwind-protect-case ()
       (protected-form)
     (:normal (format t \"This is only evaluated if PROTECTED-FORM executed normally.~%\"))
     (:abort  (format t \"This is only evaluated if PROTECTED-FORM aborted preemptively.~%\"))
     (:always (format t \"This is evaluated in either case.~%\")))

  (unwind-protect-case (aborted-p)
       (protected-form)
     (:always (perform-cleanup-if aborted-p)))
"
  (check-type abort-flag (or null symbol))
  (let ((gflag (gensym "FLAG+")))
    `(let ((,gflag t))
       (unwind-protect (multiple-value-prog1 ,protected-form (setf ,gflag nil))
	 (let ,(and abort-flag `((,abort-flag ,gflag)))
	   ,@(loop for (cleanup-kind . forms) in clauses
		   collect (ecase cleanup-kind
			     (:normal `(when (not ,gflag) ,@forms))
			     (:abort  `(when ,gflag ,@forms))
			     (:always `(progn ,@forms)))))))))

Macroexpansion:
(let ((#:flag+126 t)) (unwind-protect (multiple-value-prog1 (return-from foof 42) (setf #:flag+126 nil)) (let nil (when (not #:flag+126) (push :normal result3)) (when #:flag+126 (push :abort result3)) (progn (push :always result3)))))
Create a Common Lisp macro for the following transformation. Before code:
(check-cursor-attached cluffer:cursor-position (cursor))

What needs to change: 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:cursor-position :before ((cursor cluffer:cursor)) (declare (ignore)) (unless (cluffer:cursor-attached-p cursor) (error (quote cluffer:cursor-detached))))
You are a Common Lisp macro expert. Given this code pattern:
(builder (:mount "/mount1" (lambda (env) (is-path-info env "/" "string=.") response)) (:mount "/mount2" (lambda (env) (is-path-info env "/test" "subseq.") response)) (lambda (env) (is-path-info env "/test" "t.") response))

Write a macro that addresses: 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 (#:app212) (funcall (find-middleware :mount) #:app212 "/mount1" (lambda (env) (is-path-info env "/" "string=.") response))) (lambda (#:app214) (funcall (find-middleware :mount) #:app214 "/mount2" (lambda (env) (is-path-info env "/test" "subseq.") response))))) :initial-value (to-app (lambda (env) (is-path-info env "/test" "t.") response)) :from-end t)
Write a Common Lisp macro to handle this code pattern:
(setdocs (type unknown-arguments "Used to represent an unknown list of arguments. Instances of this class are printed as #<Unknown Arguments>") (type unavailable-argument "Used to represent an argument that isn't available in the environment. Instances of this class are printed as #<Unavailable>"))

Problem: Macro call that should be transformed by setdocs

Macro definition:
(defmacro setdocs (&body pairs)
  `(progn
     ,@(loop for (type var doc) in pairs
             collect `(setf (documentation ',var ',type) ,doc))))

Macroexpansion:
(progn (setf (documentation (quote unknown-arguments) (quote type)) "Used to represent an unknown list of arguments. Instances of this class are printed as #<Unknown Arguments>") (setf (documentation (quote unavailable-argument) (quote type)) "Used to represent an argument that isn't available in the environment. Instances of this class are printed as #<Unavailable>"))
Define a macro that eliminates this repetitive pattern:
(defvar nil)

Issue: Macro call that should be transformed by DEFVAR

Macro definition:
(defmacro DEFVAR ...)

Macroexpansion:
(progn
 (eval-when (:compile-toplevel) (sb-impl::%compiler-defvar 'nil))
 (sb-impl::%defvar 'nil (sb-c:source-location)))
Write a Common Lisp macro to handle this code pattern:
(as-> nil nil)

Problem: Macro call that should be transformed by AS->

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

Macroexpansion:
(let* ((nil nil))
  nil)