j14i/cl-macros huggingface dataset:
Define a macro that eliminates this repetitive pattern:
(define-test subtest :parent example (fail (error "An expected failure.")) (fail (warn "An expected warning.") warning))

Issue: Macro call that should be transformed by define-test

Macro definition:
(defmacro define-test (name &body arguments-and-body)
  (destructuring-bind (nparent name) (if (listp name) name (list NIL name))
    (form-fiddle:with-body-options (body options parent home (test-class 'test) (compile-at :compile-time) defun) arguments-and-body
      (let ((body (remove 'define-test body :key (lambda (a) (when (listp a) (car a))) :test #'eql))
            (defs (remove 'define-test body :key (lambda (a) (when (listp a) (car a))) :test-not #'eql))
            (home-form (or home `(find-package ,(package-name *package*)))))
        (when (and parent nparent)
          (error "Cannot specify parent through name and through a keyword argument at the same time!"))
        `(let ((*package* (find-package ,(package-name *package*)))) ; Make sure package stays consistent throughout initialisation.
           (setf (find-test ',name ,home-form)
                 (ensure-test ',test-class
                              :name ',name
                              :home ,home-form
                              :tests (list ,@(loop for form in body
                                                   collect (ecase compile-at
                                                             (:compile-time `(lambda () ,form))
                                                             (:execute `(lambda () (call-compile ',form))))))
                              :parent ',(or parent nparent)
                              ,@(loop for option in options
                                      collect `',option)))
           ,@(loop for (def subname . body) in defs
                   collect `(,def (,name ,subname)
                              :home ,home
                              ,@body))
           ,@(when defun
               `((defun ,(if (stringp name) (read-symbol name) name) (&rest test-args)
                   (apply #'test (find-test ',name ,home-form) test-args))))
           ',name)))))

Macroexpansion:
(let ((*package* (find-package #A((9) base-char . "PARACHUTE")))) (setf (find-test (quote subtest) (find-package #A((9) base-char . "PARACHUTE"))) (ensure-test (quote test) :name (quote subtest) :home (find-package #A((9) base-char . "PARACHUTE")) :tests (list (lambda nil (fail (error "An expected failure."))) (lambda nil (fail (warn "An expected warning.") warning))) :parent (quote example))) (quote subtest))
Define a macro that eliminates this repetitive pattern:
(defclause summing-to-and-returning (vars &optional result-processor) "Same as summing-to, but also returns the value of each <vars> at the end of the loop." `((summing-to ,vars ,result-processor) ,@(mapcar (lambda (var) `(returning ,var)) (ensure-list vars))))

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 summing-to-and-returning (vars &optional result-processor) "Same as summing-to, but also returns the value of each <vars> at the end of the loop." (sb-int:quasiquote ((summing-to #S(sb-impl::comma :expr vars :kind 0) #S(sb-impl::comma :expr result-processor :kind 0)) #S(sb-impl::comma :expr (mapcar (lambda (var) (sb-int:quasiquote (returning #S(sb-impl::comma :expr var :kind 0)))) (ensure-list vars)) :kind 2)))) (pushnew (quote summing-to-and-returning) *clauses*))
Write a Common Lisp macro to handle this code pattern:
(action (:after node-match) #'apply-lift)

Problem: Macro call that should be transformed by action

Macro definition:
(defmacro action ((when type &rest args) &body body)
  "Construct an action block, turning `body` into a lambda function
accepting `args` if `args` are provided. If there are no `args`, then
`body` is assumed to be a function object and is used directly with
`when` and `type` to create an `action` instance. Otherwise, the first
argument in `args` is declared to be a node of type `type`, and the
`args` and `body` are used to generate a lambda function."
  (check-type when keyword)
  (check-type type symbol)
  (assert (subtypep type 'node))
  (assert (or (not (endp args)) (= 1 (length body))))
  (if (endp args)
      `(make-action ',when ',type ,@body)
      `(make-action ',when ',type
                    (lambda (,@args)
                      (declare (type ,type ,(first args)))
                      ,@body))))

Macroexpansion:
(make-action (quote :after) (quote node-match) (function apply-lift))
Write a Common Lisp macro to handle this code pattern:
(with-handle-interrupt (lambda () (format *error-output* "Interrupted")) (prog1 (apply #'clack.handler:run app server :port port :debug debug :use-thread use-thread (delete-from-plist args :server :port :debug :use-thread)) (when (and use-thread (not silent)) (format t "~&~:(~A~) server is started.~%Listening on ~A:~A.~%" server address port))))

Problem: Macro call that should be transformed by with-handle-interrupt

Macro definition:
(defmacro with-handle-interrupt (int-handler &body body)
  (let ((main (gensym "MAIN")))
    `(flet ((,main () ,@body))
       #+(or sbcl ccl clisp allegro ecl)
       (handler-case
           (let (#+ccl (ccl:*break-hook* (lambda (condition hook)
                                           (declare (ignore hook))
                                           (error condition))))
             (,main))
         (#+sbcl sb-sys:interactive-interrupt
          #+ccl  ccl:interrupt-signal-condition
          #+clisp system::simple-interrupt-condition
          #+ecl ext:interactive-interrupt
          #+allegro excl:interrupt-signal
          ()
           (funcall ,int-handler)))
       #-(or sbcl ccl clisp allegro ecl)
       (,main))))

Macroexpansion:
(flet ((#:main163 nil (prog1 (apply (function run) app server :port port :debug debug :use-thread use-thread (delete-from-plist args :server :port :debug :use-thread)) (when (and use-thread (not silent)) (format t "~&~:(~A~) server is started.~%Listening on ~A:~A.~%" server address port))))) (handler-case (let nil (#:main163)) (sb-sys:interactive-interrupt nil (funcall (lambda nil (format *error-output* "Interrupted"))))))
You are a Common Lisp macro expert. Given this code pattern:
(acond (:foo))

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

Macro definition:
(defmacro acond (&body clauses)
  "Like COND, except result of each test-form is bound to IT (via LET) for the
scope of the corresponding clause."
  (labels ((rec (clauses)
	     (if clauses
		 (destructuring-bind ((test &body body) . rest)  clauses
		   (if body
		       `(anaphoric if ,test (progn ,@body) ,(rec rest))
		       `(anaphoric if ,test it ,(rec rest))))
		 nil)))
    (rec clauses)))

Macroexpansion:
(let ((#:it :foo)) (if #:it #:it (acond)))
Write a Common Lisp macro to handle this code pattern:
(when (or (typep (node-slot expression) 'function-call) (typep (node-slot expression) 'infix-expression) (typep (node-slot expression) 'prefix-expression) (typep (node-slot expression) 'postfix-expression)) (format stream "~&~a" indent))

Problem: 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 (or (typep (node-slot expression) (quote function-call)) (typep (node-slot expression) (quote infix-expression)) (typep (node-slot expression) (quote prefix-expression)) (typep (node-slot expression) (quote postfix-expression))) (format stream "~&~a" indent))
Create a Common Lisp macro for the following transformation. Before code:
(defgenerator product (&rest lists) "Iterates through each of the supplied lists with nested dolists, yielding an element from each for every iteration of the innermost loop. The yielded values cycle in an odometer-like fashion, with the first value changing seldom and the last changing on every yield. Eg: (product '(a b c d) '(x y)) -(values)-> (a x) (a y) (b x) (b y) (c x) (c y)... " (labels ((listholder (lists) (if (null lists) (lambda (stack) (apply #'yield (reverse stack))) (let ((nextfunc (listholder (cdr lists)))) (lambda (stack) (dolist (itm (car lists)) (funcall nextfunc (cons itm stack)))))))) (funcall (listholder lists) nil)))

What needs to change: 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 product (&rest lists) "Iterates through each of the supplied lists with nested dolists, yielding an element from each for every iteration of the innermost loop. The yielded values cycle in an odometer-like fashion, with the first value changing seldom and the last changing on every yield. Eg: (product '(a b c d) '(x y)) -(values)-> (a x) (a y) (b x) (b y) (c x) (c y)... " (with-yield (labels ((listholder (lists) (if (null lists) (lambda (stack) (apply (function yield) (reverse stack))) (let ((nextfunc (listholder (cdr lists)))) (lambda (stack) (dolist (itm (car lists)) (funcall nextfunc (cons itm stack)))))))) (funcall (listholder lists) nil))))
Create a Common Lisp macro for the following transformation. Before code:
(iterate nil)

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

Macro definition:
(defmacro ITERATE ...)

Macroexpansion:
(progn (tagbody #:ll-246 ((lambda ())) (go #:ll-246)) nil)
Define a macro that eliminates this repetitive pattern:
(is-true (with-*test-dribble* nil (explain! (run 'is1))))

Issue: Macro call that should be transformed by is-true

Macro definition:
(defmacro is-true (condition &rest reason-args)
  "Like IS this check generates a pass if CONDITION returns true
  and a failure if CONDITION returns false. Unlike IS this check
  does not inspect CONDITION to determine how to report the
  failure."
  `(if ,condition
       (add-result 'test-passed :test-expr ',condition)
       (process-failure ',condition
                        ,@(or reason-args
                              `("~S did not return a true value" ',condition)))))

Macroexpansion:
(if (with-*test-dribble* nil (explain! (run (quote is1)))) (add-result (quote test-passed) :test-expr (quote (with-*test-dribble* nil (explain! (run (quote is1)))))) (process-failure (quote (with-*test-dribble* nil (explain! (run (quote is1))))) "~S did not return a true value" (quote (with-*test-dribble* nil (explain! (run (quote is1)))))))
Write a Common Lisp macro to handle this code pattern:
(when (first in-decl) (push nil in-decl-item))

Problem: 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 (first in-decl) (push nil in-decl-item))
Write a Common Lisp macro to handle this code pattern:
(the nil nil)

Problem: Macro call that should be transformed by THE

Macro definition:
(defmacro THE ...)

Macroexpansion:
(send self nil nil)
Define a macro that eliminates this repetitive pattern:
(defjs hello (x y) (return (+ x y)))

Issue: 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 (x y) (return (+ x y)))))) (setf (gethash (quote hello) *js-definitions*) js-body) (defun hello (x y) (get-element "retval" (car (docs (db.eval js-body x y))))))
Generate a defmacro form that transforms code like this:
(do+ (for x (in '(1 2 3))) (do+ (for y (in '(a b))) (collect (list x y) :into foo)))

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 (for x (in (quote (1 2 3)))) (do+ (for y (in (quote (a b)))) (collect (list x y) :into foo)))
Create a Common Lisp macro for the following transformation. Before code:
(lambda+ nil
  :key
  nil)

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

Macro definition:
(defmacro LAMBDA+ ...)

Macroexpansion:
(lambda ()
  (let+ nil
    :key
    nil))
Define a macro that eliminates this repetitive pattern:
(check-cursor-attached cluffer:beginning-of-buffer-p (cursor))

Issue: Macro call that should be transformed by check-cursor-attached

Macro definition:
(defmacro check-cursor-attached (name arguments)
  (let ((args (substitute '(cursor cluffer:cursor) 'cursor arguments)))
    `(defmethod ,name :before ,args
       (declare (ignore ,@(set-difference (remove 'cursor arguments)
                                          lambda-list-keywords)))
       (unless (cluffer:cursor-attached-p cursor)
         (error 'cluffer:cursor-detached)))))

Macroexpansion:
(defmethod cluffer:beginning-of-buffer-p :before ((cursor cluffer:cursor)) (declare (ignore)) (unless (cluffer:cursor-attached-p cursor) (error (quote cluffer:cursor-detached))))
Generate a defmacro form that transforms code like this:
(the 'some-name)

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

Macro definition:
(defmacro THE ...)

Macroexpansion:
(send self 'some-name)
Generate a defmacro form that transforms code like this:
(fgathering nil
  :key
  nil)

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

Macro definition:
(defmacro FGATHERING ...)

Macroexpansion:
(flet ()
  :key
  nil
  (values))
Define a macro that eliminates this repetitive pattern:
(with-sql-logging (mapc #'execute-sql (table-definition class)))

Issue: Macro call that should be transformed by with-sql-logging

Macro definition:
(defmacro with-sql-logging (&body body)
  `(let ((*mito-logger-stream* *mito-migration-logger-stream*))
     (with-trace-sql ,@body)))

Macroexpansion:
(let ((*mito-logger-stream* *mito-migration-logger-stream*)) (with-trace-sql (mapc (function execute-sql) (table-definition class))))
You are a Common Lisp macro expert. Given this code pattern:
(destructuring-bind () nil)

Write a macro that addresses: Macro call that should be transformed by DESTRUCTURING-BIND

Macro definition:
(defmacro DESTRUCTURING-BIND ...)

Macroexpansion:
(sb-int:binding* ((nil (sb-c::check-ds-list nil 0 0 'nil))))
Generate a defmacro form that transforms code like this:
(lambda-ignoring-_ (exp1 _ exp2) `(,op ,exp1 ,exp2))

Pattern to recognize: Macro call that should be transformed by lambda-ignoring-_

Macro definition:
(defmacro lambda-ignoring-_ (lambda-list &body body)
  "Works like `cl:lambda' macro except automatically `declare's
 `ignore' for parameters beginning with '_' character."
  (let ((ignored-parameters
          (collect-_-symbol-in-lambda-list lambda-list)))
    (unless ignored-parameters
      (warn "No ignored parameters in: ~A" lambda-list))
    (multiple-value-bind (body decls doc)
        (parse-body body :documentation t)
      `(lambda ,lambda-list
         ,@ (if doc `(,doc))
         (declare (ignore ,@ignored-parameters))
         ,@decls
         ,@body))))

Macroexpansion:
(lambda (exp1 _ exp2) (declare (ignore _)) (sb-int:quasiquote (#S(sb-impl::comma :expr op :kind 0) #S(sb-impl::comma :expr exp1 :kind 0) #S(sb-impl::comma :expr exp2 :kind 0))))
Create a Common Lisp macro for the following transformation. Before code:
(atomically nil () (symbol-name 'this))

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

Macro definition:
(defmacro atomically (invariant &body args)
  "Encloses atomic flow block of code that can be dispatched
concurrently. Non-consing."
  (destructuring-bind (opts lambda-list body) (parse-atomic-block-args args)
    (flow-lambda-macro (flow-context)
      (with-flow-function-macro (body-fu lambda-list body)
        `(dispatch-atomically ,flow-context #',body-fu ,invariant ,@opts)))))

Macroexpansion:
(%flow-lambda (#:flow-context155) (%with-flow-function (#:body-fu156 nil (symbol-name (quote this))) (dispatch-atomically #:flow-context155 (function #:body-fu156) nil)))
Generate a defmacro form that transforms code like this:
(with-context (context) (call-next-method))

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

Macro definition:
(defmacro with-context ((context) &body body)
  `(let* ((*context* ,context)
          (*request* (context :request))
          (*response* (context :response))
          (*session* (context :session)))
     ,@body))

Macroexpansion:
(let* ((*context* context) (*request* (context :request)) (*response* (context :response)) (*session* (context :session))) (call-next-method))
Create a Common Lisp macro for the following transformation. Before code:
(do-matches (match-start match-end regex target-string (nreverse result-list) :start start :end end) (push match-start result-list) (push match-end result-list))

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

Macro definition:
(defmacro do-matches ((match-start match-end regex
                                   target-string
                                   &optional result-form
                                   &key start end)
                      &body body)
  "Iterates over TARGET-STRING and tries to match REGEX as often as
possible evaluating BODY with MATCH-START and MATCH-END bound to the
start/end positions of each match in turn.  After the last match,
returns RESULT-FORM if provided or NIL otherwise.  An implicit block
named NIL surrounds DO-MATCHES; RETURN may be used to terminate the
loop immediately.  If REGEX matches an empty string the scan is
continued one position behind this match.  BODY may start with
declarations."
  ;; this is a simplified form of DO-SCANS - we just provide two dummy
  ;; vars and ignore them
  (with-unique-names (reg-starts reg-ends)
    `(do-scans (,match-start ,match-end
                ,reg-starts ,reg-ends
                ,regex ,target-string
                ,result-form
                :start ,start :end ,end)
      ,@body)))

Macroexpansion:
(do-scans (match-start match-end #:reg-starts139 #:reg-ends140 regex target-string (nreverse result-list) :start start :end end) (push match-start result-list) (push match-end result-list))
Create a Common Lisp macro for the following transformation. Before code:
(define-modf-rewrite caaaar (expr) `(car (caaar ,(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 caaaar) *modf-rewrites*) (lambda (expr) (sb-int:quasiquote (car (caaar #S(sb-impl::comma :expr (second expr) :kind 0)))))))
You are a Common Lisp macro expert. Given this code pattern:
(define-mustache-character #\/ (make-instance 'section-end-tag :text arg-text :start start))

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

Macro definition:
(defmacro define (name template)
  "Define a named renderer of string TEMPLATE."
  `(setf (symbol-function ',name)
         (compile-template ,template)))

Macroexpansion:
(set-mustache-character #\SOLIDUS (lambda (raw-text arg-text escapep start end) (declare (ignorable raw-text arg-text escapep start end) (type simple-string raw-text arg-text) (boolean escapep) (offset start end)) (make-instance (quote section-end-tag) :text arg-text :start start)))
Generate a defmacro form that transforms code like this:
(f nil
  :key
  nil)

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

Macro definition:
(defmacro F ...)

Macroexpansion:
(lambda () :key nil)
Define a macro that eliminates this repetitive pattern:
(define-component js-minify :input-type "js" :output-type "min.js" :compile-function (lambda (input-pathname output-pathname) (inferior-shell:run `("yui-compressor" ,input-pathname "-o" ,output-pathname) :show t)))

Issue: Macro call that should be transformed by define-component

Macro definition:
(defmacro define-component (name &key input-type output-type compile-function)
  "Define an ASDF component."
  `(progn
     (defclass ,name (source-file)
       ((type :initform ,input-type)
        (output :reader output :initarg :output)))

     (defmethod perform ((o load-op) (component ,name)) t)

     (defmethod output-files ((operation compile-op) (component ,name))
       (list
        (output-pathname component ,output-type)))

     (defmethod perform ((o compile-op) (component ,name))
       (funcall ,compile-function
                (component-pathname component)
                (output-pathname component ,output-type)))

     (import ',name :asdf)))

Macroexpansion:
(progn (defclass js-minify (source-file) ((type :initform "js") (output :reader output :initarg :output))) (defmethod perform ((o load-op) (component js-minify)) t) (defmethod output-files ((operation compile-op) (component js-minify)) (list (output-pathname component "min.js"))) (defmethod perform ((o compile-op) (component js-minify)) (funcall (lambda (input-pathname output-pathname) (inferior-shell:run (sb-int:quasiquote ("yui-compressor" #S(sb-impl::comma :expr input-pathname :kind 0) "-o" #S(sb-impl::comma :expr output-pathname :kind 0))) :show t)) (component-pathname component) (output-pathname component "min.js"))) (import (quote js-minify) :asdf))