j14i/cl-macros huggingface dataset:
Generate a defmacro form that transforms code like this:
(c? (c-assert (listp (kid-values self))) (let ((new-kids (mapcan (lambda (kid-value) (list (or (find kid-value .cache :key (kv-key self) :test (kv-key-test self)) (trc nil "family-values forced to make new kid" self .cache kid-value) (funcall (kid-factory self) self kid-value)))) (^kid-values)))) (nconc (mapcan (lambda (old-kid) (unless (find old-kid new-kids) (when (fv-kid-keep self old-kid) (list old-kid)))) .cache) new-kids)))

Pattern to recognize: Macro call that should be transformed by c?

Macro definition:
(defmacro c? (&body body)
  `(make-c-dependent
    :code ',body
    :value-state :unevaluated
    :rule (c-lambda ,@body)))

Macroexpansion:
(make-c-dependent :code (quote ((c-assert (listp (kid-values self))) (let ((new-kids (mapcan (lambda (kid-value) (list (or (find kid-value .cache :key (kv-key self) :test (kv-key-test self)) (trc nil "family-values forced to make new kid" self .cache kid-value) (funcall (kid-factory self) self kid-value)))) (^kid-values)))) (nconc (mapcan (lambda (old-kid) (unless (find old-kid new-kids) (when (fv-kid-keep self old-kid) (list old-kid)))) .cache) new-kids)))) :value-state :unevaluated :rule (c-lambda (c-assert (listp (kid-values self))) (let ((new-kids (mapcan (lambda (kid-value) (list (or (find kid-value .cache :key (kv-key self) :test (kv-key-test self)) (trc nil "family-values forced to make new kid" self .cache kid-value) (funcall (kid-factory self) self kid-value)))) (^kid-values)))) (nconc (mapcan (lambda (old-kid) (unless (find old-kid new-kids) (when (fv-kid-keep self old-kid) (list old-kid)))) .cache) new-kids))))
You are a Common Lisp macro expert. Given this code pattern:
(define-modf-rewrite tenth (expr) `(cadr (cddddr (cddddr ,(second expr)))))

