j14i/cl-macros huggingface dataset:
Create a Common Lisp macro for the following transformation. Before code:
(define-error emit-type-mismatch () (sets) "Some of the emit statements emit different types:~{~%~a~}" (mapcar (lambda (x) (map 'list #'type->type-spec x)) sets))

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 emit-type-mismatch (:error-type varjo-error :prefix "Varjo") (sets) "Some of the emit statements emit different types:~{~%~a~}" (mapcar (lambda (x) (map (quote list) (function type->type-spec) x)) sets))
Define a macro that eliminates this repetitive pattern:
(printing-unreadably (id name) (class/std employee name id salary))

Issue: Macro call that should be transformed by printing-unreadably

Macro definition:
(defmacro printing-unreadably (fields-list class-std-form
                               &key (type t) (identity t))
  "Automatically generates the unreadable printing boiler plate to print classes and its fields (from FIELDS-LIST)."
  (let ((g!stream (gensym "STREAM"))
        (name (cadr class-std-form)))
    `(progn ,class-std-form
            (defmethod print-object ((,name ,name) ,g!stream)
              (print-unreadable-object (,name ,g!stream
                                        :type ,type
                                        :identity ,identity)
                (format ,g!stream
                        ,(format nil "~{~a: ~~s~^,~^ ~}" fields-list)
                        ,@(mapcar (lambda (a1)
                                    `(,a1 ,name))
                                  fields-list)))))))

Macroexpansion:
(progn (class/std employee name id salary) (defmethod print-object ((employee employee) #:stream125) (print-unreadable-object (employee #:stream125 :type t :identity t) (format #:stream125 #A((16) base-char . "ID: ~s, NAME: ~s") (id employee) (name employee)))))
Define a macro that eliminates this repetitive pattern:
(deferror "0A" feature-not-supported)

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 feature-not-supported (database-error) nil) (setf (gethash "0A" *error-table*) (quote feature-not-supported)))
Write a Common Lisp macro to handle this code pattern:
(do-generators ((g (some-numbers)) (:list l data :fill-value 0)) (yield (+ l g)))

Problem: Macro call that should be transformed by do-generator

Macro definition:
(defmacro do-generator ((var &rest vars-and-generator) &body body)
  "Steps through the specified generator, binding the value it returns to var, then executing the body for each step. If multiple variables are specified and the generator returns multiple values, the extra values will be bound to the extra variables."
  (let ((g (gensym)))
    `(let ((,g ,(car (last vars-and-generator))))
       (loop 
	  do (if-generator ((,var ,@(butlast vars-and-generator)) ,g)
			   (progn
			     ,@body)
			   (return))))))

Macroexpansion:
(let ((#:g175 (multi-gen (some-numbers) (list (list->generator data) :fill-value 0)))) (loop do (destructuring-bind (#:g177 . #:g176) (multiple-value-list (next-generator-value #:g175)) (unless #:g177 (return)) (let ((g (elt (elt #:g176 0) 0)) (l (elt (elt #:g176 1) 0))) (yield (+ l g))))))
Create a Common Lisp macro for the following transformation. Before code:
(defun-advisable nil
    (progn))

What needs to change: Macro call that should be transformed by DEFUN-ADVISABLE

Macro definition:
(defmacro DEFUN-ADVISABLE ...)

Macroexpansion:
(let ((#:oldfn135
       (handler-case (symbol-function 'nil) (undefined-function nil nil))))
  (defun nil (progn))
  (make-advisable 'nil :arguments '(progn))
  (when
      (and #:oldfn135
           (not (eql (advisable-function-arguments #:oldfn135) :not-provided))
           (equal (advisable-function-arguments #:oldfn135) '(progn)))
    (copy-advice #:oldfn135 (symbol-function 'nil))))
You are a Common Lisp macro expert. Given this code pattern:
(lret (x y) (declare (ignore x)) 1)

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

Macro definition:
(defmacro lret ((&rest bindings) &body body)
  "Return the initial value of the last binding in BINDINGS. The idea
is to create something, initialize it, and then return it.

    (lret ((x 1)
           (y (make-array 1)))
      (setf (aref y 0) x))
    => #(1)

Note that the value returned is the value initially bound. Subsequent
assignments are ignored.

    (lret ((x 1))
      (setf x 2))
    => 1

Furthermore, on Lisps that support it, the variable may be made
read-only, making assignment a compiler-time error.

`lret' may seem trivial, but it fufills the highest purpose a macro
can: it eliminates a whole class of bugs (initializing an object, but
forgetting to return it).

Cf. `aprog1' in Anaphora."
  `(lret-aux let ,bindings
     ,@body))

Macroexpansion:
(lret-aux let (x y) (declare (ignore x)) 1)
Define a macro that eliminates this repetitive pattern:
(define-alias-binding count counting)

Issue: 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 count)) (quote counting)) (quote count))
Generate a defmacro form that transforms code like this:
(all-of nil
  :key
  nil)

