j14i/cl-macros huggingface dataset:
Generate a defmacro form that transforms code like this:
(define-cfun c-realloc)

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

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

Macroexpansion:
(progn (defun c-realloc (ptr size) (let ((#:ptr213 ptr)) (declare (ignorable #:ptr213)) (let ((#:size214 size)) (declare (ignorable #:size214)) (cffi-sys:%foreign-funcall "realloc" (:pointer #:ptr213 :unsigned-long-long #:size214 :pointer) :convention :cdecl)))))
Write a Common Lisp macro to handle this code pattern:
(validate-superclass*)

Problem: Macro call that should be transformed by VALIDATE-SUPERCLASS*

Macro definition:
(defmacro VALIDATE-SUPERCLASS* ...)

Macroexpansion:
(progn)
Generate a defmacro form that transforms code like this:
(define-custom-var (:integer *integer-handler*) (constantly 0) "Designator for a function of 1 string argument (integer token).")

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

Macro definition:
(defmacro define-custom-var ((key name) &rest other-args)
  `(eval-when (:compile-toplevel :load-toplevel :execute)
     (progn (pushnew '(,name . ,key) *custom-vars* :test #'equal)
            (defvar ,name ,@other-args))))

Macroexpansion:
(eval-when (:compile-toplevel :load-toplevel :execute) (progn (pushnew (quote (*integer-handler* . :integer)) *custom-vars* :test (function equal)) (defvar *integer-handler* (constantly 0) "Designator for a function of 1 string argument (integer token).")))
Write a Common Lisp macro to handle this code pattern:
(define-inference-rule nil
    (progn))

Problem: Macro call that should be transformed by DEFINE-INFERENCE-RULE

Macro definition:
(defmacro DEFINE-INFERENCE-RULE ...)

Macroexpansion:
(setf (symbol-inference-rules 'nil)
        (sb-int:named-lambda 'nil
            (progn)))
Write a Common Lisp macro to handle this code pattern:
(aif (incf x) it :never)

Problem: Macro call that should be transformed by aif

Macro definition:
(defmacro aif (test then &optional else)
  "Like IF, except binds the result of the test to IT (via LET) for
the scope of the then and else expressions."  
  `(anaphoric if ,test ,then ,else))

Macroexpansion:
(anaphoric if (incf x) it :never)
Define a macro that eliminates this repetitive pattern:
(defmethod nil nil)

Issue: Macro call that should be transformed by DEFMETHOD

Macro definition:
(defmacro DEFMETHOD ...)

Macroexpansion:
(common-lisp:defmethod nil nil)
You are a Common Lisp macro expert. Given this code pattern:
(define-condition/a dbi-notsupported-error (dbi-database-error) ((method-name :initarg :method-name :type (or symbol string))) (:documentation "Exception raised if e.g. commit() is called for a database which do not support transactions.") (:report (lambda (condition stream) (format stream "`~A' isn't supported on the current driver." (slot-value condition 'method-name)))))

Write a macro that addresses: 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-notsupported-error (dbi-database-error) ((method-name :initarg :method-name :type (or symbol string))) (:documentation "Exception raised if e.g. commit() is called for a database which do not support transactions.") (:report (lambda (condition stream) (format stream "`~A' isn't supported on the current driver." (slot-value condition (quote method-name)))))) (deftype <dbi-notsupported-error> nil (quote dbi-notsupported-error)) (setf (find-class (quote <dbi-notsupported-error>)) (find-class (quote dbi-notsupported-error))))
Generate a defmacro form that transforms code like this:
(@ nil (progn))

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

Macro definition:
(defmacro @ ...)

Macroexpansion:
(message-oo.mangle::|PROGN:| nil nil)
Generate a defmacro form that transforms code like this:
(with-prepared-query query (conn (format nil "SELECT 1 FROM sqlite_master WHERE tbl_name = '~A' AND sql LIKE '%AUTOINCREMENT%'" table-name)) (and (first (dbi:fetch (dbi:execute query) :format :values)) t))

Pattern to recognize: 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 "SELECT 1 FROM sqlite_master WHERE tbl_name = '~A' AND sql LIKE '%AUTOINCREMENT%'" table-name) (lambda (query) (and (first (dbi.driver:fetch (dbi.driver:execute query) :format :values)) t)) :use-prepare-cached nil)
You are a Common Lisp macro expert. Given this code pattern:
(c-assert (eq :nascent (c-state c)))

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 (eq :nascent (c-state c)) (c-break "failed assertion: ~a" (quote (eq :nascent (c-state c))))))
Generate a defmacro form that transforms code like this:
(with-disable-handler-restart (handler) (with-hook-restart (setf result (multiple-value-list (apply handler result)))))

Pattern to recognize: Macro call that should be transformed by with-disable-handler-restart

Macro definition:
(defmacro with-disable-handler-restart ((handler) &body body)
  "This is intended to wrap all handler executions."
  `(restart-case
       (progn ,@body)
     (disable-handler ()
       :report
       (lambda (stream)
         (format stream "Disable handler ~a which causes the error." ,handler))
       (disable-hook *hook* ,handler))))

Macroexpansion:
(restart-case (progn (with-hook-restart (setf result (multiple-value-list (apply handler result))))) (disable-handler nil :report (lambda (stream) (format stream "Disable handler ~a which causes the error." handler)) (disable-hook *hook* handler)))
Define a macro that eliminates this repetitive pattern:
(caching-types
  nil
  :key
  nil)

Issue: Macro call that should be transformed by CACHING-TYPES

Macro definition:
(defmacro CACHING-TYPES ...)

Macroexpansion:
(call-with-disjoint-hash
 (lambda ()
   (call-with-subtype-hash
    (lambda ()
      (call-with-equiv-hash
       (lambda () (call-with-subtypep-cache (lambda () nil :key nil))))))))
Create a Common Lisp macro for the following transformation. Before code:
(answer (foo 1) 2)

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

Macro definition:
(defmacro answer (call &body forms)
  (let ((name (if (listp call) (car call) call))
        (sym (gensym)))
    `(if-called
      ',name
      (let ((,sym (fdefinition ',name)))
        (declare (ignorable ,sym))
        (let ((times 0))
          (lambda (&rest args)
            (declare (ignorable args))
            ,(let ((cases
                     `(case (prog1 times (incf times))
                        ,.(loop
                            for i from 0
                            for (form . rest) on forms
                            collect `(,(if rest i T) ,form)))))
               (if (listp call)
                   `(trivia:match args
                     ((list . ,(cdr call)) ,cases)
                     (_ (unhandled)))
                   cases))))))))

Macroexpansion:
(if-called (quote foo) (let ((#:g160 (fdefinition (quote foo)))) (declare (ignorable #:g160)) (let ((times 0)) (lambda (&rest args) (declare (ignorable args)) (trivia.level2:match args ((list 1) (case (prog1 times (incf times)) (t 2))) (_ (unhandled)))))))
You are a Common Lisp macro expert. Given this code pattern:
(define-element-maker :text "text" '(:x :y))

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

Macro definition:
(defmacro define-element-maker (element name required-attributes)
  `(progn
     (defmethod assert-required-attributes ((element (eql ,element)) attributes)
       (declare (ignore element))
       (unless (evenp (length attributes))
         (warn "attribute list may be missing data: ~A" attributes))
       (let ((missing (set-difference ,required-attributes attributes)))
	 (when missing
	   (error 'missing-attributes :message (format nil "~A missing attributes: ~{~A~^ ~}" ,element missing)))))
     (defmethod make-svg-element ((element (eql ,element)) attributes)
       (when *check-required-attributes*
         (assert-required-attributes element attributes))
       (make-instance 'svg-element :name ,name :attributes attributes))))

Macroexpansion:
(progn (defmethod assert-required-attributes ((element (eql :text)) attributes) (declare (ignore element)) (unless (evenp (length attributes)) (warn "attribute list may be missing data: ~A" attributes)) (let ((missing (set-difference (quote (:x :y)) attributes))) (when missing (error (quote missing-attributes) :message (format nil "~A missing attributes: ~{~A~^ ~}" :text missing))))) (defmethod make-svg-element ((element (eql :text)) attributes) (when *check-required-attributes* (assert-required-attributes element attributes)) (make-instance (quote svg-element) :name "text" :attributes attributes)))
You are a Common Lisp macro expert. Given this code pattern:
($/ "[_]*.mr." "i")

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

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

Macroexpansion:
(make-bson-regex (empty-str "[_]*.mr.") "i")
Create a Common Lisp macro for the following transformation. Before code:
(define-value-binding symbols (var package &rest status &aux (iterator (package-iterator package (or status '(:internal :external :inherited)))) next symbol) (declare (type function iterator)) `(multiple-value-bind (,next ,symbol) (funcall ,iterator) (if ,next (setf ,var ,symbol) (end-for))))

What needs to change: Macro call that should be transformed by define-value-binding

Macro definition:
(defmacro define-value-binding (name (var &rest args) &body body)
  (let ((vars (lambda-fiddle:extract-lambda-vars (lambda-fiddle:remove-aux-part args))))
    (emit-binding-definition name var args body :extra-vars vars)))

Macroexpansion:
(define-direct-binding symbols (var package &rest status) (let ((#:iterator164 (gensym #A((8) base-char . "ITERATOR"))) (#:next165 (gensym #A((4) base-char . "NEXT"))) (#:symbol166 (gensym #A((6) base-char . "SYMBOL"))) (#:package162 (gensym #A((7) base-char . "PACKAGE"))) (#:status163 (gensym #A((6) base-char . "STATUS")))) (values* (sb-int:quasiquote (with-interleaving (let* #S(sb-impl::comma :expr (list* (list #:package162 package) (list #:status163 (list* (quote list) status)) (list #:iterator164 (list (quote package-iterator) #:package162 (list (quote or) #:status163 (quote (:internal :external :inherited))))) (list #:next165 nil) (list #:symbol166 nil) (loop for #:var161 in (lambda-fiddle:extract-lambda-vars (enlist var)) collect (list #:var161 nil))) :kind 0) (declare (ignorable #S(sb-impl::comma :expr #:iterator164 :kind 0) #S(sb-impl::comma :expr #:next165 :kind 0) #S(sb-impl::comma :expr #:symbol166 :kind 0) #S(sb-impl::comma :expr #:package162 :kind 0) #S(sb-impl::comma :expr #:status163 :kind 0))) #S(sb-impl::comma :expr (sb-int:quasiquote (declare (type #S(sb-impl::comma :expr (quote function) :kind 0) #S(sb-impl::comma :expr #:iterator164 :kind 0)))) :kind 0)) #S(sb-impl::comma :expr nil :kind 0))) (let ((iterator #:iterator164) (next #:next165) (symbol #:symbol166) (package #:package162) (status #:status163)) (declare (ignorable iterator next symbol package status)) (sb-int:quasiquote (multiple-value-bind (#S(sb-impl::comma :expr next :kind 0) #S(sb-impl::comma :expr symbol :kind 0)) (funcall #S(sb-impl::comma :expr iterator :kind 0)) (if #S(sb-impl::comma :expr next :kind 0) (setf #S(sb-impl::comma :expr var :kind 0) #S(sb-impl::comma :expr symbol :kind 0)) (end-for))))))))
You are a Common Lisp macro expert. Given this code pattern:
(lambda-ematch0 ((list* pattern body) (list* (list pattern) body)))

Write a macro that addresses: Macro call that should be transformed by lambda-ematch0

Macro definition:
(defmacro lambda-ematch0 (&body clauses)
  (alexandria:with-gensyms (arg)
    `(lambda (,arg)
       (ematch0 ,arg
         ,@clauses))))

Macroexpansion:
(lambda (#:arg168) (ematch0 #:arg168 ((list* pattern body) (list* (list pattern) body))))
Write a Common Lisp macro to handle this code pattern:
(with-hamt set (:test test :hash hash :table table) (flet ((%insert (table x) (%set-insert table x (funcall hash x) 0 test))) (make-instance 'hash-set :test test :hash hash :table (reduce #'%insert xs :initial-value table))))

Problem: 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 ((%insert (table x) (%set-insert table x (funcall hash x) 0 test))) (make-instance (quote hash-set) :test test :hash hash :table (reduce (function %insert) xs :initial-value table))))
Write a Common Lisp macro to handle this code pattern:
(collect-min nil nil)

Problem: Macro call that should be transformed by COLLECT-MIN

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

Macroexpansion:
(common-lisp:let* ((#:generator-286 (generator nil))
                   #:items-276
                   (#:generator-284 (generator nil))
                   #:numbers-275
                   (#:number-278 nil)
                   #:result-279)
  (declare (type generator #:generator-286)
           (type generator #:generator-284)
           (type (null-or t) #:result-279))
  (tagbody
   #:ll-287
    (setq #:items-276 (next-in #:generator-286 (go end)))
    (setq #:numbers-275 (next-in #:generator-284 (go end)))
    (if (or (null #:number-278) (> #:number-278 #:numbers-275))
        (setq #:number-278 #:numbers-275
              #:result-279 #:items-276))
    (go #:ll-287)
   end)
  (if (null #:number-278)
      (setq #:result-279 nil))
  #:result-279)
Generate a defmacro form that transforms code like this:
(define-simple-definition-resolver generic-function designator-generic-function-p)

Pattern to recognize: Macro call that should be transformed by define-simple-definition-resolver

Macro definition:
(defmacro define-simple-definition-resolver (class lookup-function &body body)
  (let ((package (gensym "PACKAGE")))
    `(define-definition-resolver ,class (,class ,package)
       (when (ignore-errors ,(if body
                                 `(let ((,(first lookup-function) ,class))
                                    ,@body)
                                 `(,lookup-function ,class)))
         (list (make-instance ',class :designator ,class :package ,package))))))

Macroexpansion:
(define-definition-resolver generic-function (generic-function #:package136) (when (ignore-errors (designator-generic-function-p generic-function)) (list (make-instance (quote generic-function) :designator generic-function :package #:package136))))
Write a Common Lisp macro to handle this code pattern:
(dynamic-relet nil)

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

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

Macroexpansion:
(dynamic-wind
  :proceed
  #:proceed188
  (let ()
    (declare (special))
    (#:proceed188)))
Write a Common Lisp macro to handle this code pattern:
(between (char #\!) (string "Salvē") (char #\!))

Problem: Macro call that should be transformed by between

Macro definition:
(defmacro between (a parser b &key (id nil))
  "A main parser flanked by two other ones. Only the value of the main parser is
kept. Good for parsing backets, parentheses, etc."
  (declare (ignore id))
  `(*> ,a (<* ,parser ,b)))

Macroexpansion:
(*> (char #\EXCLAMATION_MARK) (<* (string "Salvē") (char #\EXCLAMATION_MARK)))
Define a macro that eliminates this repetitive pattern:
(with-decoder-simple-clos-semantics (setf x (decode-json-from-string "{\"x\":1}")) (is (equal (symbol-package (first-bound-slot-name x)) (find-package :keyword))))

Issue: Macro call that should be transformed by with-decoder-simple-clos-semantics

Macro definition:
(defmacro with-decoder-simple-clos-semantics (&body body)
  "Execute BODY in a dynamic environement where the decoder semantics
is such as set by SET-DECODER-SIMPLE-CLOS-SEMANTICS."
  `(with-shadowed-custom-vars
     (set-decoder-simple-clos-semantics)
     ,@body))

Macroexpansion:
(with-shadowed-custom-vars (set-decoder-simple-clos-semantics) (setf x (decode-json-from-string "{\"x\":1}")) (is (equal (symbol-package (first-bound-slot-name x)) (find-package :keyword))))
Generate a defmacro form that transforms code like this:
(dynamic-let nil
  :key
  nil)

Pattern to recognize: Macro call that should be transformed by DYNAMIC-LET

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

Macroexpansion:
(let ()
  (dynamic-wind
    :proceed
    #:g195
    (let ()
      (declare (special))
      (#:g195 :key nil))))
Define a macro that eliminates this repetitive pattern:
(max-of nil)

Issue: Macro call that should be transformed by MAX-OF

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

Macroexpansion:
(lc (nil) maximize)
Generate a defmacro form that transforms code like this:
(defhandler let (let bindings &rest body) (let ((names (loop for binding in bindings collect (force-first binding)))) `(list* ',let (list ,@(loop for binding in bindings collect (if (symbolp binding) `',binding `(list ',(first binding) ,@(e-list (rest binding)))))) (with-imposed-bindings (,let ,names (declare (ignorable ,@names)) (m-list ,@body))))))

Pattern to recognize: 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-let (let bindings &rest body) (let ((names (loop for binding in bindings collect (force-first binding)))) (sb-int:quasiquote (list* (quote #S(sb-impl::comma :expr let :kind 0)) (list #S(sb-impl::comma :expr (loop for binding in bindings collect (if (symbolp binding) (sb-int:quasiquote (quote #S(sb-impl::comma :expr binding :kind 0))) (sb-int:quasiquote (list (quote #S(sb-impl::comma :expr (first binding) :kind 0)) #S(sb-impl::comma :expr (e-list (rest binding)) :kind 2))))) :kind 2)) (with-imposed-bindings (#S(sb-impl::comma :expr let :kind 0) #S(sb-impl::comma :expr names :kind 0) (declare (ignorable #S(sb-impl::comma :expr names :kind 2))) (m-list #S(sb-impl::comma :expr body :kind 2)))))))) (setf (gethash (quote let) *form-handler*) (quote hander-let)))
Write a Common Lisp macro to handle this code pattern:
(asynchronously (val) (put 2) (flet ((%continue () (continue-flow (+ 1 val)))) (run-it (-> :heh () (funcall #'%continue)))))

Problem: Macro call that should be transformed by asynchronously

Macro definition:
(defmacro asynchronously (lambda-list &body body)
  "Splits current flow allowing manually managing its execution via #'continue-flow and
#'interrupt-flow functions. Consing: ~32 bytes per invocation"
  (with-gensyms (continue-arg condi)
    (flow-lambda-macro (flow-context)
      (let ((fu-body `((flet ((continue-flow (&optional ,continue-arg)
                                (capture-flow-value ,flow-context ,continue-arg)
                                (dispatch-rest ,flow-context))
                              (interrupt-flow (&optional ,condi)
                                (error ,condi)))
                         (declare (ignorable (function continue-flow)
                                             (function interrupt-flow)))
                         ,@body))))
        (with-flow-function-macro (body-fu lambda-list fu-body)
          `(dispatch-asynchronously ,flow-context #',body-fu))))))

Macroexpansion:
(%flow-lambda (#:flow-context151) (%with-flow-function (#:body-fu152 (val) (flet ((continue-flow (&optional #:continue-arg149) (capture-flow-value #:flow-context151 #:continue-arg149) (dispatch-rest #:flow-context151)) (interrupt-flow (&optional #:condi150) (error #:condi150))) (declare (ignorable (function continue-flow) (function interrupt-flow))) (put 2) (flet ((%continue nil (continue-flow (+ 1 val)))) (run-it (-> :heh nil (funcall (function %continue))))))) (dispatch-asynchronously #:flow-context151 (function #:body-fu152))))