j14i/cl-macros huggingface dataset:
Generate a defmacro form that transforms code like this:
(declare-deprecated-operators nil :key nil)

Pattern to recognize: Macro call that should be transformed by DECLARE-DEPRECATED-OPERATORS

Macro definition:
(defmacro DECLARE-DEPRECATED-OPERATORS ...)

Macroexpansion:
(eval-when (:compile-toplevel :load-toplevel :execute)
  (define-compiler-macro nil
      (&whole form &rest arguments)
    (declare (ignore arguments))
    (let ((where-from (or *compile-file-truename* *load-truename*)))
      (when *deprecation-warnings*
        (warn 'deprecation-warning :operator-name 'nil :source-file where-from
              :source-form form))
      (when where-from
        (pushnew where-from (gethash 'nil *deprecation-locations*) :test
                 #'equalp))
      form))
  (define-compiler-macro :key
      (&whole form &rest arguments)
    (declare (ignore arguments))
    (let ((where-from (or *compile-file-truename* *load-truename*)))
      (when *deprecation-warnings*
        (warn 'deprecation-warning :operator-name ':key :source-file where-from
              :source-form form))
      (when where-from
        (pushnew where-from (gethash ':key *deprecation-locations*) :test
                 #'equalp))
      form))
  (define-compiler-macro nil
      (&whole form &rest arguments)
    (declare (ignore arguments))
    (let ((where-from (or *compile-file-truename* *load-truename*)))
      (when *deprecation-warnings*
        (warn 'deprecation-warning :operator-name 'nil :source-file where-from
              :source-form form))
      (when where-from
        (pushnew where-from (gethash 'nil *deprecation-locations*) :test
                 #'equalp))
      form))
  (values))
Create a Common Lisp macro for the following transformation. Before code:
(defaction nil
    :key
  nil)

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

Macro definition:
(defmacro DEFACTION ...)

Macroexpansion:
(setf (gethash #A((3) base-char . "NIL") cl-rules.core::*actions*)
        (lambda :key nil))
You are a Common Lisp macro expert. Given this code pattern:
;; Regex matching with captures requires manual multiple-value-bind
(multiple-value-bind (matchp captures)
    (cl-ppcre:scan-to-strings "_(\\w+)@(\\w+)\\.com_" email)
  (if matchp
      (let ((user (aref captures 0))
            (domain (aref captures 1)))
        (format t "~a at ~a~%" user domain))
      :invalid))

;; Verbose: bind result, extract captures by index, branch - repetitive

Write a macro that addresses: Regex matching with named captures requires verbose destructuring — want $1, $2, ... anaphors bound to capture groups

Macro definition:
#+cl-ppcre
(defun dollar-symbol-p (s)
  (and (symbolp s)
       (> (length (symbol-name s)) 1)
       (string= (symbol-name s)
                "$"
                :start1 0
                :end1 1)
       (ignore-errors (parse-integer (subseq (symbol-name s) 1)))))

(defmacro! if-match ((match-regex str) then &optional else)
  (let* ((dollars (remove-duplicates
                   (remove-if-not #'dollar-symbol-p
                                  (flatten then))))
         (top (or (car (sort (mapcar #'dollar-symbol-p dollars) #'>))
                  0)))
    `(multiple-value-bind (,g!matches ,g!captures) (,match-regex ,str)
       (declare (ignorable ,g!matches ,g!captures))
       (let ((,g!captures-len (length ,g!captures)))
         (declare (ignorable ,g!captures-len))
         (symbol-macrolet ,(mapcar #`(,(symb "$" a1)
                                       (if (< ,g!captures-len ,a1)
                                           (error "Too few matchs: ~a unbound." ,(mkstr "$" a1))
                                           (aref ,g!captures ,(1- a1))))
                                   (loop for i from 1 to top collect i))
           (if ,g!matches
               ,then
               ,else))))))

Macroexpansion:
;; (if-match (#~m_(\\w+)@(\\w+)\\.com_ email)
;;   (format t "~a at ~a~%" $1 $2)
;;   :invalid)
;;
;; $1, $2 bound to capture groups via symbol-macrolet
;; Out-of-bounds $N signals a clear error at runtime
;; Nested if-match works - each has its own capture bindings
Generate a defmacro form that transforms code like this:
(deferror "08P01" protocol-violation)

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 protocol-violation (database-error) nil) (setf (gethash "08P01" *error-table*) (quote protocol-violation)))
You are a Common Lisp macro expert. Given this code pattern:
(collect-last 'some-name)

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

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

Macroexpansion:
(common-lisp:let* ((#:generator-533 (generator 'some-name))
                   #:items-527
                   (#:item-529 nil))
  (declare (type generator #:generator-533)
           (type (null-or t) #:item-529))
  (tagbody
   #:ll-534
    (setq #:items-527 (next-in #:generator-533 (go end)))
    (setq #:item-529 #:items-527)
    (go #:ll-534)
   end)
  #:item-529)
You are a Common Lisp macro expert. Given this code pattern:
(lexpr-$send nil (progn))

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

Macro definition:
(defmacro LEXPR-$SEND ...)

Macroexpansion:
(apply #'send-message nil (progn))
Create a Common Lisp macro for the following transformation. Before code:
(cond-<>>
  nil
  (progn))

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

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

Macroexpansion:
(let* ((#:var157 nil)
       (#:var158
        (if progn
            (-<>>
              #:var157)
            #:var157)))
  #:var158)
Generate a defmacro form that transforms code like this:
(set-bop nil :key nil)

Pattern to recognize: Macro call that should be transformed by SET-BOP

Macro definition:
(defmacro SET-BOP ...)

Macroexpansion:
(eval-when (:load-toplevel :compile-toplevel :execute)
  (progn
   (save-binfix)
   (mapc
    (lambda (ops)
      (mapc
       (lambda (op1)
         (when (eq (car op1) 'nil)
           (setf (cadr op1) ':key)
           (unless nil (setf (cddr op1) '(nil)))))
       ops))
    *binfix*)
   (assign-properties)))
Generate a defmacro form that transforms code like this:
(define-modf-rewrite caar (expr) `(car (car ,(second expr))))

Pattern to recognize: 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 caar) *modf-rewrites*) (lambda (expr) (sb-int:quasiquote (car (car #S(sb-impl::comma :expr (second expr) :kind 0)))))))
Write a Common Lisp macro to handle this code pattern:
(c?-with-stored (v :bar store 'nothing) (bwhen (val (value v)) (1- val)))

Problem: Macro call that should be transformed by c?-with-stored

Macro definition:
(defmacro c?-with-stored ((var key store &optional default) &body body)
  `(c? (bwhen-c-stored (,var ,key ,store ,default)
	 ,@body)))

Macroexpansion:
(c? (bwhen-c-stored (v :bar store (quote nothing)) (bwhen (val (value v)) (1- val))))
Define a macro that eliminates this repetitive pattern:
(with-hamt set (:test test :hash hash :table table) (flet ((%remove (table x) (%hamt-remove table x (funcall hash x) 0 test))) (make-instance 'hash-set :test test :hash hash :table (reduce #'%remove xs :initial-value table))))

Issue: Macro call that should be transformed by with-hamt

Macro definition:
(defmacro with-hamt (hamt (&key test hash table) &body body)
  "Accessing HAMT slots"
  `(with-accessors ((,test hamt-test)
                    (,hash hamt-hash)
                    (,table hamt-table))
       ,hamt
     ,@body))

Macroexpansion:
(with-accessors ((test hamt-test) (hash hamt-hash) (table hamt-table)) set (flet ((%remove (table x) (%hamt-remove table x (funcall hash x) 0 test))) (make-instance (quote hash-set) :test test :hash hash :table (reduce (function %remove) xs :initial-value table))))
Write a Common Lisp macro to handle this code pattern:
(fmap #'1+ (ok (in "") 1))

Problem: Macro call that should be transformed by fmap

Macro definition:
(defmacro fmap (f thing)
  "Apply a pure function to the inner contents of some parsing operation, if the
parsing itself was successful."
  `(multiple-value-bind (res next) ,thing
     (if (failure? res)
         (fail next)
         (values (funcall ,f res) next))))

Macroexpansion:
(multiple-value-bind (res next) (ok (in "") 1) (if (failure? res) (fail next) (values (funcall (function 1+) res) next)))
You are a Common Lisp macro expert. Given this code pattern:
(dict-of nil :key nil)

Write a macro that addresses: Macro call that should be transformed by DICT-OF

Macro definition:
(defmacro DICT-OF ...)

Macroexpansion:
(let ((#:dict131 (make-hash-table :test 'equal)))
  (do-for (:key nil)
    (multiple-value-call
        (lambda (#:k132 #:v133) (setf (gethash #:k132 #:dict131) #:v133))
      nil))
  #:dict131)
Write a Common Lisp macro to handle this code pattern:
(define-op (:not-in infix-list-op))

Problem: 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 (not-in-op (:include infix-list-op (name "NOT IN")) (:constructor make-not-in-op (left right))))
You are a Common Lisp macro expert. Given this code pattern:
(defhandler catch (catch tag &rest body) `(list ',catch ,(e tag) ,@(e-list body)))

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

Macro definition:
(defmacro defhandler (symbol lambda-list &body body)
  (let ((syms (force-list symbol)))
    (let ((func (intern (format nil "~A~A" 'hander- (first syms)))))
      `(progn
         (defun ,func ,lambda-list
           ,@body)
         (setf
          ,@(loop for sym in syms
               collect `(gethash ',sym *form-handler*)
               collect `',func))))))

Macroexpansion:
(progn (defun hander-catch (catch tag &rest body) (sb-int:quasiquote (list (quote #S(sb-impl::comma :expr catch :kind 0)) #S(sb-impl::comma :expr (e tag) :kind 0) #S(sb-impl::comma :expr (e-list body) :kind 2)))) (setf (gethash (quote catch) *form-handler*) (quote hander-catch)))
Define a macro that eliminates this repetitive pattern:
(define-mustache-character #\> (make-instance 'partial-tag :text arg-text))

Issue: Macro call that should be transformed by define

Macro definition:
(defmacro define (name template)
  "Define a named renderer of string TEMPLATE."
  `(setf (symbol-function ',name)
         (compile-template ,template)))

Macroexpansion:
(set-mustache-character #\GREATER-THAN_SIGN (lambda (raw-text arg-text escapep start end) (declare (ignorable raw-text arg-text escapep start end) (type simple-string raw-text arg-text) (boolean escapep) (offset start end)) (make-instance (quote partial-tag) :text arg-text)))
Define a macro that eliminates this repetitive pattern:
(defannotation annotation (options function-definition-form) (:arity 2) (let ((name (definition-form-symbol (progn-form-last function-definition-form)))) `(progn (set-annotation-options ',name ',options) ,function-definition-form)))

Issue: Macro call that should be transformed by defannotation

Macro definition:
(defmacro defannotation (name lambda-list options &body body)
  `(progn
     (set-annotation-options ',name ',options)
     (defmacro ,name ,lambda-list ,@body)))

Macroexpansion:
(progn (set-annotation-options (quote annotation) (quote (:arity 2))) (defmacro annotation (options function-definition-form) (let ((name (definition-form-symbol (progn-form-last function-definition-form)))) (sb-int:quasiquote (progn (set-annotation-options (quote #S(sb-impl::comma :expr name :kind 0)) (quote #S(sb-impl::comma :expr options :kind 0))) #S(sb-impl::comma :expr function-definition-form :kind 0))))))
Generate a defmacro form that transforms code like this:
(enable-sharp-number-syntax)

Pattern to recognize: Macro call that should be transformed by ENABLE-SHARP-NUMBER-SYNTAX

Macro definition:
(defmacro ENABLE-SHARP-NUMBER-SYNTAX ...)

Macroexpansion:
(eval-when (:compile-toplevel :execute)
  (setf *readtable* (copy-readtable *readtable*))
  (set-sharp-number-syntax-in-readtable)
  (values))
Generate a defmacro form that transforms code like this:
(define-bug no-args-remove-in-unrep-inlining () (func args args-code) " Sorry that you have hit this bug, if you have time please copy this error, your stack trace and (if possible) the code that triggered this error and raise an issue at https://github.com/cbaggers/varjo/issues Thankyou, and our apologies. ---- When trying to compile the function ~a we knew we had to inline as a local function to to one of the arguments being of an unrepresentable type. However No arguments were identified for moving from the function to the surrounding let. func: ~a args: ~a args-code: ~a " (slot-value func 'name) func args args-code)

Pattern to recognize: 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 no-args-remove-in-unrep-inlining (:error-type varjo-error :prefix "Varjo Bug") (func args args-code) " Sorry that you have hit this bug, if you have time please copy this error, your stack trace and (if possible) the code that triggered this error and raise an issue at https://github.com/cbaggers/varjo/issues Thankyou, and our apologies. ---- When trying to compile the function ~a we knew we had to inline as a local function to to one of the arguments being of an unrepresentable type. However No arguments were identified for moving from the function to the surrounding let. func: ~a args: ~a args-code: ~a " (slot-value func (quote name)) func args args-code)
Write a Common Lisp macro to handle this code pattern:
(do-combinations 'some-name)

Problem: Macro call that should be transformed by DO-COMBINATIONS

Macro definition:
(defmacro DO-COMBINATIONS ...)

Macroexpansion:
(progn)
You are a Common Lisp macro expert. Given this code pattern:
(false NIL)

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

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

Macroexpansion:
(eval-in-context *context* (make-instance (quote comparison-result) :expression (quote (false nil)) :value-form (quote nil) :body (lambda nil nil) :expected (quote nil) :comparison (quote geq)))
Create a Common Lisp macro for the following transformation. Before code:
(defjs map3() (emit this.name (ps:create :count 1)))

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

Macro definition:
(defmacro defjs (name args &body body)
  "Define client side javascript. Works like defun; body is in lisp, with parenscript
   additions, like return. So (defjs hello (x y) (return (+ x y))) defines an adder. 
   macro creates a lisp function which sends the javascript function over to the mongo 
   server to be evaluated. Result is processed and returned to the reader. 
   This will execute 10 times on the server :
   (mapcar (lambda (x) (hello 10 x)) (list 1 2 3 4 5 6 7 8 9 10))"
  `(let* ((js-body (parenscript:ps (lambda ,args ,@body))))
     (setf (gethash ',name *js-definitions*) js-body)
     (defun ,name ,args
       (get-element "retval" (car (docs (db.eval js-body ,@args)))))))

Macroexpansion:
(let* ((js-body (parenscript:ps (lambda nil (emit this.name (parenscript:create :count 1)))))) (setf (gethash (quote map3) *js-definitions*) js-body) (defun map3 nil (get-element "retval" (car (docs (db.eval js-body))))))
Define a macro that eliminates this repetitive pattern:
(define-error stage-order-error () (stage-type) "stage of type ~s is not valid at this place in the pipeline, this is either out of order or a stage of this type already exists" stage-type)

Issue: 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 stage-order-error (:error-type varjo-error :prefix "Varjo") (stage-type) "stage of type ~s is not valid at this place in the pipeline, this is either out of order or a stage of this type already exists" stage-type)
You are a Common Lisp macro expert. Given this code pattern:
(c-assert fm-parent)

Write a macro that addresses: 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 fm-parent (c-break "failed assertion: ~a" (quote fm-parent))))
Define a macro that eliminates this repetitive pattern:
(letv)

Issue: Macro call that should be transformed by LETV

Macro definition:
(defmacro LETV ...)

Macroexpansion:
(block nil)
Generate a defmacro form that transforms code like this:
(define-error symbol-unidentified (:error-type varjo-critical-error) (sym) "Symbol '~s' is unidentified. ~@[However the symbol is valid in these stages: ~{~%- ~a~}~]" sym (mapcar #'string-downcase (mapcar #'string (find-stages-that-have-var sym))))

Pattern to recognize: 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 symbol-unidentified (:error-type varjo-critical-error :prefix "Varjo") (sym) "Symbol '~s' is unidentified. ~@[However the symbol is valid in these stages: ~{~%- ~a~}~]" sym (mapcar (function string-downcase) (mapcar (function string) (find-stages-that-have-var sym))))
Create a Common Lisp macro for the following transformation. Before code:
(defannotation doc (docstring definition-form) (:arity 2) "Add DOCSTRING documentation for DEFINITION-FORM." (progn-form-replace-last (lambda (definition-form) (case (definition-form-type definition-form) ((defvar defparameter defconstant defun defmethod defmacro deftype define-compiler-macro) (destructuring-bind (def name arg . body) definition-form `(,def ,name ,arg ,docstring ,@body))) ((defstruct) (destructuring-bind (def name-and-options . slots) definition-form `(,def ,name-and-options ,docstring ,@slots))) ((defclass define-condition) (destructuring-bind (def name supers slots . opts) definition-form (pushnew `(:documentation ,docstring) opts :key #'car) `(,def ,name ,supers ,slots ,@opts))) ((defgeneric) (destructuring-bind (def name args . opts) definition-form (pushnew `(:documentation ,docstring) opts :key #'car) `(,def ,name ,args ,@opts))) (t (error "Documentation not supported: ~a" definition-form)))) definition-form))

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

Macro definition:
(defmacro defannotation (name lambda-list options &body body)
  `(progn
     (set-annotation-options ',name ',options)
     (defmacro ,name ,lambda-list ,@body)))

Macroexpansion:
(progn (set-annotation-options (quote doc) (quote (:arity 2))) (defmacro doc (docstring definition-form) "Add DOCSTRING documentation for DEFINITION-FORM." (progn-form-replace-last (lambda (definition-form) (case (definition-form-type definition-form) ((defvar defparameter defconstant defun defmethod defmacro deftype define-compiler-macro) (destructuring-bind (def name arg . body) definition-form (sb-int:quasiquote (#S(sb-impl::comma :expr def :kind 0) #S(sb-impl::comma :expr name :kind 0) #S(sb-impl::comma :expr arg :kind 0) #S(sb-impl::comma :expr docstring :kind 0) #S(sb-impl::comma :expr body :kind 2))))) ((defstruct) (destructuring-bind (def name-and-options . slots) definition-form (sb-int:quasiquote (#S(sb-impl::comma :expr def :kind 0) #S(sb-impl::comma :expr name-and-options :kind 0) #S(sb-impl::comma :expr docstring :kind 0) #S(sb-impl::comma :expr slots :kind 2))))) ((defclass define-condition) (destructuring-bind (def name supers slots . opts) definition-form (pushnew (sb-int:quasiquote (:documentation #S(sb-impl::comma :expr docstring :kind 0))) opts :key (function car)) (sb-int:quasiquote (#S(sb-impl::comma :expr def :kind 0) #S(sb-impl::comma :expr name :kind 0) #S(sb-impl::comma :expr supers :kind 0) #S(sb-impl::comma :expr slots :kind 0) #S(sb-impl::comma :expr opts :kind 2))))) ((defgeneric) (destructuring-bind (def name args . opts) definition-form (pushnew (sb-int:quasiquote (:documentation #S(sb-impl::comma :expr docstring :kind 0))) opts :key (function car)) (sb-int:quasiquote (#S(sb-impl::comma :expr def :kind 0) #S(sb-impl::comma :expr name :kind 0) #S(sb-impl::comma :expr args :kind 0) #S(sb-impl::comma :expr opts :kind 2))))) (t (error "Documentation not supported: ~a" definition-form)))) definition-form)))
Define a macro that eliminates this repetitive pattern:
(psetf)

Issue: Macro call that should be transformed by PSETF

Macro definition:
(defmacro PSETF ...)

Macroexpansion:
nil