j14i/cl-macros huggingface dataset:
Generate a defmacro form that transforms code like this:
(defun-compile-time walk-multiple-value-prog1 (map-function reduce-function screamer? partial? nested? form environment) (unless (null (rest (last form))) (error "Improper MULTIPLE-VALUE-PROG1: ~S" form)) (unless (>= (length form) 2) (error "MULTIPLE-VALUE-PROG1 must have at least one argument, a FORM: ~S" form)) (if reduce-function (funcall reduce-function (funcall map-function form 'multiple-value-prog1) (reduce reduce-function (mapcar #'(lambda (subform) (walk map-function reduce-function screamer? partial? nested? subform environment)) (rest form)))) (funcall map-function form 'multiple-value-prog1)))

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 walk-multiple-value-prog1 (map-function reduce-function screamer? partial? nested? form environment) (unless (null (rest (last form))) (error "Improper MULTIPLE-VALUE-PROG1: ~S" form)) (unless (>= (length form) 2) (error "MULTIPLE-VALUE-PROG1 must have at least one argument, a FORM: ~S" form)) (if reduce-function (funcall reduce-function (funcall map-function form (quote multiple-value-prog1)) (reduce reduce-function (mapcar (function (lambda (subform) (walk map-function reduce-function screamer? partial? nested? subform environment))) (rest form)))) (funcall map-function form (quote multiple-value-prog1)))) (eval-when (:compile-toplevel) (compile (quote walk-multiple-value-prog1))))
Write a Common Lisp macro to handle this code pattern:
(with-open-temporary-file (f :keep keep) (pathname f))

Problem: Macro call that should be transformed by with-open-temporary-file

Macro definition:
(defmacro with-open-temporary-file ((stream &rest args &key keep &allow-other-keys) &body body)
  "Create a temporary file using OPEN-TEMPORARY with ARGS and run BODY
  with STREAM bound to the temporary file stream.  Returns the values
  returned by BODY.  By default, the file is deleted when BODY is
  exited. If a true value is passed in KEEP, the file is not deleted
  when the body is exited.  See OPEN-TEMPORARY for more permitted
  options."
  `(with-open-stream (,stream (open-temporary ,@(alexandria:remove-from-plist args :keep)))
     #+sbcl
     (declare (sb-ext:muffle-conditions sb-ext:code-deletion-note))
     ,(if (and (constantp keep)
               keep)
          `(progn ,@body)
          `(unwind-protect
                (progn ,@body)
             (unless ,keep
               (close ,stream)
               (delete-file (pathname ,stream)))))))

Macroexpansion:
(with-open-stream (f (open-temporary)) (declare (sb-ext:muffle-conditions sb-ext:code-deletion-note)) (unwind-protect (progn (pathname f)) (unless keep (close f) (delete-file (pathname f)))))
Write a Common Lisp macro to handle this code pattern:
(defclause returning (&rest forms) "Returns each form in <forms> as the value of the do+ form when the loop ends. If multiple forms are specified, by one or more RETURNING clauses, multiple values are returned, in the order the corresponding forms appear lexically. If one of the <forms> is (cl:values ...), then each value will be returned as if the values were spelled as direct arguments of the RETURNING form." (let (result-clauses) (dolist (form forms) (if (and (listp form) (eq 'values (car form))) (dolist (form (cdr form)) (push (make-result :form form) result-clauses)) (push (make-result :form form) result-clauses))) (nreverse result-clauses)))

Problem: 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 returning (&rest forms) "Returns each form in <forms> as the value of the do+ form when the loop ends. If multiple forms are specified, by one or more RETURNING clauses, multiple values are returned, in the order the corresponding forms appear lexically. If one of the <forms> is (cl:values ...), then each value will be returned as if the values were spelled as direct arguments of the RETURNING form." (let (result-clauses) (dolist (form forms) (if (and (listp form) (eq (quote values) (car form))) (dolist (form (cdr form)) (push (make-result :form form) result-clauses)) (push (make-result :form form) result-clauses))) (nreverse result-clauses))) (pushnew (quote returning) *clauses*))
Write a Common Lisp macro to handle this code pattern:
(next-in nil)

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

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

Macroexpansion:
(do-next-in nil #'(lambda ()))
Define a macro that eliminates this repetitive pattern:
(pop-last-preprocessor-directive-token directive-token-list directive-symbol)

Issue: Macro call that should be transformed by pop-last-preprocessor-directive-token

Macro definition:
(defmacro pop-last-preprocessor-directive-token (token-list directive-name)
  "For #ifdef, #ifndef, and #undef"
  (with-gensyms (dsym_)
    `(let ((,dsym_ ,directive-name))
       (prog1 (pop-preprocessor-directive-token ,token-list ,dsym_)
         (check-no-preprocessor-token ,token-list ,dsym_)))))

