j14i/cl-macros huggingface dataset:
Generate a defmacro form that transforms code like this:
(bind (((:struct metabang-bind-test-1- a c) (make-metabang-bind-test-1 :a 1 :b 2 :c 3))) (ensure-same '(4 1 3) (list values a c) :test 'equal))

Pattern to recognize: 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-189| (make-metabang-bind-test-1 :a 1 :b 2 :c 3)) (a (metabang-bind-test-1-a #:|values-189|)) (c (metabang-bind-test-1-c #:|values-189|))) (declare (ignorable #:|values-189|)) (progn (ensure-same (quote (4 1 3)) (list values a c) :test (quote equal))))
Create a Common Lisp macro for the following transformation. Before code:
(cond->
  nil
  nil)

What needs to change: Macro call that should be transformed by COND->

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

Macroexpansion:
(let* ((#:var127 nil)
       (#:var128
        (if nil
            (->
              #:var127)
            #:var127)))
  #:var128)
Write a Common Lisp macro to handle this code pattern:
(do-sequences! ((place seq :start start :end end) (new new)) (setf place new))

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 ((place seq :start start :end end) (new new)) (setf place new))
Create a Common Lisp macro for the following transformation. Before code:
(define-simple-documentation-lookup function cl:function)

What needs to change: Macro call that should be transformed by define-simple-documentation-lookup

Macro definition:
(defmacro define-simple-documentation-lookup (class documentation-type)
  `(defmethod documentation ((,class ,class))
     ,(if (eql documentation-type T)
          `(cl:documentation (object ,class) 'T)
          `(cl:documentation (designator ,class) ',documentation-type))))

Macroexpansion:
(defmethod documentation ((function function)) (common-lisp:documentation (designator function) (quote common-lisp:function)))
Generate a defmacro form that transforms code like this:
(with-quote-char (sxql:yield sql))

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

Macro definition:
(defmacro with-quote-char (&body body)
  `(let ((sxql:*quote-character* (or sxql:*quote-character*
                                     (connection-quote-character *connection*))))
     ,@body))

Macroexpansion:
(let ((sxql/sql-type:*quote-character* (or sxql/sql-type:*quote-character* (connection-quote-character *connection*)))) (sxql/sql-type:yield sql))
Define a macro that eliminates this repetitive pattern:
(define-component make)

Issue: Macro call that should be transformed by define-component

Macro definition:
(defmacro define-component (name &key input-type output-type compile-function)
  "Define an ASDF component."
  `(progn
     (defclass ,name (source-file)
       ((type :initform ,input-type)
        (output :reader output :initarg :output)))

     (defmethod perform ((o load-op) (component ,name)) t)

     (defmethod output-files ((operation compile-op) (component ,name))
       (list
        (output-pathname component ,output-type)))

     (defmethod perform ((o compile-op) (component ,name))
       (funcall ,compile-function
                (component-pathname component)
                (output-pathname component ,output-type)))

     (import ',name :asdf)))

Macroexpansion:
(progn (defclass make (source-file) ((type :initform nil) (output :reader output :initarg :output))) (defmethod perform ((o load-op) (component make)) t) (defmethod output-files ((operation compile-op) (component make)) (list (output-pathname component nil))) (defmethod perform ((o compile-op) (component make)) (funcall nil (component-pathname component) (output-pathname component nil))) (import (quote make) :asdf))
Write a Common Lisp macro to handle this code pattern:
(defclause-driver (for var in list &optional by (step ''cdr)) "Elements of a list" (top-level-check) (let* ((on-var (make-var-and-binding 'list list :type 'list)) (setqs (do-dsetq var `(car ,on-var))) (test `(if (endp ,on-var) (go ,*loop-end*)))) (setq *loop-end-used?* t) (return-driver-code :next (list test setqs (generate-function-step-code on-var step)) :variable var)))

Problem: 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-for-in-5 (&key ((:for var)) ((:in list)) ((:by step) (quote (quote cdr))) generate) "Elements of a list" (top-level-check) (let* ((on-var (make-var-and-binding (quote list) list :type (quote list))) (setqs (do-dsetq var (sb-int:quasiquote (car #S(sb-impl::comma :expr on-var :kind 0))))) (test (sb-int:quasiquote (if (endp #S(sb-impl::comma :expr on-var :kind 0)) (go #S(sb-impl::comma :expr *loop-end* :kind 0)))))) (setq *loop-end-used?* t) (return-driver-code :next (list test setqs (generate-function-step-code on-var step)) :variable var))) (install-clause-info (quote (for :in)) (quote (for :in &optional :by)) (quote clause-for-in-5) "Elements of a list" t) (quote (for var in list &optional by (step (quote (quote cdr))))))
Write a Common Lisp macro to handle this code pattern:
(make-$instance nil :key nil)

Problem: Macro call that should be transformed by MAKE-$INSTANCE

Macro definition:
(defmacro MAKE-$INSTANCE ...)

Macroexpansion:
(let ((class (symbol-value nil)))
  (funcall (mcs-slot-value class (index-of-basicnew-fn)) class :key nil))
Define a macro that eliminates this repetitive pattern:
(define-simple-object-lookup class find-class)

Issue: Macro call that should be transformed by define-simple-object-lookup

Macro definition:
(defmacro define-simple-object-lookup (class lookup-function &body body)
  `(defmethod object ((,class ,class))
     ,(if body
          `(let ((,(first lookup-function) ,class))
             ,@body)
          `(,lookup-function (designator ,class)))))

Macroexpansion:
(defmethod object ((class class)) (find-class (designator class)))
Generate a defmacro form that transforms code like this:
(f_
  nil
  :key
  nil)

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

Macro definition:
(defmacro F_ ...)

Macroexpansion:
(lambda (_) nil :key nil)
Create a Common Lisp macro for the following transformation. Before code:
(eswitch (x :test =) (12 :oops) (13.0 :yay))

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

Macro definition:
(defmacro eswitch (&whole whole (object &key (test 'eql) (key 'identity))
                          &body clauses)
  "Like SWITCH, but signals an error if no key matches."
  (generate-switch-body whole object clauses test key '(error)))

Macroexpansion:
(let ((#:value132 (identity x))) (cond ((= #:value132 12) :oops) ((= #:value132 13.0) :yay) (t (error "No keys match in SWITCH. Testing against ~S with ~S." #:value132 (quote =)))))
Define a macro that eliminates this repetitive pattern:
(define-modf-rewrite caaar (expr) `(car (caar ,(second expr))))

Issue: 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 caaar) *modf-rewrites*) (lambda (expr) (sb-int:quasiquote (car (caar #S(sb-impl::comma :expr (second expr) :kind 0)))))))
Define a macro that eliminates this repetitive pattern:
(def-neo4j-fun set-relationship-property (relationship-id property value) :put (:uri-spec (format nil "relationship/~A/properties/~A" relationship-id (if (symbolp property) (string-downcase (symbol-name property)) property))) (:encode value :string) (:status-handlers (204 (values t body)) (400 (error 'invalid-data-sent-error :uri uri :json json)) (404 (error 'relationship-not-found-error :uri uri))))

Issue: Macro call that should be transformed by def-neo4j-fun

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

Macroexpansion:
(progn (defun set-relationship-property (&key relationship-id property value) (let ((uri (format nil "relationship/~A/properties/~A" relationship-id (if (symbolp property) (string-downcase (symbol-name property)) property))) (json (encode-neo4j-json-payload value :string))) (make-neo4j-request :put uri json (list (list 204 (lambda (body uri json) (values t body))) (list 400 (lambda (body uri json) (error (quote invalid-data-sent-error) :uri uri :json json))) (list 404 (lambda (body uri json) (error (quote relationship-not-found-error) :uri uri))))))))
Define a macro that eliminates this repetitive pattern:
(iterate nil (progn))

Issue: Macro call that should be transformed by ITERATE

Macro definition:
(defmacro ITERATE ...)

Macroexpansion:
(progn (tagbody #:ll-252 ((lambda () (progn))) (go #:ll-252)) nil)
Create a Common Lisp macro for the following transformation. Before code:
(do+ (for y (to x)) (collect y) (when (= x y) (update x)))

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

Macro definition:
(defmacro do+ (&body body)
  "High-level, extensible iteration construct. Refer to the manual for syntax and semantics."
  `(do+/internal nil ,@body))

Macroexpansion:
(do+/internal nil (for y (to x)) (collect y) (when (= x y) (update x)))
Generate a defmacro form that transforms code like this:
(enable-infix-reader)

Pattern to recognize: Macro call that should be transformed by ENABLE-INFIX-READER

Macro definition:
(defmacro ENABLE-INFIX-READER ...)

Macroexpansion:
(eval-when (:compile-toplevel :load-toplevel :execute)
  (push *readtable* *readtables*)
  (setq *readtable* (copy-readtable))
  (set-macro-character #\LEFT_CURLY_BRACKET #'infix-reader nil)
  (set-macro-character #\RIGHT_CURLY_BRACKET #'infix-end nil))
You are a Common Lisp macro expert. Given this code pattern:
(bind ((instance (make-instance 'metabang-bind-class-1 :a 1 :b 2 :c 3)) ((:slots a (my-c c) (the-b b)) instance)) (setf a :changed) (list (slot-value instance 'a) the-b my-c))

Write a macro that addresses: 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* ((instance (make-instance (quote metabang-bind-class-1) :a 1 :b 2 :c 3)) (#:|values-171| instance)) (declare (ignorable #:|values-171|)) (with-slots ((a a) (my-c c) (the-b b)) #:|values-171| (progn (setf a :changed) (list (slot-value instance (quote a)) the-b my-c))))
Define a macro that eliminates this repetitive pattern:
(collect nil)

Issue: Macro call that should be transformed by COLLECT

Macro definition:
(defmacro COLLECT ...)

Macroexpansion:
(common-lisp:let* ((#:generator-581 (generator nil))
                   #:items-576
                   (#:lastcons-577 (list nil))
                   (#:lst-578 #:lastcons-577))
  (declare (type generator #:generator-581)
           (type cons #:lastcons-577)
           (type list #:lst-578))
  (tagbody
   #:ll-582
    (setq #:items-576 (next-in #:generator-581 (go end)))
    (setq #:lastcons-577 (setf (cdr #:lastcons-577) (cons #:items-576 nil)))
    (go #:ll-582)
   end)
  (cdr #:lst-578))
Write a Common Lisp macro to handle this code pattern:
(when initializer `(make-nodelist ,initializer))

Problem: 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 initializer (sb-int:quasiquote (make-nodelist #S(sb-impl::comma :expr initializer :kind 0))))
Generate a defmacro form that transforms code like this:
(with-env [struct 'a])

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 (#:g132) (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 #:g132 (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)) [struct (quote a]))) (setf (find-class (quote foo) nil) nil) (setf (find-class (quote bar) nil) nil) #:g132)
You are a Common Lisp macro expert. Given this code pattern:
(action (:after node-let node) (multiple-value-bind (new-node new-changed?) (maybe-collapse-alias-let node) (when new-changed? (setf changed? t) new-node)))

Write a macro that addresses: 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-let) (lambda (node) (declare (type node-let node)) (multiple-value-bind (new-node new-changed?) (maybe-collapse-alias-let node) (when new-changed? (setf changed? t) new-node))))
Write a Common Lisp macro to handle this code pattern:
(swhen x (setf it :ok))

Problem: Macro call that should be transformed by swhen

Macro definition:
(defmacro swhen (test &body body)
  "Like WHEN, except binds the test form to IT (via SYMBOL-MACROLET) for the
scope of the body. IT can be set with SETF."
  `(symbolic when ,test ,@body))

Macroexpansion:
(symbolic when x (setf it :ok))
Write a Common Lisp macro to handle this code pattern:
(lambda+ 'some-name)

Problem: Macro call that should be transformed by LAMBDA+

Macro definition:
(defmacro LAMBDA+ ...)

Macroexpansion:
(lambda (#:g129 #:g130) (let+ ('#:g129 (some-name #:g130))))
Define a macro that eliminates this repetitive pattern:
(augment final-code final)

Issue: Macro call that should be transformed by augment

Macro definition:
(defmacro augment (var stuff)
  `(setf ,var (nconc ,var ,stuff)))

Macroexpansion:
(setf final-code (nconc final-code final))
Define a macro that eliminates this repetitive pattern:
(define-simple-definition-resolver type-definition (designator) (eql :defined (sb-int:info :type :kind designator)))

Issue: Macro call that should be transformed by define-simple-definition-resolver

Macro definition:
(defmacro define-simple-definition-resolver (class lookup-function &body body)
  (let ((package (gensym "PACKAGE")))
    `(define-definition-resolver ,class (,class ,package)
       (when (ignore-errors ,(if body
                                 `(let ((,(first lookup-function) ,class))
                                    ,@body)
                                 `(,lookup-function ,class)))
         (list (make-instance ',class :designator ,class :package ,package))))))

Macroexpansion:
(define-definition-resolver type-definition (type-definition #:package144) (when (ignore-errors (let ((designator type-definition)) (eql :defined (sb-int:info :type :kind designator)))) (list (make-instance (quote type-definition) :designator type-definition :package #:package144))))
Define a macro that eliminates this repetitive pattern:
(*> +tag-start+ +peek-no-slash+)

Issue: 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 (#:*>-offset262) (multiple-value-bind (#:*>-res263 #:*>-next264) (funcall +tag-start+ #:*>-offset262) (if (ok? #:*>-res263) (funcall +peek-no-slash+ #:*>-next264) (fail #:*>-next264))))
Define a macro that eliminates this repetitive pattern:
(collect-append 'some-name)

Issue: Macro call that should be transformed by COLLECT-APPEND

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

Macroexpansion:
(common-lisp:let* ((#:generator-230 (generator 'some-name))
                   #:items-225
                   (#:lst-226 nil)
                   (#:list-227 nil))
  (declare (type generator #:generator-230)
           (type list #:lst-226)
           (type list #:list-227))
  (tagbody
   #:ll-231
    (setq #:items-225 (next-in #:generator-230 (go end)))
    (when #:items-225
      (common-lisp:multiple-value-bind (copy lastcons)
          (copy-list-last #:items-225)
        (when #:list-227 (rplacd #:list-227 copy))
        (setq #:list-227 lastcons)
        (when (null #:lst-226) (setq #:lst-226 copy))))
    (go #:ll-231)
   end)
  #:lst-226)