j14i/cl-macros huggingface dataset:
Create a Common Lisp macro for the following transformation. Before code:
(define-modf-rewrite cdddar (expr) `(cdr (cddar ,(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 cdddar) *modf-rewrites*) (lambda (expr) (sb-int:quasiquote (cdr (cddar #S(sb-impl::comma :expr (second expr) :kind 0)))))))
Create a Common Lisp macro for the following transformation. Before code:
(with-output-to-temporary-file (f) (write-string "hello" f))

What needs to change: Macro call that should be transformed by with-output-to-temporary-file

Macro definition:
(defmacro with-output-to-temporary-file ((stream &rest args) &body body)
  "Create a temporary file using OPEN-TEMPORARY with ARGS and run BODY
  with STREAM bound to the temporary file stream.  Returns the
  pathname of the file that has been created.  See OPEN-TEMPORARY for
  permitted options."
  `(with-open-stream (,stream (open-temporary ,@args))
     ,@body
     (pathname ,stream)))

Macroexpansion:
(with-open-stream (f (open-temporary)) (write-string "hello" f) (pathname f))
Create a Common Lisp macro for the following transformation. Before code:
(with-cache ("foo" :expire 2 :store storage) (error "MUST NOT BE ERROR"))

What needs to change: Macro call that should be transformed by with-cache

