j14i/cl-macros huggingface dataset:
Generate a defmacro form that transforms code like this:
(with-env (setp 4 [arr 0 2]))

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

Macro definition:
(defmacro with-env (&body body)
  (let ((body-value (gensym)))
    `(let (,body-value)
       (defclass foo () ((a :initform 3)))
       (defmethod get-val ((object foo) &rest slot/s) (slot-value object (car slot/s)))
       (defmethod (setf get-val) (new-value (object foo) &rest slot/s)
         (setf (slot-value object (car slot/s)) new-value))
       (defstruct bar a)
       (setq ,body-value
             (let ((str (alexandria:copy-array "abcde"))
                   (vec (alexandria:copy-array #(a b c d e)))
                   (arr (alexandria:copy-array #2A((1 2 3)
                                                   (4 5 6))))
                   (list      (copy-list '(a b c d e)))
                   (ht        (eval (read-from-string "{'a 'b 'c 'd}")))
                   (ht-eq     (eval (read-from-string "{eq \"a\" 1
                                                    \"b\" 2}")))
                   (ht-equalp (eval (read-from-string "{equalp '(1 2 3) \"a\"
                                                               '(4 5 6) \"b\"}")))
                   (assoc-list (copy-tree '((a . 1) (b . 2))))
                   (plist      (copy-list '(:a 4 :c 5)))
                   (clos-object (make-instance 'foo))
                   (struct      (make-bar :a 3)))
               (declare (ignorable str vec arr list ht ht-eq ht-equalp
                                   assoc-list plist clos-object struct))
               ,@body))
       (setf (find-class 'foo nil) nil)
       (setf (find-class 'bar nil) nil)
       ,body-value))

Macroexpansion:
(let (#:g133) (defclass foo nil ((a :initform 3))) (defmethod get-val ((object foo) &rest slot/s) (slot-value object (car slot/s))) (defmethod (setf get-val) (new-value (object foo) &rest slot/s) (setf (slot-value object (car slot/s)) new-value)) (defstruct bar a) (setq #:g133 (let ((str (alexandria:copy-array "abcde")) (vec (alexandria:copy-array #(a b c d e))) (arr (alexandria:copy-array #2A((1 2 3) (4 5 6)))) (list (copy-list (quote (a b c d e)))) (ht (eval (read-from-string "{'a 'b 'c 'd}"))) (ht-eq (eval (read-from-string "{eq \"a\" 1
                                                    \"b\" 2}"))) (ht-equalp (eval (read-from-string "{equalp '(1 2 3) \"a\"
                                                               '(4 5 6) \"b\"}"))) (assoc-list (copy-tree (quote ((a . 1) (b . 2))))) (plist (copy-list (quote (:a 4 :c 5)))) (clos-object (make-instance (quote foo))) (struct (make-bar :a 3))) (declare (ignorable str vec arr list ht ht-eq ht-equalp assoc-list plist clos-object struct)) (setp 4 [arr 0 2]))) (setf (find-class (quote foo) nil) nil) (setf (find-class (quote bar) nil) nil) #:g133)
Write a Common Lisp macro to handle this code pattern:
(defmacro/ps nil
    nil)

Problem: Macro call that should be transformed by DEFMACRO/PS

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

Macroexpansion:
(progn (defmacro nil ()) (import-macros-from-lisp 'nil))
Define a macro that eliminates this repetitive pattern:
(action (:after node-direct-application) #'validate-candidate)

Issue: 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) (function validate-candidate))
Create a Common Lisp macro for the following transformation. Before code:
(flet* nil
  (progn))

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

Macro definition:
(defmacro FLET* ...)

Macroexpansion:
(flet ()
  (progn))
Define a macro that eliminates this repetitive pattern:
(max-of nil
  :key
  nil)

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

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

Macroexpansion:
(lc (nil :key nil) maximize)
Create a Common Lisp macro for the following transformation. Before code:
(bind (((:accessors-r/o (my-a a) (my-c c) (d the-d)) (make-instance 'metabang-bind-class-2 :a 1 :b 2 :c 3 :d 4 :e 5))) (list d my-c my-a))

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

Macro definition:
(defmacro bind ((&rest bindings) &body body)
  "Bind is a replacement for let*, destructuring-bind, multiple-value-bind and more. 

An example is probably the best way to describe its syntax:

    \(bind \(\(a 2\)
           \(\(b &rest args &key \(c 2\) &allow-other-keys\) '\(:a :c 5 :d 10 :e 54\)\)
           \(\(:values d e\) \(truncate 4.5\)\)
           \(\(:structure xxx- slot1 slot2\) \(make-xxx\)\)
           \(\(:flet name \(arg1 arg2\)\) \(+ arg1 arg2\)\)\)
         \(list a b c d e args\)\)

Simple bindings are as in let*. Destructuring is done if the first item
in a binding is a list. Multiple value binding is done if the first item
in a binding is a list and the first item in the list is ':values'. Other
forms have their own syntax. For example, :structure first has the conc
name and then slot names whereas :flet has the function name and a list
of arguments and then the function body (in an implicit progn)."
  (let (declarations)
    (loop while (and (consp (car body)) (eq (caar body) 'declare)) do
          (push (first body) declarations)
          (setf body (rest body)))
    (if bindings
	(let ((*all-declarations* (bind-expand-declarations (nreverse declarations))))
	  (prog1
	      (bind-macro-helper bindings body)
	    (check-for-unused-variable-declarations *all-declarations*)))
        `(locally
             ,@declarations
           ,@body))))

