j14i/cl-macros huggingface dataset:
Generate a defmacro form that transforms code like this:
(define-op (:is-null unary-op))

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

Macro definition:
(defmacro define-op ((op-name struct-type &key sql-op-name include-slots (package (find-package '#:sxql/operator))) &body body)
  (check-type op-name symbol)
  (let ((struct-name (intern (concatenate 'string (symbol-name op-name) #.(string :-op)) package)))
    `(defstruct (,struct-name (:include ,struct-type
                               (name ,(or sql-op-name
                                          (with-output-to-string (s)
                                            (loop for c across (symbol-name op-name)
                                                  if (char= c #\-)
                                                    do (write-char #\Space s)
                                                  else
                                                    do (write-char c s)))))
                               ,@include-slots)
                              (:constructor ,(intern (concatenate 'string
                                                                  #.(string :make-)
                                                                  (symbol-name op-name)
                                                                  #.(string :-op))
                                                     package)
                                  ,(ecase struct-type
                                     ((unary-op
                                       unary-splicing-op
                                       unary-postfix-op) '(var))
                                     ((infix-op
                                       infix-splicing-op
                                       infix-list-op) '(left right))
                                     (conjunctive-op '(&rest expressions)))))
       ,@body)))

Macroexpansion:
(defstruct (is-null-op (:include unary-op (name "IS NULL")) (:constructor make-is-null-op (var))))
Define a macro that eliminates this repetitive pattern:
(draw scene (:rect :x 250 :y 250 :height 200 :width 200) :fill (xlink-href rg1))

Issue: 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 ((#:g150 (funcall (function make-svg-element) :rect (append (list :x 250 :y 250 :height 200 :width 200) (list :fill (xlink-href rg1)))))) (add-element scene #:g150) #:g150)
Write a Common Lisp macro to handle this code pattern:
(some-<> nil nil)

Problem: Macro call that should be transformed by SOME-<>

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

Macroexpansion:
(let* ((#:g121 nil))
  (if (null #:g121)
      nil
      (-> #:g121 nil)))
Create a Common Lisp macro for the following transformation. Before code:
(eswitch (x :key 1+) (11 :oops) (14 :yay))

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

Macro definition:
(defmacro eswitch (&whole whole (object &key (test 'eql) (key 'identity))
                          &body clauses)
  "Like SWITCH, but signals an error if no key matches."
  (generate-switch-body whole object clauses test key '(error)))

Macroexpansion:
(let ((#:value133 (1+ x))) (cond ((eql #:value133 11) :oops) ((eql #:value133 14) :yay) (t (error "No keys match in SWITCH. Testing against ~S with ~S." #:value133 (quote eql)))))
Create a Common Lisp macro for the following transformation. Before code:
(bind (((:slots-read-only a c) (make-instance 'metabang-bind-class-1 :a 1 :b 2 :c 3))) (list a c))

What needs to change: 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-169| (make-instance (quote metabang-bind-class-1) :a 1 :b 2 :c 3)) (a (slot-value #:|values-169| (quote a))) (c (slot-value #:|values-169| (quote c)))) (declare (ignorable #:|values-169|)) (progn (list a c)))
Generate a defmacro form that transforms code like this:
(defjs reduce2(k vals) (return k))

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

Macro definition:
(defmacro defjs (name args &body body)
  "Define client side javascript. Works like defun; body is in lisp, with parenscript
   additions, like return. So (defjs hello (x y) (return (+ x y))) defines an adder. 
   macro creates a lisp function which sends the javascript function over to the mongo 
   server to be evaluated. Result is processed and returned to the reader. 
   This will execute 10 times on the server :
   (mapcar (lambda (x) (hello 10 x)) (list 1 2 3 4 5 6 7 8 9 10))"
  `(let* ((js-body (parenscript:ps (lambda ,args ,@body))))
     (setf (gethash ',name *js-definitions*) js-body)
     (defun ,name ,args
       (get-element "retval" (car (docs (db.eval js-body ,@args)))))))

Macroexpansion:
(let* ((js-body (parenscript:ps (lambda (k vals) (return k))))) (setf (gethash (quote reduce2) *js-definitions*) js-body) (defun reduce2 (k vals) (get-element "retval" (car (docs (db.eval js-body k vals))))))
Define a macro that eliminates this repetitive pattern:
(with-special-initargs* nil
  nil)

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

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

Macroexpansion:
(progn nil)
Create a Common Lisp macro for the following transformation. Before code:
($map-reduce "foo" m r :out "testit" :query ($> "l" -900) :limit 2)

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

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

Macroexpansion:
(db.find "$cmd" (kv (kv "mapreduce" "foo") (kv "map" (or (jsdef m) (quote m))) (kv "reduce" (or (jsdef r) (quote r))) (when nil (kv "finalize" (jsdef nil))) (kv "out" (if "testit" "testit" (concatenate (quote string) "mr." "foo"))) (kv "verbose" t) (kv "limit" 2) (kv "keeptemp" nil) (kv "query" ($> "l" -900))))
Define a macro that eliminates this repetitive pattern:
(collect-at-end nil :key nil)

Issue: Macro call that should be transformed by COLLECT-AT-END

Macro definition:
(defmacro COLLECT-AT-END ...)

Macroexpansion:
(dolist (#:a127 nil)
  (let ((c (cons #:a127 nil)))
    (when (null nil) (setf nil c))
    (unless (null :key) (setf (cdr :key) c))
    (setf :key c)))
Write a Common Lisp macro to handle this code pattern:
(isnt "1" 1)

Problem: Macro call that should be transformed by isnt

Macro definition:
(defmacro isnt (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
                   :notp t
                   :duration ,duration)))))))

Macroexpansion:
(let ((#:expected199 1)) (let* ((#:new-args197 (list)) (#:desc198 (parse-description-and-test #:new-args197))) (with-catching-errors (:description #:desc198 :expected #:expected199) (with-duration ((#:duration195 #:result196) "1") (test #:result196 #:expected199 #:new-args197 :notp t :duration #:duration195)))))
You are a Common Lisp macro expert. Given this code pattern:
(all-of 'some-name)

Write a macro that addresses: Macro call that should be transformed by ALL-OF

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

Macroexpansion:
(lc ('some-name) always)
You are a Common Lisp macro expert. Given this code pattern:
(defun-compile-time cps-convert-multiple-value-prog1 (form forms continuation types value? environment) (if value? (let ((dummy-argument (gensym "DUMMY-"))) (cps-convert form `#'(lambda (&rest ,dummy-argument) (declare (magic)) ,(cps-convert-progn forms `#'(lambda () (declare (magic)) (possibly-beta-reduce-funcall continuation types `(values-list ,dummy-argument) t)) nil nil environment)) types t environment)) (cps-convert-progn (cons form forms) continuation types nil environment)))

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 cps-convert-multiple-value-prog1 (form forms continuation types value? environment) (if value? (let ((dummy-argument (gensym "DUMMY-"))) (cps-convert form (sb-int:quasiquote (function (lambda (&rest #S(sb-impl::comma :expr dummy-argument :kind 0)) (declare (magic)) #S(sb-impl::comma :expr (cps-convert-progn forms (sb-int:quasiquote (function (lambda nil (declare (magic)) (possibly-beta-reduce-funcall continuation types (sb-int:quasiquote (values-list #S(sb-impl::comma :expr dummy-argument :kind 0))) t)))) nil nil environment) :kind 0)))) types t environment)) (cps-convert-progn (cons form forms) continuation types nil environment))) (eval-when (:compile-toplevel) (compile (quote cps-convert-multiple-value-prog1))))
Write a Common Lisp macro to handle this code pattern:
(collect-first nil nil)

Problem: Macro call that should be transformed by COLLECT-FIRST

Macro definition:
(defmacro COLLECT-FIRST ...)

Macroexpansion:
(common-lisp:let* ((#:generator-624 (generator nil))
                   #:items-618
                   (#:item-620 nil))
  (declare (type generator #:generator-624)
           (type (null-or t) #:item-620))
  (tagbody
   #:ll-625
    (setq #:items-618 (next-in #:generator-624 (go end)))
    (setq #:item-620 #:items-618)
   end)
  #:item-620)
Write a Common Lisp macro to handle this code pattern:
(do-instance-combinations nil)

Problem: Macro call that should be transformed by DO-INSTANCE-COMBINATIONS

Macro definition:
(defmacro DO-INSTANCE-COMBINATIONS ...)

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

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

Macro definition:
(defmacro DEFPACKAGE ...)

Macroexpansion:
(common-lisp:defpackage 'some-name
  (:use :adhoc :closer-mop :cl)
  (:shadowing-import-from :closer-mop
                          #:defmethod
                          #:standard-generic-function
                          #:defgeneric
                          #:standard-method
                          #:standard-class)
  (:shadowing-import-from :adhoc #:defpackage #:variable #:the))
Define a macro that eliminates this repetitive pattern:
(dynenv-function 'some-name)

Issue: Macro call that should be transformed by DYNENV-FUNCTION

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

Macroexpansion:
(dynenv-function% ''some-name)
Generate a defmacro form that transforms code like this:
(f0
  nil
  :key
  nil)

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

Macro definition:
(defmacro F0 ...)

Macroexpansion:
(lambda () nil :key nil)
Create a Common Lisp macro for the following transformation. Before code:
(enable-curly-syntax)

What needs to change: Macro call that should be transformed by ENABLE-CURLY-SYNTAX

Macro definition:
(defmacro ENABLE-CURLY-SYNTAX ...)

Macroexpansion:
(eval-when (:compile-toplevel :load-toplevel :execute)
  (setf *original-readtable* *readtable*
        *readtable* (make-curly-readtable)))
Write a Common Lisp macro to handle this code pattern:
(defsynonym :maximizing :max)

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 :maximizing) (quote synonym)) (quote :max)))
Generate a defmacro form that transforms code like this:
(defun-compile-time every-other (list) (cond ((null list) list) ((null (rest list)) list) (t (cons (first list) (every-other (rest (rest list)))))))

Pattern to recognize: 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 every-other (list) (cond ((null list) list) ((null (rest list)) list) (t (cons (first list) (every-other (rest (rest list))))))) (eval-when (:compile-toplevel) (compile (quote every-other))))
You are a Common Lisp macro expert. Given this code pattern:
(define-error return-type-mismatch () (sets) "Some of the return statements return different types:~{~%~a~}" (mapcar (lambda (x) (map 'list #'type->type-spec x)) sets))

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 return-type-mismatch (:error-type varjo-error :prefix "Varjo") (sets) "Some of the return statements return different types:~{~%~a~}" (mapcar (lambda (x) (map (quote list) (function type->type-spec) x)) sets))
Write a Common Lisp macro to handle this code pattern:
(define-op (:exists unary-splicing-op))

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

Macro definition:
(defmacro define-op ((op-name struct-type &key sql-op-name include-slots (package (find-package '#:sxql/operator))) &body body)
  (check-type op-name symbol)
  (let ((struct-name (intern (concatenate 'string (symbol-name op-name) #.(string :-op)) package)))
    `(defstruct (,struct-name (:include ,struct-type
                               (name ,(or sql-op-name
                                          (with-output-to-string (s)
                                            (loop for c across (symbol-name op-name)
                                                  if (char= c #\-)
                                                    do (write-char #\Space s)
                                                  else
                                                    do (write-char c s)))))
                               ,@include-slots)
                              (:constructor ,(intern (concatenate 'string
                                                                  #.(string :make-)
                                                                  (symbol-name op-name)
                                                                  #.(string :-op))
                                                     package)
                                  ,(ecase struct-type
                                     ((unary-op
                                       unary-splicing-op
                                       unary-postfix-op) '(var))
                                     ((infix-op
                                       infix-splicing-op
                                       infix-list-op) '(left right))
                                     (conjunctive-op '(&rest expressions)))))
       ,@body)))

Macroexpansion:
(defstruct (exists-op (:include unary-splicing-op (name "EXISTS")) (:constructor make-exists-op (var))))
Create a Common Lisp macro for the following transformation. Before code:
(define-modf-rewrite fourth (expr) `(cadddr ,(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 fourth) *modf-rewrites*) (lambda (expr) (sb-int:quasiquote (cadddr #S(sb-impl::comma :expr (second expr) :kind 0))))))
Define a macro that eliminates this repetitive pattern:
($ "query" ($ nil nil))

Issue: Macro call that should be transformed by $

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

Macroexpansion:
(kv "query" ($ nil nil))
Define a macro that eliminates this repetitive pattern:
(defmethod* nil
    (progn))

Issue: Macro call that should be transformed by DEFMETHOD*

Macro definition:
(defmacro DEFMETHOD* ...)

Macroexpansion:
(defmethod (progn) (the t ()))
You are a Common Lisp macro expert. Given this code pattern:
(builder (:backtrace :output log-file :result-on-error '(500 (:content-type "text/plain") ("Internal Server Error"))) (lambda (env) (declare (ignore env)) (error "Error occured")))

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 (#:app198) (funcall (find-middleware :backtrace) #:app198 :output log-file :result-on-error (quote (500 (:content-type "text/plain") ("Internal Server Error"))))))) :initial-value (to-app (lambda (env) (declare (ignore env)) (error "Error occured"))) :from-end t)
Generate a defmacro form that transforms code like this:
(call-methods (methods) (mapcar (curry #'list 'call-method) methods))

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

Macro definition:
(defmacro call-method (method &optional methods)
  `(cl:call-method ,method ,methods))

Macroexpansion:
(call-methods (methods) (mapcar (curry (function list) (quote call-method)) methods))
Write a Common Lisp macro to handle this code pattern:
(cswitch (13 :test =) (12 :oops) (13.0 :yay))

Problem: 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 ((#:value134 (identity 13))) (cond ((= #:value134 12) :oops) ((= #:value134 13.0) :yay) (t (cerror "Return NIL from CSWITCH." "No keys match in SWITCH. Testing against ~S with ~S." #:value134 (quote =)))))
Create a Common Lisp macro for the following transformation. Before code:
(define-modf-function nthcdr 2 (new-val nth obj) (replace-nthcdr nth obj new-val))

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

Macro definition:
(defmacro define-modf-function (name nth-arg (new-val &rest args) &body body)
  "Define a new modf function.  It inverts NAME forms by modifying the NTH-ARG
term of the arguments of the place form in the MODF macro."
  ;; Side effect in a macro, I know.  How can you do this via EVAL-WHEN if I
  ;; want it to run even if not a toplevel macro?
  (setf (gethash name *modf-nth-arg*)
        nth-arg)
  `(progn
     (eval-when (:compile-toplevel :load-toplevel :execute)
       (setf (gethash ',name *modf-nth-arg*)
             ,nth-arg))
     (defun ,(intern (modf-name name) :modf) (,new-val ,@args)
       ,@body)))

Macroexpansion:
(progn (eval-when (:compile-toplevel :load-toplevel :execute) (setf (gethash (quote nthcdr) *modf-nth-arg*) 2)) (defun |BUILDER:COMMON-LISP:NTHCDR| (new-val nth obj) (replace-nthcdr nth obj new-val)))
Create a Common Lisp macro for the following transformation. Before code:
(-> :g (a) (+ a 2))

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

Macro definition:
(defmacro -> (invariant &body args)
  "See flow:atomically"
  `(atomically ,invariant ,@args))

Macroexpansion:
(atomically :g (a) (+ a 2))
Define a macro that eliminates this repetitive pattern:
(defgenerator combinations-with-replacement (list r) "Emits every possible combination, including repetitions, of the items in list in sets of size r. Eg: (combinations-with-replacement '(a b c) 2) -(values)-> (a a) (a b) (a c) (b b) (b c) (c c)" (labels ((proc (data output r) (if (zerop r) (apply #'yield (reverse output)) (loop for d on data do (proc d (cons (car d) output) (1- r)))))) (if (< (length list) r) (lambda () 'generator-stop) (proc list nil r))))

Issue: 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-with-replacement (list r) "Emits every possible combination, including repetitions, of the items in list in sets of size r. Eg: (combinations-with-replacement '(a b c) 2) -(values)-> (a a) (a b) (a c) (b b) (b c) (c c)" (with-yield (labels ((proc (data output r) (if (zerop r) (apply (function yield) (reverse output)) (loop for d on data do (proc 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:
(signal-reader-error "~S not allowed as a delimiter here" start-delimiter)

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

Macro definition:
(defmacro signal-reader-error (format-control &rest format-arguments)
  "Like ERROR but signals a SIMPLE-READER-ERROR for the stream
*STREAM*."
  `(error 'simple-reader-error
          :stream *stream*
          :format-control ,format-control
          :format-arguments (list ,@format-arguments)))

Macroexpansion:
(error (quote simple-reader-error) :stream *stream* :format-control "~S not allowed as a delimiter here" :format-arguments (list start-delimiter))