j14i/cl-macros huggingface dataset:
You are a Common Lisp macro expert. Given this code pattern:
(builder :session (:csrf :one-time t) #'(lambda (env) (let ((req (make-request env))) `(200 (:content-type "text/html") (,(if (and (eq :post (request-method req)) (assoc "name" (request-body-parameters req) :test #'string=)) (cdr (assoc "name" (request-body-parameters req) :test #'string=)) (html-form env)))))))

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 (find-middleware :session) (lambda (#:app206) (funcall (find-middleware :csrf) #:app206 :one-time t)))) :initial-value (to-app (function (lambda (env) (let ((req (make-request env))) (sb-int:quasiquote (200 (:content-type "text/html") (#S(sb-impl::comma :expr (if (and (eq :post (request-method req)) (assoc "name" (request-body-parameters req) :test (function string=))) (cdr (assoc "name" (request-body-parameters req) :test (function string=))) (html-form env)) :kind 0)))))))) :from-end t)
Generate a defmacro form that transforms code like this:
(match ARG (PATTERN BODY...))

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

Macro definition:
(defmacro match (arg &body clauses)
  "Matches ARG with CLAUSES. CLAUSES is a list of the form of (PATTERN
. BODY) where PATTERN is a pattern specifier and BODY is an implicit
progn. If ARG matches some PATTERN, `match` then evaluates
the corresponding BODY and returns the evaluated value.  If no pattern matches,
then returns NIL.

Evaluating a form (FAIL) in the clause body causes the latest pattern
matching to fail. For example,

    (match 1
      (x (if (eql x 1)
             (fail)
             x))
      (_ 'ok))

returns OK, because the form (FAIL) in the first clause is
evaluated.

If BODY starts with the symbols WHEN or UNLESS, then the next form
will be used to introduce (FAIL). That is,

    (match list ((list x) when (oddp x) x))
    (match list ((list x) unless (evenp x) x))

will be translated to

    (match list ((list x) (if (oddp x) x (fail))))
    (match list ((list x) (if (evenp x) (fail) x)))

Examples:

    (match 1 (1 1))
    => 1
    (match 1 (2 2))
    => 2
    (match 1 (x x))
    => 1
    (match (list 1 2 3)
      (list x y z) (+ x y z))
    => 6"
  (compile-match-1 arg clauses nil))

Macroexpansion:
(%or (%or (let ((pattern arg)) body...) (fail)) nil)
Create a Common Lisp macro for the following transformation. Before code:
(make-name-transformer "BAZ-" name)

What needs to change: Macro call that should be transformed by make-name-transformer

Macro definition:
(defmacro make-name-transformer (&rest elements)
  "Return an accessor name transformer.
The unquoted `name' symbol argument is substituted for the slot name.
Class option examples:

  :accessor-name-transformer (make-name-transformer \"FOO-\" name \"-BAR\")

Use the slot name directly:

  :accessor-name-transformer (make-name-transformer name)"
  `(lambda (name definition)
    (declare (ignorable definition))
    (concatenate-symbol ,@(mapcar (lambda (el)
                                    (if (and (symbolp el)
                                             (string= (symbol-name el) "NAME"))
                                        'name
                                        el))
                                  elements))))

Macroexpansion:
(lambda (name definition) (declare (ignorable definition)) (concatenate-symbol "BAZ-" name))
Generate a defmacro form that transforms code like this:
(dynamic-wind
  nil
  (progn))

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

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

Macroexpansion:
(flet ((#:dynamic-wind-thunk222 (#:proceed-thunk223)
         (macrolet ((proceed (&body #:proceed-body224)
                      `(if ,'#:proceed-thunk223
                           (funcall (the function ,'#:proceed-thunk223))
                           (progn ,@#:proceed-body224))))
           nil
           (progn))))
  (declare (inline #:dynamic-wind-thunk222))
  (let ((*dynamic-wind-stack*
         (cons #'#:dynamic-wind-thunk222 *dynamic-wind-stack*)))
    (#:dynamic-wind-thunk222 nil)))
You are a Common Lisp macro expert. Given this code pattern:
(defmacro+ps nil
    (progn))

Write a macro that addresses: Macro call that should be transformed by DEFMACRO+PS

Macro definition:
(defmacro DEFMACRO+PS ...)

Macroexpansion:
(progn
 (defmacro nil (progn))
 (defpsmacro nil
     (progn)))
Generate a defmacro form that transforms code like this:
(defhandler defun (defun name lambda-list &rest body) `(list* ',defun ,(apply 'dump-fbinding name lambda-list body)))

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

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

Macroexpansion:
(progn (defun hander-defun (defun name lambda-list &rest body) (sb-int:quasiquote (list* (quote #S(sb-impl::comma :expr defun :kind 0)) #S(sb-impl::comma :expr (apply (quote dump-fbinding) name lambda-list body) :kind 0)))) (setf (gethash (quote defun) *form-handler*) (quote hander-defun)))
Define a macro that eliminates this repetitive pattern:
(defalias path:absolute-p (pathname) cl-fad:pathname-absolute-p)

Issue: Macro call that should be transformed by defalias

Macro definition:
(defmacro defalias (name args realname)
  `(progn
     (defun ,name ,args
       ,(if (eql '&rest (first args))
            `(apply #',realname ,(second args))
            `(,realname ,@args)))
     (define-compiler-macro ,name (&rest args)
       (list* ',realname args))))

Macroexpansion:
(progn (defun path:absolute-p (pathname) (pathname-absolute-p pathname)) (define-compiler-macro path:absolute-p (&rest args) (list* (quote pathname-absolute-p) args)))
Create a Common Lisp macro for the following transformation. Before code:
(defvar-compile-time *block-tags* '() "This must be globally NIL.")

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 *block-tags* (quote nil) "This must be globally NIL."))
Define a macro that eliminates this repetitive pattern:
(unwind-protect-case () (error "FOOF!") (:normal (push :normal result1)) (:abort (push :abort result1)) (:always (push :always result1)))

Issue: Macro call that should be transformed by unwind-protect-case

Macro definition:
(defmacro unwind-protect-case ((&optional abort-flag) protected-form &body clauses)
  "Like CL:UNWIND-PROTECT, but you can specify the circumstances that
the cleanup CLAUSES are run.

  clauses ::= (:NORMAL form*)* | (:ABORT form*)* | (:ALWAYS form*)*

Clauses can be given in any order, and more than one clause can be
given for each circumstance. The clauses whose denoted circumstance
occured, are executed in the order the clauses appear.

ABORT-FLAG is the name of a variable that will be bound to T in
CLAUSES if the PROTECTED-FORM aborted preemptively, and to NIL
otherwise.

Examples:

  (unwind-protect-case ()
       (protected-form)
     (:normal (format t \"This is only evaluated if PROTECTED-FORM executed normally.~%\"))
     (:abort  (format t \"This is only evaluated if PROTECTED-FORM aborted preemptively.~%\"))
     (:always (format t \"This is evaluated in either case.~%\")))

  (unwind-protect-case (aborted-p)
       (protected-form)
     (:always (perform-cleanup-if aborted-p)))
"
  (check-type abort-flag (or null symbol))
  (let ((gflag (gensym "FLAG+")))
    `(let ((,gflag t))
       (unwind-protect (multiple-value-prog1 ,protected-form (setf ,gflag nil))
	 (let ,(and abort-flag `((,abort-flag ,gflag)))
	   ,@(loop for (cleanup-kind . forms) in clauses
		   collect (ecase cleanup-kind
			     (:normal `(when (not ,gflag) ,@forms))
			     (:abort  `(when ,gflag ,@forms))
			     (:always `(progn ,@forms)))))))))

Macroexpansion:
(let ((#:flag+125 t)) (unwind-protect (multiple-value-prog1 (error "FOOF!") (setf #:flag+125 nil)) (let nil (when (not #:flag+125) (push :normal result1)) (when #:flag+125 (push :abort result1)) (progn (push :always result1)))))
Define a macro that eliminates this repetitive pattern:
(defun/1 clearerr (fd) (setf (feof fd) 0 (ferror fd) 0))

Issue: 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 clearerr (fd) (declare (optimize (speed 0) (debug 3) (sb-ext:inhibit-warnings 3))) (setf (feof fd) 0 (ferror fd) 0)) (defparameter clearerr (vacietis.c:mkptr& (symbol-function (quote clearerr)))))
You are a Common Lisp macro expert. Given this code pattern:
(signal-syntax-error "Unknown item ~A in char-class list." item)

Write a macro that addresses: Macro call that should be transformed by signal-syntax-error

Macro definition:
(defmacro signal-syntax-error (format-control &rest format-arguments)
  `(signal-syntax-error* nil ,format-control ,@format-arguments))

Macroexpansion:
(signal-syntax-error* nil "Unknown item ~A in char-class list." item)
Define a macro that eliminates this repetitive pattern:
(class-stealth-mixins nil)

Issue: Macro call that should be transformed by CLASS-STEALTH-MIXINS

Macro definition:
(defmacro CLASS-STEALTH-MIXINS ...)

Macroexpansion:
(gethash nil *stealth-mixins*)
You are a Common Lisp macro expert. Given this code pattern:
(with-temp (d :directory t :debug (<= 1 *debug-prolog*)) (with-temp (input-file :tmpdir d :template "XXXXXX.prolog" :debug (<= 1 *debug-prolog*)) (with-open-file (s input-file :direction :output :if-does-not-exist :error) (dolist (r rules) (print-rule s r))) (let* ((executable (namestring (make-pathname :type "out" :defaults input-file)))) (run-command-with-debug-print `("gplc" ,input-file "-o" ,executable) :input input :output output :error error) (run-command-with-debug-print `(,executable) :input input :output output :error error))))

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

Macro definition:
(defmacro with-temp ((var &key directory template (tmpdir "/tmp/") debug) &body body)
  "Create a temporary file, then remove the file by unwind-protect.
Most arguments are analogous to mktemp.
When DIRECTORY is non-nil, creates a directory instead.
DEBUG is a form.
When evaluated to non-nil, it does not remove the directory so that you can investigate what happened inside the directory.
It may be evaluated multiple times."
  (with-gensyms (command)
    `(let ((,var (uiop:run-program
                  (let ((,command (format nil "mktemp --tmpdir='~a' ~@[-d~*~] ~@[~a~]"
                                          ,tmpdir ,directory ,template)))
                    (when ,debug
                      (format *error-output* "~&; ~a~%" ,command))
                    ,command)
                  :output '(:string :stripped t))))
       (unwind-protect
            (progn ,@body)
         (if ,debug
             (format *error-output* "~&; not removing ~a for debugging~%" ,var)
             (uiop:run-program (format nil "rm -rf ~a" (namestring ,var)) :ignore-error-status t))))))

Macroexpansion:
(let ((d (uiop/run-program:run-program (let ((#:command173 (format nil "mktemp --tmpdir='~a' ~@[-d~*~] ~@[~a~]" "/tmp/" t nil))) (when (<= 1 *debug-prolog*) (format *error-output* "~&; ~a~%" #:command173)) #:command173) :output (quote (:string :stripped t))))) (unwind-protect (progn (with-temp (input-file :tmpdir d :template "XXXXXX.prolog" :debug (<= 1 *debug-prolog*)) (with-open-file (s input-file :direction :output :if-does-not-exist :error) (dolist (r rules) (print-rule s r))) (let* ((executable (namestring (make-pathname :type "out" :defaults input-file)))) (run-command-with-debug-print (sb-int:quasiquote ("gplc" #S(sb-impl::comma :expr input-file :kind 0) "-o" #S(sb-impl::comma :expr executable :kind 0))) :input input :output output :error error) (run-command-with-debug-print (sb-int:quasiquote (#S(sb-impl::comma :expr executable :kind 0))) :input input :output output :error error)))) (if (<= 1 *debug-prolog*) (format *error-output* "~&; not removing ~a for debugging~%" d) (uiop/run-program:run-program (format nil "rm -rf ~a" (namestring d)) :ignore-error-status t))))
Write a Common Lisp macro to handle this code pattern:
(f_%
  'some-name)

Problem: Macro call that should be transformed by F_%

Macro definition:
(defmacro F_% ...)

Macroexpansion:
(lambda (&rest #:|ignore130|) (declare (ignore #:|ignore130|)) 'some-name)
Write a Common Lisp macro to handle this code pattern:
(assoc-cdr :message at-data)

Problem: Macro call that should be transformed by assoc-cdr

Macro definition:
(defmacro assoc-cdr (key alist &optional (test '#'eql))
  `(cdr (assoc ,key ,alist :test ,test)))

Macroexpansion:
(cdr (assoc :message at-data :test (function eql)))
Generate a defmacro form that transforms code like this:
(deferror "40001" serialization-failure transaction-rollback)

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

Macro definition:
(defmacro deferror (code typename &optional (superclass 'database-error))
  `(progn (define-condition ,typename (,superclass) ())
          (setf (gethash ,code *error-table*) ',typename)))

Macroexpansion:
(progn (define-condition serialization-failure (transaction-rollback) nil) (setf (gethash "40001" *error-table*) (quote serialization-failure)))
Generate a defmacro form that transforms code like this:
(alist-bind (name value) form (maybe-add-constant name value))

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

Macro definition:
(defmacro alist-bind ((&rest vars) alist &body body)
  "Inefficient but doesn't really matter here"
  (once-only (alist)
    `(let (,@(mapcar (lambda (x)
                       (if (consp x)
                           `(,(car x) (aval ,(cadr x) ,alist))
                           `(,x (aval ,(make-keyword x) ,alist))))
                     vars))
       ,@body)))

Macroexpansion:
(let ((#:alist245 form)) (let ((name (aval :name #:alist245)) (value (aval :value #:alist245))) (maybe-add-constant name value)))
Write a Common Lisp macro to handle this code pattern:
(do-for nil
  :key
  nil)

Problem: Macro call that should be transformed by DO-FOR

Macro definition:
(defmacro DO-FOR ...)

Macroexpansion:
(block nil (lc ((block nil (tagbody (return (progn :key nil))))) progn))
Write a Common Lisp macro to handle this code pattern:
(with-standard-readtable
  nil
  :key
  nil)

Problem: Macro call that should be transformed by WITH-STANDARD-READTABLE

Macro definition:
(defmacro WITH-STANDARD-READTABLE ...)

Macroexpansion:
(bind ((*readtable* (with-standard-io-syntax (copy-readtable *readtable*))))
  nil
  :key
  nil)
Write a Common Lisp macro to handle this code pattern:
(define-bug name-mismatch (:error-type varjo-critical-error) (lisp glsl taken) "The glsl name ~s was generated for the lisp-name ~s However this clashes with glsl name for the previous symbol ~s. This is Varjo bug, please raise an issue on github. Sorry for the inconvenience" glsl lisp taken)

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

Macro definition:
(defmacro define-bug (name (&key (error-type 'varjo-error) (prefix "Varjo Bug"))
                            (&rest args) error-string &body body)
  `(defcondition ,name (:error-type ,error-type :prefix ,prefix) ,args
       ,error-string ,@body))

Macroexpansion:
(defcondition name-mismatch (:error-type varjo-critical-error :prefix "Varjo Bug") (lisp glsl taken) "The glsl name ~s was generated for the lisp-name ~s However this clashes with glsl name for the previous symbol ~s. This is Varjo bug, please raise an issue on github. Sorry for the inconvenience" glsl lisp taken)
Define a macro that eliminates this repetitive pattern:
(with-yield-binds (values (format nil "~A JOIN ~A~:[~;~:* ON ~A~]~:[~;~:* USING ~A~]" (join-clause-kind clause) (yield (join-clause-statement clause)) (if (join-clause-on clause) (yield (join-clause-on clause)) nil) (if (join-clause-using clause) (yield (join-clause-using clause)) nil))))

Issue: Macro call that should be transformed by with-yield-binds

Macro definition:
(defmacro with-yield-binds (&body body)
  `(let ((*bind-values* nil)
         (*use-global-bind-values* t))
     (values
      (progn ,@body)
      (loop for bind in (reverse *bind-values*)
            append bind))))

Macroexpansion:
(let ((*bind-values* nil) (*use-global-bind-values* t)) (values (progn (values (format nil "~A JOIN ~A~:[~;~:* ON ~A~]~:[~;~:* USING ~A~]" (join-clause-kind clause) (yield (join-clause-statement clause)) (if (join-clause-on clause) (yield (join-clause-on clause)) nil) (if (join-clause-using clause) (yield (join-clause-using clause)) nil)))) (loop for bind in (reverse *bind-values*) append bind)))
Create a Common Lisp macro for the following transformation. Before code:
(*> #'any)

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

Macro definition:
(defmacro *> (parser &rest parsers)
  "Combination of parsers yielding the result of the rightmost one."
  (let ((offset (gensym "*>-OFFSET")))
    `(lambda (,offset)
       ,(reduce (lambda (i p)
                  (let ((res  (gensym "*>-RES"))
                        (next (gensym "*>-NEXT")))
                    `(multiple-value-bind (,res ,next) ,i
                       (if (ok? ,res)
                           (funcall ,p ,next)
                           (fail ,next)))))
                parsers
                :initial-value `(funcall ,parser ,offset)))))

Macroexpansion:
(lambda (#:*>-offset160) (funcall (function any) #:*>-offset160))
Generate a defmacro form that transforms code like this:
(skip)

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

Macro definition:
(defmacro skip () `(next))

Macroexpansion:
(trivia.next:next)
Write a Common Lisp macro to handle this code pattern:
(define-method-combination% max :operator max :identity-with-one-argument t)

Problem: Macro call that should be transformed by define-method-combination%

Macro definition:
(defmacro define-method-combination% (name &rest args)
  "Define a method-combination for the static-dispatch system only.

   Arguments are of the same form as to CL:DEFINE-METHOD-COMBINATION."

  `(eval-when (:compile-toplevel :load-toplevel :execute)
     (setf
      (combination-function ',name)
      ,(match args
         ((or nil
              (list* (and (type symbol) (not nil)) _))

          (destructuring-bind (&key (operator name) (identity-with-one-argument nil))
              args

            `(method-combination-function-short ,name ,operator ,identity-with-one-argument)))

         (_
          `(method-combination-function ,name ,@args))))))

Macroexpansion:
(eval-when (:compile-toplevel :load-toplevel :execute) (setf (combination-function (quote max)) (method-combination-function-short max max t)))
Define a macro that eliminates this repetitive pattern:
(maybe-once-only nil)

Issue: Macro call that should be transformed by MAYBE-ONCE-ONLY

Macro definition:
(defmacro MAYBE-ONCE-ONLY ...)

Macroexpansion:
(let* ((#:g181 nil))
  `(let* ,(nreverse #:g181)))
Write a Common Lisp macro to handle this code pattern:
(sif (car it) (setf it 'a) :foo)

Problem: Macro call that should be transformed by sif

Macro definition:
(defmacro sif (test then &optional else)
  "Like IF, except binds the test form to IT (via SYMBOL-MACROLET) for
the scope of the then and else expressions. IT can be set with SETF"
  `(symbolic if ,test ,then ,else))

Macroexpansion:
(symbolic if (car it) (setf it (quote a)) :foo)
Create a Common Lisp macro for the following transformation. Before code:
(define-test shuffle :serial NIL (true 1) (true 2) (true 3) (true 4) (true 5))

What needs to change: 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 shuffle) (find-package #A((9) base-char . "PARACHUTE"))) (ensure-test (quote test) :name (quote shuffle) :home (find-package #A((9) base-char . "PARACHUTE")) :tests (list (lambda nil (true 1)) (lambda nil (true 2)) (lambda nil (true 3)) (lambda nil (true 4)) (lambda nil (true 5))) :parent (quote nil) (quote :serial) (quote nil))) (quote shuffle))
Generate a defmacro form that transforms code like this:
(-> (one) :ignore-invariant t () (increment))

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

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

Macroexpansion:
(atomically (one) :ignore-invariant t nil (increment))