j14i/cl-macros huggingface dataset:
Generate a defmacro form that transforms code like this:
(receive (one two three four) (values 1 2 3) (list one two three four))

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

Macro definition:
(defmacro receive (formals expr &body body)
  "Stricter version of `multiple-value-bind'.

Use `receive' when you want to enforce that EXPR should return a
certain number of values, or a minimum number of values.

If FORMALS is a proper list, then EXPR must return exactly as many
values -- no more and no less -- as there are variables in FORMALS.

If FORMALS is an improper list (VARS . REST), then EXPR must return at
least as many values as there are VARS, and any further values are
bound, as a list, to REST.

Lastly, if FORMALS is a symbol, bind that symbol to all the values
returned by EXPR, as if by `multiple-value-list'.

From Scheme (SRFI-8)."
  ;; It's probably not worth stack-allocating the thunk.
  (cond ((null formals)
         `(multiple-value-call
              (lambda ()
                ,@body)
            ,expr))
        ((atom formals)
         ;; This could also be written:
         #+(or) `(let ((,formals (multiple-value-list ,expr)))
                   ,@body)
         ;; But I want it to be possible to declare FORMALS to have
         ;; dynamic extent, and most Lisps support that for &rest
         ;; lists.
         `(multiple-value-call
              (lambda (&rest ,formals)
                ,@body)
            ,expr))
        ((proper-list-p formals)
         (when (intersection formals lambda-list-keywords)
           (error "Lambda list keywords in formals: ~a" formals))
         `(multiple-value-call
              (lambda ,formals
                ,@body)
            ,expr))
        (t (let* ((last (last formals))
                  (vars (append (butlast formals)
                                (list (car last))))
                  (rest (cdr last)))
             (when (intersection (cons rest vars) lambda-list-keywords)
               (error "Lambda list keywords in formals: ~a" formals))
             `(multiple-value-call
                  (lambda (,@vars &rest ,rest)
                    ,@body)
                ,expr)))))

Macroexpansion:
(multiple-value-call (lambda (one two three four) (list one two three four)) (values 1 2 3))
Generate a defmacro form that transforms code like this:
(rem-plist-val! nil nil)

Pattern to recognize: Macro call that should be transformed by REM-PLIST-VAL!

Macro definition:
(defmacro rem-plist-val! (id place &key (test '(default-test)) (key '(default-key)))
  `(setf ,place
    (rem-plist-val ,id ,place :test ,test :key ,key)))

Macroexpansion:
(setf nil (rem-plist-val nil nil :test (default-test) :key (default-key)))
Define a macro that eliminates this repetitive pattern:
(~> (-> :g (a) (+ 1 a)) (list nil) (-> :g (a) (+ a 2)) (>> (-> :g (b) (+ b 6)) (-> :g (b) (+ b 7))) (list (-> :g (a) (+ a 3)) (-> :g (a) (+ a 4)) (-> :g (a) (values (+ a 5) -1))))

Issue: Macro call that should be transformed by ~>

Macro definition:
(defmacro ~> (&rest body)
  "See flow:concurrently"
  `(concurrently ,@body))

Macroexpansion:
(concurrently (-> :g (a) (+ 1 a)) (list nil) (-> :g (a) (+ a 2)) (>> (-> :g (b) (+ b 6)) (-> :g (b) (+ b 7))) (list (-> :g (a) (+ a 3)) (-> :g (a) (+ a 4)) (-> :g (a) (values (+ a 5) -1))))
Write a Common Lisp macro to handle this code pattern:
(with-access-values nil
    :key
  nil)

Problem: Macro call that should be transformed by WITH-ACCESS-VALUES

Macro definition:
(defmacro with-access-values ((&rest bindings) obj &body body)
  "A macro which binds local variables from accessed values on object
   according to bindings

   bindings: (local-symbol-and-access-key
              or (local-symbol access-key)
               ...)
   obj: the thing we are accessing data from
  "
  (flet ((key-for (it)
           (etypecase it
             (symbol `(quote ,it))
             ((or string keyword list) it))))
    (let* ((o (gensym "OBJ"))
           (expanded-bindings
             (iter (for b in (ensure-list bindings))
               (when (first-iteration-p)
                 (collect `(,o ,obj)))
               (typecase b
                 (null)
                 (list (collect `(,(first b) (access ,o ,(key-for (second b))))))
                 (symbol (collect `(,b (access ,o ,(key-for b)))))))))
      `(let* ,expanded-bindings
        ,@body))))

Macroexpansion:
(let* ()
  nil)
Generate a defmacro form that transforms code like this:
(builder (:auth/basic :authenticator (lambda (user pass) (and (string= user "hoge") (string= pass "fuga")))) (lambda (env) `(200 () (,(format nil "Hello, ~A" (getf env :remote-user))))))

Pattern to recognize: 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 (#:app186) (funcall (find-middleware :auth/basic) #:app186 :authenticator (lambda (user pass) (and (string= user "hoge") (string= pass "fuga"))))))) :initial-value (to-app (lambda (env) (sb-int:quasiquote (200 nil (#S(sb-impl::comma :expr (format nil "Hello, ~A" (getf env :remote-user)) :kind 0)))))) :from-end t)
Define a macro that eliminates this repetitive pattern:
(builder (:static :path "/public/" :root (asdf:system-relative-pathname :lack #P"data/")) (lambda (env) (declare (ignore env)) `(200 (:content-type "text/plain") ("Happy Valentine!"))))

Issue: 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 (#:app226) (funcall (find-middleware :static) #:app226 :path "/public/" :root (asdf/system:system-relative-pathname :lack #P"data/"))))) :initial-value (to-app (lambda (env) (declare (ignore env)) (sb-int:quasiquote (200 (:content-type "text/plain") ("Happy Valentine!"))))) :from-end t)
You are a Common Lisp macro expert. Given this code pattern:
(ematch0 missing ((list) pattern) ((list* var rest) (bind-missing-vars-with-nil (with-gensyms (it) `(guard1 ,it t nil (guard1 ,var t) ,it ,pattern)) rest)))

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

Macro definition:
(defmacro ematch0 (what &body clauses)
  `(match0 ,what
     ,@clauses
     (_ (error "level0 match error!"))))

Macroexpansion:
(match0 missing ((list) pattern) ((list* var rest) (bind-missing-vars-with-nil (with-gensyms (it) (sb-int:quasiquote (guard1 #S(sb-impl::comma :expr it :kind 0) t nil (guard1 #S(sb-impl::comma :expr var :kind 0) t) #S(sb-impl::comma :expr it :kind 0) #S(sb-impl::comma :expr pattern :kind 0)))) rest)) (_ (error "level0 match error!")))
Write a Common Lisp macro to handle this code pattern:
(builder :accesslog (lambda (env) (declare (ignore env)) '(200 () ("ok"))))

Problem: 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 (find-middleware :accesslog))) :initial-value (to-app (lambda (env) (declare (ignore env)) (quote (200 nil ("ok"))))) :from-end t)
Write a Common Lisp macro to handle this code pattern:
(define-op (:/ conjunctive-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 (/-op (:include conjunctive-op (name "/")) (:constructor make-/-op (&rest expressions))))
Generate a defmacro form that transforms code like this:
(when (node-slot initializer) (del-proxy initializer))

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 (node-slot initializer) (del-proxy initializer))
Create a Common Lisp macro for the following transformation. Before code:
(letrec nil)

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

Macro definition:
(defmacro LETREC ...)

Macroexpansion:
(let ()
  (flet ()
    nil
    (setf)))
Define a macro that eliminates this repetitive pattern:
(next-in nil nil)

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

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

Macroexpansion:
(do-next-in nil #'(lambda () nil))
Write a Common Lisp macro to handle this code pattern:
(defjsmacro 'some-name)

Problem: Macro call that should be transformed by DEFJSMACRO

Macro definition:
(defmacro DEFJSMACRO ...)

Macroexpansion:
(defpsmacro 'some-name)
You are a Common Lisp macro expert. Given this code pattern:
(defclause (repeat n) "Repeat the loop some number of times" (top-level-check) (let* ((c-type (or (expression-type n) 'fixnum)) (count-var (make-var-and-binding 'count n :type c-type))) (setq *loop-end-used?* t) (return-code :body `((if (<= ,count-var 0) (go ,*loop-end*))) :step `((setq ,count-var (1- ,count-var))))))

Write a macro that addresses: 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-repeat-2 (&key ((:repeat n))) "Repeat the loop some number of times" (top-level-check) (let* ((c-type (or (expression-type n) (quote fixnum))) (count-var (make-var-and-binding (quote count) n :type c-type))) (setq *loop-end-used?* t) (return-code :body (sb-int:quasiquote ((if (<= #S(sb-impl::comma :expr count-var :kind 0) 0) (go #S(sb-impl::comma :expr *loop-end* :kind 0))))) :step (sb-int:quasiquote ((setq #S(sb-impl::comma :expr count-var :kind 0) (1- #S(sb-impl::comma :expr count-var :kind 0)))))))) (install-clause-info (quote (repeat)) (quote (repeat)) (quote clause-repeat-2) "Repeat the loop some number of times" nil) (quote (repeat n)))
Write a Common Lisp macro to handle this code pattern:
(inext nil (progn))

Problem: Macro call that should be transformed by INEXT

Macro definition:
(defmacro INEXT ...)

Macroexpansion:
(let ((vals (multiple-value-list (funcall (i-coro nil) (progn)))))
  (if (not vals)
      (coexit!)
      (car vals)))
You are a Common Lisp macro expert. Given this code pattern:
(with-preprocessor-state-slots (state) (when if-section-skip-reason (return-from process-preprocessing-directive nil)) (let ((token-list-for-print (remove-whitespace-marker directive-token-list))) (error 'preprocess-error :format-control "[File ~A: Line ~D] #error: ~{~A~^ ~}" :format-arguments (list (if file-pathname (enough-namestring file-pathname)) line-number token-list-for-print))))

Write a macro that addresses: Macro call that should be transformed by with-preprocessor-state-slots

Macro definition:
(defmacro with-preprocessor-state-slots ((state) &body body)
  `(with-accessors ((file-pathname pp-state-file-pathname)
                    (token-list pp-state-token-list)
                    (result-list pp-state-result-list)
                    (line-number pp-state-line-number)
                    (tokens-in-line pp-state-tokens-in-line)
                    (macro-alist pp-state-macro-alist)
                    (if-section-stack pp-state-if-section-stack)
                    (if-section-skip-reason pp-state-if-section-skip-reason)
                    (include-stack pp-state-include-stack))
       ,state
     ,@body))

Macroexpansion:
(with-accessors ((file-pathname pp-state-file-pathname) (token-list pp-state-token-list) (result-list pp-state-result-list) (line-number pp-state-line-number) (tokens-in-line pp-state-tokens-in-line) (macro-alist pp-state-macro-alist) (if-section-stack pp-state-if-section-stack) (if-section-skip-reason pp-state-if-section-skip-reason) (include-stack pp-state-include-stack)) state (when if-section-skip-reason (return-from process-preprocessing-directive nil)) (let ((token-list-for-print (remove-whitespace-marker directive-token-list))) (error (quote preprocess-error) :format-control "[File ~A: Line ~D] #error: ~{~A~^ ~}" :format-arguments (list (if file-pathname (enough-namestring file-pathname)) line-number token-list-for-print))))
Create a Common Lisp macro for the following transformation. Before code:
(defvar-compile-time *function-record-table* (make-hash-table :test #'equal) "The function record table.")

What needs to change: 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 *function-record-table* (make-hash-table :test (function equal)) "The function record table."))
Generate a defmacro form that transforms code like this:
(defun/1 ldexp (x n) (* x (expt 2 n)))

Pattern to recognize: 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 ldexp (x n) (declare (optimize (speed 0) (debug 3) (sb-ext:inhibit-warnings 3))) (* x (expt 2 n))) (defparameter ldexp (vacietis.c:mkptr& (symbol-function (quote ldexp)))))
Create a Common Lisp macro for the following transformation. Before code:
(do+ (for x (in '(1 3 5 7 9))) (for k (from 10 :to 0)) (initially (format t "initially k = ~S~%" k)) (for m (to 100 :by 5)) (initially (format t "another init form~%")) (with (y 42) z) (stop-when (eql x 7)) (counting loops) (finally (format t "finally k = ~S~%" k)) (accumulating-to w) (accumulating-to p :initially 0 :by #'+ :finally #'-) (returning (list 'x x 'y y 'z z 'k k 'm m 'w w 'p p 'loops loops 'max-length max-length 'longest-list longest-list)) (finally (format t "another final form~%")) (finding max-x (maximizing x)) (for list (in '((1 2) (3) (4 5 6) (7 8) (9)))) (finding max-length (maximizing (length list) :saving list :in longest-list)) (let ((foo "look ma, body is nested!")) (declare (ignore foo)) (format t "~%loop no. ~A~%" loops) (format t "before collect, x ~A y ~A z ~A k ~A m ~A w ~A ~% list ~A max-length ~A longest-list ~A ~%" x y z k m w list max-length longest-list) (collect x :into w) (collect x :into p) (format t "after collect, x ~A y ~A z ~A k ~A m ~A w ~A ~% list ~A max-length ~A longest-list ~A ~%" x y z k m w list max-length longest-list)))

What needs to change: 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 (for x (in (quote (1 3 5 7 9)))) (for k (from 10 :to 0)) (initially (format t "initially k = ~S~%" k)) (for m (to 100 :by 5)) (initially (format t "another init form~%")) (with (y 42) z) (stop-when (eql x 7)) (counting loops) (finally (format t "finally k = ~S~%" k)) (accumulating-to w) (accumulating-to p :initially 0 :by (function +) :finally (function -)) (returning (list (quote x) x (quote y) y (quote z) z (quote k) k (quote m) m (quote w) w (quote p) p (quote loops) loops (quote max-length) max-length (quote longest-list) longest-list)) (finally (format t "another final form~%")) (finding max-x (maximizing x)) (for list (in (quote ((1 2) (3) (4 5 6) (7 8) (9))))) (finding max-length (maximizing (length list) :saving list :in longest-list)) (let ((foo "look ma, body is nested!")) (declare (ignore foo)) (format t "~%loop no. ~A~%" loops) (format t "before collect, x ~A y ~A z ~A k ~A m ~A w ~A ~% list ~A max-length ~A longest-list ~A ~%" x y z k m w list max-length longest-list) (collect x :into w) (collect x :into p) (format t "after collect, x ~A y ~A z ~A k ~A m ~A w ~A ~% list ~A max-length ~A longest-list ~A ~%" x y z k m w list max-length longest-list)))
Generate a defmacro form that transforms code like this:
(do+ (options :name outer-loop) (do+ (options :name inner-loop) (do+ (terminate outer-loop 3))))

Pattern to recognize: 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 (options :name outer-loop) (do+ (options :name inner-loop) (do+ (terminate outer-loop 3))))
Write a Common Lisp macro to handle this code pattern:
(-<>
  nil
  :key
  nil)

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

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

Macroexpansion:
(let* ((#:var208 nil) (#:var209 (:key #:var208)) (#:var210 (nil #:var209)))
  #:var210)
Create a Common Lisp macro for the following transformation. Before code:
(defvar* nil :key nil)

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

Macro definition:
(defmacro DEFVAR* ...)

Macroexpansion:
(defvar/param defvar nil :key nil)
Define a macro that eliminates this repetitive pattern:
(enable-punch-syntax)

Issue: Macro call that should be transformed by enable-punch-syntax

Macro definition:
(defmacro enable-punch-syntax ()
  '(eval-when (:compile-toplevel :load-toplevel :execute)
    (cl-syntax:use-syntax punch-syntax)))

Macroexpansion:
(eval-when (:compile-toplevel :load-toplevel :execute) (cl-syntax:use-syntax punch-syntax))
Create a Common Lisp macro for the following transformation. Before code:
(define-error invalid-for-loop-type () (decl-obj) "Invalid type ~a used as counter for for-loop" (primary-type decl-obj))

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 invalid-for-loop-type (:error-type varjo-error :prefix "Varjo") (decl-obj) "Invalid type ~a used as counter for for-loop" (primary-type decl-obj))
Create a Common Lisp macro for the following transformation. Before code:
(defun-compile-time cps-convert-multiple-value-call (nondeterministic? function forms continuation types value? environment) (let ((dummy-argument (gensym "DUMMY-")) (other-arguments (gensym "OTHER-"))) (cps-convert function `#'(lambda (&optional ,dummy-argument &rest ,other-arguments) (declare (magic) (ignore ,other-arguments)) ,(cps-convert-multiple-value-call-internal nondeterministic? dummy-argument forms continuation types value? environment)) nil t environment)))

What needs to change: 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-call (nondeterministic? function forms continuation types value? environment) (let ((dummy-argument (gensym "DUMMY-")) (other-arguments (gensym "OTHER-"))) (cps-convert function (sb-int:quasiquote (function (lambda (&optional #S(sb-impl::comma :expr dummy-argument :kind 0) &rest #S(sb-impl::comma :expr other-arguments :kind 0)) (declare (magic) (ignore #S(sb-impl::comma :expr other-arguments :kind 0))) #S(sb-impl::comma :expr (cps-convert-multiple-value-call-internal nondeterministic? dummy-argument forms continuation types value? environment) :kind 0)))) nil t environment))) (eval-when (:compile-toplevel) (compile (quote cps-convert-multiple-value-call))))
Write a Common Lisp macro to handle this code pattern:
(defvar-unbound *stream* "Bound to the stream which is read from while parsing a string.")

Problem: Macro call that should be transformed by defvar-unbound

Macro definition:
(defmacro defvar-unbound (variable-name documentation)
  "Like DEFVAR, but the variable will be unbound rather than getting
an initial value.  This is useful for variables which should have no
global value but might have a dynamically bound value."
  ;; stolen from comp.lang.lisp article <k7727i3s.fsf@comcast.net> by
  ;; "prunesquallor@comcast.net"
  `(eval-when (:load-toplevel :compile-toplevel :execute)
    (defvar ,variable-name)
    (setf (documentation ',variable-name 'variable)
            ,documentation)))

Macroexpansion:
(eval-when (:load-toplevel :compile-toplevel :execute) (defvar *stream*) (setf (documentation (quote *stream*) (quote variable)) "Bound to the stream which is read from while parsing a string."))