Macroexpansion:
(let ((#:dsym_269 directive-symbol)) (prog1 (pop-preprocessor-directive-token directive-token-list #:dsym_269) (check-no-preprocessor-token directive-token-list #:dsym_269)))
Write a Common Lisp macro to handle this code pattern:
(-> :heh () (funcall #'%continue))

Problem: Macro call that should be transformed by ->

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

Macroexpansion:
(atomically :heh nil (funcall (function %continue)))
Define a macro that eliminates this repetitive pattern:
(defstruct*
  nil
  (progn))

Issue: Macro call that should be transformed by DEFSTRUCT*

Macro definition:
(defmacro DEFSTRUCT* ...)

Macroexpansion:
(progn
 (defclass nil nil ((progn :initform nil :initarg :progn :accessor nil-progn)))
 (defun make-nil (&rest structure-ext.as-class::args)
   (apply #'make-instance 'nil structure-ext.as-class::args))
 (defgeneric copy-nil
     (structure-ext.as-class::arg))
 (defmethod copy-nil ((structure-ext.as-class::arg nil))
   (let ((structure-ext.as-class::obj
          (make-instance (class-of structure-ext.as-class::arg))))
     (dolist
         (structure-ext.as-class::slot
          (structure-ext.as-class::slots<=obj structure-ext.as-class::arg))
       (if (slot-boundp structure-ext.as-class::arg
                        structure-ext.as-class::slot)
           (setf (slot-value structure-ext.as-class::obj
                             structure-ext.as-class::slot)
                   (slot-value structure-ext.as-class::arg
                               structure-ext.as-class::slot))
           (slot-makunbound structure-ext.as-class::obj
                            structure-ext.as-class::slot)))
     structure-ext.as-class::obj))
 (defun nil-p (structure-ext.as-class::arg)
   (typep structure-ext.as-class::arg 'nil))
 'nil)
You are a Common Lisp macro expert. Given this code pattern:
(draw scene (:rect :x 30 :y 300 :width 400 :height 150) :fill "rgb(230,230,230)" :stroke "black")

Write a macro that addresses: 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 ((#:g165 (funcall (function make-svg-element) :rect (append (list :x 30 :y 300 :width 400 :height 150) (list :fill "rgb(230,230,230)" :stroke "black"))))) (add-element scene #:g165) #:g165)
You are a Common Lisp macro expert. Given this code pattern:
(builder (:session :store (make-dbi-store :connector (lambda () *conn*))) (lambda (env) (unless (gethash :counter (getf env :lack.session)) (setf (gethash :counter (getf env :lack.session)) 0)) `(200 (:content-type "text/plain") (,(format nil "Hello, you've been here for ~Ath times!" (incf (gethash :counter (getf env :lack.session))))))))

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 (#:app232) (funcall (find-middleware :session) #:app232 :store (make-dbi-store :connector (lambda nil *conn*)))))) :initial-value (to-app (lambda (env) (unless (gethash :counter (getf env :lack.session)) (setf (gethash :counter (getf env :lack.session)) 0)) (sb-int:quasiquote (200 (:content-type "text/plain") (#S(sb-impl::comma :expr (format nil "Hello, you've been here for ~Ath times!" (incf (gethash :counter (getf env :lack.session)))) :kind 0)))))) :from-end t)
Write a Common Lisp macro to handle this code pattern:
(next-in nil (progn))

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

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

Macroexpansion:
(do-next-in nil #'(lambda () (progn)))
Generate a defmacro form that transforms code like this:
(define-custom-var (:string-scope *string-scope-variables*) nil "A list of symbols naming dynamic variables which should be re-bound in the scope of every JSON String.")

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

Macro definition:
(defmacro define-custom-var ((key name) &rest other-args)
  `(eval-when (:compile-toplevel :load-toplevel :execute)
     (progn (pushnew '(,name . ,key) *custom-vars* :test #'equal)
            (defvar ,name ,@other-args))))

Macroexpansion:
(eval-when (:compile-toplevel :load-toplevel :execute) (progn (pushnew (quote (*string-scope-variables* . :string-scope)) *custom-vars* :test (function equal)) (defvar *string-scope-variables* nil "A list of symbols naming dynamic variables which should be re-bound in the scope of every JSON String.")))
Create a Common Lisp macro for the following transformation. Before code:
(asif (incf (car x)) it (list :oops it))

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

Macro definition:
(defmacro asif (test then &optional else)
  "Like IF, except binds the result of the test to IT (via LET) for
the the scope of the then-expression, and the test form to IT (via
SYMBOL-MACROLET) for the scope of the else-expression. Within scope of
the else-expression, IT can be set with SETF."
    `(let ((it ,test))
       (if it
	   ,then
	   (symbolic ignore-first ,test ,else))))

Macroexpansion:
(let ((it (incf (car x)))) (if it it (symbolic ignore-first (incf (car x)) (list :oops it))))
Write a Common Lisp macro to handle this code pattern:
(defcategory :critical)

Problem: Macro call that should be transformed by defcategory

Macro definition:
(defmacro defcategory (category &optional expands-as set)
  `(defcategory-fn ',category ',expands-as ,set))

Macroexpansion:
(defcategory-fn (quote :critical) (quote nil) nil)
Generate a defmacro form that transforms code like this:
(deferror "22007" invalid-datetime-format data-exception)

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 invalid-datetime-format (data-exception) nil) (setf (gethash "22007" *error-table*) (quote invalid-datetime-format)))
Generate a defmacro form that transforms code like this:
(when (first in-decl) (setf (first in-decl-item) nil))

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 (first in-decl) (setf (first in-decl-item) nil))
Write a Common Lisp macro to handle this code pattern:
(collect-or 'some-name)

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

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

Macroexpansion:
(common-lisp:let* ((#:generator-332 (generator 'some-name))
                   #:bools-328
                   (#:bool-329 nil))
  (declare (type generator #:generator-332))
  (tagbody
   #:ll-333
    (setq #:bools-328 (next-in #:generator-332 (go end)))
    (if (setq #:bool-329 #:bools-328)
        (go end))
    (go #:ll-333)
   end)
  #:bool-329)
Create a Common Lisp macro for the following transformation. Before code:
(lambda* nil
  (progn))

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

Macro definition:
(defmacro LAMBDA* ...)

Macroexpansion:
(lambda ()
  (with-yield
    (progn)))
Write a Common Lisp macro to handle this code pattern:
(maybe-do-not-silence-errors (handler-case (call-next-method) (error (err) (warn "Unhandled error when evaluating ~a:~% ~a~%" (or (ignore-errors (format-result result :oneline)) result) err) (setf (description result) (format NIL "The test failed to evaluate properly:~% ~a" err)) (setf (status result) :failed))))

Problem: Macro call that should be transformed by maybe-do-not-silence-errors

Macro definition:
(defmacro maybe-do-not-silence-errors (&body body)
  `(if *silence-plain-compilation-errors-p*
       ,@body
       (let ((ok nil))
         (unwind-protect
              (multiple-value-prog1
                  (call-next-method)
                (setf ok t))
           (unless ok (setf (status result) :failed))))))

Macroexpansion:
(if *silence-plain-compilation-errors-p* (handler-case (call-next-method) (error (err) (warn "Unhandled error when evaluating ~a:~% ~a~%" (or (ignore-errors (format-result result :oneline)) result) err) (setf (description result) (format nil "The test failed to evaluate properly:~% ~a" err)) (setf (status result) :failed))) (let ((ok nil)) (unwind-protect (multiple-value-prog1 (call-next-method) (setf ok t)) (unless ok (setf (status result) :failed)))))
You are a Common Lisp macro expert. Given this code pattern:
(terminate)

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

Macro definition:
(defmacro TERMINATE ...)

Macroexpansion:
(finish)
You are a Common Lisp macro expert. Given this code pattern:
(@ nil nil)

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

Macro definition:
(defmacro @ ...)

Macroexpansion:
(message-oo.mangle::nil nil)
Generate a defmacro form that transforms code like this:
(in-readtable nil)

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

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

Macroexpansion:
(eval-when (:compile-toplevel :load-toplevel :execute)
  (setf *readtable* (ensure-readtable 'nil))
  (when (or (find-package :swank) (find-package :slynk))
    (editor-hints.named-readtables::%frob-swank-readtable-alist *package*
                                                                *readtable*))
  *readtable*)
Create a Common Lisp macro for the following transformation. Before code:
(define-op (:!= infix-op))

What needs to change: 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 infix-op (name "!=")) (:constructor make-!=-op (left right))))
Write a Common Lisp macro to handle this code pattern:
(make-name-transformer nil)

Problem: Macro call that should be transformed by MAKE-NAME-TRANSFORMER

Macro definition:
(defmacro MAKE-NAME-TRANSFORMER ...)

Macroexpansion:
(lambda (name definition)
  (declare (ignorable definition))
  (concatenate-symbol nil))
Write a Common Lisp macro to handle this code pattern:
(defalias path:= (a b) cl-fad:pathname-equal)

Problem: 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:= (a b) (pathname-equal a b)) (define-compiler-macro path:= (&rest args) (list* (quote pathname-equal) args)))
Define a macro that eliminates this repetitive pattern:
($ "$max" ($ "value-1" 610))

Issue: Macro call that should be transformed by $

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

Macroexpansion:
(kv "$max" ($ "value-1" 610))
You are a Common Lisp macro expert. Given this code pattern:
(def-neo4j-fun set-node-property (node-id property value) :put (:uri-spec (format nil "node/~A/properties/~A" node-id (if (symbolp property) (string-downcase (symbol-name property)) property))) (:encode value :string) (:status-handlers (204 (values t body)) (400 (error 'invalid-data-sent-error :uri uri :json json))))

Write a macro that addresses: Macro call that should be transformed by def-neo4j-fun

Macro definition:
(defmacro def-neo4j-fun (name lambda-list method &rest args)
  `(progn
     (defun ,name (&key ,@lambda-list)
       (let ((uri ,(cadr (assoc :uri-spec args)))
             (json (encode-neo4j-json-payload ,@(aif (assoc :encode args)
                                                     (cdr it)
                                                     (list '() :string)))))
         (make-neo4j-request ,method uri json
                             (list ,@(mapcar (lambda (handler)
                                               `(list ,(car handler) (lambda (body uri json)
                                                                  ,(cadr handler))))
                                             (cdr (assoc :status-handlers args)))))))))

Macroexpansion:
(progn (defun set-node-property (&key node-id property value) (let ((uri (format nil "node/~A/properties/~A" node-id (if (symbolp property) (string-downcase (symbol-name property)) property))) (json (encode-neo4j-json-payload value :string))) (make-neo4j-request :put uri json (list (list 204 (lambda (body uri json) (values t body))) (list 400 (lambda (body uri json) (error (quote invalid-data-sent-error) :uri uri :json json))))))))
Write a Common Lisp macro to handle this code pattern:
(case-insensitive-mode-p flags)

Problem: Macro call that should be transformed by case-insensitive-mode-p

Macro definition:
(defmacro case-insensitive-mode-p (flags)
  "Accessor macro to extract the first flag out of a three-element flag list."
  `(first ,flags))

Macroexpansion:
(first flags)
Write a Common Lisp macro to handle this code pattern:
(check-cursor-attached cluffer:end-of-line (cursor))

Problem: 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:end-of-line :before ((cursor cluffer:cursor)) (declare (ignore)) (unless (cluffer:cursor-attached-p cursor) (error (quote cluffer:cursor-detached))))
Define a macro that eliminates this repetitive pattern:
(define-accumulation-binding collecting (var form &aux (head (cons NIL NIL)) (tail head)) (declare (type list var) (type cons head tail)) `(setf ,tail (setf (cdr ,tail) (cons ,form NIL)) ,var (cdr ,head)))

Issue: Macro call that should be transformed by define-accumulation-binding

Macro definition:
(defmacro define-accumulation-binding (name (var &rest args) &body body)
  `(define-form-binding ,name (,var ,@args)
     ,@(form-fiddle:lambda-declarations `(lambda () ,@body))
     (values
      (progn ,@(form-fiddle:lambda-forms `(lambda () ,@body)))
      (delist var))))

Macroexpansion:
(define-form-binding collecting (var form &aux (head (cons nil nil)) (tail head)) (declare (type list var) (type cons head tail)) (values (progn (sb-int:quasiquote (setf #S(sb-impl::comma :expr tail :kind 0) (setf (cdr #S(sb-impl::comma :expr tail :kind 0)) (cons #S(sb-impl::comma :expr form :kind 0) nil)) #S(sb-impl::comma :expr var :kind 0) (cdr #S(sb-impl::comma :expr head :kind 0))))) (delist var)))
Define a macro that eliminates this repetitive pattern:
(do-generator-value-list (vals (apply #'multi-gen generators)) (yield (apply function (mapcar #'car vals))))

Issue: Macro call that should be transformed by do-generator

Macro definition:
(defmacro do-generator ((var &rest vars-and-generator) &body body)
  "Steps through the specified generator, binding the value it returns to var, then executing the body for each step. If multiple variables are specified and the generator returns multiple values, the extra values will be bound to the extra variables."
  (let ((g (gensym)))
    `(let ((,g ,(car (last vars-and-generator))))
       (loop 
	  do (if-generator ((,var ,@(butlast vars-and-generator)) ,g)
			   (progn
			     ,@body)
			   (return))))))

Macroexpansion:
(let ((#:g165 (apply (function multi-gen) generators))) (loop do (if-generator (vals #:g165) (progn (yield (apply function (mapcar (function car) vals)))) (return))))
Generate a defmacro form that transforms code like this:
(with-reader-case nil
  nil)

Pattern to recognize: Macro call that should be transformed by WITH-READER-CASE

Macro definition:
(defmacro WITH-READER-CASE ...)

Macroexpansion:
(let ()
  (let ((#:previous-case179 (readtable-case *readtable*)))
    (setf (readtable-case *readtable*) nil)
    (unwind-protect (progn nil)
      (setf (readtable-case *readtable*) #:previous-case179))))