j14i/cl-macros huggingface dataset:
Generate a defmacro form that transforms code like this:
(ok nil)

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

Macro definition:
(defmacro ok (test &optional desc)
  (with-gensyms (duration result)
    (once-only (test desc)
      `(with-catching-errors (:expected T :description ,desc)
         (with-duration ((,duration ,result) ,test)
           (test ,result t ,desc
                 :duration ,duration
                 :test-fn (lambda (x y)
                            (eq (not (null x)) y))
                 :got-form ,test))))))

Macroexpansion:
(let ((#:test146 nil) (#:desc147 nil)) (with-catching-errors (:expected t :description #:desc147) (with-duration ((#:duration144 #:result145) #:test146) (test #:result145 t #:desc147 :duration #:duration144 :test-fn (lambda (x y) (eq (not (null x)) y)) :got-form #:test146))))
Write a Common Lisp macro to handle this code pattern:
(dict-of 'some-name)

Problem: Macro call that should be transformed by DICT-OF

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

Macroexpansion:
(let ((#:dict134 (make-hash-table :test 'equal)))
  (do-for nil
    (multiple-value-call
        (lambda (#:k135 #:v136) (setf (gethash #:k135 #:dict134) #:v136))
      'some-name))
  #:dict134)
Create a Common Lisp macro for the following transformation. Before code:
(action (:traverse node-let node new-subs) (loop :for (name . expr) :in (node-let-bindings node) :do (when (find name subs :key #'ast-substitution-from) (util:coalton-bug "Failure to apply ast substitution on variable ~A to node-let" name)) :do (when rename-bound-variables (push (make-ast-substitution :from name :to (make-node-variable :type (node-type expr) :value (gensym (symbol-name name)))) new-subs))) (make-node-let :type (node-type node) :bindings (loop :for (name . node) :in (node-let-bindings node) :collect (cons (if rename-bound-variables (node-variable-value (ast-substitution-to (find name new-subs :key #'ast-substitution-from))) name) (funcall *traverse* node new-subs))) :subexpr (funcall *traverse* (node-let-subexpr node) new-subs)))

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 :traverse) (quote node-let) (lambda (node new-subs) (declare (type node-let node)) (loop :for (name . expr) :in (node-let-bindings node) :do (when (find name subs :key (function ast-substitution-from)) (util:coalton-bug "Failure to apply ast substitution on variable ~A to node-let" name)) :do (when rename-bound-variables (push (make-ast-substitution :from name :to (make-node-variable :type (node-type expr) :value (gensym (symbol-name name)))) new-subs))) (make-node-let :type (node-type node) :bindings (loop :for (name . node) :in (node-let-bindings node) :collect (cons (if rename-bound-variables (node-variable-value (ast-substitution-to (find name new-subs :key (function ast-substitution-from)))) name) (funcall *traverse* node new-subs))) :subexpr (funcall *traverse* (node-let-subexpr node) new-subs))))
Generate a defmacro form that transforms code like this:
(define-simple-type-map special-operator :special-operator)

Pattern to recognize: Macro call that should be transformed by define-simple-type-map

Macro definition:
(defmacro define-simple-type-map (class type)
  `(defmethod type ((,class ,class))
     ',type))

Macroexpansion:
(defmethod type ((special-operator special-operator)) (quote :special-operator))
Write a Common Lisp macro to handle this code pattern:
(some-<> (diamond-wand init (cddr exp) nil t))

Problem: Macro call that should be transformed by some-<>

Macro definition:
(defmacro some-<> (init &body exps) (diamond-wand init exps nil t))

Macroexpansion:
(block #:g126 (diamond-wand init (cddr exp) nil t))
Generate a defmacro form that transforms code like this:
(define-op (:not-null unary-op))

Pattern to recognize: 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 (not-null-op (:include unary-op (name "NOT NULL")) (:constructor make-not-null-op (var))))
You are a Common Lisp macro expert. Given this code pattern:
(collect-nth nil nil)

Write a macro that addresses: Macro call that should be transformed by COLLECT-NTH

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

Macroexpansion:
(common-lisp:let* ((#:generator-398 (generator nil))
                   #:items-390
                   (#:counter-392 nil)
                   (#:item-393 nil))
  (declare (type generator #:generator-398)
           (type (null-or fixnum) #:counter-392)
           (type (null-or t) #:item-393))
  (tagbody
   #:ll-399
    (setq #:items-390 (next-in #:generator-398 (go end)))
    (when (zerop #:counter-392) (setq #:item-393 #:items-390) (go end))
    (decf #:counter-392)
    (go #:ll-399)
   end)
  #:item-393)
Write a Common Lisp macro to handle this code pattern:
(defannotation ignore* (vars) (:alias ignore :inline t) "Shorthand for (DECLARE (IGNORE ...))." (%declare-list-or-symbol vars 'ignore))

Problem: Macro call that should be transformed by defannotation

Macro definition:
(defmacro defannotation (name lambda-list options &body body)
  `(progn
     (set-annotation-options ',name ',options)
     (defmacro ,name ,lambda-list ,@body)))

Macroexpansion:
(progn (set-annotation-options (quote ignore*) (quote (:alias ignore :inline t))) (defmacro ignore* (vars) "Shorthand for (DECLARE (IGNORE ...))." (%declare-list-or-symbol vars (quote ignore))))
Write a Common Lisp macro to handle this code pattern:
(dreletf* nil
  nil)

Problem: Macro call that should be transformed by DRELETF*

Macro definition:
(defmacro DRELETF* ...)

Macroexpansion:
(progn nil)
You are a Common Lisp macro expert. Given this code pattern:
(signal-syntax-error "Too much choices in branch: ~S." parse-tree)

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 "Too much choices in branch: ~S." parse-tree)
Write a Common Lisp macro to handle this code pattern:
(ψ nil nil)

Problem: Macro call that should be transformed by Ψ

Macro definition:
(defmacro Ψ ...)

Macroexpansion:
(mapcar (λ nil) nil)
Create a Common Lisp macro for the following transformation. Before code:
(with-yield (dolist (x data) (yield x)))

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

Macro definition:
(defmacro with-yield (&body body)
  (let ((point (gensym))
        (current (gensym)))
    `(let (,point ,current)
       (with-call/cc
	 (labels ((yield (&rest values)
		    (setf ,current values)
		    (let/cc k
		      (setf ,point k))))
	   ,@body
	   (setf ,point nil)))
       (gen-lambda ()
	 (cond ((null ,point)
		'generator-stop)
	       (t
		(let ((current ,current))
		  (funcall ,point nil)
		  ;values-handler: see gen-lambda
		  (apply #'values (funcall values-handler current)))))))))

Macroexpansion:
(let (#:g139 #:g140) (with-call/cc (labels ((yield (&rest values) (setf #:g140 values) (let/cc k (setf #:g139 k)))) (dolist (x data) (yield x)) (setf #:g139 nil))) (gen-lambda nil (cond ((null #:g139) (quote generator-stop)) (t (let ((current #:g140)) (funcall #:g139 nil) (apply (function values) (funcall values-handler current)))))))
Create a Common Lisp macro for the following transformation. Before code:
(ensure-getf options :special special)

What needs to change: Macro call that should be transformed by ensure-getf

Macro definition:
(defmacro ensure-getf (place key &optional default)
  (once-only (key default)
    `(setf (getf ,place ,key) (getf ,place ,key ,default))))

Macroexpansion:
(let ((#:key177 :special) (#:default178 special)) (setf (getf options #:key177) (getf options #:key177 #:default178)))
Define a macro that eliminates this repetitive pattern:
(sif (car x) (setf it :oops) (setf it :yes!))

Issue: 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 x) (setf it :oops) (setf it :yes!))
You are a Common Lisp macro expert. Given this code pattern:
(draw scene (:rect :x 75 :y 75 :height 30 :width 30) :fill "purple")

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 ((#:g144 (funcall (function make-svg-element) :rect (append (list :x 75 :y 75 :height 30 :width 30) (list :fill "purple"))))) (add-element scene #:g144) #:g144)
Create a Common Lisp macro for the following transformation. Before code:
(without-dependency-capture
  nil
  nil)

What needs to change: Macro call that should be transformed by WITHOUT-DEPENDENCY-CAPTURE

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

Macroexpansion:
(let ((%dependent% nil))
  nil
  nil)
Write a Common Lisp macro to handle this code pattern:
(list-of nil
  :key
  nil)

Problem: Macro call that should be transformed by LIST-OF

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

Macroexpansion:
(lc (nil :key nil) collect)
Write a Common Lisp macro to handle this code pattern:
(do-sequences! ((item1 seq1 :start start1 :end end1) (item2 seq2 :start start2 :end end2)) (setf item1 item2))

Problem: Macro call that should be transformed by do-sequences!

Macro definition:
(defmacro do-sequences! (name/seqs &body forms &environment env)
  "Mutable version of DO-SEQUENCES.

   This is the same as DO-SEQUENCES however each NAME, is the name of
   a symbol-macro, that is introduced, which expands to the 'place',
   suitable for use with SETF, of the current sequence element, rather
   than a variable storing its value. This allows the elements of the
   sequence to be mutated.

   NOTE: This macro does not support destructuring of the sequence
   elements."

  (let-if ((name name/seqs)
           (seqs (first forms) name/seqs)
           (forms (rest forms) forms))
      (symbolp name/seqs)

    (let ((safety (cadr (assoc 'safety (declaration-information 'optimize env)))))
      `(,(if (> safety 2)
             'do-sequences!-safe%
             'do-sequences!-fast%)

         ,name
         ,seqs
         ,@forms))))

Macroexpansion:
(do-sequences!-fast% nil ((item1 seq1 :start start1 :end end1) (item2 seq2 :start start2 :end end2)) (setf item1 item2))
Create a Common Lisp macro for the following transformation. Before code:
(alist-bind (type width) form `(,@(parse-type type (aval :tag type)) :bitfield-p t :bit-width ,width))

What needs to change: 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 ((#:alist237 form)) (let ((type (aval :type #:alist237)) (width (aval :width #:alist237))) (sb-int:quasiquote (#S(sb-impl::comma :expr (parse-type type (aval :tag type)) :kind 2) :bitfield-p t :bit-width #S(sb-impl::comma :expr width :kind 0)))))
Define a macro that eliminates this repetitive pattern:
(incf nil (progn))

Issue: Macro call that should be transformed by INCF

Macro definition:
(defmacro INCF ...)

Macroexpansion:
(setq nil (+ (progn) nil))
You are a Common Lisp macro expert. Given this code pattern:
(defsynonym in :in)

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

Macro definition:
(defmacro defsynonym (symbol synonym)
  "Set SYNONYM for a SYMBOL. "
  `(eval-always
     (setf (get ',symbol 'synonym) ',synonym)))

Macroexpansion:
(eval-always (setf (get (quote in) (quote synonym)) (quote :in)))
You are a Common Lisp macro expert. Given this code pattern:
(unwind-protect-case () (random 10) (:normal (push :normal result)) (:abort (push :abort result)) (:always (push :always result)))

Write a macro that addresses: 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+123 t)) (unwind-protect (multiple-value-prog1 (random 10) (setf #:flag+123 nil)) (let nil (when (not #:flag+123) (push :normal result)) (when #:flag+123 (push :abort result)) (progn (push :always result)))))
Write a Common Lisp macro to handle this code pattern:
(-<> 'some-name)

Problem: Macro call that should be transformed by -<>

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

Macroexpansion:
'some-name
You are a Common Lisp macro expert. Given this code pattern:
(form &key key &aux (result NIL))

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

Macro definition:
(defmacro for (&environment env bindings &body body)
  (let ((*environment* env))
    (multiple-value-bind (bind-init bind-forms bind-exit bind-post) (convert-bindings bindings)
      (multiple-value-bind (clause-init body-forms clause-exit) (convert-clauses body)
        `(with-interleaving
           ,@bind-init
           ,@clause-init
           (with-for-block ()
             (with-for-tagbody
                 (progn ,@bind-forms
                        ,@body-forms
                        ,@bind-post)
               (return-for
                ,@clause-exit
                ,@bind-exit))))))))

Macroexpansion:
(form &key key &aux (result nil))
You are a Common Lisp macro expert. Given this code pattern:
(yield-all generator)

Write a macro that addresses: Macro call that should be transformed by yield-all

Macro definition:
(defmacro yield-all (generator)
  "Walks through generator, re-yielding all of the items in it. Only meant for use inside of a defgenerator or with-yield block."
  (let ((x (gensym)))
    `(do-generator (,x ,generator)
       (yield ,x))))

Macroexpansion:
(do-generator (#:g183 generator) (yield #:g183))
You are a Common Lisp macro expert. Given this code pattern:
(lret* ((element-type (array-element-type vec)) (out (make-array length :element-type element-type))) (replace out vec) (fill out pad :start (length vec)) out)

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

Macro definition:
(defmacro lret* ((&rest bindings) &body body)
  "Cf. `lret'."
  `(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) (fill out pad :start (length vec)) out)
Write a Common Lisp macro to handle this code pattern:
(in-compile-time nil
  (progn))

Problem: Macro call that should be transformed by IN-COMPILE-TIME

Macro definition:
(defmacro IN-COMPILE-TIME ...)

Macroexpansion:
(macrolet ((#:macro143 (&environment ())
             (progn)))
  (#:macro143))
Generate a defmacro form that transforms code like this:
(with-output-to-file (file-stream pathname :if-exists if-exists :if-does-not-exist if-does-not-exist :external-format external-format) (write-sequence string file-stream))

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

Macro definition:
(defmacro with-output-to-file ((stream-name file-name &rest args
                                            &key (direction nil direction-p)
                                            &allow-other-keys)
			       &body body)
  "Evaluate BODY with STREAM-NAME to an output stream on the file
FILE-NAME. ARGS is sent as is to the call to OPEN except EXTERNAL-FORMAT,
which is only sent to WITH-OPEN-FILE when it's not NIL."
  (declare (ignore direction))
  (when direction-p
    (error "Can't specify :DIRECTION for WITH-OUTPUT-TO-FILE."))
  `(with-open-file* (,stream-name ,file-name :direction :output ,@args)
     ,@body))

Macroexpansion:
(with-open-file* (file-stream pathname :direction :output :if-exists if-exists :if-does-not-exist if-does-not-exist :external-format external-format) (write-sequence string file-stream))
Generate a defmacro form that transforms code like this:
(>> (loop repeat 5 collecting (-> :p (a) (declare (type fixnum a)) (the fixnum (1+ a)))))

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

Macro definition:
(defmacro >> (&rest flow)
  "See flow:serially"
  `(serially ,@flow))

Macroexpansion:
(serially (loop repeat 5 collecting (-> :p (a) (declare (type fixnum a)) (the fixnum (1+ a)))))
You are a Common Lisp macro expert. Given this code pattern:
(>> (-> :p () 1) (-> :p (a) (+ a 1)) (-> :p (v) (setf result v) (mt:open-latch latch)))

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

Macro definition:
(defmacro >> (&rest flow)
  "See flow:serially"
  `(serially ,@flow))

Macroexpansion:
(serially (-> :p nil 1) (-> :p (a) (+ a 1)) (-> :p (v) (setf result v) (cl-muth:open-latch latch)))
Generate a defmacro form that transforms code like this:
(define-op (:a> infix-op :sql-op-name "@>"))

Pattern to recognize: 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 (a>-op (:include infix-op (name "@>")) (:constructor make-a>-op (left right))))
You are a Common Lisp macro expert. Given this code pattern:
(lambda-coro
  nil
  :key
  nil)

Write a macro that addresses: Macro call that should be transformed by LAMBDA-CORO

Macro definition:
(defmacro LAMBDA-CORO ...)

Macroexpansion:
(progn
 (defcoroutine #:name131
     (#:arg132)
   (macrolet ((yield (form)
                (let ((g!-it (gensym "IT")))
                  `(progn
                    (let ((,g!-it ,form))
                      (cl-coroutine:yield ,g!-it))
                    ,'#:arg132)))
              (last-yield-value ()
                '#:arg132))
     nil
     :key
     nil
     (coexit!)))
 (make-coroutine '#:name131))
Define a macro that eliminates this repetitive pattern:
(some->> nil)

Issue: Macro call that should be transformed by SOME->>

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

Macroexpansion:
(let* ((#:g125 nil))
  #:g125)