j14i/cl-macros huggingface dataset:
Generate a defmacro form that transforms code like this:
(deferror "54" program-limit-exceeded)

Pattern to recognize: 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 program-limit-exceeded (database-error) nil) (setf (gethash "54" *error-table*) (quote program-limit-exceeded)))
Create a Common Lisp macro for the following transformation. Before code:
($/ query "i")

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

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

Macroexpansion:
(make-bson-regex (empty-str query) "i")
Create a Common Lisp macro for the following transformation. Before code:
(with-unique-names (value repeat) `((,name (,value) (tagbody (rplacd ,tail ,value) ,repeat (when (consp (cdr ,tail)) (setq ,tail (cdr ,tail)) (go ,repeat))))))

What needs to change: Macro call that should be transformed by with-unique-names

Macro definition:
(defmacro with-unique-names (names &body body)
  `(let ,(mapcar (lambda (sym)
                   `(,sym (gensym ,(symbol-name sym))))
                  names)
     ,@body))

Macroexpansion:
(let ((value (gensym #A((5) base-char . "VALUE"))) (repeat (gensym #A((6) base-char . "REPEAT")))) (quasiquote ((#S(sb-impl::comma :expr name :kind 0) (#S(sb-impl::comma :expr value :kind 0)) (tagbody (rplacd #S(sb-impl::comma :expr tail :kind 0) #S(sb-impl::comma :expr value :kind 0)) #S(sb-impl::comma :expr repeat :kind 0) (when (consp (cdr #S(sb-impl::comma :expr tail :kind 0))) (setq #S(sb-impl::comma :expr tail :kind 0) (cdr #S(sb-impl::comma :expr tail :kind 0))) (go #S(sb-impl::comma :expr repeat :kind 0))))))))
Write a Common Lisp macro to handle this code pattern:
(lambda-match (PATTERN BODY...))

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

Macro definition:
(defmacro lambda-match (&body clauses)
  "Equivalent to (lambda (arg) (match arg CLAUSES...))."
  (with-unique-names (arg)
    `(lambda (,arg) (match ,arg ,@clauses))))

Macroexpansion:
(lambda (#:arg122) (match #:arg122 (pattern body...)))
Generate a defmacro form that transforms code like this:
(defclass/a dbi-query (dbi-query-base) ((prepared :type t :initarg :prepared :accessor query-prepared) (results :initarg :results :accessor query-results) (row-count :type (or integer null) :initarg :row-count :initform nil :accessor query-row-count) (cached :initarg :cached :initform nil :accessor query-cached-p)) (:documentation "Class that represents a prepared DB query."))

Pattern to recognize: Macro call that should be transformed by defclass/a

Macro definition:
(defmacro defclass/a (name superclasses slots &rest class-options)
  `(progn
     (defclass ,name ,superclasses ,slots ,@class-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 (defclass dbi-query (dbi-query-base) ((prepared :type t :initarg :prepared :accessor query-prepared) (results :initarg :results :accessor query-results) (row-count :type (or integer null) :initarg :row-count :initform nil :accessor query-row-count) (cached :initarg :cached :initform nil :accessor query-cached-p)) (:documentation "Class that represents a prepared DB query.")) (deftype <dbi-query> nil (quote dbi-query)) (setf (find-class (quote <dbi-query>)) (find-class (quote dbi-query))))
Generate a defmacro form that transforms code like this:
(mapping nil nil)

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

Macro definition:
(defmacro MAPPING ...)

Macroexpansion:
(mapping-mac nil
  nil)
Generate a defmacro form that transforms code like this:
(with-yield-binds (format nil "(~A ~A ~A)" (yield (infix-list-op-left op)) (sql-op-name op) (if (sql-statement-p (infix-list-op-right op)) (format nil "(~A)" (yield (infix-list-op-right op))) (yield (apply #'make-sql-list (infix-list-op-right op))))))

Pattern to recognize: 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 "(~A ~A ~A)" (yield (infix-list-op-left op)) (sql-op-name op) (if (sql-statement-p (infix-list-op-right op)) (format nil "(~A)" (yield (infix-list-op-right op))) (yield (apply (function make-sql-list) (infix-list-op-right op)))))) (loop for bind in (reverse *bind-values*) append bind)))
Write a Common Lisp macro to handle this code pattern:
(with-prepared-query query (conn (format nil "PRAGMA index_list(\"~A\")" table-name)) (append (loop with results = (dbi:execute query) for index = (dbi:fetch results :format :plist) while index collect (let* ((columns (mapcar (lambda (info) (getf info :|name|)) (dbi:fetch-all (dbi:execute (dbi:prepare conn (format nil "PRAGMA index_info(\"~A\")" (getf index :|name|)))) :format :plist))) (unique-key (= (getf index :|unique|) 1)) (primary-key (and unique-key primary-keys (equal columns primary-keys)))) (when primary-key (setf primary-keys nil)) (list (getf index :|name|) :unique-key unique-key :primary-key primary-key :columns columns))) (if primary-keys (list (list "PRIMARY" :unique-key t :primary-key t :columns primary-keys)) nil)))

Problem: Macro call that should be transformed by with-prepared-query

Macro definition:
(defmacro with-prepared-query (query (conn sql &key use-prepare-cached) &body body)
  `(call-with-prepared-query ,conn ,sql (lambda (,query) ,@body) :use-prepare-cached ,use-prepare-cached))

Macroexpansion:
(call-with-prepared-query conn (format nil "PRAGMA index_list(\"~A\")" table-name) (lambda (query) (append (loop with results = (dbi.driver:execute query) for index = (dbi.driver:fetch results :format :plist) while index collect (let* ((columns (mapcar (lambda (info) (getf info :|name|)) (dbi.driver:fetch-all (dbi.driver:execute (prepare conn (format nil "PRAGMA index_info(\"~A\")" (getf index :|name|)))) :format :plist))) (unique-key (= (getf index :|unique|) 1)) (primary-key (and unique-key primary-keys (equal columns primary-keys)))) (when primary-key (setf primary-keys nil)) (list (getf index :|name|) :unique-key unique-key :primary-key primary-key :columns columns))) (if primary-keys (list (list "PRIMARY" :unique-key t :primary-key t :columns primary-keys)) nil))) :use-prepare-cached nil)
Generate a defmacro form that transforms code like this:
(lret* ((type `(integer ,start (,end))) (len (ceiling (- end start) step)) (vector (make-array len :element-type type :initial-element start))) (nlet lp ((i 0) (n start)) (declare (type array-index i n)) (if (= i len) vector (progn (setf (aref vector i) n) (lp (1+ i) (+ n step))))))

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* ((type (sb-int:quasiquote (integer #S(sb-impl::comma :expr start :kind 0) (#S(sb-impl::comma :expr end :kind 0))))) (len (ceiling (- end start) step)) (vector (make-array len :element-type type :initial-element start))) (nlet lp ((i 0) (n start)) (declare (type array-index i n)) (if (= i len) vector (progn (setf (aref vector i) n) (lp (1+ i) (+ n step))))))
Define a macro that eliminates this repetitive pattern:
(f0
  nil
  (progn))

Issue: Macro call that should be transformed by F0

Macro definition:
(defmacro F0 ...)

Macroexpansion:
(lambda () nil (progn))
Create a Common Lisp macro for the following transformation. Before code:
(define-simple-clause while (form) `(unless ,form (end-for)))

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

Macro definition:
(defmacro define-simple-clause (name args &body body)
  (multiple-value-bind (args outer-let inner-let result-let) (compute-binding-parts NIL NIL args)
    `(define-direct-clause ,name ,(rest args)
       (let ,outer-let
         (values* `(let* ,(list
                           ,@result-let)
                     (declare (ignorable ,,@(mapcar #'delist outer-let))))
                  (let ,inner-let
                    (declare (ignorable ,@(mapcar #'delist inner-let)))
                    ,@body))))))

Macroexpansion:
(define-direct-clause while (form) (let nil (values* (sb-int:quasiquote (let* #S(sb-impl::comma :expr (list) :kind 0) (declare (ignorable)))) (let nil (declare (ignorable)) (sb-int:quasiquote (unless #S(sb-impl::comma :expr form :kind 0) (end-for)))))))
Write a Common Lisp macro to handle this code pattern:
(do-generator-value-list (vals (apply #'multi-gen generators)) (yield (apply function (mapcar #'car vals))))

Problem: Macro call that should be transformed by do-generator-value-list

Macro definition:
(defmacro do-generator-value-list ((var generator) &body body)
  "Like do-generator, except all values emitted by the generator are placed in a list under the user defined variable."
  (let ((g (gensym)))
    `(let ((,g ,generator))
       (loop 
	  do (if-generator (,var ,g)
			   (progn ,@body)
			   (return))))))

Macroexpansion:
(let ((#:g181 (apply (function multi-gen) generators))) (loop do (if-generator (vals #:g181) (progn (yield (apply function (mapcar (function car) vals)))) (return))))
You are a Common Lisp macro expert. Given this code pattern:
(define-case-aware-token-p-function pp-pragma-operator-p find-pp-operator-name with-c-syntax.preprocess-operator:|_Pragma|)

Write a macro that addresses: Macro call that should be transformed by define-case-aware-token-p-function

Macro definition:
(defmacro define-case-aware-token-p-function (function-name find-symbol-function symbol)
  `(defun ,function-name (token &optional (readtable-case (readtable-case *readtable*)))
     (and (symbolp token)
          (eq (,find-symbol-function (string token) readtable-case)
              ',symbol))))

Macroexpansion:
(defun pp-pragma-operator-p (token &optional (readtable-case (readtable-case *readtable*))) (and (symbolp token) (eq (find-pp-operator-name (string token) readtable-case) (quote with-c-syntax.preprocess-operator:|_Pragma|))))
Generate a defmacro form that transforms code like this:
(compile-$flavor-$methods nil (progn))

Pattern to recognize: Macro call that should be transformed by COMPILE-$FLAVOR-$METHODS

Macro definition:
(defmacro COMPILE-$FLAVOR-$METHODS ...)

Macroexpansion:
(eval-when (:load-toplevel) (combine-class-methods nil (progn)))
Create a Common Lisp macro for the following transformation. Before code:
(define-compile-struct sql-op (name ""))

What needs to change: Macro call that should be transformed by define-compile-struct

Macro definition:
(defmacro define-compile-struct (structure-name &rest defstruct-options)
  (flet ((symbolcat (&rest symbols)
           (intern (format nil "~{~A~^-~}" symbols) #.*package*)))
    (let ((compiled-name (symbolcat structure-name :compiled)))
      `(progn
         (defstruct (,compiled-name (:include ,structure-name ,@defstruct-options))
           (sql nil :type string)
           (bind nil :type list))

         (defmethod find-compile-function ((object ,structure-name))
           (function ,(symbolcat :make compiled-name)))

         (defmethod print-object ((object ,compiled-name) stream)
           (format stream "#<SXQL-COMPILED: ~A [~{~A~^, ~}]>"
                   (,(symbolcat compiled-name :sql) object)
                   (,(symbolcat compiled-name :bind) object)))

         (defmethod yield ((object ,compiled-name))
           (values
            (,(symbolcat compiled-name :sql) object)
            (,(symbolcat compiled-name :bind) object)))))))

Macroexpansion:
(progn (defstruct (sql-op-compiled (:include sql-op (name ""))) (sql nil :type string) (bind nil :type list)) (defmethod find-compile-function ((object sql-op)) (function make-sql-op-compiled)) (defmethod print-object ((object sql-op-compiled) stream) (format stream "#<SXQL-COMPILED: ~A [~{~A~^, ~}]>" (sql-op-compiled-sql object) (sql-op-compiled-bind object))) (defmethod yield ((object sql-op-compiled)) (values (sql-op-compiled-sql object) (sql-op-compiled-bind object))))
Write a Common Lisp macro to handle this code pattern:
(def-neo4j-fun lookup-index ((type :node) name key value) :get (:uri-spec (format nil "index/~A/~A/~A/~A" (string-downcase (symbol-name type)) name key (urlencode value))) (:status-handlers (200 (decode-neo4j-json-output body)) (404 (error 'index-entry-not-found-error :uri uri))))

Problem: 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 lookup-index (&key (type :node) name key value) (let ((uri (format nil "index/~A/~A/~A/~A" (string-downcase (symbol-name type)) name key (urlencode value))) (json (encode-neo4j-json-payload nil :string))) (make-neo4j-request :get uri json (list (list 200 (lambda (body uri json) (decode-neo4j-json-output body))) (list 404 (lambda (body uri json) (error (quote index-entry-not-found-error) :uri uri))))))))
You are a Common Lisp macro expert. Given this code pattern:
(is 'blah 'blah "Blah with multiline description!")

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 ((#:expected189 (quote blah))) (let* ((#:new-args187 (list "Blah with multiline description!")) (#:desc188 (parse-description-and-test #:new-args187))) (with-catching-errors (:description #:desc188 :expected #:expected189) (with-duration ((#:duration185 #:result186) (quote blah)) (test #:result186 #:expected189 #:new-args187 :duration #:duration185)))))
Define a macro that eliminates this repetitive pattern:
(lret* ((element-type (array-element-type vec)) (out (make-array length :element-type element-type))) (replace out vec) (loop for i from (length vec) below length by pad-len do (replace out pad :start1 i)))

Issue: 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* ((element-type (array-element-type vec)) (out (make-array length :element-type element-type))) (replace out vec) (loop for i from (length vec) below length by pad-len do (replace out pad :start1 i)))
You are a Common Lisp macro expert. Given this code pattern:
(collect-nconc nil)

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

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

Macroexpansion:
(common-lisp:let* ((#:generator-567 (generator nil))
                   #:items-562
                   (#:lst-563 nil)
                   (#:list-564 nil))
  (declare (type generator #:generator-567)
           (type list #:lst-563)
           (type list #:list-564))
  (tagbody
   #:ll-568
    (setq #:items-562 (next-in #:generator-567 (go end)))
    (when #:items-562
      (when #:list-564 (setf (cdr (last #:list-564)) #:items-562))
      (setq #:list-564 #:items-562)
      (when (null #:lst-563) (setq #:lst-563 #:items-562)))
    (go #:ll-568)
   end)
  #:lst-563)
Generate a defmacro form that transforms code like this:
(define-op (:or conjunctive-op))

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

Macro definition:
(defmacro define-op ((op-name struct-type &key sql-op-name include-slots (package (find-package '#:sxql/operator))) &body body)
  (check-type op-name symbol)
  (let ((struct-name (intern (concatenate 'string (symbol-name op-name) #.(string :-op)) package)))
    `(defstruct (,struct-name (:include ,struct-type
                               (name ,(or sql-op-name
                                          (with-output-to-string (s)
                                            (loop for c across (symbol-name op-name)
                                                  if (char= c #\-)
                                                    do (write-char #\Space s)
                                                  else
                                                    do (write-char c s)))))
                               ,@include-slots)
                              (:constructor ,(intern (concatenate 'string
                                                                  #.(string :make-)
                                                                  (symbol-name op-name)
                                                                  #.(string :-op))
                                                     package)
                                  ,(ecase struct-type
                                     ((unary-op
                                       unary-splicing-op
                                       unary-postfix-op) '(var))
                                     ((infix-op
                                       infix-splicing-op
                                       infix-list-op) '(left right))
                                     (conjunctive-op '(&rest expressions)))))
       ,@body)))

Macroexpansion:
(defstruct (or-op (:include conjunctive-op (name "OR")) (:constructor make-or-op (&rest expressions))))
You are a Common Lisp macro expert. Given this code pattern:
(define-modf-rewrite cadddr (expr) `(car (cdddr ,(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 cadddr) *modf-rewrites*) (lambda (expr) (sb-int:quasiquote (car (cdddr #S(sb-impl::comma :expr (second expr) :kind 0)))))))
You are a Common Lisp macro expert. Given this code pattern:
(with-dot nil
  nil)

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

Macro definition:
(defmacro with-dot (() &body body)
  `(progn ,@(replace-dot-calls body)))

Macroexpansion:
(progn nil)
You are a Common Lisp macro expert. Given this code pattern:
(with-yield (iterate:iterate (for i in data) (yield i)))

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

Macro definition:
(defmacro with-yield (&body body)
  (let ((point (gensym))
        (current (gensym)))
    `(let (,point ,current)
       (with-call/cc
	 (labels ((yield (&rest values)
		    (setf ,current values)
		    (let/cc k
		      (setf ,point k))))
	   ,@body
	   (setf ,point nil)))
       (gen-lambda ()
	 (cond ((null ,point)
		'generator-stop)
	       (t
		(let ((current ,current))
		  (funcall ,point nil)
		  ;values-handler: see gen-lambda
		  (apply #'values (funcall values-handler current)))))))))

Macroexpansion:
(let (#:g149 #:g150) (with-call/cc (labels ((yield (&rest values) (setf #:g150 values) (let/cc k (setf #:g149 k)))) (iterate (for i in data) (yield i)) (setf #:g149 nil))) (gen-lambda nil (cond ((null #:g149) (quote generator-stop)) (t (let ((current #:g150)) (funcall #:g149 nil) (apply (function values) (funcall values-handler current)))))))
Generate a defmacro form that transforms code like this:
(stypecase (car x) (fixnum (setf it :no)))

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

Macro definition:
(defmacro stypecase (keyform &body cases)
  "Like TYPECASE, except binds the keyform to IT (via SYMBOL-MACROLET) for the
scope of the cases. IT can be set with SETF."
  `(symbolic typecase ,keyform ,@cases))

Macroexpansion:
(symbolic typecase (car x) (fixnum (setf it :no)))
Write a Common Lisp macro to handle this code pattern:
(ps-once-only nil
  (progn))

Problem: Macro call that should be transformed by PS-ONCE-ONLY

Macro definition:
(defmacro PS-ONCE-ONLY ...)

Macroexpansion:
(let* ()
  `(let* ()
     ,(let* ()
        (progn))))
You are a Common Lisp macro expert. Given this code pattern:
(defgenerator izip (&rest generators) "Steps through multiple generators in parallel, emitting each of their items as values. Stops with the end of the shortest source generator." (do-generator-value-list (vars (apply #'multi-gen generators)) (apply #'yield (mapcar #'car vars))))

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

Macro definition:
(defmacro defgenerator (name arguments &body body)
  (multiple-value-bind (remaining-forms declarations doc-string)
      (alexandria:parse-body body :documentation t)
    `(defun ,name ,arguments
       ,doc-string
       ,@declarations
       (with-yield
	 ,@remaining-forms))))

Macroexpansion:
(defun izip (&rest generators) "Steps through multiple generators in parallel, emitting each of their items as values. Stops with the end of the shortest source generator." (with-yield (do-generator-value-list (vars (apply (function multi-gen) generators)) (apply (function yield) (mapcar (function car) vars)))))
Create a Common Lisp macro for the following transformation. Before code:
(augment step-code step)

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

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

Macroexpansion:
(setf step-code (nconc step-code step))
Generate a defmacro form that transforms code like this:
(m nil
  (progn))

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

Macro definition:
(defmacro M ...)

Macroexpansion:
(lambda (&rest #:|macro-lambda-list122|)
  (destructuring-bind () #:|macro-lambda-list122| (progn)))
You are a Common Lisp macro expert. Given this code pattern:
(define-bug doesnt-have-dimensions () (vtype) "Compiler bug: Attempted to find the dimensions of ~a. If you have the time, please report this on github." vtype)

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

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

Macroexpansion:
(defcondition doesnt-have-dimensions (:error-type varjo-error :prefix "Varjo Bug") (vtype) "Compiler bug: Attempted to find the dimensions of ~a. If you have the time, please report this on github." vtype)