j14i/cl-macros huggingface dataset:
Generate a defmacro form that transforms code like this:
(check-cursor-attached cluffer:item-before-cursor (cursor))

Pattern to recognize: 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:item-before-cursor :before ((cursor cluffer:cursor)) (declare (ignore)) (unless (cluffer:cursor-attached-p cursor) (error (quote cluffer:cursor-detached))))
Create a Common Lisp macro for the following transformation. Before code:
(*> (char #\e) (alt (char #\M) (char #\m)))

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 (#:*>-offset169) (multiple-value-bind (#:*>-res170 #:*>-next171) (funcall (char #\LATIN_SMALL_LETTER_E) #:*>-offset169) (if (ok? #:*>-res170) (funcall (alt (char #\LATIN_CAPITAL_LETTER_M) (char #\LATIN_SMALL_LETTER_M)) #:*>-next171) (fail #:*>-next171))))
Write a Common Lisp macro to handle this code pattern:
(binary-reader ((days int 4)) (funcall f days))

Problem: Macro call that should be transformed by binary-reader

Macro definition:
(defmacro binary-reader (fields &body value)
  "A slightly convoluted macro for defining interpreter functions. It
allows two forms. The first is to pass a single type identifier, in
which case a value of this type will be read and returned directly.
The second is to pass a list of lists containing names and types, and
then a body. In this case the names will be bound to values read from
the socket and interpreted as the given types, and then the body will
be run in the resulting environment. If the last field is of type
bytes, string, or uint2s, all remaining data will be read and
interpreted as an array of the given type."
  (let ((stream-name (gensym))
        (size-name (gensym))
        (length-used 0))
    (flet ((read-type (type &optional modifier)
             (ecase type
               (bytes `(read-bytes ,stream-name (- ,size-name ,length-used)))
               (string `(enc-read-string ,stream-name
                                         :byte-length (- ,size-name ,length-used)))
               (uint2s `(let* ((size (/ (- ,size-name ,length-used) 2))
                               (result
                                 (make-array size
                                             :element-type '(unsigned-byte 16)
                                             :initial-element 0)))
                          (dotimes (i size)
                            (setf (elt result i) (read-uint2 ,stream-name)))
                          result))
               (int (assert (integerp modifier))
                (incf length-used modifier)
                `(,(integer-reader-name modifier t) ,stream-name))
               (uint (assert (integerp modifier))
                (incf length-used modifier)
                `(,(integer-reader-name modifier nil) ,stream-name)))))
      `(lambda (,stream-name ,size-name)
         (declare (type stream ,stream-name)
                  (type integer ,size-name)
                  (ignorable ,size-name))
         ,(if (consp fields)
              (progn
                `(let ,(loop :for field :in fields
                            :collect `(,(first field)
                                       ,(apply #'read-type (cdr field))))
                  ,@value))
              (read-type fields (car value)))))))

Macroexpansion:
(lambda (#:g206 #:g207) (declare (type stream #:g206) (type integer #:g207) (ignorable #:g207)) (let ((days (read-int4 #:g206))) (funcall f days)))
Generate a defmacro form that transforms code like this:
(builder (lambda (app) (lambda (env) (funcall app env))) *app*)

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 (let ((#:res165 (lambda (app) (lambda (env) (funcall app env))))) (typecase #:res165 (keyword (find-middleware #:res165)) (cons (if (keywordp (car #:res165)) (let ((#:res-mw164 (find-middleware (car #:res165)))) (lambda (#:app163) (apply #:res-mw164 #:app163 (cdr #:res165)))) #:res165)) (standard-object (lambda (#:app163) (funcall (intern (string :wrap) :clack.middleware) #:res165 #:app163))) (otherwise #:res165))))) :initial-value (to-app *app*) :from-end t)
Generate a defmacro form that transforms code like this:
(defvar-compile-time *ordered-lambda-list-keywords* '(&optional &rest &key &allow-other-keys &aux) "The allowed lambda list keywords in order.")

Pattern to recognize: 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 *ordered-lambda-list-keywords* (quote (&optional &rest &key &allow-other-keys &aux)) "The allowed lambda list keywords in order."))
Create a Common Lisp macro for the following transformation. Before code:
(macroexpand-convention (form) (if (consp form) (expand-documentation-using-head (first form) docstring form) form))

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

Macro definition:
(defmacro macroexpand-convention ((original-form) &body body)
  "Executes BODY as like `progn' and return the result as the first
value.  As the second value, returns a boolean whether the result is
not same with ORIGINAL-FORM or not.
This macro is designed to follow the `macroexpand' convention."
  `(multiple-value-bind (result expanded-p)
       (progn ,@body)
     (values result
             (or expanded-p
                 (not (eq result ,original-form))))))

Macroexpansion:
(multiple-value-bind (result expanded-p) (progn (if (consp form) (expand-documentation-using-head (first form) docstring form) form)) (values result (or expanded-p (not (eq result form)))))
Write a Common Lisp macro to handle this code pattern:
(action (:after node-application) #'apply-specialization)

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-application) (function apply-specialization))
You are a Common Lisp macro expert. Given this code pattern:
(if-generator (x gen) nil (if fail-if-short (error 'insufficient-items "Insufficient items in generator") (return nil)))

Write a macro that addresses: Macro call that should be transformed by if-generator

Macro definition:
(defmacro if-generator ((var gen) true-clause &optional false-clause)
  "Pulls a single iteration out of gen. If a single var is specified, it places all the values from the iteration in a list under var. If var is a list, destructures values into the vars in the list. If the generator has stopped, evaluates false-clause, otherwise evaluates true-clause."
  `(,@(if (listp var)
	 `(multiple-value-bind ,var
	      (funcall ,gen))
	 `(let ((,var (multiple-value-list (funcall ,gen))))))
      (if (eq 'generator-stop
	      ,(if (listp var)
		   (car var)
		   `(car ,var)))
	  ,false-clause
	  ,true-clause)))

Macroexpansion:
(let ((x (multiple-value-list (funcall gen)))) (if (eq (quote generator-stop) (car x)) (if fail-if-short (error (quote insufficient-items) "Insufficient items in generator") (return nil)) nil))
Write a Common Lisp macro to handle this code pattern:
(m nil
  :key
  nil)

Problem: Macro call that should be transformed by M

Macro definition:
(defmacro M ...)

Macroexpansion:
(lambda (&rest #:|macro-lambda-list123|)
  (destructuring-bind () #:|macro-lambda-list123| :key nil))
Define a macro that eliminates this repetitive pattern:
(with-table-name nil (yield (when-op-left op)))

Issue: Macro call that should be transformed by with-table-name

Macro definition:
(defmacro with-table-name (table-name &body body)
  `(let ((*table-name-scope* ,table-name))
     ,@body))

Macroexpansion:
(let ((*table-name-scope* nil)) (yield (when-op-left op)))
Define a macro that eliminates this repetitive pattern:
(summing-to total)

Issue: Macro call that should be transformed by sum

Macro definition:
(defmacro sum (value &key (to (error "sum requires a target accumulator (:to key)")))
  "Syntactic sugar for collect, intended to be used when the accumulator computes a sum."
  `(collect ,value :into ,to))

Macroexpansion:
(accumulating-to total :initially 0 :by (function +) :finally nil)
Write a Common Lisp macro to handle this code pattern:
(ignore-errors nil (progn))

Problem: Macro call that should be transformed by IGNORE-ERRORS

Macro definition:
(defmacro IGNORE-ERRORS ...)

Macroexpansion:
(handler-case (progn nil (progn)) (error (condition) (values nil condition)))
Create a Common Lisp macro for the following transformation. Before code:
(with-path curvy (move-to 350 350))

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

Macro definition:
(defmacro with-path (path &body cmds)
  (let ((s (gensym "stream"))
        (n (gensym)))
    `(flet ((assert-string (s)
              (error-unless-string s)))
       (with-output-to-string (,s ,path)
         ;; Do trivial breaking up of the path data - SVG does not have
         ;; to accept indefinitely long lines of data.
         (let ((,n 0))
           (dolist (inst (mapcar #'assert-string (list ,@cmds)) (format ,s "~&"))
             (format ,s "~@{~A~}" inst)
             (incf ,n)
             (when (= (mod ,n 10) 0)
               (format ,s "~&"))))))))

Macroexpansion:
(flet ((assert-string (s) (error-unless-string s))) (with-output-to-string (#:|stream136| curvy) (let ((#:g137 0)) (dolist (inst (mapcar (function assert-string) (list (move-to 350 350))) (format #:|stream136| "~&")) (format #:|stream136| "~@{~A~}" inst) (incf #:g137) (when (= (mod #:g137 10) 0) (format #:|stream136| "~&"))))))
Write a Common Lisp macro to handle this code pattern:
(define-global-var nil (progn))

Problem: Macro call that should be transformed by DEFINE-GLOBAL-VAR

Macro definition:
(defmacro DEFINE-GLOBAL-VAR ...)

Macroexpansion:
(sb-ext:defglobal nil (progn))
You are a Common Lisp macro expert. Given this code pattern:
(define-modf-method pathname-type 1 (new-val path) (make-pathname :type new-val :defaults path))

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

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

Macroexpansion:
(progn (eval-when (:compile-toplevel :load-toplevel :execute) (setf (gethash (quote pathname-type) *modf-nth-arg*) 1)) (defmethod |BUILDER:COMMON-LISP:PATHNAME-TYPE| (new-val path) (make-pathname :type new-val :defaults path)))
Define a macro that eliminates this repetitive pattern:
(define-mustache-character #\> (make-instance 'partial-tag :text arg-text))

Issue: Macro call that should be transformed by define-mustache-character

Macro definition:
(defmacro define-mustache-character (char &body body)
  `(set-mustache-character
    ,char (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))
            ,@body)))

Macroexpansion:
(set-mustache-character #\GREATER-THAN_SIGN (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 partial-tag) :text arg-text)))
Write a Common Lisp macro to handle this code pattern:
(declare-deprecated-operators 'some-name)

Problem: Macro call that should be transformed by DECLARE-DEPRECATED-OPERATORS

Macro definition:
(defmacro DECLARE-DEPRECATED-OPERATORS ...)

Macroexpansion:
(eval-when (:compile-toplevel :load-toplevel :execute)
  (define-compiler-macro 'some-name
      (&whole form &rest arguments)
    (declare (ignore arguments))
    (let ((where-from (or *compile-file-truename* *load-truename*)))
      (when *deprecation-warnings*
        (warn 'deprecation-warning :operator-name ''some-name :source-file
              where-from :source-form form))
      (when where-from
        (pushnew where-from (gethash ''some-name *deprecation-locations*) :test
                 #'equalp))
      form))
  (values))
Define a macro that eliminates this repetitive pattern:
(define-path-instruction-pair arc-to "A" (rx ry x-rotation large-arc-flag sweep-flag x y))

Issue: Macro call that should be transformed by define-path-instruction-pair

Macro definition:
(defmacro define-path-instruction-pair (name instruction (&rest args))
  (let ((draw-relative (intern (concatenate 'string (string name) "-R"))))
    `(progn
       (defun ,name (,@args)
         (format-instruction ,instruction ,@args))
       (defun ,draw-relative (,@args)
         (format-instruction ,(string-downcase instruction) ,@args)))))

Macroexpansion:
(progn (defun arc-to (rx ry x-rotation large-arc-flag sweep-flag x y) (format-instruction "A" rx ry x-rotation large-arc-flag sweep-flag x y)) (defun arc-to-r (rx ry x-rotation large-arc-flag sweep-flag x y) (format-instruction "a" rx ry x-rotation large-arc-flag sweep-flag x y)))
You are a Common Lisp macro expert. Given this code pattern:
(matrix-ctypecase 'some-name)

Write a macro that addresses: Macro call that should be transformed by MATRIX-CTYPECASE

Macro definition:
(defmacro MATRIX-CTYPECASE ...)

Macroexpansion:
(let ((#:g248 quote))
  (ctypecase #:g248))
Generate a defmacro form that transforms code like this:
(draw scene (:rect :x (- (random 750) 25) :y (- (random 750) 25) :rx 4 :ry 4 :height (+ 5 (random 65)) :width (+ 5 (random 65))) :stroke "rgb(232, 229, 148)" :opacity (+ 0.3 (random 0.2)) :fill (one-of *groovy-test-colors*))

Pattern to recognize: 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 ((#:g147 (funcall (function make-svg-element) :rect (append (list :x (- (random 750) 25) :y (- (random 750) 25) :rx 4 :ry 4 :height (+ 5 (random 65)) :width (+ 5 (random 65))) (list :stroke "rgb(232, 229, 148)" :opacity (+ 0.3 (random 0.2)) :fill (one-of *groovy-test-colors*)))))) (add-element scene #:g147) #:g147)
Create a Common Lisp macro for the following transformation. Before code:
(define-option-expander intern (package &rest symbols) (mapcar #'(lambda (s) (intern (string s) package)) symbols))

What needs to change: Macro call that should be transformed by define-option-expander

Macro definition:
(defmacro define-option-expander (name (package &rest arguments) &body body)
  (let ((args (gensym "ARGS")))
    `(defmethod expand-option ((,(gensym "TYPE") (eql ,(intern (string name) "KEYWORD"))) ,package ,args)
       (destructuring-bind ,arguments ,args
         ,@body))))

Macroexpansion:
(defmethod expand-option ((#:type136 (eql :intern)) package #:args135) (destructuring-bind (&rest symbols) #:args135 (mapcar (function (lambda (s) (intern (string s) package))) symbols)))
Write a Common Lisp macro to handle this code pattern:
(with-html-string (:div (:p "Hello") (:a "world")))

Problem: Macro call that should be transformed by with-html

Macro definition:
(defmacro with-html (&body body &environment env)
  "Interpret BODY as HTML. Consult README.txt for the syntax."
  `(let ((*html* (ensure-html-stream *html*)))
     ,(if (and (null (cdr body)) (atom (car body)))
          (car body)
          `(progn ,@(parse-html body env)))))

Macroexpansion:
(with-output-to-string (*html*) (with-html (:div (:p "Hello") (:a "world"))))
Write a Common Lisp macro to handle this code pattern:
(draw scene (:path :d "M 1000 750 L 2000 750 L 2500 1250") :fill "none" :stroke "black" :stroke-width 100 :marker-end (xlink-href marker))

Problem: 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 ((#:g153 (funcall (function make-svg-element) :path (append (list :d "M 1000 750 L 2000 750 L 2500 1250") (list :fill "none" :stroke "black" :stroke-width 100 :marker-end (xlink-href marker)))))) (add-element scene #:g153) #:g153)
Write a Common Lisp macro to handle this code pattern:
(assoc-cdr :message uinfo)

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 uinfo :test (function eql)))
You are a Common Lisp macro expert. Given this code pattern:
(define-op (:similar-to infix-op))

Write a macro that addresses: 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 (similar-to-op (:include infix-op (name "SIMILAR TO")) (:constructor make-similar-to-op (left right))))
Define a macro that eliminates this repetitive pattern:
(rem-bops nil :key nil)

Issue: Macro call that should be transformed by REM-BOPS

Macro definition:
(defmacro REM-BOPS ...)

Macroexpansion:
(eval-when (:load-toplevel :compile-toplevel :execute)
  (progn (save-binfix) (mapc 'rmbop '(nil :key nil)) (assign-properties)))
Generate a defmacro form that transforms code like this:
(who-ps-html nil)

Pattern to recognize: Macro call that should be transformed by WHO-PS-HTML

Macro definition:
(defmacro WHO-PS-HTML ...)

Macroexpansion:
(stringify nil)
Create a Common Lisp macro for the following transformation. Before code:
(defun-compile-time walk-full (map-function form) (unless (null (rest (last form))) (error "Improper FULL: ~S" form)) (unless (= (length form) 2) (error "FULL must have exactly one argument, a FORM: ~S" form)) (funcall map-function form 'full))

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 walk-full (map-function form) (unless (null (rest (last form))) (error "Improper FULL: ~S" form)) (unless (= (length form) 2) (error "FULL must have exactly one argument, a FORM: ~S" form)) (funcall map-function form (quote full))) (eval-when (:compile-toplevel) (compile (quote walk-full))))
You are a Common Lisp macro expert. Given this code pattern:
(-<>> nil)

Write a macro that addresses: Macro call that should be transformed by -<>>

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

Macroexpansion:
nil