Write a macro that addresses: 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 tenth) *modf-rewrites*) (lambda (expr) (sb-int:quasiquote (cadr (cddddr (cddddr #S(sb-impl::comma :expr (second expr) :kind 0))))))))
Create a Common Lisp macro for the following transformation. Before code:
(named-lambda fac (&key x) (if (> x 1) (* x (fac :x (- x 1))) x))

What needs to change: Macro call that should be transformed by named-lambda

Macro definition:
(defmacro named-lambda (name lambda-list &body body)
  "Expands into a lambda-expression within whose BODY NAME denotes the
corresponding function."
  `(labels ((,name ,lambda-list ,@body))
     #',name))

Macroexpansion:
(function (named-lambda fac (&key x) (if (> x 1) (* x (fac :x (- x 1))) x)))
Create a Common Lisp macro for the following transformation. Before code:
(defgeneric nil (progn))

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

Macro definition:
(defmacro DEFGENERIC ...)

Macroexpansion:
(common-lisp:defgeneric nil
    (progn))
Generate a defmacro form that transforms code like this:
(quote :literal)

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

Macro definition:
(defmacro quote (x) (list 'cl:quote x))

Macroexpansion:
(common-lisp:quote :literal)
Create a Common Lisp macro for the following transformation. Before code:
(some-<>> nil nil)

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

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

Macroexpansion:
(let* ((#:g131 nil))
  (if (null #:g131)
      nil
      (->> #:g131 nil)))
Define a macro that eliminates this repetitive pattern:
(deferror "42601" columns-error 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 columns-error (syntax-error-or-access-violation) nil) (setf (gethash "42601" *error-table*) (quote columns-error)))
Define a macro that eliminates this repetitive pattern:
(do+ (for x (among '(1 2 3 4))) (accumulating-to-and-returning foo) (pick x))

Issue: 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 x (among (quote (1 2 3 4)))) (accumulating-to-and-returning foo) (pick x))
Create a Common Lisp macro for the following transformation. Before code:
(with-local-readtable
  nil)

What needs to change: Macro call that should be transformed by WITH-LOCAL-READTABLE

Macro definition:
(defmacro WITH-LOCAL-READTABLE ...)

Macroexpansion:
(bind ((*readtable* (copy-readtable *readtable*)))
  nil)
Define a macro that eliminates this repetitive pattern:
(gen-lambda () (if (not data) 'generator-stop (prog1 (car data) (setf data (cdr data)))))

Issue: Macro call that should be transformed by gen-lambda

Macro definition:
(defmacro gen-lambda (params &body rest)
  "Version of lambda that wraps the anonymous function in an instance of the basic-generator class. This allows the lambda to be identified as a generator by its type. Basic-generator objects are derived from funcallable-standard-class, therefore they can be called as functions."
  `(let ((values-handler (create-values-handler)))
     (declare (ignorable values-handler))
     (make-instance 
      'basic-generator 
      :function (lambda ,params ,@rest))))

Macroexpansion:
(let ((values-handler (create-values-handler))) (declare (ignorable values-handler)) (make-instance (quote basic-generator) :function (lambda nil (if (not data) (quote generator-stop) (prog1 (car data) (setf data (cdr data)))))))
Generate a defmacro form that transforms code like this:
(gather-result nil)

Pattern to recognize: Macro call that should be transformed by GATHER-RESULT

Macro definition:
(defmacro GATHER-RESULT ...)

Macroexpansion:
(common-lisp:funcall nil nil t)
Create a Common Lisp macro for the following transformation. Before code:
(defsynonym finally-protected :finally-protected)

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

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

Macroexpansion:
(eval-always (setf (get (quote finally-protected) (quote synonym)) (quote :finally-protected)))
Generate a defmacro form that transforms code like this:
(defun/1 fread (mem element_size count fd) (handler-case (let* ((start (memptr-ptr mem)) (end (+ start (* element_size count))) (position (read-sequence (memptr-mem mem) (fd-stream fd) :start start :end end))) (when (< position end) (setf (feof fd) 1)) (- position start)) (error () (setf (ferror fd) EIO) 0)))

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 fread (mem element_size count fd) (declare (optimize (speed 0) (debug 3) (sb-ext:inhibit-warnings 3))) (handler-case (let* ((start (memptr-ptr mem)) (end (+ start (* element_size count))) (position (read-sequence (memptr-mem mem) (fd-stream fd) :start start :end end))) (when (< position end) (setf (feof fd) 1)) (- position start)) (error nil (setf (ferror fd) eio) 0))) (defparameter fread (vacietis.c:mkptr& (symbol-function (quote fread)))))
You are a Common Lisp macro expert. Given this code pattern:
(collect-alist nil (progn))

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

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

Macroexpansion:
(common-lisp:let* ((#:generator-440 (generator (progn)))
                   #:values-433
                   (#:generator-438 (generator nil))
                   #:keys-432
                   (#:alist-434 nil))
  (declare (type generator #:generator-440)
           (type generator #:generator-438)
           (type list #:alist-434))
  (tagbody
   #:ll-441
    (setq #:values-433 (next-in #:generator-440 (go end)))
    (setq #:keys-432 (next-in #:generator-438 (go end)))
    (setq #:alist-434 (cons (cons #:keys-432 #:values-433) #:alist-434))
    (go #:ll-441)
   end)
  #:alist-434)
Create a Common Lisp macro for the following transformation. Before code:
(-<> (diamond-wand init (cddr exp)))

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

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

Macroexpansion:
(diamond-wand init (cddr exp))
Write a Common Lisp macro to handle this code pattern:
(dynamic-wind
  'some-name)

Problem: Macro call that should be transformed by DYNAMIC-WIND

Macro definition:
(defmacro DYNAMIC-WIND ...)

Macroexpansion:
(flet ((#:dynamic-wind-thunk228 (#:proceed-thunk229)
         (macrolet ((proceed (&body #:proceed-body230)
                      `(if ,'#:proceed-thunk229
                           (funcall (the function ,'#:proceed-thunk229))
                           (progn ,@#:proceed-body230))))
           'some-name)))
  (declare (inline #:dynamic-wind-thunk228))
  (let ((*dynamic-wind-stack*
         (cons #'#:dynamic-wind-thunk228 *dynamic-wind-stack*)))
    (#:dynamic-wind-thunk228 nil)))
Write a Common Lisp macro to handle this code pattern:
(match nil
  nil)

Problem: Macro call that should be transformed by MATCH

Macro definition:
(defmacro MATCH ...)

Macroexpansion:
(match* (nil)
  ((nil)))
Define a macro that eliminates this repetitive pattern:
(let-syntax common-lisp:nil :key common-lisp:nil)

Issue: Macro call that should be transformed by LET-SYNTAX

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

Macroexpansion:
(common-lisp:progn :key common-lisp:nil)
Generate a defmacro form that transforms code like this:
(defmethod nil (progn))

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

Macro definition:
(defmacro DEFMETHOD ...)

Macroexpansion:
(common-lisp:defmethod nil (progn))
You are a Common Lisp macro expert. Given this code pattern:
(defstore example (a &optional (b (the integer (init-b a))) &rest args))

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

Macro definition:
(defmacro defstore (store-name store-lambda-list &body body &environment env)
  (let* ((store-class-name (second (find :store-class body :key #'first)))
         (store-class (etypecase store-class-name
                        (null (find-class 'standard-store))
                        (symbol (find-class store-class-name))))
         (form (apply #'defstore-using-class store-class store-name store-lambda-list
                      :environment env
                      (mapcan #'(lambda (item)
                                  (cond ((eql (first item) :store-class)
                                         `(:store-class ',store-class-name))
                                        ((and (member (first item) '(:documentation :specialization-class)))
                                         (if (= 2 (length item))
                                             item
                                             (error "Invalid store definition option: ~W." item)))
                                        (t
                                         (list (first item) (rest item)))))
                              body))))
    `(eval-when (:compile-toplevel :load-toplevel :execute)
       ,form)))

Macroexpansion:
(eval-when (:compile-toplevel :load-toplevel :execute) (progn (defun a-init-function152 (a) (declare (ignorable a)) (the integer (init-b a))) (ensure-store (quote example) (quote (a &optional (b (the integer (a-init-function152 a)) #:b?162) &rest args)))))
You are a Common Lisp macro expert. Given this code pattern:
(ensure-arg-list-key-value! nil :key nil)

Write a macro that addresses: Macro call that should be transformed by ENSURE-ARG-LIST-KEY-VALUE!

Macro definition:
(defmacro ensure-arg-list-key-value! (default ids place &key (test '#'equalper) (key '#'identity))
  `(progn
    (iter (for id in (ensure-list ,ids))
      (setf ,place (ensure-arg-list-key-value ,default id ,place :test ,test :key ,key)))
    ,place))

Macroexpansion:
(progn
 (iter
   (for id in (ensure-list :key))
   (setf nil
           (ensure-arg-list-key-value nil id nil :test #'equalper :key
                                      #'identity)))
 nil)
Define a macro that eliminates this repetitive pattern:
(let+ nil
  :key
  nil)

Issue: Macro call that should be transformed by LET+

Macro definition:
(defmacro LET+ ...)

Macroexpansion:
(locally :key nil)
Create a Common Lisp macro for the following transformation. Before code:
(finalize-savepoint :commited (call-next-method conn identifier))

What needs to change: Macro call that should be transformed by finalize-savepoint

Macro definition:
(defmacro finalize-savepoint (new-state &body body)
  `(let ((state (get-transaction-state conn)))
     (unless (typep state 'savepoint-state)
       (error "Please, use release-savepoint inside of with-savepoint block."))
     (unless (equal (get-identifier state)
                    identifier)
       ;; TODO: probably optional `identifier' parameter
       ;;       is excessive and should be removed?
       (error "Identifier mismatch"))

     (multiple-value-prog1
         (progn ,@body)
       (setf (get-state state)
             ,new-state))))

Macroexpansion:
(let ((state (get-transaction-state conn))) (unless (typep state (quote savepoint-state)) (error "Please, use release-savepoint inside of with-savepoint block.")) (unless (equal (get-identifier state) identifier) (error "Identifier mismatch")) (multiple-value-prog1 (progn (call-next-method conn identifier)) (setf (get-state state) :commited)))
Create a Common Lisp macro for the following transformation. Before code:
(define-component css-minify :input-type "css" :output-type "min.css" :compile-function (lambda (input-pathname output-pathname) (inferior-shell:run `("yui-compressor" ,input-pathname "-o" ,output-pathname) :show t)))

What needs to change: 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 css-minify (source-file) ((type :initform "css") (output :reader output :initarg :output))) (defmethod perform ((o load-op) (component css-minify)) t) (defmethod output-files ((operation compile-op) (component css-minify)) (list (output-pathname component "min.css"))) (defmethod perform ((o compile-op) (component css-minify)) (funcall (lambda (input-pathname output-pathname) (inferior-shell:run (sb-int:quasiquote ("yui-compressor" #S(sb-impl::comma :expr input-pathname :kind 0) "-o" #S(sb-impl::comma :expr output-pathname :kind 0))) :show t)) (component-pathname component) (output-pathname component "min.css"))) (import (quote css-minify) :asdf))
Define a macro that eliminates this repetitive pattern:
(with-csv-output-stream (csv-stream stream) (iter (for item in (alexandria:ensure-list items)) (unless (first-iteration-p) (write-char *separator* csv-stream)) (write-csv-value item csv-stream)) (write-sequence *write-newline* csv-stream) (unless stream (get-output-stream-string csv-stream)))

Issue: Macro call that should be transformed by with-csv-output-stream

Macro definition:
(defmacro with-csv-output-stream ((name inp) &body body)
  (alexandria:with-unique-names (opened?)
    `(multiple-value-bind (,name ,opened?) (%out-stream ,inp)
      (flet ((body () ,@body))
        (unwind-protect (body)
          (when (and ,name ,opened?)
            (close ,name)))))))

Macroexpansion:
(multiple-value-bind (csv-stream #:opened?197) (%out-stream stream) (flet ((body nil (iter (for item in (alexandria:ensure-list items)) (unless (first-iteration-p) (write-char *separator* csv-stream)) (write-csv-value item csv-stream)) (write-sequence *write-newline* csv-stream) (unless stream (get-output-stream-string csv-stream)))) (unwind-protect (body) (when (and csv-stream #:opened?197) (close csv-stream)))))
You are a Common Lisp macro expert. Given this code pattern:
;; Functions that build code also need gensyms for hygiene
(defun build-setter (var)
  (let ((g (gensym)))
    `(lambda (,g)
       (setf ,var ,g))))
;; Gensym boilerplate in code-generating functions

Write a macro that addresses: Functions that generate code also need gensyms — want same G! prefix convention extended to defun

Macro definition:
(defmacro defun! (name args &body body)
  (let ((syms (remove-duplicates
               (remove-if-not #'g!-symbol-p
                              (flatten body)))))
    (multiple-value-bind (body declarations docstring)
        (parse-body body :documentation t)
      `(defun ,name ,args
         ,@(when docstring
             (list docstring))
         ,@declarations
         (let ,(mapcar (lambda (s)
                         `(,s (gensym ,(subseq (symbol-name s)
                                               2))))
                       syms)
           ,@body)))))

Macroexpansion:
;; (defun! build-setter (var)
;;   `(lambda (,g!param)
;;      (setf ,var ,g!param)))
;;
;; g!param is automatically gensym'd when the function runs
;; Each call produces a fresh uninterned symbol
Define a macro that eliminates this repetitive pattern:
(define-option-expander shadowing-import-from (package import-package &rest symbols) (shadowing-import (collect-symbols-from import-package symbols) package))

Issue: Macro call that should be transformed by define-option-expander

Macro definition:
(defmacro define-option-expander (name (package &rest arguments) &body body)
  (let ((args (gensym "ARGS")))
    `(defmethod expand-option ((,(gensym "TYPE") (eql ,(intern (string name) "KEYWORD"))) ,package ,args)
       (destructuring-bind ,arguments ,args
         ,@body))))

Macroexpansion:
(defmethod expand-option ((#:type130 (eql :shadowing-import-from)) package #:args129) (destructuring-bind (import-package &rest symbols) #:args129 (shadowing-import (collect-symbols-from import-package symbols) package)))
Write a Common Lisp macro to handle this code pattern:
(c-assert (not (member nil new-kids)))

Problem: Macro call that should be transformed by c-assert

Macro definition:
(defmacro c-assert (assertion &optional places fmt$ &rest fmt-args)
  (declare (ignorable assertion places fmt$ fmt-args))
   #+(or)`(progn) 
  `(unless *stop*
     (unless ,assertion
       ,(if fmt$
            `(c-break ,fmt$ ,@fmt-args)
          `(c-break "failed assertion: ~a" ',assertion)))))

Macroexpansion:
(unless *stop* (unless (not (member nil new-kids)) (c-break "failed assertion: ~a" (quote (not (member nil new-kids))))))
Create a Common Lisp macro for the following transformation. Before code:
(with-inactive-layers nil
  (progn))

What needs to change: Macro call that should be transformed by WITH-INACTIVE-LAYERS

Macro definition:
(defmacro WITH-INACTIVE-LAYERS ...)

Macroexpansion:
(progn (progn))
Write a Common Lisp macro to handle this code pattern:
(with-active-layers* nil
  (progn))

Problem: Macro call that should be transformed by WITH-ACTIVE-LAYERS*

Macro definition:
(defmacro WITH-ACTIVE-LAYERS* ...)

Macroexpansion:
(progn (progn))
Create a Common Lisp macro for the following transformation. Before code:
(define-condition/a dbi-interface-error (dbi-error) () (:documentation "Exception for errors related to the DBI interface rather than the database itself."))

What needs to change: Macro call that should be transformed by define-condition/a

Macro definition:
(defmacro define-condition/a (name parent-types slots &body options)
  `(progn
     (define-condition ,name ,parent-types ,slots ,@options)
     (deftype ,(intern (format nil "<~A>" (symbol-name name))) () ',name)
     (setf (find-class ',(intern (format nil "<~A>" (symbol-name name))))
           (find-class ',name))))

Macroexpansion:
(progn (define-condition dbi-interface-error (dbi-error) nil (:documentation "Exception for errors related to the DBI interface rather than the database itself.")) (deftype <dbi-interface-error> nil (quote dbi-interface-error)) (setf (find-class (quote <dbi-interface-error>)) (find-class (quote dbi-interface-error))))
Write a Common Lisp macro to handle this code pattern:
(gen-lambda-with-sticky-stop () (loop for g in generators for v in valfuncs do (let ((data (multiple-value-list (funcall v g)))) (if (car data) (progn (push (car data) sigs) (push (cdr data) stor)) (sticky-stop)))) (when (= 0 (length (remove-if (lambda (x) (eq x :filled)) sigs))) (sticky-stop)) (let ((tmp stor)) (setf stor nil) (setf sigs nil) (apply #'values (nreverse tmp))))

Problem: Macro call that should be transformed by gen-lambda

Macro definition:
(defmacro gen-lambda (params &body rest)
  "Version of lambda that wraps the anonymous function in an instance of the basic-generator class. This allows the lambda to be identified as a generator by its type. Basic-generator objects are derived from funcallable-standard-class, therefore they can be called as functions."
  `(let ((values-handler (create-values-handler)))
     (declare (ignorable values-handler))
     (make-instance 
      'basic-generator 
      :function (lambda ,params ,@rest))))

Macroexpansion:
(make-instance (quote basic-generator) :function (sticky-stop-lambda nil (loop for g in generators for v in valfuncs do (let ((data (multiple-value-list (funcall v g)))) (if (car data) (progn (push (car data) sigs) (push (cdr data) stor)) (sticky-stop)))) (when (= 0 (length (remove-if (lambda (x) (eq x :filled)) sigs))) (sticky-stop)) (let ((tmp stor)) (setf stor nil) (setf sigs nil) (apply (function values) (nreverse tmp)))))
Generate a defmacro form that transforms code like this:
(lret* ((shape (ensure-shape shape)) (array (make-array shape))) (loop for i from 0 below (array-total-size array) do (setf (row-major-aref array i) (array-index-row-major array i))))

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

Macro definition:
(defmacro lret* ((&rest bindings) &body body)
  "Cf. `lret'."
  `(lret-aux let* ,bindings
     ,@body))

Macroexpansion:
(lret-aux let* ((shape (ensure-shape shape)) (array (make-array shape))) (loop for i from 0 below (array-total-size array) do (setf (row-major-aref array i) (array-index-row-major array i))))
You are a Common Lisp macro expert. Given this code pattern:
(let-match ((PATTERN ARG)) BODY...)

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

Macro definition:
(defmacro let-match (bindings &body body)
  "Similar to LET, except not only a variable but also a pattern can
be used in BINDINGS."
  `(optima::ematch* ,(mapcar #'cadr bindings)
     (,(mapcar #'car bindings) ,.body)))

Macroexpansion:
(optima::ematch* (arg) ((pattern) body...))