j14i/cl-macros huggingface dataset:
Generate a defmacro form that transforms code like this:
(signal-syntax-error* (1- (lexer-pos lexer)) "Quantifier '~A' not allowed." next-char)

Pattern to recognize: Macro call that should be transformed by signal-syntax-error*

Macro definition:
(defmacro signal-syntax-error* (pos format-control &rest format-arguments)
  `(error 'ppcre-syntax-error
          :pos ,pos
          :format-control ,format-control
          :format-arguments (list ,@format-arguments)))

Macroexpansion:
(error (quote ppcre-syntax-error) :pos (1- (lexer-pos lexer)) :format-control "Quantifier '~A' not allowed." :format-arguments (list next-char))
Create a Common Lisp macro for the following transformation. Before code:
(while 'some-name)

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

Macro definition:
(defmacro WHILE ...)

Macroexpansion:
(loop while 'some-name
      do (progn))
Write a Common Lisp macro to handle this code pattern:
(with-reader-syntax (hash-table) (is (equalp (alexandria:plist-hash-table '(:a 1 :b 2) :test 'equalp) (er "{:a 1 :b 2}"))) (is (equalp (alexandria:plist-hash-table '(:a 1 :b 2) :test 'eq) (er "{eq :a 1 :b 2}"))) (is (equalp (alexandria:plist-hash-table '("a" 1.0 "b" 2) :test 'equalp) (er "{\"a\" 1 \"b\" 2}"))))

Problem: Macro call that should be transformed by with-reader-syntax

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

Macroexpansion:
(let ((*array-function* (quote make-t-array-from-initial-contents)) (*hash-table-function* (quote alexandria:plist-hash-table)) (*get-val-function* (quote get-val)) (*get-val-array-function* (quote aref)) (*set-function* (quote remove-duplicates)) (*alists-are-lists* nil) (*plists-are-lists* nil) (*readtable* (%enable-reader-syntax *readtable* (quote hash-table)))) (is (equalp (alexandria:plist-hash-table (quote (:a 1 :b 2)) :test (quote equalp)) (er "{:a 1 :b 2}"))) (is (equalp (alexandria:plist-hash-table (quote (:a 1 :b 2)) :test (quote eq)) (er "{eq :a 1 :b 2}"))) (is (equalp (alexandria:plist-hash-table (quote ("a" 1.0 "b" 2)) :test (quote equalp)) (er "{\"a\" 1 \"b\" 2}"))))
You are a Common Lisp macro expert. Given this code pattern:
(is "<~S>" "<~S>")

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

Macro definition:
(defmacro is (got expected &rest args)
  (with-gensyms (duration result new-args desc)
    (once-only (expected)
      `(let* ((,new-args (list ,@args))
              (,desc (parse-description-and-test ,new-args)))
         (with-catching-errors (:description ,desc :expected ,expected)
           (with-duration ((,duration ,result) ,got)
             (test ,result ,expected ,new-args
                   :duration ,duration)))))))