Macroexpansion:
(let* ((#:|values-175| (make-instance (quote metabang-bind-class-2) :a 1 :b 2 :c 3 :d 4 :e 5)) (my-a (a #:|values-175|)) (my-c (c #:|values-175|)) (d (the-d #:|values-175|))) (declare (ignorable #:|values-175|)) (progn (list d my-c my-a)))
Write a Common Lisp macro to handle this code pattern:
(signal-reader-error "No character for char-code #x~X" number)

Problem: Macro call that should be transformed by signal-reader-error

Macro definition:
(defmacro signal-reader-error (format-control &rest format-arguments)
  "Like ERROR but signals a SIMPLE-READER-ERROR for the stream
*STREAM*."
  `(error 'simple-reader-error
          :stream *stream*
          :format-control ,format-control
          :format-arguments (list ,@format-arguments)))

Macroexpansion:
(error (quote simple-reader-error) :stream *stream* :format-control "No character for char-code #x~X" :format-arguments (list number))
Generate a defmacro form that transforms code like this:
(ct-let nil
  (progn))

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

Macro definition:
(defmacro CT-LET ...)

Macroexpansion:
(cond
 (*within-captured-dynenv*
  (let ()
    (let ((#:new-var-space156
           (reduce
            (lambda (#:accum157 #:item158)
              (destructuring-bind
                  (#:name159 . #:value160)
                  #:item158
                (update-alist #:name159 #:value160 #:accum157)))
            (list) :initial-value *var-space*)))
      `(symbol-macrolet ((var-space ,#:new-var-space156))
         ,(let ((*var-space* #:new-var-space156))
            (progn))))))
 (t
  (error
   "No macrodynamic environment has been captured to establish CT-LET bindings.")))
Write a Common Lisp macro to handle this code pattern:
(defannotation optimize* (quality) (:alias optimize :inline t) "Shorthand for (DECLARE (OPTIMIZE ...))." `(declare (optimize ,quality)))

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 optimize*) (quote (:alias optimize :inline t))) (defmacro optimize* (quality) "Shorthand for (DECLARE (OPTIMIZE ...))." (sb-int:quasiquote (declare (optimize #S(sb-impl::comma :expr quality :kind 0))))))
Generate a defmacro form that transforms code like this:
(define-op (:distinct unary-splicing-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 (distinct-op (:include unary-splicing-op (name "DISTINCT")) (:constructor make-distinct-op (var))))
Define a macro that eliminates this repetitive pattern:
(drelet 'some-name)

Issue: Macro call that should be transformed by DRELET

Macro definition:
(defmacro DRELET ...)

Macroexpansion:
(dynamic-relet 'some-name)
Create a Common Lisp macro for the following transformation. Before code:
(sum x :to total)

What needs to change: 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:
(collect x :into total)
Write a Common Lisp macro to handle this code pattern:
(λ)

Problem: Macro call that should be transformed by Λ

Macro definition:
(defmacro Λ ...)

Macroexpansion:
(lambda (&optional α) (cond))
Generate a defmacro form that transforms code like this:
(do-generator (g generator) (when (funcall predicate g) (yield g)))

Pattern to recognize: 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 ((#:g163 generator)) (loop do (if-generator ((g) #:g163) (progn (when (funcall predicate g) (yield g))) (return))))
Generate a defmacro form that transforms code like this:
(defpattern plist (&rest args) `(and ,@(loop for (key . value) in (plist-alist args) collect `(property ,key ,value))))

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

Macro definition:
(defmacro defpattern (name lambda-list &body body)
  "Defines a derived pattern specifier named NAME. This is analogous
to DEFTYPE.

Examples:

    ;; Defines a LIST pattern.
    (defpattern list (&rest args)
      (when args
        `(cons ,(car args) (list ,@(cdr args)))))"
  `(eval-when (:compile-toplevel :load-toplevel :execute)
     (setf (pattern-expand-function ',name) (lambda ,lambda-list ,@body))))

Macroexpansion:
(%defpattern plist (quote &rest) (quote args) (lambda (quasiquote (and #S(sb-impl::comma :expr (loop for (key . value) in (plist-alist args) collect (quasiquote (property #S(sb-impl::comma :expr key :kind 0) #S(sb-impl::comma :expr value :kind 0)))) :kind 2)))))
Generate a defmacro form that transforms code like this:
(defun/1 tmpnam (str) (let ((newname (string-to-char* (symbol-name (gensym))))) (if (eql str NULL) newname (progn (replace str newname :end1 (length newname)) str))))

Pattern to recognize: Macro call that should be transformed by defun/1

Macro definition:
(defmacro defun/1 (name arglist &body body)
  "Lisp-1 defun; makes function pointers work."
  `(progn
     (defun ,name ,arglist
       (declare (optimize (speed 0) (debug 3)
                          ;; FIXME: Why do minor warnings result in load errors?
                          #+sbcl (sb-ext:inhibit-warnings 3)))
        
       ,@body)
     (defparameter ,name (vacietis.c:mkptr& (symbol-function ',name)))))

Macroexpansion:
(progn (defun tmpnam (str) (declare (optimize (speed 0) (debug 3) (sb-ext:inhibit-warnings 3))) (let ((newname (string-to-char* (symbol-name (gensym))))) (if (eql str null) newname (progn (replace str newname :end1 (length newname)) str)))) (defparameter tmpnam (vacietis.c:mkptr& (symbol-function (quote tmpnam)))))
Define a macro that eliminates this repetitive pattern:
(when (eql (top-sign) 'skip-first-attribute) (pop-sign))

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 (eql (top-sign) (quote skip-first-attribute)) (pop-sign))
Define a macro that eliminates this repetitive pattern:
(lambda-ignoring-_ (dspecs inits _t) (finalize-decl-specs dspecs) `(,dspecs ,(mapcar (lambda (i) (finalize-init-declarator dspecs i)) inits)))

Issue: Macro call that should be transformed by lambda-ignoring-_

Macro definition:
(defmacro lambda-ignoring-_ (lambda-list &body body)
  "Works like `cl:lambda' macro except automatically `declare's
 `ignore' for parameters beginning with '_' character."
  (let ((ignored-parameters
          (collect-_-symbol-in-lambda-list lambda-list)))
    (unless ignored-parameters
      (warn "No ignored parameters in: ~A" lambda-list))
    (multiple-value-bind (body decls doc)
        (parse-body body :documentation t)
      `(lambda ,lambda-list
         ,@ (if doc `(,doc))
         (declare (ignore ,@ignored-parameters))
         ,@decls
         ,@body))))

Macroexpansion:
(lambda (dspecs inits _t) (declare (ignore _t)) (finalize-decl-specs dspecs) (sb-int:quasiquote (#S(sb-impl::comma :expr dspecs :kind 0) #S(sb-impl::comma :expr (mapcar (lambda (i) (finalize-init-declarator dspecs i)) inits) :kind 0))))
You are a Common Lisp macro expert. Given this code pattern:
(enable-quasi-quoted-bivalent-to-bivalent-emitting-form-syntax 'some-name)

Write a macro that addresses: Macro call that should be transformed by ENABLE-QUASI-QUOTED-BIVALENT-TO-BIVALENT-EMITTING-FORM-SYNTAX

Macro definition:
(defmacro ENABLE-QUASI-QUOTED-BIVALENT-TO-BIVALENT-EMITTING-FORM-SYNTAX ...)

Macroexpansion:
(eval-when (:compile-toplevel :execute)
  (setf *readtable* (copy-readtable *readtable*))
  (set-quasi-quoted-bivalent-to-bivalent-emitting-form-syntax-in-readtable
   'some-name :with-inline-emitting nil :declarations 'nil :start-character nil
   :end-character nil :unquote-character #\COMMA :splice-character
   #\COMMERCIAL_AT :destructive-splice-character #\FULL_STOP
   :dispatched-quasi-quote-name "biv")
  (values))
You are a Common Lisp macro expert. Given this code pattern:
(defclause until (condition) "Specifies a termination clause for the loop. When, at the beginning of an iteration, the clause evaluates to true, the loop stops." (make-termination :condition condition))

Write a macro that addresses: 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 until (condition) "Specifies a termination clause for the loop. When, at the beginning of an iteration, the clause evaluates to true, the loop stops." (make-termination :condition condition)) (pushnew (quote until) *clauses*))
Write a Common Lisp macro to handle this code pattern:
(fgathering nil
  nil)

Problem: Macro call that should be transformed by FGATHERING

Macro definition:
(defmacro FGATHERING ...)

Macroexpansion:
(flet ()
  nil
  (values))
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:
(let* ((#:nil129 (ensure-generic*-function 'nil))
       (temp-method (defmethod #:nil128 nil))
       (actual-gf
        (ensure-generic*-function 'nil :lambda-list
                                  (sb-mop:generic-function-lambda-list
                                   (symbol-function '#:nil128))
                                  :special-variables 'nil))
       (actual-method
        (add-method* #:nil129
                     (make-instance 'method* :special-variables (list)
                                    :qualifiers '(:key) :specializers
                                    (sb-mop:method-specializers temp-method)
                                    :lambda-list
                                    (sb-mop:method-lambda-list temp-method)
                                    :documentation
                                    (documentation temp-method t) :function
                                    (sb-mop:method-function temp-method)))))
  (declare (ignorable #:nil129)
           (ignore actual-gf))
  (setf (documentation actual-method t) (documentation temp-method t))
  actual-method)
Write a Common Lisp macro to handle this code pattern:
(acond ((= 1 2) :no) (nil :nono) (t :yes))

Problem: Macro call that should be transformed by acond

Macro definition:
(defmacro acond (&body clauses)
  "Like COND, except result of each test-form is bound to IT (via LET) for the
scope of the corresponding clause."
  (labels ((rec (clauses)
	     (if clauses
		 (destructuring-bind ((test &body body) . rest)  clauses
		   (if body
		       `(anaphoric if ,test (progn ,@body) ,(rec rest))
		       `(anaphoric if ,test it ,(rec rest))))
		 nil)))
    (rec clauses)))

Macroexpansion:
(let ((#:it (= 1 2))) (if #:it (let ((it #:it)) (declare (ignorable it)) :no) (acond (nil :nono) (t :yes))))
Create a Common Lisp macro for the following transformation. Before code:
(define-accumulation-binding maximizing (var form &key key) (let ((result (gensym "RESULT"))) `(let ((,result ,form)) (when (or (not ,var) (< ,(if key `(funcall ,key ,var) var) ,(if key `(funcall ,key ,result) result))) (setf ,var ,result)))))

What needs to change: 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 maximizing (var form &key key) (values (progn (let ((result (gensym "RESULT"))) (sb-int:quasiquote (let ((#S(sb-impl::comma :expr result :kind 0) #S(sb-impl::comma :expr form :kind 0))) (when (or (not #S(sb-impl::comma :expr var :kind 0)) (< #S(sb-impl::comma :expr (if key (sb-int:quasiquote (funcall #S(sb-impl::comma :expr key :kind 0) #S(sb-impl::comma :expr var :kind 0))) var) :kind 0) #S(sb-impl::comma :expr (if key (sb-int:quasiquote (funcall #S(sb-impl::comma :expr key :kind 0) #S(sb-impl::comma :expr result :kind 0))) result) :kind 0))) (setf #S(sb-impl::comma :expr var :kind 0) #S(sb-impl::comma :expr result :kind 0))))))) (delist var)))
Write a Common Lisp macro to handle this code pattern:
(symbol-value-in-$instance nil nil)

Problem: Macro call that should be transformed by SYMBOL-VALUE-IN-$INSTANCE

Macro definition:
(defmacro SYMBOL-VALUE-IN-$INSTANCE ...)

Macroexpansion:
(slot-value nil nil)
Generate a defmacro form that transforms code like this:
(define-modf-rewrite caaadr (expr) `(car (caadr ,(second expr))))

Pattern to recognize: Macro call that should be transformed by define-modf-rewrite

Macro definition:
(defmacro define-modf-rewrite (name (expr) &body body)
  "Define a new rewrite rule.  If a form starting with NAME is encountered, call
the defined function to return a form that we can deal with (i.e. one defined
via DEFINE-MODF-EXPANDER, DEFINE-MODF-FUNCTION, and DEFINE-MODF-METHOD)."
  `(eval-when (:compile-toplevel :load-toplevel :execute)
     (setf (gethash ',name *modf-rewrites*)
           (lambda (,expr)
             ,@body))))

Macroexpansion:
(eval-when (:compile-toplevel :load-toplevel :execute) (setf (gethash (quote caaadr) *modf-rewrites*) (lambda (expr) (sb-int:quasiquote (car (caadr #S(sb-impl::comma :expr (second expr) :kind 0)))))))
You are a Common Lisp macro expert. Given this code pattern:
(defobject nil)

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

Macro definition:
(defmacro DEFOBJECT ...)

Macroexpansion:
(object :parents (list) :properties (list))
Write a Common Lisp macro to handle this code pattern:
(collect-plist nil nil)

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

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

Macroexpansion:
(common-lisp:let* ((#:generator-190 (generator nil))
                   #:values-183
                   (#:generator-188 (generator nil))
                   #:indicators-182
                   (#:plist-184 nil))
  (declare (type generator #:generator-190)
           (type generator #:generator-188)
           (type list #:plist-184))
  (tagbody
   #:ll-191
    (setq #:values-183 (next-in #:generator-190 (go end)))
    (setq #:indicators-182 (next-in #:generator-188 (go end)))
    (setq #:plist-184 (list* #:indicators-182 #:values-183 #:plist-184))
    (go #:ll-191)
   end)
  #:plist-184)
You are a Common Lisp macro expert. Given this code pattern:
(-> nil (progn))

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

Macro definition:
(defmacro -> ...)

Macroexpansion:
(progn nil)
Write a Common Lisp macro to handle this code pattern:
(with-reader-case nil)

Problem: Macro call that should be transformed by WITH-READER-CASE

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

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