j14i/cl-macros huggingface dataset:
You are a Common Lisp macro expert. Given this code pattern:
(deferror "XX" internal-error)

Write a macro that addresses: 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 internal-error (database-error) nil) (setf (gethash "XX" *error-table*) (quote internal-error)))
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:
(-<>> (diamond-wand init (cddr exp) t))

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

Macro definition:
(defmacro -<> (init &body exps) (diamond-wand init exps))

Macroexpansion:
(diamond-wand init (cddr exp) t)
Generate a defmacro form that transforms code like this:
(f_n
  'some-name)

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

Macro definition:
(defmacro F_N ...)

Macroexpansion:
(lambda (&rest _) 'some-name)
Define a macro that eliminates this repetitive pattern:
(is-error (error "Raising an error") 'simple-error)

Issue: Macro call that should be transformed by is

Macro definition:
(defmacro is (got expected &rest args)
  (with-gensyms (duration result new-args desc)
    (once-only (expected)
      `(let* ((,new-args (list ,@args))
              (,desc (parse-description-and-test ,new-args)))
         (with-catching-errors (:description ,desc :expected ,expected)
           (with-duration ((,duration ,result) ,got)
             (test ,result ,expected ,new-args
                   :duration ,duration)))))))

Macroexpansion:
(with-duration ((#:duration182 #:error181) (handler-case (error "Raising an error") (condition (#:error181) #:error181))) (test #:error181 (quote simple-error) nil :duration #:duration182 :got-form (quote (error "Raising an error")) :test-fn (function typep) :report-expected-label "raise a condition"))
Define a macro that eliminates this repetitive pattern:
(with-temp (input-file :tmpdir d :template "XXXXXX.prolog" :debug (<= 1 *debug-prolog*)) (with-open-file (s input-file :direction :output :if-does-not-exist :error) (dolist (r rules) (print-rule s r))) (run-command-with-debug-print `(,*yap* "-l" ,input-file ,@args) :input input :output output :error error))

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

Macro definition:
(defmacro with-temp ((var &key directory template (tmpdir "/tmp/") debug) &body body)
  "Create a temporary file, then remove the file by unwind-protect.
Most arguments are analogous to mktemp.
When DIRECTORY is non-nil, creates a directory instead.
DEBUG is a form.
When evaluated to non-nil, it does not remove the directory so that you can investigate what happened inside the directory.
It may be evaluated multiple times."
  (with-gensyms (command)
    `(let ((,var (uiop:run-program
                  (let ((,command (format nil "mktemp --tmpdir='~a' ~@[-d~*~] ~@[~a~]"
                                          ,tmpdir ,directory ,template)))
                    (when ,debug
                      (format *error-output* "~&; ~a~%" ,command))
                    ,command)
                  :output '(:string :stripped t))))
       (unwind-protect
            (progn ,@body)
         (if ,debug
             (format *error-output* "~&; not removing ~a for debugging~%" ,var)
             (uiop:run-program (format nil "rm -rf ~a" (namestring ,var)) :ignore-error-status t))))))

Macroexpansion:
(let ((input-file (uiop/run-program:run-program (let ((#:command180 (format nil "mktemp --tmpdir='~a' ~@[-d~*~] ~@[~a~]" d nil "XXXXXX.prolog"))) (when (<= 1 *debug-prolog*) (format *error-output* "~&; ~a~%" #:command180)) #:command180) :output (quote (:string :stripped t))))) (unwind-protect (progn (with-open-file (s input-file :direction :output :if-does-not-exist :error) (dolist (r rules) (print-rule s r))) (run-command-with-debug-print (sb-int:quasiquote (#S(sb-impl::comma :expr *yap* :kind 0) "-l" #S(sb-impl::comma :expr input-file :kind 0) #S(sb-impl::comma :expr args :kind 2))) :input input :output output :error error)) (if (<= 1 *debug-prolog*) (format *error-output* "~&; not removing ~a for debugging~%" input-file) (uiop/run-program:run-program (format nil "rm -rf ~a" (namestring input-file)) :ignore-error-status t))))
Define a macro that eliminates this repetitive pattern:
(with-lock (lru-pool-lock pool) (get-from-lru-pool pool host-port))

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

Macro definition:
(defmacro with-lock (lock &body body)
  (declare (ignorable lock))
  #+thread-support `(bt2:with-lock-held (,lock)
                      ,@body)
  #-thread-support `(progn ,@body))

Macroexpansion:
(bt2:with-lock-held ((lru-pool-lock pool)) (get-from-lru-pool pool host-port))
Create a Common Lisp macro for the following transformation. Before code:
(with-ps-gensyms nil)

What needs to change: Macro call that should be transformed by WITH-PS-GENSYMS

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

Macroexpansion:
(let* ())
Create a Common Lisp macro for the following transformation. Before code:
(aetypecase 1.0 (fixnum (* 2 it)) (float (+ 2.0 it)) (symbol :oops))

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

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

Macroexpansion:
(anaphoric etypecase 1.0 (fixnum (* 2 it)) (float (+ 2.0 it)) (symbol :oops))
You are a Common Lisp macro expert. Given this code pattern:
(defun-compile-time walk-lambda-list-reducing (map-function reduce-function screamer? partial? nested? lambda-list environment &optional mode) (cond ((null lambda-list) (funcall reduce-function)) ((member (first lambda-list) *ordered-lambda-list-keywords* :test #'eq) (walk-lambda-list-reducing map-function reduce-function screamer? partial? nested? (rest lambda-list) environment (first lambda-list))) (t (ecase mode ((nil &rest &allow-other-keys &aux) (walk-lambda-list-reducing map-function reduce-function screamer? partial? nested? (rest lambda-list) environment mode)) ((&optional &key) (if (and (consp (first lambda-list)) (consp (rest (first lambda-list)))) (funcall reduce-function (walk map-function reduce-function screamer? partial? nested? (second (first lambda-list)) environment) (walk-lambda-list-reducing map-function reduce-function screamer? partial? nested? (rest lambda-list) environment mode)) (walk-lambda-list-reducing map-function reduce-function screamer? partial? nested? (rest lambda-list) environment mode)))))))

Write a macro that addresses: Macro call that should be transformed by defun-compile-time

Macro definition:
(defmacro defun-compile-time (function-name lambda-list &body body)
  `(eval-when (:compile-toplevel :load-toplevel :execute)
     (cl:defun ,function-name ,lambda-list ,@body)
     (eval-when (:compile-toplevel) (compile ',function-name))))

Macroexpansion:
(eval-when (:compile-toplevel :load-toplevel :execute) (common-lisp:defun walk-lambda-list-reducing (map-function reduce-function screamer? partial? nested? lambda-list environment &optional mode) (cond ((null lambda-list) (funcall reduce-function)) ((member (first lambda-list) *ordered-lambda-list-keywords* :test (function eq)) (walk-lambda-list-reducing map-function reduce-function screamer? partial? nested? (rest lambda-list) environment (first lambda-list))) (t (ecase mode ((nil &rest &allow-other-keys &aux) (walk-lambda-list-reducing map-function reduce-function screamer? partial? nested? (rest lambda-list) environment mode)) ((&optional &key) (if (and (consp (first lambda-list)) (consp (rest (first lambda-list)))) (funcall reduce-function (walk map-function reduce-function screamer? partial? nested? (second (first lambda-list)) environment) (walk-lambda-list-reducing map-function reduce-function screamer? partial? nested? (rest lambda-list) environment mode)) (walk-lambda-list-reducing map-function reduce-function screamer? partial? nested? (rest lambda-list) environment mode))))))) (eval-when (:compile-toplevel) (compile (quote walk-lambda-list-reducing))))
Generate a defmacro form that transforms code like this:
(defsynonym sum :sum)

Pattern to recognize: 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 sum) (quote synonym)) (quote :sum)))
Define a macro that eliminates this repetitive pattern:
(with-special-initargs nil
  (progn))

Issue: Macro call that should be transformed by WITH-SPECIAL-INITARGS

Macro definition:
(defmacro WITH-SPECIAL-INITARGS ...)

Macroexpansion:
(funcall-with-special-initargs (list) (lambda () (progn)))
Write a Common Lisp macro to handle this code pattern:
(with-html-string (:div (:p "Text " (:a "link text") " more text")))

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 (:div (:p "Text " (:a "link text") " more text"))))
Generate a defmacro form that transforms code like this:
(ematch0 patterns ((list) nil) ((list* first rest) (let ((first* (correct-pattern (pattern-expand-all/lift first)))) (cons first* (let ((*lexvars* (variables first*))) (expand-multipatterns rest))))))

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 patterns ((list) nil) ((list* first rest) (let ((first* (correct-pattern (pattern-expand-all/lift first)))) (cons first* (let ((*lexvars* (variables first*))) (expand-multipatterns rest))))) (_ (error "level0 match error!")))
Create a Common Lisp macro for the following transformation. Before code:
(is something 'a 'a)

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

Macro definition:
(defmacro is (comp expected form &optional description &rest format-args)
  `(eval-in-context
    *context*
    (make-instance 'comparison-result
                   :expression '(is ,comp ,expected ,form)
                   :value-form ',form
                   :body (lambda () ,form)
                   :expected ,expected
                   :comparison ,(maybe-quote comp)
                   ,@(when description
                       `(:description (format NIL ,description ,@format-args))))))

Macroexpansion:
(eval-in-context *context* (make-instance (quote comparison-result) :expression (quote (is something (quote a) (quote a))) :value-form (quote (quote a)) :body (lambda nil (quote a)) :expected (quote a) :comparison (quote something)))
You are a Common Lisp macro expert. Given this code pattern:
(define-alias nil
    nil)

Write a macro that addresses: Macro call that should be transformed by DEFINE-ALIAS

Macro definition:
(defmacro DEFINE-ALIAS ...)

Macroexpansion:
(progn
 (macrolet ((thunk ()
              (let ())))
   (defun nil () nil (thunk)))
 (define-compiler-macro nil
     nil
   nil
   `(let ,(list)
      ,(let ()))))
You are a Common Lisp macro expert. Given this code pattern:
(yield-for-union-ops "UNION ALL")

Write a macro that addresses: Macro call that should be transformed by yield-for-union-ops

Macro definition:
(defmacro yield-for-union-ops (keyword)
  `(multiple-value-bind (statements others)
      (loop for obj in (conjunctive-op-expressions op)
            if (sql-statement-p obj)
              collecting obj into statements
            else
              collecting obj into others
            finally (return (values statements others)))
     (with-yield-binds
       (format nil (if *inside-select*
                       "(~{~A~^ ~})"
                       "~{~A~^ ~}")
               (append (list (format nil ,(format nil "~~{~~A~~^ ~a ~~}" keyword)
                                     (mapcar #'yield statements)))
                       (when others
                         (list (format nil "~{~A~^ ~}"
                                       (mapcar #'yield others)))))))))

Macroexpansion:
(multiple-value-bind (statements others) (loop for obj in (conjunctive-op-expressions op) if (sql-statement-p obj) collecting obj into statements else collecting obj into others finally (return (values statements others))) (with-yield-binds (format nil (if *inside-select* "(~{~A~^ ~})" "~{~A~^ ~}") (append (list (format nil #A((19) base-char . "~{~A~^ UNION ALL ~}") (mapcar (function yield) statements))) (when others (list (format nil "~{~A~^ ~}" (mapcar (function yield) others))))))))
Define a macro that eliminates this repetitive pattern:
(*> (string "Mālum") #'eof)

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 (#:*>-offset200) (multiple-value-bind (#:*>-res201 #:*>-next202) (funcall (string "Mālum") #:*>-offset200) (if (ok? #:*>-res201) (funcall (function eof) #:*>-next202) (fail #:*>-next202))))
Define a macro that eliminates this repetitive pattern:
(signals error (error "an error"))

Issue: Macro call that should be transformed by signals

Macro definition:
(defmacro signals (condition-spec
                   &body body)
  "Generates a pass if BODY signals a condition of type
CONDITION. BODY is evaluated in a block named NIL, CONDITION is
not evaluated."
  (let ((block-name (gensym)))
    (destructuring-bind (condition &optional reason-control &rest reason-args)
        (ensure-list condition-spec)
      `(block ,block-name
         (handler-bind ((,condition (lambda (c)
                                      (declare (ignore c))
                                      ;; ok, body threw condition
                                      (add-result 'test-passed
                                                  :test-expr ',condition)
                                      (return-from ,block-name t))))
           (block nil
             ,@body))
         (process-failure
           ',condition
           ,@(if reason-control
                 `(,reason-control ,@reason-args)
                 `("Failed to signal a ~S" ',condition)))
         (return-from ,block-name nil)))))

Macroexpansion:
(block #:g285 (handler-bind ((error (lambda (c) (declare (ignore c)) (add-result (quote test-passed) :test-expr (quote error)) (return-from #:g285 t)))) (block nil (error "an error"))) (process-failure (quote error) "Failed to signal a ~S" (quote error)) (return-from #:g285 nil))
Generate a defmacro form that transforms code like this:
(define-error cannot-not-shadow-core () () "You cannot shadow or replace core macros or special functions.")

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 cannot-not-shadow-core (:error-type varjo-error :prefix "Varjo") nil "You cannot shadow or replace core macros or special functions.")
You are a Common Lisp macro expert. Given this code pattern:
(with-form-field-values (name) form (print name))

Write a macro that addresses: Macro call that should be transformed by with-form-field-values

Macro definition:
(defmacro with-form-field-values (fields form &body body)
  "Bind the value of FIELDS in FORM.

Example:

@lisp
(with-form-field-values (name) form
   (print name))
@end lisp"
  `(let ,(loop for field in fields
               collect `(,field (field-value (get-field ,form ',field))))
     ,@body))

Macroexpansion:
(let ((name (field-value (get-field form (quote name))))) (print name))
Write a Common Lisp macro to handle this code pattern:
(c-assert (null (c-callers old)))

Problem: 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 (null (c-callers old)) (c-break "failed assertion: ~a" (quote (null (c-callers old))))))
Create a Common Lisp macro for the following transformation. Before code:
(accase (car x) (:y (setf x :no)) (:z (setf x :yes)))

What needs to change: 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) (:y (setf x :no)) (:z (setf x :yes)))
You are a Common Lisp macro expert. Given this code pattern:
(is-error (error 'my-condition) 'simple-error)

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

Macro definition:
(defmacro is (got expected &rest args)
  (with-gensyms (duration result new-args desc)
    (once-only (expected)
      `(let* ((,new-args (list ,@args))
              (,desc (parse-description-and-test ,new-args)))
         (with-catching-errors (:description ,desc :expected ,expected)
           (with-duration ((,duration ,result) ,got)
             (test ,result ,expected ,new-args
                   :duration ,duration)))))))

Macroexpansion:
(with-duration ((#:duration184 #:error183) (handler-case (error (quote my-condition)) (condition (#:error183) #:error183))) (test #:error183 (quote simple-error) nil :duration #:duration184 :got-form (quote (error (quote my-condition))) :test-fn (function typep) :report-expected-label "raise a condition"))
Generate a defmacro form that transforms code like this:
(define-value-binding table-pairs (var table &aux (iterator (hash-table-iterator table)) next key val) (declare (type hash-table table) (type function iterator)) `(multiple-value-bind (,next ,key ,val) (funcall ,iterator) (cond (,next (update ,(first var) ,key) (update ,(second var) ,val)) (T (end-for)))))

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

Macro definition:
(defmacro define-value-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)))

Macroexpansion:
(define-direct-binding table-pairs (var table) (let ((#:iterator157 (gensym #A((8) base-char . "ITERATOR"))) (#:next158 (gensym #A((4) base-char . "NEXT"))) (#:key159 (gensym #A((3) base-char . "KEY"))) (#:val160 (gensym #A((3) base-char . "VAL"))) (#:table156 (gensym #A((5) base-char . "TABLE")))) (values* (sb-int:quasiquote (with-interleaving (let* #S(sb-impl::comma :expr (list* (list #:table156 table) (list #:iterator157 (list (quote hash-table-iterator) #:table156)) (list #:next158 nil) (list #:key159 nil) (list #:val160 nil) (loop for #:var155 in (lambda-fiddle:extract-lambda-vars (enlist var)) collect (list #:var155 nil))) :kind 0) (declare (ignorable #S(sb-impl::comma :expr #:iterator157 :kind 0) #S(sb-impl::comma :expr #:next158 :kind 0) #S(sb-impl::comma :expr #:key159 :kind 0) #S(sb-impl::comma :expr #:val160 :kind 0) #S(sb-impl::comma :expr #:table156 :kind 0))) #S(sb-impl::comma :expr (sb-int:quasiquote (declare (type #S(sb-impl::comma :expr (quote hash-table) :kind 0) #S(sb-impl::comma :expr #:table156 :kind 0)))) :kind 0) #S(sb-impl::comma :expr (sb-int:quasiquote (declare (type #S(sb-impl::comma :expr (quote function) :kind 0) #S(sb-impl::comma :expr #:iterator157 :kind 0)))) :kind 0)) #S(sb-impl::comma :expr nil :kind 0))) (let ((iterator #:iterator157) (next #:next158) (key #:key159) (val #:val160) (table #:table156)) (declare (ignorable iterator next key val table)) (sb-int:quasiquote (multiple-value-bind (#S(sb-impl::comma :expr next :kind 0) #S(sb-impl::comma :expr key :kind 0) #S(sb-impl::comma :expr val :kind 0)) (funcall #S(sb-impl::comma :expr iterator :kind 0)) (cond (#S(sb-impl::comma :expr next :kind 0) (update #S(sb-impl::comma :expr (first var) :kind 0) #S(sb-impl::comma :expr key :kind 0)) (update #S(sb-impl::comma :expr (second var) :kind 0) #S(sb-impl::comma :expr val :kind 0))) (t (end-for)))))))))
Create a Common Lisp macro for the following transformation. Before code:
(sccase (car x) (:y (setf it :no)) (:z (setf it :yes)))

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

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

Macroexpansion:
(symbolic ccase (car x) (:y (setf it :no)) (:z (setf it :yes)))
Define a macro that eliminates this repetitive pattern:
(defsynonym :summing :sum)

Issue: 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 :summing) (quote synonym)) (quote :sum)))
Write a Common Lisp macro to handle this code pattern:
(define-bug nil-return-set () (form possible-set) "Could not establish return-set. Our apologies for this mistake. If you have the time please raise an issue at https://github.com/cbaggers/varjo/issues including the code that triggered this issue. Problematic form: ~a Possible Set: ~a" form possible-set)

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 nil-return-set (:error-type varjo-error :prefix "Varjo Bug") (form possible-set) "Could not establish return-set. Our apologies for this mistake. If you have the time please raise an issue at https://github.com/cbaggers/varjo/issues including the code that triggered this issue. Problematic form: ~a Possible Set: ~a" form possible-set)
Generate a defmacro form that transforms code like this:
(when (eql (top-sign) 'skip-first-parameter) (pop-sign))

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

Macro definition:
(defmacro when (test &body forms)
  `(if ,test
	   ,(cl:if (cadr forms)
			   `(progn ,@forms)
			   (car forms))))

Macroexpansion:
(if (eql (top-sign) (quote skip-first-parameter)) (pop-sign))
You are a Common Lisp macro expert. Given this code pattern:
(matrix-ccase 'some-name)

Write a macro that addresses: Macro call that should be transformed by MATRIX-CCASE

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

Macroexpansion:
(let ((#:g243 quote))
  (ccase #:g243))