j14i/cl-macros huggingface dataset:
Write a Common Lisp macro to handle this code pattern:
(dlet* nil
  (progn))

Problem: Macro call that should be transformed by DLET*

Macro definition:
(defmacro DLET* ...)

Macroexpansion:
(dynamic-let* nil
  (progn))
Write a Common Lisp macro to handle this code pattern:
(deferror "22" data-exception)

Problem: Macro call that should be transformed by deferror

Macro definition:
(defmacro deferror (code typename &optional (superclass 'database-error))
  `(progn (define-condition ,typename (,superclass) ())
          (setf (gethash ,code *error-table*) ',typename)))

Macroexpansion:
(progn (define-condition data-exception (database-error) nil) (setf (gethash "22" *error-table*) (quote data-exception)))
Generate a defmacro form that transforms code like this:
(newq 'some-name)

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

Macro definition:
(defmacro NEWQ ...)

Macroexpansion:
(new ''some-name)
Generate a defmacro form that transforms code like this:
(if-generator (tmp gen) (mapcar #'list tmp))

Pattern to recognize: Macro call that should be transformed by if-generator

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

Macroexpansion:
(let ((tmp (multiple-value-list (funcall gen)))) (if (eq (quote generator-stop) (car tmp)) nil (mapcar (function list) tmp)))
Write a Common Lisp macro to handle this code pattern:
(with-yield-binds (format nil "CREATE~:[~; OR REPLACE~] VIEW ~A AS ~A" (create-view-statement-or-replace statement) (yield (create-view-statement-view-name statement)) (let ((as (create-view-statement-as statement))) (typecase as (string as) (otherwise (yield as))))))

Problem: Macro call that should be transformed by with-yield-binds

Macro definition:
(defmacro with-yield-binds (&body body)
  `(let ((*bind-values* nil)
         (*use-global-bind-values* t))
     (values
      (progn ,@body)
      (loop for bind in (reverse *bind-values*)
            append bind))))

Macroexpansion:
(let ((*bind-values* nil) (*use-global-bind-values* t)) (values (progn (format nil "CREATE~:[~; OR REPLACE~] VIEW ~A AS ~A" (create-view-statement-or-replace statement) (yield (create-view-statement-view-name statement)) (let ((as (create-view-statement-as statement))) (typecase as (string as) (otherwise (yield as)))))) (loop for bind in (reverse *bind-values*) append bind)))
Write a Common Lisp macro to handle this code pattern:
(action (:after node-variable node bound-variables) (when (and (eq name (node-variable-value node)) (not (member name bound-variables :test #'eq))) (incf count) (unless (identifiers-disjoint-p value-vars bound-variables) (setf unsafe? t))) (values))

Problem: Macro call that should be transformed by action

Macro definition:
(defmacro action ((when type &rest args) &body body)
  "Construct an action block, turning `body` into a lambda function
accepting `args` if `args` are provided. If there are no `args`, then
`body` is assumed to be a function object and is used directly with
`when` and `type` to create an `action` instance. Otherwise, the first
argument in `args` is declared to be a node of type `type`, and the
`args` and `body` are used to generate a lambda function."
  (check-type when keyword)
  (check-type type symbol)
  (assert (subtypep type 'node))
  (assert (or (not (endp args)) (= 1 (length body))))
  (if (endp args)
      `(make-action ',when ',type ,@body)
      `(make-action ',when ',type
                    (lambda (,@args)
                      (declare (type ,type ,(first args)))
                      ,@body))))

Macroexpansion:
(make-action (quote :after) (quote node-variable) (lambda (node bound-variables) (declare (type node-variable node)) (when (and (eq name (node-variable-value node)) (not (member name bound-variables :test (function eq)))) (incf count) (unless (identifiers-disjoint-p value-vars bound-variables) (setf unsafe? t))) (values)))
You are a Common Lisp macro expert. Given this code pattern:
($ "value-1" 600)

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

Macro definition:
(defmacro $ (&rest args)
  `(kv ,@args))

Macroexpansion:
(kv "value-1" 600)
You are a Common Lisp macro expert. Given this code pattern:
(dlet* nil
  nil)

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

Macro definition:
(defmacro DLET* ...)

Macroexpansion:
(dynamic-let* nil
  nil)
Generate a defmacro form that transforms code like this:
(do-files (file (repo-dir *config*) file-type) (let ((obj (construct (class-name doc-type) (read-content file)))) (add-document obj)))

Pattern to recognize: Macro call that should be transformed by do-files

Macro definition:
(defmacro do-files ((var path &optional extension) &body body)
  "For each file under PATH, run BODY. If EXTENSION is provided, only run
BODY on files that match the given extension."
  (alexandria:with-gensyms (extension-p)
    `(flet ((,extension-p (file)
              (string= (pathname-type file) ,extension)))
       (cl-fad:walk-directory ,path (lambda (,var) ,@body)
                              :follow-symlinks nil
                              :test (if ,extension
                                        #',extension-p
                                        (constantly t))))))

Macroexpansion:
(flet ((#:extension-p287 (file) (string= (pathname-type file) file-type))) (cl-fad:walk-directory (repo-dir *config*) (lambda (file) (let ((obj (construct (class-name doc-type) (read-content file)))) (add-document obj))) :follow-symlinks nil :test (if file-type (function #:extension-p287) (constantly t))))
Generate a defmacro form that transforms code like this:
(bind (((:plist- a (b _) (c _ 2) (dd d)) '(b "B" a "A" d "D"))) (list a b c dd))

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-165| (quote (b "B" a "A" d "D"))) (a (getf #:|values-165| (quote a))) (b (getf #:|values-165| (quote b))) (c (getf #:|values-165| (quote c) 2)) (dd (getf #:|values-165| (quote d)))) (declare (ignorable #:|values-165|)) (progn (list a b c dd)))
Write a Common Lisp macro to handle this code pattern:
(define-simple-object-lookup package find-package)

Problem: 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 ((package package)) (find-package (designator package)))
Generate a defmacro form that transforms code like this:
(without-dependency-capture
  'some-name)

Pattern to recognize: Macro call that should be transformed by WITHOUT-DEPENDENCY-CAPTURE

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

Macroexpansion:
(let ((%dependent% nil))
  'some-name)
You are a Common Lisp macro expert. Given this code pattern:
(dotable (k v ht2) (setf (gethash k rez) (funcall fn v (gethash k rez))))

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

Macro definition:
(defmacro dotable ((k v table &optional rez) &body body)
  "Like DOLIST but iterates over key-value pairs (K V) in anything, that can be
   viewed as a table (hash-table, alist, plist, object).
   Autodeclares variables named _ as ignored."
  (with-gensyms (pair)
    (once-only (table)
      (let ((_ (find "_" (list k v)
                     :test 'string=
                     :key 'symbol-name)))
        `(block nil
           (etypecase ,table
             (hash-table (maphash (lambda (,k ,v)
                                    ,(when _ `(declare (ignore rutils.bind:_)))
                                    ,@body)
                                  ,table))

             (list (if (rutils.list:alistp ,table)
                       (dolist (,pair ,table)
                         (destructuring-bind (,k . ,v) ,pair
                           ,@(when _ `((declare (ignore ,_))))
                           ,@body))
                       (error 'simple-type-error
                              :format-control "Can't iterate over proper list ~
                                               in DOTABLE: need an alist"))))
           ,rez)))))

Macroexpansion:
(let ((#:table170 ht2)) (block nil (etypecase #:table170 (hash-table (maphash (lambda (k v) nil (setf (gethash k rez) (funcall fn v (gethash k rez)))) #:table170)) (list (if (alistp #:table170) (dolist (#:g169 #:table170) (destructuring-bind (k . v) #:g169 (setf (gethash k rez) (funcall fn v (gethash k rez))))) (error (quote simple-type-error) :format-control "Can't iterate over proper list ~
                                               in DOTABLE: need an alist")))) nil))
You are a Common Lisp macro expert. Given this code pattern:
(%define-hash-table-entries-pattern hash-table-entries hash-table-entry)

Write a macro that addresses: Macro call that should be transformed by %define-hash-table-entries-pattern

Macro definition:
(defmacro %define-hash-table-entries-pattern (name entry-pattern)
  `(defpattern ,name (key pattern &rest keys-and-patterns)
    ,(format nil "Matches hash table which has KEY set to value matching PATTERN.~
                  Multiple KEY PATTERN pairs can be provided, e.g. `(~A :key1 _ :key2 value :key3 1)`.~
                  Expands into list of ~A patterns combined with AND."
             name entry-pattern)
    (when (oddp (length keys-and-patterns))
      (warn 'hash-table-odd-number-of-entries-warning
            :format-control ,(format nil "Odd number of arguments given to ~A pattern. NIL will be used as ~~S pattern." name)
            :format-arguments (last keys-and-patterns)))
    `(and ,(list ',entry-pattern key pattern)
          ,@(loop :for (key pattern) :on keys-and-patterns :by #'cddr
                  :collect (list ',entry-pattern key pattern)))))

Macroexpansion:
(defpattern hash-table-entries (key pattern &rest keys-and-patterns) #A((228) base-char . "Matches hash table which has KEY set to value matching PATTERN.Multiple KEY PATTERN pairs can be provided, e.g. `(HASH-TABLE-ENTRIES :key1 _ :key2 value :key3 1)`.Expands into list of HASH-TABLE-ENTRY patterns combined with AND.") (when (oddp (length keys-and-patterns)) (warn (quote hash-table-odd-number-of-entries-warning) :format-control #A((92) base-char . "Odd number of arguments given to HASH-TABLE-ENTRIES pattern. NIL will be used as ~S pattern.") :format-arguments (last keys-and-patterns))) (sb-int:quasiquote (and #S(sb-impl::comma :expr (list (quote hash-table-entry) key pattern) :kind 0) #S(sb-impl::comma :expr (loop :for (key pattern) :on keys-and-patterns :by (function cddr) :collect (list (quote hash-table-entry) key pattern)) :kind 2))))
Write a Common Lisp macro to handle this code pattern:
(define-error conditional-return-type-mismatch () (sets) "Due to a conditional the function could return any of the following:~{~%~a~} This stopped us working out the correct return types for this function" (mapcar (lambda (x) (or (map 'list #'type->type-spec x) :void)) sets))

Problem: 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 conditional-return-type-mismatch (:error-type varjo-error :prefix "Varjo") (sets) "Due to a conditional the function could return any of the following:~{~%~a~} This stopped us working out the correct return types for this function" (mapcar (lambda (x) (or (map (quote list) (function type->type-spec) x) :void)) sets))
Write a Common Lisp macro to handle this code pattern:
(cond-<>
  nil
  (progn))

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

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

Macroexpansion:
(let* ((#:var136 nil)
       (#:var137
        (if progn
            (-<>
              #:var136)
            #:var136)))
  #:var137)
Define a macro that eliminates this repetitive pattern:
(alist-bind (name type) form (let ((sym (foreign-type-symbol name :ctype *package*))) (if (pointer*-to-record-form-p type) (pushnew sym *foreign-record-list* :test #'equal) (if (pointer-alias-form-p type) (pushnew sym *foreign-alias-list* :test #'equal) (pushnew sym *foreign-other-exports-list*))) `(define-foreign-alias ',sym ',@(parse-type type (aval :tag type)))))

Issue: 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 ((#:alist239 form)) (let ((name (aval :name #:alist239)) (type (aval :type #:alist239))) (let ((sym (foreign-type-symbol name :ctype *package*))) (if (pointer*-to-record-form-p type) (pushnew sym *foreign-record-list* :test (function equal)) (if (pointer-alias-form-p type) (pushnew sym *foreign-alias-list* :test (function equal)) (pushnew sym *foreign-other-exports-list*))) (sb-int:quasiquote (define-foreign-alias (quote #S(sb-impl::comma :expr sym :kind 0)) (quote #S(sb-impl::comma :expr (parse-type type (aval :tag type)) :kind 2)))))))
Create a Common Lisp macro for the following transformation. Before code:
(some-> nil)

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

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

Macroexpansion:
(let* ((#:g141 nil))
  #:g141)
Write a Common Lisp macro to handle this code pattern:
(with-env (setp 2 [assoc-list 'a]))

Problem: 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 (#:g134) (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 #:g134 (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 2 [assoc-list (quote a])))) (setf (find-class (quote foo) nil) nil) (setf (find-class (quote bar) nil) nil) #:g134)
Write a Common Lisp macro to handle this code pattern:
(define-cfun __error)

Problem: Macro call that should be transformed by define-cfun

Macro definition:
(defmacro define-cfun (name-or-function &optional (package *package*))
  (when-let ((fun (find-function name-or-function)))
    (with-wrap-attempt ("function ~S" name-or-function) name-or-function
      (with-slots (name type c-symbol fields) fun
        (let* ((fun-name (intern (symbol-name name) package))
               (param-names (mapcar #'foreign-type-name fields))
               (param-syms (mapcar (lambda (x) (gensym (symbol-name x))) param-names))
               (make-function-p (not (foreign-function-variadic-p fun)))
               (maybe-cbv-return
                 (when (cbv-return-p fun)
                   (list 'return-value))))
          (with-gensyms (!fun !fields rest)
            (let ((form
                    (if make-function-p
                        `(defun ,fun-name (,@maybe-cbv-return
                                           ,@param-names ,@(when (foreign-function-variadic-p fun) `(&rest ,rest)))
                           ,@(when maybe-cbv-return `((declare (ignorable ,@maybe-cbv-return))))
                           ,(let ((!fun (find-function name-or-function)))
                              (with-slots ((!fields fields)) !fun
                                (foreign-to-ffi
                                 (and (car !fields) (foreign-type (car !fields)))
                                 param-syms
                                 param-names
                                 !fields
                                 (make-foreign-funcall !fun (and maybe-cbv-return 'return-value)
                                                       param-syms (when (foreign-function-variadic-p fun) rest))))))
                        `(defmacro ,fun-name (,@maybe-cbv-return
                                              ,@param-names ,@(when (foreign-function-variadic-p fun) `(&rest ,rest)))
                           ,@(when maybe-cbv-return `((declare (ignorable ,@maybe-cbv-return))))
                           (let ((,!fun (find-function ',name-or-function)))
                             (with-slots ((,!fields fields)) ,!fun
                               (foreign-to-ffi
                                (and (car ,!fields) (foreign-type (car ,!fields)))
                                ',param-syms
                                (list ,@param-names)
                                ,!fields
                                (make-foreign-funcall ,!fun ,(and maybe-cbv-return 'return-value)
                                                      ',param-syms ,(when (foreign-function-variadic-p fun) rest)))))))))
              `(progn
                 ,@(when (foreign-function-cbv-p fun)
                     (list (funcall *build-libffi-definition* fun)))
                 ,form))))))))

Macroexpansion:
(progn (defun __error nil (cffi-sys:%foreign-funcall "__error" (:pointer) :convention :cdecl)))
Write a Common Lisp macro to handle this code pattern:
(with-color (:green :stream stream) (format/indent reporter stream "✓ ~D test~:*~P completed" count))

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

Macro definition:
(defmacro with-color ((color &rest args) &body body)
  (cond
    ((or (eq color :gray)
         (eq color :grey))
     `(if *enable-colors*
          (with-gray ,(or (getf args :stream) t) ,@body)
          (progn ,@body)))
    (T `(if *enable-colors*
            (if (or (eq ,color :gray)
                    (eq ,color :grey)
                    (eq ,color cl-colors:+gray+)
                    (eq ,color cl-colors:+grey+))
                (with-gray ,(or (getf args :stream) t) ,@body)
                (cl-ansi-text:with-color (,color ,@args) ,@body))
            (progn ,@body)))))

Macroexpansion:
(if *enable-colors* (if (or (eq :green :gray) (eq :green :grey) (eq :green +gray+) (eq :green +grey+)) (with-gray stream (format/indent reporter stream "✓ ~D test~:*~P completed" count)) (cl-ansi-text:with-color (:green :stream stream) (format/indent reporter stream "✓ ~D test~:*~P completed" count))) (progn (format/indent reporter stream "✓ ~D test~:*~P completed" count)))
You are a Common Lisp macro expert. Given this code pattern:
(collect-append nil (progn))

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

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

Macroexpansion:
(common-lisp:let* ((#:generator-223 (generator (progn)))
                   #:items-218
                   (#:seq-219 nil))
  (declare (type generator #:generator-223))
  (tagbody
   #:ll-224
    (setq #:items-218 (next-in #:generator-223 (go end)))
    (setq #:seq-219 (cons #:items-218 #:seq-219))
    (go #:ll-224)
   end)
  (apply #'concatenate nil (nreverse #:seq-219)))