j14i/cl-macros huggingface dataset:
Create a Common Lisp macro for the following transformation. Before code:
(with-reader-syntax (array) (is (equalp #(1 2) (eval (read-from-string "#[1 2]")))) (is (equalp #2A((1 2 3) (4 5 6)) (eval (read-from-string "#[1 2 3 4 5 6]")))) (is (equalp #2A((1 2 3) (4 5 6)) (eval (read-from-string "#[[1 2 3] [4 5 6]]")))) (is (equalp #(1 2) (eval (read-from-string "(let ((a 1) (b 2)) #[a b])")))))

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

Macro definition:
(defmacro with-reader-syntax (reader-macro-identifiers &body body)
  "This macro is only made for use by read-and-eval functionality,
and rather directed towards tests than users. So, do not export."
  (let ((identifiers (loop :for identifier :in reader-macro-identifiers
                           :collect `(quote ,identifier))))
    `(let ((*array-function*         'make-t-array-from-initial-contents)
           (*hash-table-function*    'alexandria:plist-hash-table)
           (*get-val-function*       'get-val)
           (*get-val-array-function* 'cl:aref)
           (*set-function*           'cl:remove-duplicates)
           (*alists-are-lists*       nil)
           (*plists-are-lists*       nil)
           (*readtable*             (%enable-reader-syntax *readtable* ,@identifiers)))
       ,@body)))

Macroexpansion:
(let ((*array-function* (quote make-t-array-from-initial-contents)) (*hash-table-function* (quote alexandria:plist-hash-table)) (*get-val-function* (quote get-val)) (*get-val-array-function* (quote aref)) (*set-function* (quote remove-duplicates)) (*alists-are-lists* nil) (*plists-are-lists* nil) (*readtable* (%enable-reader-syntax *readtable* (quote array)))) (is (equalp #(1 2) (eval (read-from-string "#[1 2]")))) (is (equalp #2A((1 2 3) (4 5 6)) (eval (read-from-string "#[1 2 3 4 5 6]")))) (is (equalp #2A((1 2 3) (4 5 6)) (eval (read-from-string "#[[1 2 3] [4 5 6]]")))) (is (equalp #(1 2) (eval (read-from-string "(let ((a 1) (b 2)) #[a b])")))))
Create a Common Lisp macro for the following transformation. Before code:
(with-attributes nil
    :key
  nil)

What needs to change: Macro call that should be transformed by WITH-ATTRIBUTES

Macro definition:
(defmacro WITH-ATTRIBUTES ...)

Macroexpansion:
(let ((#:unit162 :key))
  (symbol-macrolet ()
    nil))
Define a macro that eliminates this repetitive pattern:
(defmethod nil :key nil)

Issue: Macro call that should be transformed by DEFMETHOD

Macro definition:
(defmacro DEFMETHOD ...)

Macroexpansion:
(common-lisp:defmethod nil :key ())
Create a Common Lisp macro for the following transformation. Before code:
(collect-append nil)

What needs to change: Macro call that should be transformed by COLLECT-APPEND

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

Macroexpansion:
(common-lisp:let* ((#:generator-207 (generator nil))
                   #:items-202
                   (#:lst-203 nil)
                   (#:list-204 nil))
  (declare (type generator #:generator-207)
           (type list #:lst-203)
           (type list #:list-204))
  (tagbody
   #:ll-208
    (setq #:items-202 (next-in #:generator-207 (go end)))
    (when #:items-202
      (common-lisp:multiple-value-bind (copy lastcons)
          (copy-list-last #:items-202)
        (when #:list-204 (rplacd #:list-204 copy))
        (setq #:list-204 lastcons)
        (when (null #:lst-203) (setq #:lst-203 copy))))
    (go #:ll-208)
   end)
  #:lst-203)
Define a macro that eliminates this repetitive pattern:
(any-of 'some-name)

Issue: Macro call that should be transformed by ANY-OF

Macro definition:
(defmacro ANY-OF ...)

Macroexpansion:
(lc ('some-name) thereis)
Write a Common Lisp macro to handle this code pattern:
(producing nil)

Problem: Macro call that should be transformed by PRODUCING

Macro definition:
(defmacro PRODUCING ...)

Macroexpansion:
(non-opt-producing nil)
Define a macro that eliminates this repetitive pattern:
(setdocs (type call "Class container for stack frame information. See POS See CALL See ARGS See FILE See LINE See FORM") (function pos "Returns the position of the call on the stack. See CALL") (function call "Returns the stack call function. Can be either a function object or the name of a global function. See CALL") (function args "Returns a list of arguments that were used in the frame call. If the arguments list is not available, this may also return an instance of UNKNOWN-ARGUMENTS. The values in the list may be instances of UNAVAILABLE-ARGUMENT if the argument is unknown or could not be captured for some reason. See UNKNOWN-ARGUMENTS See UNAVAILABLE-ARGUMENT See CALL") (function locals "Returns a dotted alist of locals bound in the frame call. If the locals are not available, returns NIL. See CALL") (function file "If possible, returns the file the called function is defined in. See CALL") (function line "If possible, returns the line number in the file where the function is defined. See CALL") (function form "If possible, returns the actual definition form of the function. See CALL"))

Issue: Macro call that should be transformed by setdocs

Macro definition:
(defmacro setdocs (&body pairs)
  `(progn
     ,@(loop for (type var doc) in pairs
             collect `(setf (documentation ',var ',type) ,doc))))

Macroexpansion:
(progn (setf (documentation (quote call) (quote type)) "Class container for stack frame information. See POS See CALL See ARGS See FILE See LINE See FORM") (setf (documentation (quote pos) (quote function)) "Returns the position of the call on the stack. See CALL") (setf (documentation (quote call) (quote function)) "Returns the stack call function. Can be either a function object or the name of a global function. See CALL") (setf (documentation (quote args) (quote function)) "Returns a list of arguments that were used in the frame call. If the arguments list is not available, this may also return an instance of UNKNOWN-ARGUMENTS. The values in the list may be instances of UNAVAILABLE-ARGUMENT if the argument is unknown or could not be captured for some reason. See UNKNOWN-ARGUMENTS See UNAVAILABLE-ARGUMENT See CALL") (setf (documentation (quote locals) (quote function)) "Returns a dotted alist of locals bound in the frame call. If the locals are not available, returns NIL. See CALL") (setf (documentation (quote file) (quote function)) "If possible, returns the file the called function is defined in. See CALL") (setf (documentation (quote line) (quote function)) "If possible, returns the line number in the file where the function is defined. See CALL") (setf (documentation (quote form) (quote function)) "If possible, returns the actual definition form of the function. See CALL"))
Generate a defmacro form that transforms code like this:
(defhandler the (the value-type form) `(list ',the ',value-type ,(e form)))

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-the (the value-type form) (sb-int:quasiquote (list (quote #S(sb-impl::comma :expr the :kind 0)) (quote #S(sb-impl::comma :expr value-type :kind 0)) #S(sb-impl::comma :expr (e form) :kind 0)))) (setf (gethash (quote the) *form-handler*) (quote hander-the)))
Generate a defmacro form that transforms code like this:
(resolving)

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

Macro definition:
(defmacro RESOLVING ...)

Macroexpansion:
(resolve)
Create a Common Lisp macro for the following transformation. Before code:
(action (:after node-direct-application node) (when (eq name (node-direct-application-rator node)) (incf count)) (values))

What needs to change: 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-direct-application) (lambda (node) (declare (type node-direct-application node)) (when (eq name (node-direct-application-rator node)) (incf count)) (values)))
Generate a defmacro form that transforms code like this:
(log-message :debug "Frob ~a happened" (car frobs))

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

Macro definition:
(defmacro log-message (category description &rest arguments)
  `(log-manager-message (log-manager) ,category ,description ,@arguments))

Macroexpansion:
(log-manager-message (log-manager) :debug "Frob ~a happened" (car frobs))
You are a Common Lisp macro expert. Given this code pattern:
;; Recursive factorial - stack overflow on large N in CL
;; (CL does not guarantee tail-call optimization)
(defun fact (n)
  (labels ((iter (n acc)
             (if (zerop n)
               acc
               (iter (- n 1) (* n acc)))))
    (iter n 1)))
;; (fact 1000000) => stack overflow on most implementations

Write a macro that addresses: Need guaranteed tail-call elimination for recursive algorithms — CL doesn't mandate TCO

Macro definition:
(defmacro! nlet-tail (n letargs &body body)
  (let ((gs (loop for i in letargs
               collect (gensym))))
    `(macrolet
         ((,n ,gs
            `(progn
               (psetq
                ,@(apply #'nconc
                         (mapcar
                          #'list
                          ',(mapcar #'car letargs)
                          (list ,@gs))))
               (go ,',g!n))))
       (block ,g!b
         (let ,letargs
           (tagbody
              ,g!n (return-from
                    ,g!b (progn ,@body))))))))

Macroexpansion:
;; (defun fact (n)
;;   (nlet-tail fact ((n n) (acc 1))
;;     (if (zerop n)
;;       acc
;;       (fact (- n 1) (* acc n)))))
;;
;; "Calling" (fact ...) expands via macrolet to:
;; (progn (psetq n (- n 1) acc (* acc n)) (go #:TAG))
;; = a jump, not a function call. Zero stack consumption.
Define a macro that eliminates this repetitive pattern:
(and 'some-name)

Issue: Macro call that should be transformed by AND

Macro definition:
(defmacro AND ...)

Macroexpansion:
(the t 'some-name)
You are a Common Lisp macro expert. Given this code pattern:
(define-error clean-global-env-error () () "Cannot clean the global environment")

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

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

Macroexpansion:
(defcondition clean-global-env-error (:error-type varjo-error :prefix "Varjo") nil "Cannot clean the global environment")
You are a Common Lisp macro expert. Given this code pattern:
(define-custom-var (:beginning-of-string *beginning-of-string-handler*) (constantly t) "Designator for a function of no arguments (called at encountering an opening quote for a String).")

Write a macro that addresses: 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 (*beginning-of-string-handler* . :beginning-of-string)) *custom-vars* :test (function equal)) (defvar *beginning-of-string-handler* (constantly t) "Designator for a function of no arguments (called at encountering an opening quote for a String).")))
Create a Common Lisp macro for the following transformation. Before code:
(lret* ((element-type (array-element-type vec)) (out (make-array length :element-type element-type))) (replace out vec) (loop for i from (length vec) below length by pad-len do (replace out pad :start1 i)))

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

Macro definition:
(defmacro lret ((&rest bindings) &body body)
  "Return the initial value of the last binding in BINDINGS. The idea
is to create something, initialize it, and then return it.

    (lret ((x 1)
           (y (make-array 1)))
      (setf (aref y 0) x))
    => #(1)

Note that the value returned is the value initially bound. Subsequent
assignments are ignored.

    (lret ((x 1))
      (setf x 2))
    => 1

Furthermore, on Lisps that support it, the variable may be made
read-only, making assignment a compiler-time error.

`lret' may seem trivial, but it fufills the highest purpose a macro
can: it eliminates a whole class of bugs (initializing an object, but
forgetting to return it).

Cf. `aprog1' in Anaphora."
  `(lret-aux let ,bindings
     ,@body))

Macroexpansion:
(lret-aux let* ((element-type (array-element-type vec)) (out (make-array length :element-type element-type))) (replace out vec) (loop for i from (length vec) below length by pad-len do (replace out pad :start1 i)))
Write a Common Lisp macro to handle this code pattern:
(*> +bracket-open+ #'many-dtext +bracket-close+)

Problem: 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 (#:*>-offset155) (multiple-value-bind (#:*>-res158 #:*>-next159) (multiple-value-bind (#:*>-res156 #:*>-next157) (funcall +bracket-open+ #:*>-offset155) (if (ok? #:*>-res156) (funcall (function many-dtext) #:*>-next157) (fail #:*>-next157))) (if (ok? #:*>-res158) (funcall +bracket-close+ #:*>-next159) (fail #:*>-next159))))
Define a macro that eliminates this repetitive pattern:
(f_n
  nil
  :key
  nil)

Issue: Macro call that should be transformed by F_N

Macro definition:
(defmacro F_N ...)

Macroexpansion:
(lambda (&rest _) nil :key nil)
You are a Common Lisp macro expert. Given this code pattern:
(without-dependency-capture
  nil
  :key
  nil)

Write a macro that addresses: Macro call that should be transformed by WITHOUT-DEPENDENCY-CAPTURE

Macro definition:
(defmacro WITHOUT-DEPENDENCY-CAPTURE ...)

Macroexpansion:
(let ((%dependent% nil))
  nil
  :key
  nil)
Create a Common Lisp macro for the following transformation. Before code:
(defhandler tagbody (tagbody &rest tags-and-forms) `(list* ',tagbody (tagbody-restore-tags (list ,@(loop for f in tags-and-forms collect (if (or (symbolp f) (integerp f)) `(list 'tagbody-restore-tag ',f) (e f)))))))

What needs to change: 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-tagbody (tagbody &rest tags-and-forms) (sb-int:quasiquote (list* (quote #S(sb-impl::comma :expr tagbody :kind 0)) (tagbody-restore-tags (list #S(sb-impl::comma :expr (loop for f in tags-and-forms collect (if (or (symbolp f) (integerp f)) (sb-int:quasiquote (list (quote tagbody-restore-tag) (quote #S(sb-impl::comma :expr f :kind 0)))) (e f))) :kind 2)))))) (setf (gethash (quote tagbody) *form-handler*) (quote hander-tagbody)))
Generate a defmacro form that transforms code like this:
(when-let* (x y) (1+ x))

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

Macro definition:
(defmacro when-let (bindings &body forms)
    "Creates new variable bindings, and conditionally executes FORMS.

BINDINGS must be either single binding of the form:

 (variable initial-form)

or a list of bindings of the form:

 ((variable-1 initial-form-1)
  (variable-2 initial-form-2)
  ...
  (variable-n initial-form-n))

All initial-forms are executed sequentially in the specified order. Then all
the variables are bound to the corresponding values.

If all variables were bound to true values, then FORMS are executed as an
implicit PROGN."
  (let* ((binding-list (if (and (consp bindings) (symbolp (car bindings)))
                           (list bindings)
                           bindings))
         (variables (mapcar #'car binding-list)))
    `(let ,binding-list
       (when (and ,@variables)
         ,@forms))))

Macroexpansion:
(let ((x y)) (when x (progn (1+ x))))
Write a Common Lisp macro to handle this code pattern:
(defsyntax nil
  (progn))

Problem: Macro call that should be transformed by DEFSYNTAX

Macro definition:
(defmacro defsyntax (name &body options)
  `(progn
     (setf (get ',name :options) ',options)
     (defvar ,name (defreadtable ,name ,@options))))

Macroexpansion:
(progn
 (setf (get 'nil :options) '((progn)))
 (defvar nil
   (defreadtable nil
     (progn))))
Create a Common Lisp macro for the following transformation. Before code:
(define-binary-ops |\|| logior ^ logxor & logand * * / (lambda (x y) (if (and (integerp x) (integerp y)) (truncate x y) (/ x y))) % rem << ash >> (lambda (int count) (ash int (- count))))

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

Macro definition:
(defmacro define (name value &rest docstring)
  "Like a #define but also visible to Lisp code."
  `(progn
     (eval-when (:compile-toplevel :load-toplevel :execute)
       (defvar ,(pp-defines *package*) (make-hash-table))
       (setf (gethash ',name ,(pp-defines *package*)) ,(prin1-to-string value)))
     (defparameter ,name ,value ,@docstring)))

Macroexpansion:
(progn (progn (declaim (inline vacietis.c:|\||)) (defun vacietis.c:|\|| (x y) (logior x y))) (progn (declaim (inline vacietis.c:^)) (defun vacietis.c:^ (x y) (logxor x y))) (progn (declaim (inline vacietis.c:&)) (defun vacietis.c:& (x y) (logand x y))) (progn (declaim (inline vacietis.c:*)) (defun vacietis.c:* (x y) (* x y))) (progn (declaim (inline vacietis.c:/)) (defun vacietis.c:/ (x y) ((lambda (x y) (if (and (integerp x) (integerp y)) (truncate x y) (/ x y))) x y))) (progn (declaim (inline vacietis.c:%)) (defun vacietis.c:% (x y) (rem x y))) (progn (declaim (inline vacietis.c:<<)) (defun vacietis.c:<< (x y) (ash x y))) (progn (declaim (inline vacietis.c:>>)) (defun vacietis.c:>> (x y) ((lambda (int count) (ash int (- count))) x y))))
You are a Common Lisp macro expert. Given this code pattern:
(with-slots nil
    :key
  nil)

Write a macro that addresses: Macro call that should be transformed by WITH-SLOTS

Macro definition:
(defmacro WITH-SLOTS ...)

Macroexpansion:
(let ((#:g180 :key))
  (declare (ignorable #:g180))
  (declare (sb-pcl::%variable-rebinding #:g180 :key))
  (symbol-macrolet ()
    nil))
Create a Common Lisp macro for the following transformation. Before code:
(defclause (while expr) "Exit loop if test is nil" (setq *loop-end-used?* t) (return-code :body `((if (not ,(walk-expr expr)) (go ,*loop-end*)))))

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

Macro definition:
(defmacro defclause (clause-template &body body)
  (define-clause 'defun clause-template body nil))

Macroexpansion:
(eval-when (:compile-toplevel :load-toplevel :execute) (defun clause-while-14 (&key ((:while expr))) "Exit loop if test is nil" (setq *loop-end-used?* t) (return-code :body (sb-int:quasiquote ((if (not #S(sb-impl::comma :expr (walk-expr expr) :kind 0)) (go #S(sb-impl::comma :expr *loop-end* :kind 0))))))) (install-clause-info (quote (while)) (quote (while)) (quote clause-while-14) "Exit loop if test is nil" nil) (quote (while expr)))
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:
(nil nil)
Generate a defmacro form that transforms code like this:
(fmap #'nreverse (recurse (list res) sep-next))

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

Macro definition:
(defmacro fmap (f thing)
  "Apply a pure function to the inner contents of some parsing operation, if the
parsing itself was successful."
  `(multiple-value-bind (res next) ,thing
     (if (failure? res)
         (fail next)
         (values (funcall ,f res) next))))

Macroexpansion:
(multiple-value-bind (res next) (recurse (list res) sep-next) (if (failure? res) (fail next) (values (funcall (function nreverse) res) next)))
Define a macro that eliminates this repetitive pattern:
(defgenerator permutations (list &optional r) "Emits every possible permutation of the items in list in a set of size r. If r is not specified, the size of list is used. Eg: (permutations '(a b c d) 2) -(values)-> (a b) (a c) (a d) (b a) (b c) (b d) (c a) (c b) (c d) (d a) (d b) (d c)" (let ((r (or r (length list)))) (labels ((proc (data output) (if (= r (length output)) (apply #'yield (reverse output)) (dotimes (i (length data)) (proc (xsubseq data i i :type 'list) (cons (elt data i) output)))))) (proc list nil))))

Issue: 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 permutations (list &optional r) "Emits every possible permutation of the items in list in a set of size r. If r is not specified, the size of list is used. Eg: (permutations '(a b c d) 2) -(values)-> (a b) (a c) (a d) (b a) (b c) (b d) (c a) (c b) (c d) (d a) (d b) (d c)" (with-yield (let ((r (or r (length list)))) (labels ((proc (data output) (if (= r (length output)) (apply (function yield) (reverse output)) (dotimes (i (length data)) (proc (xsubseq data i i :type (quote list)) (cons (elt data i) output)))))) (proc list nil)))))
Define a macro that eliminates this repetitive pattern:
(when (node-slot identifier) (del-proxy type))

Issue: Macro call that should be transformed by when

Macro definition:
(defmacro when (test &body forms)
  `(if ,test
	   ,(cl:if (cadr forms)
			   `(progn ,@forms)
			   (car forms))))

Macroexpansion:
(if (node-slot identifier) (del-proxy type))
Generate a defmacro form that transforms code like this:
(some->>
  nil
  nil)

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

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

Macroexpansion:
(let* ((#:var197 nil)
       (#:var198
        (if #:var197
            (nil #:var197)
            nil)))
  #:var198)