Pattern to recognize: Macro call that should be transformed by ALL-OF

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

Macroexpansion:
(lc (nil :key nil) always)
You are a Common Lisp macro expert. Given this code pattern:
(with-standard-definer-options nil)

Write a macro that addresses: Macro call that should be transformed by WITH-STANDARD-DEFINER-OPTIONS

Macro definition:
(defmacro WITH-STANDARD-DEFINER-OPTIONS ...)

Macroexpansion:
`(progn
  ,@(when (getf -options- :export)
      `((eval-when (:compile-toplevel :load-toplevel :execute)
          (export ',nil)))))
You are a Common Lisp macro expert. Given this code pattern:
(defcategory :debug (or :debug :info))

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

Macro definition:
(defmacro defcategory (category &optional expands-as set)
  `(defcategory-fn ',category ',expands-as ,set))

Macroexpansion:
(defcategory-fn (quote :debug) (quote (or :debug :info)) nil)
Generate a defmacro form that transforms code like this:
(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 `(,*xsb* "--nobanner" "--quietload" "--noprompt" "-e" ,(format nil "consult('~a')." input-file) ,@args) :input input :output output :error error))

Pattern to recognize: 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 ((#:command178 (format nil "mktemp --tmpdir='~a' ~@[-d~*~] ~@[~a~]" d nil "XXXXXX.prolog"))) (when (<= 1 *debug-prolog*) (format *error-output* "~&; ~a~%" #:command178)) #:command178) :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 *xsb* :kind 0) "--nobanner" "--quietload" "--noprompt" "-e" #S(sb-impl::comma :expr (format nil "consult('~a')." 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:
(matrix-ccase nil)

Issue: Macro call that should be transformed by MATRIX-CCASE

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

Macroexpansion:
nil
Generate a defmacro form that transforms code like this:
(ps
  'some-name)

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

Macro definition:
(defmacro PS ...)

Macroexpansion:
"'someName';"
Define a macro that eliminates this repetitive pattern:
(deferror "57" operator-intervention)

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 operator-intervention (database-error) nil) (setf (gethash "57" *error-table*) (quote operator-intervention)))
Generate a defmacro form that transforms code like this:
(defhandler lambda (lambda lambda-list &rest body) (apply 'dump-fbinding lambda lambda-list body))

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

Macro definition:
(defmacro defhandler (symbol lambda-list &body body)
  (let ((syms (force-list symbol)))
    (let ((func (intern (format nil "~A~A" 'hander- (first syms)))))
      `(progn
         (defun ,func ,lambda-list
           ,@body)
         (setf
          ,@(loop for sym in syms
               collect `(gethash ',sym *form-handler*)
               collect `',func))))))

Macroexpansion:
(progn (defun hander-lambda (lambda lambda-list &rest body) (apply (quote dump-fbinding) lambda lambda-list body)) (setf (gethash (quote lambda) *form-handler*) (quote hander-lambda)))
You are a Common Lisp macro expert. Given this code pattern:
(dynamic-wind)

Write a macro that addresses: Macro call that should be transformed by DYNAMIC-WIND

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

Macroexpansion:
(flet ((#:dynamic-wind-thunk213 (#:proceed-thunk214)
         (macrolet ((proceed (&body #:proceed-body215)
                     `(if ,'#:proceed-thunk214
                          (funcall (the function ,'#:proceed-thunk214))
                          (progn ,@#:proceed-body215)))))))
  (declare (inline #:dynamic-wind-thunk213))
  (let ((*dynamic-wind-stack*
         (cons #'#:dynamic-wind-thunk213 *dynamic-wind-stack*)))
    (#:dynamic-wind-thunk213 nil)))
Define a macro that eliminates this repetitive pattern:
(fgather-next nil nil)

Issue: Macro call that should be transformed by FGATHER-NEXT

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

Macroexpansion:
(nil nil nil)
Generate a defmacro form that transforms code like this:
(xor tmp true)

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

Macro definition:
(defmacro xor (&rest datums)
  "Evaluates its arguments one at a time, from left to right. If more than one
argument evaluates to a true value no further DATUMS are evaluated, and NIL is
returned as both primary and secondary value. If exactly one argument
evaluates to true, its value is returned as the primary value after all the
arguments have been evaluated, and T is returned as the secondary value. If no
arguments evaluate to true NIL is returned as primary, and T as secondary
value."
  (with-gensyms (xor tmp true)
    `(let (,tmp ,true)
       (declare (ignorable ,tmp))
       (block ,xor
         ,@(mapcar (lambda (datum)
                     `(if (setf ,tmp ,datum)
                          (if ,true
                              (return-from ,xor (values nil nil))
                              (setf ,true ,tmp))))
                   datums)
         (return-from ,xor (values ,true t))))))

Macroexpansion:
(let (#:tmp138 #:true139) (declare (ignorable #:tmp138)) (block #:xor137 (if (setf #:tmp138 tmp) (if #:true139 (return-from #:xor137 (values nil nil)) (setf #:true139 #:tmp138))) (if (setf #:tmp138 true) (if #:true139 (return-from #:xor137 (values nil nil)) (setf #:true139 #:tmp138))) (return-from #:xor137 (values #:true139 t))))
Define a macro that eliminates this repetitive pattern:
(defclause stop-when (condition) "Synonym for until." `(until ,condition))

Issue: Macro call that should be transformed by defclause

Macro definition:
(defmacro defclause (name arglist &body body)
  "Same as cl:defmacro, but additionally records <name> in *clauses* as a known clause macro."
  `(progn
     (defmacro ,name ,arglist ,@body)
     (pushnew ',name *clauses*)))

Macroexpansion:
(progn (defmacro stop-when (condition) "Synonym for until." (sb-int:quasiquote (until #S(sb-impl::comma :expr condition :kind 0)))) (pushnew (quote stop-when) *clauses*))
Create a Common Lisp macro for the following transformation. Before code:
(defclause (finding expr minimizing min-expr &optional into variable) "Return value which minimizes expression" (return-find-extremum-code expr min-expr variable :min))

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

Macro definition:
(defmacro defclause (clause-template &body body)
  (define-clause 'defun clause-template body nil))

Macroexpansion:
(eval-when (:compile-toplevel :load-toplevel :execute) (defun clause-finding-minimizing-17 (&key ((:finding expr)) ((:minimizing min-expr)) ((:into variable))) "Return value which minimizes expression" (return-find-extremum-code expr min-expr variable :min)) (install-clause-info (quote (finding :minimizing)) (quote (finding :minimizing &optional :into)) (quote clause-finding-minimizing-17) "Return value which minimizes expression" nil) (quote (finding expr minimizing min-expr &optional into variable)))
Create a Common Lisp macro for the following transformation. Before code:
(defun/1 frexp (x nptr) (let ((n (ceiling (log (abs x) 2)))) (setf (deref* nptr) n) (/ x (expt 2 n))))

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 frexp (x nptr) (declare (optimize (speed 0) (debug 3) (sb-ext:inhibit-warnings 3))) (let ((n (ceiling (log (abs x) 2)))) (setf (deref* nptr) n) (/ x (expt 2 n)))) (defparameter frexp (vacietis.c:mkptr& (symbol-function (quote frexp)))))
Create a Common Lisp macro for the following transformation. Before code:
(newq nil)

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

Macro definition:
(defmacro NEWQ ...)

Macroexpansion:
(new 'nil)
Create a Common Lisp macro for the following transformation. Before code:
(do* () (progn))

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

Macro definition:
(defmacro DO* ...)

Macroexpansion:
(block nil
  (let* ()
    (declare (ignorable))
    (tagbody
      (go #:g189)
     #:g188
      (tagbody)
      (setq)
     #:g189
      (unless progn (go #:g188))
      (return-from nil (progn)))))
Write a Common Lisp macro to handle this code pattern:
(with-active-layers* 'some-name)

Problem: Macro call that should be transformed by WITH-ACTIVE-LAYERS*

Macro definition:
(defmacro WITH-ACTIVE-LAYERS* ...)

Macroexpansion:
(dynamic-wind
  :proceed
  #:proceed212
  (%with-active-layers 'some-name
    (#:proceed212)))
Write a Common Lisp macro to handle this code pattern:
(lret* ((y 1) (y 2)) (declare (ignorable y)) 3)

Problem: Macro call that should be transformed by lret*

Macro definition:
(defmacro lret* ((&rest bindings) &body body)
  "Cf. `lret'."
  `(lret-aux let* ,bindings
     ,@body))

Macroexpansion:
(lret-aux let* ((y 1) (y 2)) (declare (ignorable y)) 3)
You are a Common Lisp macro expert. Given this code pattern:
(define-custom-var (:aggregate-scope *aggregate-scope-variables*) nil "A list of symbols naming dynamic variables which should be re-bound in the scope of every JSON aggregate value (Object, Array or String).")

Write a macro that addresses: Macro call that should be transformed by define-custom-var

Macro definition:
(defmacro define-custom-var ((key name) &rest other-args)
  `(eval-when (:compile-toplevel :load-toplevel :execute)
     (progn (pushnew '(,name . ,key) *custom-vars* :test #'equal)
            (defvar ,name ,@other-args))))

Macroexpansion:
(eval-when (:compile-toplevel :load-toplevel :execute) (progn (pushnew (quote (*aggregate-scope-variables* . :aggregate-scope)) *custom-vars* :test (function equal)) (defvar *aggregate-scope-variables* nil "A list of symbols naming dynamic variables which should be re-bound in the scope of every JSON aggregate value (Object, Array or String).")))
You are a Common Lisp macro expert. Given this code pattern:
(with-env [clos-object 'a])

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

Macro definition:
(defmacro with-env (&body body)
  (let ((body-value (gensym)))
    `(let (,body-value)
       (defclass foo () ((a :initform 3)))
       (defmethod get-val ((object foo) &rest slot/s) (slot-value object (car slot/s)))
       (defmethod (setf get-val) (new-value (object foo) &rest slot/s)
         (setf (slot-value object (car slot/s)) new-value))
       (defstruct bar a)
       (setq ,body-value
             (let ((str (alexandria:copy-array "abcde"))
                   (vec (alexandria:copy-array #(a b c d e)))
                   (arr (alexandria:copy-array #2A((1 2 3)
                                                   (4 5 6))))
                   (list      (copy-list '(a b c d e)))
                   (ht        (eval (read-from-string "{'a 'b 'c 'd}")))
                   (ht-eq     (eval (read-from-string "{eq \"a\" 1
                                                    \"b\" 2}")))
                   (ht-equalp (eval (read-from-string "{equalp '(1 2 3) \"a\"
                                                               '(4 5 6) \"b\"}")))
                   (assoc-list (copy-tree '((a . 1) (b . 2))))
                   (plist      (copy-list '(:a 4 :c 5)))
                   (clos-object (make-instance 'foo))
                   (struct      (make-bar :a 3)))
               (declare (ignorable str vec arr list ht ht-eq ht-equalp
                                   assoc-list plist clos-object struct))
               ,@body))
       (setf (find-class 'foo nil) nil)
       (setf (find-class 'bar nil) nil)
       ,body-value))

Macroexpansion:
(let (#:g131) (defclass foo nil ((a :initform 3))) (defmethod get-val ((object foo) &rest slot/s) (slot-value object (car slot/s))) (defmethod (setf get-val) (new-value (object foo) &rest slot/s) (setf (slot-value object (car slot/s)) new-value)) (defstruct bar a) (setq #:g131 (let ((str (alexandria:copy-array "abcde")) (vec (alexandria:copy-array #(a b c d e))) (arr (alexandria:copy-array #2A((1 2 3) (4 5 6)))) (list (copy-list (quote (a b c d e)))) (ht (eval (read-from-string "{'a 'b 'c 'd}"))) (ht-eq (eval (read-from-string "{eq \"a\" 1
                                                    \"b\" 2}"))) (ht-equalp (eval (read-from-string "{equalp '(1 2 3) \"a\"
                                                               '(4 5 6) \"b\"}"))) (assoc-list (copy-tree (quote ((a . 1) (b . 2))))) (plist (copy-list (quote (:a 4 :c 5)))) (clos-object (make-instance (quote foo))) (struct (make-bar :a 3))) (declare (ignorable str vec arr list ht ht-eq ht-equalp assoc-list plist clos-object struct)) [clos-object (quote a]))) (setf (find-class (quote foo) nil) nil) (setf (find-class (quote bar) nil) nil) #:g131)
Define a macro that eliminates this repetitive pattern:
(do+ (returning 1) (returning 2 3) (returning (values 4 5) 6) (returning 7) (terminate))

Issue: Macro call that should be transformed by do+

Macro definition:
(defmacro do+ (&body body)
  "High-level, extensible iteration construct. Refer to the manual for syntax and semantics."
  `(do+/internal nil ,@body))

Macroexpansion:
(do+/internal nil (returning 1) (returning 2 3) (returning (values 4 5) 6) (returning 7) (terminate))
Generate a defmacro form that transforms code like this:
(when (eql (info-size) 0) (format stream ";"))

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 (info-size) 0) (format stream ";"))
Define a macro that eliminates this repetitive pattern:
(sccase (car x) (:y (setf it :no)) (:x (setf it :yes)))

Issue: 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)) (:x (setf it :yes)))
You are a Common Lisp macro expert. Given this code pattern:
(-<>)

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

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

Macroexpansion:
nil
Generate a defmacro form that transforms code like this:
(max-of nil
  (progn))

Pattern to recognize: Macro call that should be transformed by MAX-OF

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

Macroexpansion:
(lc (nil (progn)) maximize)
Generate a defmacro form that transforms code like this:
(js)

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

Macro definition:
(defmacro JS ...)

Macroexpansion:
(ps)
You are a Common Lisp macro expert. Given this code pattern:
(defvar-compile-time *screamer?* nil "This must be NIL except when defining internal Screamer functions.")

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

Macro definition:
(defmacro defvar-compile-time (name &optional initial-value documentation)
  `(eval-when (:compile-toplevel :load-toplevel :execute)
     (defvar ,name ,initial-value ,documentation)))

Macroexpansion:
(eval-when (:compile-toplevel :load-toplevel :execute) (defvar *screamer?* nil "This must be NIL except when defining internal Screamer functions."))
Write a Common Lisp macro to handle this code pattern:
(the-part nil nil)

Problem: Macro call that should be transformed by THE-PART

Macro definition:
(defmacro THE-PART ...)

Macroexpansion:
(send part nil nil)
Generate a defmacro form that transforms code like this:
(some->>)

Pattern to recognize: Macro call that should be transformed by SOME->>

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

Macroexpansion:
nil