Macro definition:
(defmacro with-cache ((key &key store expire) &body body)
  "If a cache indicated by KEY exists, this just returns the cache
value without evaluating BODY. Otherwise, this evaluates BODY and
stores the evaluated value into STORE with KEY and EXPIRE. KEY is a
form that an evaluated value indicates the cache key.

Example:

    (defun f (x)
      (with-cache (x *store*)
        (very-complex-computation x)))"
  (once-only (key store expire)
    (with-gensyms (value exists-p)
      `(multiple-value-bind (,value ,exists-p)
           (getcache ,key ,store)
         (if ,exists-p
             ,value
             (let ((,value (progn ,@body)))
               (setcache ,key ,value ,store :expire ,expire)
               ,value))))))

Macroexpansion:
(let ((#:key252 "foo") (#:store253 storage) (#:expire254 2)) (multiple-value-bind (#:value255 #:exists-p256) (getcache #:key252 #:store253) (if #:exists-p256 #:value255 (let ((#:value255 (progn (error "MUST NOT BE ERROR")))) (setcache #:key252 #:value255 #:store253 :expire #:expire254) #:value255))))
Create a Common Lisp macro for the following transformation. Before code:
(draw scene (:rect :x 0 :y 0 :height "100%" :width "100%") :fill (xlink-href rg))

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

Macro definition:
(defmacro draw (scene (shape &rest params) &rest opts)
  (let ((element (gensym)))
    `(let ((,element (funcall #'make-svg-element ,shape (append (list ,@params) (list ,@opts)))))
       (add-element ,scene ,element)
       ,element)))

Macroexpansion:
(let ((#:g160 (funcall (function make-svg-element) :rect (append (list :x 0 :y 0 :height "100%" :width "100%") (list :fill (xlink-href rg)))))) (add-element scene #:g160) #:g160)
You are a Common Lisp macro expert. Given this code pattern:
(define FOPEN_MAX 1024)

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

Macro definition:
(defmacro define (name value &rest docstring)
  "Like a #define but also visible to Lisp code."
  `(progn
     (eval-when (:compile-toplevel :load-toplevel :execute)
       (defvar ,(pp-defines *package*) (make-hash-table))
       (setf (gethash ',name ,(pp-defines *package*)) ,(prin1-to-string value)))
     (defparameter ,name ,value ,@docstring)))

Macroexpansion:
(progn (eval-when (:compile-toplevel :load-toplevel :execute) (defvar *preprocessor-defines* (make-hash-table)) (setf (gethash (quote fopen_max) *preprocessor-defines*) #A((4) base-char . "1024"))) (defparameter fopen_max 1024))
Generate a defmacro form that transforms code like this:
(define-simple-object-lookup macro macro-function)

Pattern to recognize: Macro call that should be transformed by define-simple-object-lookup

Macro definition:
(defmacro define-simple-object-lookup (class lookup-function &body body)
  `(defmethod object ((,class ,class))
     ,(if body
          `(let ((,(first lookup-function) ,class))
             ,@body)
          `(,lookup-function (designator ,class)))))

Macroexpansion:
(defmethod object ((macro macro)) (macro-function (designator macro)))
Create a Common Lisp macro for the following transformation. Before code:
($ nil nil)

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

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

Macroexpansion:
(kv nil nil)
Write a Common Lisp macro to handle this code pattern:
(dletf* nil
  :key
  nil)

Problem: Macro call that should be transformed by DLETF*

Macro definition:
(defmacro DLETF* ...)

Macroexpansion:
(progn :key nil)
Generate a defmacro form that transforms code like this:
(define-binary-op-mapping-definer define-comparison-ops `(progn (defmethod ,op ((x memptr) (y memptr)) (if (and (eq (memptr-mem x) (memptr-mem y)) (,cl (memptr-ptr x) (memptr-ptr y))) 1 0)) (defmethod ,op ((x number) (y number)) (if (,cl x y) 1 0))))

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

Macro definition:
(defmacro define (name value &rest docstring)
  "Like a #define but also visible to Lisp code."
  `(progn
     (eval-when (:compile-toplevel :load-toplevel :execute)
       (defvar ,(pp-defines *package*) (make-hash-table))
       (setf (gethash ',name ,(pp-defines *package*)) ,(prin1-to-string value)))
     (defparameter ,name ,value ,@docstring)))

Macroexpansion:
(defmacro define-comparison-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 (defmethod #S(sb-impl::comma :expr op :kind 0) ((x memptr) (y memptr)) (if (and (eq (memptr-mem x) (memptr-mem y)) (#S(sb-impl::comma :expr cl :kind 0) (memptr-ptr x) (memptr-ptr y))) 1 0)) (defmethod #S(sb-impl::comma :expr op :kind 0) ((x number) (y number)) (if (#S(sb-impl::comma :expr cl :kind 0) x y) 1 0)))))) :kind 2))))
Write a Common Lisp macro to handle this code pattern:
(with-unique-js-names nil nil)

Problem: Macro call that should be transformed by WITH-UNIQUE-JS-NAMES

Macro definition:
(defmacro WITH-UNIQUE-JS-NAMES ...)

Macroexpansion:
(with-ps-gensyms nil
  nil)
Write a Common Lisp macro to handle this code pattern:
(yield-for-union-ops "UNION")

Problem: 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((15) base-char . "~{~A~^ UNION ~}") (mapcar (function yield) statements))) (when others (list (format nil "~{~A~^ ~}" (mapcar (function yield) others))))))))
Write a Common Lisp macro to handle this code pattern:
(defgenerator combinations (list r) "Emits every possible combination of the items in list in sets of size r. Eg: (combinations '(a b c d) 2) -(values)-> (a b) (a c) (a d) (b c) (b d) (c d)" (labels ((proc (data output r) (if (zerop r) (apply #'yield (reverse output)) (loop for d on data do (proc (cdr d) (cons (car d) output) (1- r)))))) (if (< (length list) r) (lambda () 'generator-stop) (proc list nil r))))

Problem: Macro call that should be transformed by defgenerator

Macro definition:
(defmacro defgenerator (name arguments &body body)
  (multiple-value-bind (remaining-forms declarations doc-string)
      (alexandria:parse-body body :documentation t)
    `(defun ,name ,arguments
       ,doc-string
       ,@declarations
       (with-yield
	 ,@remaining-forms))))

Macroexpansion:
(defun combinations (list r) "Emits every possible combination of the items in list in sets of size r. Eg: (combinations '(a b c d) 2) -(values)-> (a b) (a c) (a d) (b c) (b d) (c d)" (with-yield (labels ((proc (data output r) (if (zerop r) (apply (function yield) (reverse output)) (loop for d on data do (proc (cdr d) (cons (car d) output) (1- r)))))) (if (< (length list) r) (lambda nil (quote generator-stop)) (proc list nil r)))))
Create a Common Lisp macro for the following transformation. Before code:
(make-simple-appender-to-place 'some-name)

What needs to change: Macro call that should be transformed by MAKE-SIMPLE-APPENDER-TO-PLACE

Macro definition:
(defmacro MAKE-SIMPLE-APPENDER-TO-PLACE ...)

Macroexpansion:
(progn
 (setf 'some-name (alexandria:ensure-list 'some-name))
 (let ((#:tail132 (last 'some-name)))
   (lambda (&rest values)
     (append-at-end 'some-name #:tail132 values)
     'some-name)))
Generate a defmacro form that transforms code like this:
(define-simple-documentation-lookup package T)

Pattern to recognize: Macro call that should be transformed by define-simple-documentation-lookup

Macro definition:
(defmacro define-simple-documentation-lookup (class documentation-type)
  `(defmethod documentation ((,class ,class))
     ,(if (eql documentation-type T)
          `(cl:documentation (object ,class) 'T)
          `(cl:documentation (designator ,class) ',documentation-type))))

Macroexpansion:
(defmethod documentation ((package package)) (common-lisp:documentation (object package) (quote t)))
Create a Common Lisp macro for the following transformation. Before code:
(special-symbol-reprogv nil
    :key
  nil)

What needs to change: Macro call that should be transformed by SPECIAL-SYMBOL-REPROGV

Macro definition:
(defmacro SPECIAL-SYMBOL-REPROGV ...)

Macroexpansion:
(let (#:symbol-list209)
  (tagbody
   #:retry210
    (setq #:symbol-list209 nil)
    (unless (every #'special-symbol-p #:symbol-list209)
      (cerror "Retry to rebind the place(s)."
              "Attempt at rebinding one or more non-special places: ~S" 'nil)
      (go #:retry210)))
  (dynamic-reprogv #:symbol-list209
      :key
    nil))
You are a Common Lisp macro expert. Given this code pattern:
(defmacro-clause 'some-name)

Write a macro that addresses: Macro call that should be transformed by DEFMACRO-CLAUSE

Macro definition:
(defmacro DEFMACRO-CLAUSE ...)

Macroexpansion:
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defmacro clause-quote-1 (&key ((:quote some-name))))
  (iterate::install-clause-info '(quote) '(quote) 'clause-quote-1 nil nil)
  ''some-name)
Create a Common Lisp macro for the following transformation. Before code:
(define-modf-rewrite cdaar (expr) `(cdr (caar ,(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 cdaar) *modf-rewrites*) (lambda (expr) (sb-int:quasiquote (cdr (caar #S(sb-impl::comma :expr (second expr) :kind 0)))))))
Define a macro that eliminates this repetitive pattern:
(trace$method 'some-name)

Issue: Macro call that should be transformed by TRACE$METHOD

Macro definition:
(defmacro TRACE$METHOD ...)

Macroexpansion:
(mcs-trace quote some-name)
Write a Common Lisp macro to handle this code pattern:
(bind (((:slots-r/o a c) (make-instance 'metabang-bind-class-1 :a 1 :b 2 :c 3))) (list a c))

Problem: Macro call that should be transformed by bind

Macro definition:
(defmacro bind ((&rest bindings) &body body)
  "Bind is a replacement for let*, destructuring-bind, multiple-value-bind and more. 

An example is probably the best way to describe its syntax:

    \(bind \(\(a 2\)
           \(\(b &rest args &key \(c 2\) &allow-other-keys\) '\(:a :c 5 :d 10 :e 54\)\)
           \(\(:values d e\) \(truncate 4.5\)\)
           \(\(:structure xxx- slot1 slot2\) \(make-xxx\)\)
           \(\(:flet name \(arg1 arg2\)\) \(+ arg1 arg2\)\)\)
         \(list a b c d e args\)\)

Simple bindings are as in let*. Destructuring is done if the first item
in a binding is a list. Multiple value binding is done if the first item
in a binding is a list and the first item in the list is ':values'. Other
forms have their own syntax. For example, :structure first has the conc
name and then slot names whereas :flet has the function name and a list
of arguments and then the function body (in an implicit progn)."
  (let (declarations)
    (loop while (and (consp (car body)) (eq (caar body) 'declare)) do
          (push (first body) declarations)
          (setf body (rest body)))
    (if bindings
	(let ((*all-declarations* (bind-expand-declarations (nreverse declarations))))
	  (prog1
	      (bind-macro-helper bindings body)
	    (check-for-unused-variable-declarations *all-declarations*)))
        `(locally
             ,@declarations
           ,@body))))

Macroexpansion:
(let* ((#:|values-172| (make-instance (quote metabang-bind-class-1) :a 1 :b 2 :c 3)) (a (slot-value #:|values-172| (quote a))) (c (slot-value #:|values-172| (quote c)))) (declare (ignorable #:|values-172|)) (progn (list a c)))
You are a Common Lisp macro expert. Given this code pattern:
(define-error invalid-context-symbol () (context-symb) "Sorry but the symbol '~a' is not valid as a context specifier" context-symb)

Write a macro that addresses: 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 invalid-context-symbol (:error-type varjo-error :prefix "Varjo") (context-symb) "Sorry but the symbol '~a' is not valid as a context specifier" context-symb)
Generate a defmacro form that transforms code like this:
(cswitch (13 :key 1-) (12 :yay) (13.0 :oops))

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

Macro definition:
(defmacro cswitch (&whole whole (object &key (test 'eql) (key 'identity))
                          &body clauses)
  "Like SWITCH, but signals a continuable error if no key matches."
  (generate-switch-body whole object clauses test key '(cerror "Return NIL from CSWITCH.")))

Macroexpansion:
(let ((#:value135 (1- 13))) (cond ((eql #:value135 12) :yay) ((eql #:value135 13.0) :oops) (t (cerror "Return NIL from CSWITCH." "No keys match in SWITCH. Testing against ~S with ~S." #:value135 (quote eql)))))
Create a Common Lisp macro for the following transformation. Before code:
(signal-syntax-error* (lexer-pos lexer) "Invalid character in named register group.")

What needs to change: Macro call that should be transformed by signal-syntax-error*

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

Macroexpansion:
(error (quote ppcre-syntax-error) :pos (lexer-pos lexer) :format-control "Invalid character in named register group." :format-arguments (list))
You are a Common Lisp macro expert. Given this code pattern:
(define-path-instruction-pair curve-to "C" (control-x1 control-y1 control-x2 control-y2 x y))

Write a macro that addresses: Macro call that should be transformed by define-path-instruction-pair

Macro definition:
(defmacro define-path-instruction-pair (name instruction (&rest args))
  (let ((draw-relative (intern (concatenate 'string (string name) "-R"))))
    `(progn
       (defun ,name (,@args)
         (format-instruction ,instruction ,@args))
       (defun ,draw-relative (,@args)
         (format-instruction ,(string-downcase instruction) ,@args)))))

Macroexpansion:
(progn (defun curve-to (control-x1 control-y1 control-x2 control-y2 x y) (format-instruction "C" control-x1 control-y1 control-x2 control-y2 x y)) (defun curve-to-r (control-x1 control-y1 control-x2 control-y2 x y) (format-instruction "c" control-x1 control-y1 control-x2 control-y2 x y)))
Create a Common Lisp macro for the following transformation. Before code:
(dlet nil
  :key
  nil)

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

Macro definition:
(defmacro DLET ...)

Macroexpansion:
(dynamic-let nil
  :key
  nil)
Create a Common Lisp macro for the following transformation. Before code:
(mvlet* ((form exp? (expand-in-env-1 self form env)) (exps? (or exps? exp?))) (if (not exp?) (values form exps?) (rec form exps?)))

What needs to change: 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 (form exp?) (expand-in-env-1 self form env) (mvlet* ((exps? (or exps? exp?))) (if (not exp?) (values form exps?) (rec form exps?))))
Create a Common Lisp macro for the following transformation. Before code:
(dict-of nil)

What needs to change: Macro call that should be transformed by DICT-OF

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

Macroexpansion:
(let ((#:dict122 (make-hash-table :test 'equal)))
  (do-for nil
    (multiple-value-call
        (lambda (#:k123 #:v124) (setf (gethash #:k123 #:dict122) #:v124))
      nil))
  #:dict122)
Write a Common Lisp macro to handle this code pattern:
(mapping 'some-name)

Problem: Macro call that should be transformed by MAPPING

Macro definition:
(defmacro MAPPING ...)

Macroexpansion:
(mapping-mac 'some-name)
Write a Common Lisp macro to handle this code pattern:
(dotable (item _ set1) (unless (gethash item set2) (add# item set)))

Problem: Macro call that should be transformed by dotable

Macro definition:
(defmacro dotable ((k v table &optional rez) &body body)
  "Like DOLIST but iterates over key-value pairs (K V) in anything, that can be
   viewed as a table (hash-table, alist, plist, object).
   Autodeclares variables named _ as ignored."
  (with-gensyms (pair)
    (once-only (table)
      (let ((_ (find "_" (list k v)
                     :test 'string=
                     :key 'symbol-name)))
        `(block nil
           (etypecase ,table
             (hash-table (maphash (lambda (,k ,v)
                                    ,(when _ `(declare (ignore rutils.bind:_)))
                                    ,@body)
                                  ,table))

             (list (if (rutils.list:alistp ,table)
                       (dolist (,pair ,table)
                         (destructuring-bind (,k . ,v) ,pair
                           ,@(when _ `((declare (ignore ,_))))
                           ,@body))
                       (error 'simple-type-error
                              :format-control "Can't iterate over proper list ~
                                               in DOTABLE: need an alist"))))
           ,rez)))))

Macroexpansion:
(let ((#:table168 set1)) (block nil (etypecase #:table168 (hash-table (maphash (lambda (item _) (declare (ignore rutils.bind:_)) (unless (gethash item set2) (|ADD#| item set))) #:table168)) (list (if (alistp #:table168) (dolist (#:g167 #:table168) (destructuring-bind (item . _) #:g167 (declare (ignore _)) (unless (gethash item set2) (|ADD#| item set)))) (error (quote simple-type-error) :format-control "Can't iterate over proper list ~
                                               in DOTABLE: need an alist")))) nil))
Write a Common Lisp macro to handle this code pattern:
(defsynonym :multiply :mult)

Problem: Macro call that should be transformed by defsynonym

Macro definition:
(defmacro defsynonym (symbol synonym)
  "Set SYNONYM for a SYMBOL. "
  `(eval-always
     (setf (get ',symbol 'synonym) ',synonym)))

Macroexpansion:
(eval-always (setf (get (quote :multiply) (quote synonym)) (quote :mult)))
Define a macro that eliminates this repetitive pattern:
(define-custom-var (:boolean *boolean-handler*))

Issue: 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 (*boolean-handler* . :boolean)) *custom-vars* :test (function equal)) (defvar *boolean-handler*)))
Generate a defmacro form that transforms code like this:
(->> nil :key nil)

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

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

Macroexpansion:
((:key nil))