Macroexpansion:
(let ((#:expected171 "<~S>")) (let* ((#:new-args169 (list)) (#:desc170 (parse-description-and-test #:new-args169))) (with-catching-errors (:description #:desc170 :expected #:expected171) (with-duration ((#:duration167 #:result168) "<~S>") (test #:result168 #:expected171 #:new-args169 :duration #:duration167)))))
Write a Common Lisp macro to handle this code pattern:
(define-test finish (finish T) (finish (error "NOPE")))

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

Macro definition:
(defmacro define-test (name &body arguments-and-body)
  (destructuring-bind (nparent name) (if (listp name) name (list NIL name))
    (form-fiddle:with-body-options (body options parent home (test-class 'test) (compile-at :compile-time) defun) arguments-and-body
      (let ((body (remove 'define-test body :key (lambda (a) (when (listp a) (car a))) :test #'eql))
            (defs (remove 'define-test body :key (lambda (a) (when (listp a) (car a))) :test-not #'eql))
            (home-form (or home `(find-package ,(package-name *package*)))))
        (when (and parent nparent)
          (error "Cannot specify parent through name and through a keyword argument at the same time!"))
        `(let ((*package* (find-package ,(package-name *package*)))) ; Make sure package stays consistent throughout initialisation.
           (setf (find-test ',name ,home-form)
                 (ensure-test ',test-class
                              :name ',name
                              :home ,home-form
                              :tests (list ,@(loop for form in body
                                                   collect (ecase compile-at
                                                             (:compile-time `(lambda () ,form))
                                                             (:execute `(lambda () (call-compile ',form))))))
                              :parent ',(or parent nparent)
                              ,@(loop for option in options
                                      collect `',option)))
           ,@(loop for (def subname . body) in defs
                   collect `(,def (,name ,subname)
                              :home ,home
                              ,@body))
           ,@(when defun
               `((defun ,(if (stringp name) (read-symbol name) name) (&rest test-args)
                   (apply #'test (find-test ',name ,home-form) test-args))))
           ',name)))))

Macroexpansion:
(let ((*package* (find-package #A((9) base-char . "PARACHUTE")))) (setf (find-test (quote finish) (find-package #A((9) base-char . "PARACHUTE"))) (ensure-test (quote test) :name (quote finish) :home (find-package #A((9) base-char . "PARACHUTE")) :tests (list (lambda nil (finish t)) (lambda nil (finish (error "NOPE")))) :parent (quote nil))) (quote finish))
Generate a defmacro form that transforms code like this:
(flet* nil
  :key
  nil)

Pattern to recognize: Macro call that should be transformed by FLET*

Macro definition:
(defmacro FLET* ...)

Macroexpansion:
(flet ()
  :key
  nil)
Define a macro that eliminates this repetitive pattern:
(cond-> nil)

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

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

Macroexpansion:
(let* ((#:g138 nil))
  #:g138)
Create a Common Lisp macro for the following transformation. Before code:
(dotable (item _ set2) (add# item set))

What needs to change: 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 ((#:table166 set2)) (block nil (etypecase #:table166 (hash-table (maphash (lambda (item _) (declare (ignore rutils.bind:_)) (|ADD#| item set)) #:table166)) (list (if (alistp #:table166) (dolist (#:g165 #:table166) (destructuring-bind (item . _) #:g165 (declare (ignore _)) (|ADD#| item set))) (error (quote simple-type-error) :format-control "Can't iterate over proper list ~
                                               in DOTABLE: need an alist")))) nil))
Create a Common Lisp macro for the following transformation. Before code:
(do-generator (val generator) (yield (apply function val)))

What needs to change: 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 ((#:g166 generator)) (loop do (if-generator ((val) #:g166) (progn (yield (apply function val))) (return))))
Define a macro that eliminates this repetitive pattern:
(with-env (setp 5 [clos-object 'a]))

Issue: 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 (#:g138) (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 #:g138 (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 5 [clos-object (quote a])))) (setf (find-class (quote foo) nil) nil) (setf (find-class (quote bar) nil) nil) #:g138)
Define a macro that eliminates this repetitive pattern:
(deferror "42P01" undefined-table syntax-error-or-access-violation)

Issue: 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 undefined-table (syntax-error-or-access-violation) nil) (setf (gethash "42P01" *error-table*) (quote undefined-table)))
Define a macro that eliminates this repetitive pattern:
(declare-unary-operator 'some-name)

Issue: Macro call that should be transformed by DECLARE-UNARY-OPERATOR

Macro definition:
(defmacro DECLARE-UNARY-OPERATOR ...)

Macroexpansion:
(eval-when (:compile-toplevel :load-toplevel :execute)
  (infix-math/data::save-unary-operator ''some-name))
Generate a defmacro form that transforms code like this:
(do-subclasses (itype index) (discover itype))

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

Macro definition:
(defmacro do-subclasses ((var class) &body body)
  "Iterate over the subclasses of CLASS performing BODY with VAR
lexically bound to the current subclass."
  (alexandria:with-gensyms (klasses)
    `(let ((,klasses (all-subclasses (find-class ',class))))
       (loop for ,var in ,klasses do ,@body))))

Macroexpansion:
(let ((#:klasses284 (all-subclasses (find-class (quote index))))) (loop for itype in #:klasses284 do (discover itype)))
Write a Common Lisp macro to handle this code pattern:
(adding-smart-slot-methods obj slot (:= (slot-value obj slot) val))

Problem: Macro call that should be transformed by adding-smart-slot-methods

Macro definition:
(defmacro adding-smart-slot-methods (obj slot expr)
  (with-gensyms (err class name alt args val)
    `(handler-case ,expr
       (simple-error (,err)
         (let ((,class (class-of ,obj))
               (,name (symbol-name ,slot)))
           (dolist (,alt (c2mop:class-slots ,class)
                         (error ,err))
             (let ((,alt (c2mop:slot-definition-name ,alt)))
               (when (string= ,name (symbol-name ,alt))
                 (add-method (ensure-generic-function 'smart-slot-value)
                             (make-instance
                              'standard-method
                              :specializers
                              (list ,class
                                    (c2mop:intern-eql-specializer ,slot))
                              :lambda-list '(,obj ,slot)
                              :function
                              (lambda (,args _)
                                (declare (ignorable _))
                                (slot-value (first ,args) ,alt))))
                 (add-method (ensure-generic-function 'smart-set-slot-value)
                             (make-instance
                              'standard-method
                              :specializers
                              (list ,class
                                    (c2mop:intern-eql-specializer ,slot)
                                    (find-class 't))
                              :lambda-list '(,obj ,slot ,val)
                              :function
                              (lambda (,args _)
                                (declare (ignorable _))
                                (:= (slot-value (first ,args) ,alt)
                                    (third ,args)))))
                 (let ((,slot ,alt))
                   (return ,expr))))))))))

Macroexpansion:
(handler-case (:= (slot-value obj slot) val) (simple-error (#:g155) (let ((#:g156 (class-of obj)) (#:g157 (symbol-name slot))) (dolist (#:g158 (sb-mop:class-slots #:g156) (error #:g155)) (let ((#:g158 (sb-mop:slot-definition-name #:g158))) (when (string= #:g157 (symbol-name #:g158)) (add-method (ensure-generic-function (quote smart-slot-value)) (make-instance (quote standard-method) :specializers (list #:g156 (sb-mop:intern-eql-specializer slot)) :lambda-list (quote (obj slot)) :function (lambda (#:g159 _) (declare (ignorable _)) (slot-value (first #:g159) #:g158)))) (add-method (ensure-generic-function (quote smart-set-slot-value)) (make-instance (quote standard-method) :specializers (list #:g156 (sb-mop:intern-eql-specializer slot) (find-class (quote t))) :lambda-list (quote (obj slot #:g160)) :function (lambda (#:g159 _) (declare (ignorable _)) (:= (slot-value (first #:g159) #:g158) (third #:g159))))) (let ((slot #:g158)) (return (:= (slot-value obj slot) val)))))))))
Create a Common Lisp macro for the following transformation. Before code:
(ct-flet nil
  :key
  nil)

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

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

Macroexpansion:
(cond (*within-captured-dynenv* (progn :key nil))
      (t
       (error
        "No macrodynamic environment has been captured to establish CT-FLET bindings.")))
Define a macro that eliminates this repetitive pattern:
(define nil)

Issue: Macro call that should be transformed by DEFINE

Macro definition:
(defmacro DEFINE ...)

Macroexpansion:
(eval-when (:load-toplevel :execute)
  (check-if-bound 'nil)
  (setf (get 'nil 'read-macro)
          (lambda (#:stream145) (let ((*standard-input* #:stream145)))))
  'nil)
You are a Common Lisp macro expert. Given this code pattern:
(define-error env-parent-context-mismatch () (env-a env-b) "Attempting to make an environment with different context to it's parent ~s~%~s~%~s" (cons (v-context env-a) (v-context env-b)) env-a env-b)

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

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

Macroexpansion:
(defcondition env-parent-context-mismatch (:error-type varjo-error :prefix "Varjo") (env-a env-b) "Attempting to make an environment with different context to it's parent ~s~%~s~%~s" (cons (v-context env-a) (v-context env-b)) env-a env-b)
Generate a defmacro form that transforms code like this:
(gen-lambda-with-sticky-stop () (unless (cdr ldata) (get-next)) (setf ldata (cdr ldata)) (if (eq (car ldata) 'generator-stop) (sticky-stop) (apply #'values (ensure-list (car ldata)))))

Pattern to recognize: Macro call that should be transformed by gen-lambda-with-sticky-stop

Macro definition:
(defmacro gen-lambda-with-sticky-stop (&rest rest)
  `(make-instance 
    'basic-generator 
    :function (sticky-stop-lambda ,@rest)))

Macroexpansion:
(make-instance (quote basic-generator) :function (sticky-stop-lambda nil (unless (cdr ldata) (get-next)) (setf ldata (cdr ldata)) (if (eq (car ldata) (quote generator-stop)) (sticky-stop) (apply (function values) (ensure-list (car ldata))))))
You are a Common Lisp macro expert. Given this code pattern:
(action (:after node-variable node new-subs) (alexandria:when-let ((res (or (find (node-variable-value node) subs :key #'ast-substitution-from) (find (node-variable-value node) new-subs :key #'ast-substitution-from)))) (ast-substitution-to res)))

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-variable) (lambda (node new-subs) (declare (type node-variable node)) (alexandria:when-let ((res (or (find (node-variable-value node) subs :key (function ast-substitution-from)) (find (node-variable-value node) new-subs :key (function ast-substitution-from))))) (ast-substitution-to res))))
Create a Common Lisp macro for the following transformation. Before code:
(define-modf-expander car 1 (expr val new-val) (declare (ignore expr)) `(cons ,new-val (cdr ,val)))

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

Macro definition:
(defmacro define-modf-expander (name nth-arg
                                (expr val new-val)
                                &body body)
  "Define a new expander which inverts forms starting with NAME.  Your function
should return an expansion from EXPR to a form that will build a new object that
has NEW-VAL in the place specified by expr.  NTH-ARG marks which argument is
considered the actual data which will be inverted next."
  (setf
   (gethash name *modf-nth-arg*)
   nth-arg)
  `(eval-when (:compile-toplevel :load-toplevel :execute)
     (setf
      (gethash ',name *modf-nth-arg*)
      ,nth-arg
      (gethash ',name *modf-expansions*)
      (lambda (,expr ,val ,new-val)
        ,@body))))

Macroexpansion:
(eval-when (:compile-toplevel :load-toplevel :execute) (setf (gethash (quote car) *modf-nth-arg*) 1 (gethash (quote car) *modf-expansions*) (lambda (expr val new-val) (declare (ignore expr)) (sb-int:quasiquote (cons #S(sb-impl::comma :expr new-val :kind 0) (cdr #S(sb-impl::comma :expr val :kind 0)))))))
Generate a defmacro form that transforms code like this:
(true 2)

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

Macro definition:
(defmacro true (form &optional description &rest format-args)
  `(eval-in-context
    *context*
    (make-instance 'comparison-result
                   :expression '(true ,form)
                   :value-form ',form
                   :body (lambda () ,form)
                   :expected 'T
                   :comparison 'geq
                   ,@(when description
                       `(:description (format NIL ,description ,@format-args))))))

Macroexpansion:
(eval-in-context *context* (make-instance (quote comparison-result) :expression (quote (true 2)) :value-form (quote 2) :body (lambda nil 2) :expected (quote t) :comparison (quote geq)))
Create a Common Lisp macro for the following transformation. Before code:
(defstruct-compile-time (variable (:print-function print-variable) (:predicate variable?) (:constructor make-variable-internal)) name (noticers nil) (enumerated-domain t) (enumerated-antidomain nil) value (possibly-integer? t) (possibly-noninteger-real? t) (possibly-nonreal-number? t) (possibly-boolean? t) (possibly-nonboolean-nonnumber? t) (lower-bound nil) (upper-bound nil))

What needs to change: Macro call that should be transformed by defstruct-compile-time

Macro definition:
(defmacro defstruct-compile-time (options &body items)
  `(eval-when (:compile-toplevel :load-toplevel :execute)
     (defstruct ,options ,@items)))

Macroexpansion:
(eval-when (:compile-toplevel :load-toplevel :execute) (defstruct (variable (:print-function print-variable) (:predicate variable?) (:constructor make-variable-internal)) name (noticers nil) (enumerated-domain t) (enumerated-antidomain nil) value (possibly-integer? t) (possibly-noninteger-real? t) (possibly-nonreal-number? t) (possibly-boolean? t) (possibly-nonboolean-nonnumber? t) (lower-bound nil) (upper-bound nil)))
Define a macro that eliminates this repetitive pattern:
(cond-> 'some-name)

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

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

Macroexpansion:
(let* ((#:g140 'some-name))
  #:g140)