j14i/cl-macros huggingface dataset:
Generate a defmacro form that transforms code like this:
(with-wcs-math-error-handling (ret (sin x)) (check-wcs-math-result))

Pattern to recognize: Macro call that should be transformed by with-wcs-math-error-handling

Macro definition:
(defmacro with-wcs-math-error-handling
    ((var-or-var-list
      (function x &optional (y nil y-supplied-p))
      &rest keyargs
      &key underflow-value)
     &body body)
  (declare (ignorable underflow-value))
  (let ((x_ (gensym)) (y_ (gensym)) (args_ (gensym))
        (var-list (ensure-list var-or-var-list)))
    `(let* ((,x_ ,x)
            (,y_ ,y)
            (,args_ (list ,x_ ,@(if y-supplied-p `(,y_)))))
       (declare (ignorable ,y_)
                (type list ,args_)
                (dynamic-extent ,args_))
       (catch 'return-from-with-wcs-math-error-handling
         (multiple-value-bind ,var-list
             (call-with-wcs-math-error-handler ',function ,args_
                                               ,@keyargs)
           (flet ((check-wcs-math-result
                      (&optional (ret ,(first var-list))
                                 (arg-list ,args_))
                    (check-wcs-math-result ret arg-list)))
             ,@body))))))

Macroexpansion:
(let* ((#:g212 x) (#:g213 nil) (#:g214 (list #:g212))) (declare (ignorable #:g213) (type list #:g214) (dynamic-extent #:g214)) (catch (quote return-from-with-wcs-math-error-handling) (multiple-value-bind (ret) (call-with-wcs-math-error-handler (quote sin) #:g214) (flet ((check-wcs-math-result (&optional (ret ret) (arg-list #:g214)) (check-wcs-math-result ret arg-list))) (check-wcs-math-result)))))
Write a Common Lisp macro to handle this code pattern:
(when (eql (first body) :init) (setf initializer (second body)) (setf body (rest (rest body))))

Problem: Macro call that should be transformed by when

Macro definition:
(defmacro when (test &body forms)
  `(if ,test
	   ,(cl:if (cadr forms)
			   `(progn ,@forms)
			   (car forms))))

Macroexpansion:
(if (eql (first body) :init) (progn (setf initializer (second body)) (setf body (rest (rest body)))))
Define a macro that eliminates this repetitive pattern:
(orf (slot-value self 'category-cache) (make-hash-table :test 'equal))

Issue: Macro call that should be transformed by orf

Macro definition:
(defmacro orf (location form &environment env)
  (multiple-value-bind (vars values new setter getter)
      (get-setf-expansion location env)
    (when (cdr new)
      (error "Can't work with setf-expansion for ~s - ~d values from setter ~s"
             location (length new) new))
    (let ((current (car new)))
      `(let* (,@(mapcar 'list vars values)
              (,current ,getter))
         (or ,current
             (progn (setf ,current ,form)
               ,setter))))))

Macroexpansion:
(let* ((#:self130 self) (#:new129 (slot-value #:self130 (quote category-cache)))) (or #:new129 (progn (setf #:new129 (make-hash-table :test (quote equal))) (sb-pcl::set-slot-value #:self130 (quote category-cache) #:new129))))
Generate a defmacro form that transforms code like this:
(defclause (finding expr maximizing max-expr &optional into variable) "Return value which maximizes expression" (return-find-extremum-code expr max-expr variable :max))

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

Macro definition:
(defmacro defclause (clause-template &body body)
  (define-clause 'defun clause-template body nil))

Macroexpansion:
(eval-when (:compile-toplevel :load-toplevel :execute) (defun clause-finding-maximizing-16 (&key ((:finding expr)) ((:maximizing max-expr)) ((:into variable))) "Return value which maximizes expression" (return-find-extremum-code expr max-expr variable :max)) (install-clause-info (quote (finding :maximizing)) (quote (finding :maximizing &optional :into)) (quote clause-finding-maximizing-16) "Return value which maximizes expression" nil) (quote (finding expr maximizing max-expr &optional into variable)))
Generate a defmacro form that transforms code like this:
(with-preprocessor-state-slots (state) (unless (token-equal-p (pop-preprocessor-directive-token token-list :|_Pragma|) "(") (error 'preprocess-error :format-control "~A should be followed by '('" :format-arguments (list :|_Pragma|))) (let ((pragma-string (pop-preprocessor-directive-token token-list :|_Pragma|))) (unless (stringp pragma-string) (error 'preprocess-error :format-control "~A argument '~A' is not a string." :format-arguments (list :|_Pragma| pragma-string))) (unless (token-equal-p (pop-preprocessor-directive-token token-list :|_Pragma|) ")") (error 'preprocess-error :format-control "~A should be ended by ')'" :format-arguments (list :|_Pragma|))) (let ((pragma-tokens (with-input-from-string (stream pragma-string) (tokenize-source stream nil)))) (process-preprocessing-directive 'with-c-syntax.preprocessor-directive:|pragma| pragma-tokens state))))

Pattern to recognize: Macro call that should be transformed by with-preprocessor-state-slots

Macro definition:
(defmacro with-preprocessor-state-slots ((state) &body body)
  `(with-accessors ((file-pathname pp-state-file-pathname)
                    (token-list pp-state-token-list)
                    (result-list pp-state-result-list)
                    (line-number pp-state-line-number)
                    (tokens-in-line pp-state-tokens-in-line)
                    (macro-alist pp-state-macro-alist)
                    (if-section-stack pp-state-if-section-stack)
                    (if-section-skip-reason pp-state-if-section-skip-reason)
                    (include-stack pp-state-include-stack))
       ,state
     ,@body))

Macroexpansion:
(with-accessors ((file-pathname pp-state-file-pathname) (token-list pp-state-token-list) (result-list pp-state-result-list) (line-number pp-state-line-number) (tokens-in-line pp-state-tokens-in-line) (macro-alist pp-state-macro-alist) (if-section-stack pp-state-if-section-stack) (if-section-skip-reason pp-state-if-section-skip-reason) (include-stack pp-state-include-stack)) state (unless (token-equal-p (pop-preprocessor-directive-token token-list :|_Pragma|) "(") (error (quote preprocess-error) :format-control "~A should be followed by '('" :format-arguments (list :|_Pragma|))) (let ((pragma-string (pop-preprocessor-directive-token token-list :|_Pragma|))) (unless (stringp pragma-string) (error (quote preprocess-error) :format-control "~A argument '~A' is not a string." :format-arguments (list :|_Pragma| pragma-string))) (unless (token-equal-p (pop-preprocessor-directive-token token-list :|_Pragma|) ")") (error (quote preprocess-error) :format-control "~A should be ended by ')'" :format-arguments (list :|_Pragma|))) (let ((pragma-tokens (with-input-from-string (stream pragma-string) (tokenize-source stream nil)))) (process-preprocessing-directive (quote with-c-syntax.preprocessor-directive:|pragma|) pragma-tokens state))))
Generate a defmacro form that transforms code like this:
(define nil
  :key
  nil)

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

Macro definition:
(defmacro DEFINE ...)

Macroexpansion:
(eval-when (:load-toplevel :execute)
  (check-if-bound 'nil)
  (setf (get 'nil 'read-macro)
          (lambda (#:stream148)
            (let ((*standard-input* #:stream148))
              :key
              nil)))
  'nil)
You are a Common Lisp macro expert. Given this code pattern:
(dotable (item _ set1) (when (gethash item set2) (add# item set)))

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

Macro definition:
(defmacro dotable ((k v table &optional rez) &body body)
  "Like DOLIST but iterates over key-value pairs (K V) in anything, that can be
   viewed as a table (hash-table, alist, plist, object).
   Autodeclares variables named _ as ignored."
  (with-gensyms (pair)
    (once-only (table)
      (let ((_ (find "_" (list k v)
                     :test 'string=
                     :key 'symbol-name)))
        `(block nil
           (etypecase ,table
             (hash-table (maphash (lambda (,k ,v)
                                    ,(when _ `(declare (ignore rutils.bind:_)))
                                    ,@body)
                                  ,table))

             (list (if (rutils.list:alistp ,table)
                       (dolist (,pair ,table)
                         (destructuring-bind (,k . ,v) ,pair
                           ,@(when _ `((declare (ignore ,_))))
                           ,@body))
                       (error 'simple-type-error
                              :format-control "Can't iterate over proper list ~
                                               in DOTABLE: need an alist"))))
           ,rez)))))

Macroexpansion:
(let ((#:table162 set1)) (block nil (etypecase #:table162 (hash-table (maphash (lambda (item _) (declare (ignore rutils.bind:_)) (when (gethash item set2) (|ADD#| item set))) #:table162)) (list (if (alistp #:table162) (dolist (#:g161 #:table162) (destructuring-bind (item . _) #:g161 (declare (ignore _)) (when (gethash item set2) (|ADD#| item set)))) (error (quote simple-type-error) :format-control "Can't iterate over proper list ~
                                               in DOTABLE: need an alist")))) nil))
Create a Common Lisp macro for the following transformation. Before code:
(for nil
    :key
  nil)

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

Macro definition:
(defmacro FOR ...)

Macroexpansion:
(let ((#:|generator!122| :key))
  (assert (typep #:|generator!122| 'generator!))
  (unwind-protect
      (loop :while (has-next-p #:|generator!122|)
            :do (let ((nil (next #:|generator!122|)))
                  nil)))
  (stop #:|generator!122|))
Write a Common Lisp macro to handle this code pattern:
(fmap #'char-upcase (any (in "hello")))

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) (any (in "hello")) (if (failure? res) (fail next) (values (funcall (function char-upcase) res) next)))
Write a Common Lisp macro to handle this code pattern:
(binary-reader ((usec-bits uint 8)) (funcall f (interpret-usec-bits usec-bits)))

Problem: Macro call that should be transformed by binary-reader

Macro definition:
(defmacro binary-reader (fields &body value)
  "A slightly convoluted macro for defining interpreter functions. It
allows two forms. The first is to pass a single type identifier, in
which case a value of this type will be read and returned directly.
The second is to pass a list of lists containing names and types, and
then a body. In this case the names will be bound to values read from
the socket and interpreted as the given types, and then the body will
be run in the resulting environment. If the last field is of type
bytes, string, or uint2s, all remaining data will be read and
interpreted as an array of the given type."
  (let ((stream-name (gensym))
        (size-name (gensym))
        (length-used 0))
    (flet ((read-type (type &optional modifier)
             (ecase type
               (bytes `(read-bytes ,stream-name (- ,size-name ,length-used)))
               (string `(enc-read-string ,stream-name
                                         :byte-length (- ,size-name ,length-used)))
               (uint2s `(let* ((size (/ (- ,size-name ,length-used) 2))
                               (result
                                 (make-array size
                                             :element-type '(unsigned-byte 16)
                                             :initial-element 0)))
                          (dotimes (i size)
                            (setf (elt result i) (read-uint2 ,stream-name)))
                          result))
               (int (assert (integerp modifier))
                (incf length-used modifier)
                `(,(integer-reader-name modifier t) ,stream-name))
               (uint (assert (integerp modifier))
                (incf length-used modifier)
                `(,(integer-reader-name modifier nil) ,stream-name)))))
      `(lambda (,stream-name ,size-name)
         (declare (type stream ,stream-name)
                  (type integer ,size-name)
                  (ignorable ,size-name))
         ,(if (consp fields)
              (progn
                `(let ,(loop :for field :in fields
                            :collect `(,(first field)
                                       ,(apply #'read-type (cdr field))))
                  ,@value))
              (read-type fields (car value)))))))

Macroexpansion:
(lambda (#:g210 #:g211) (declare (type stream #:g210) (type integer #:g211) (ignorable #:g211)) (let ((usec-bits (read-uint8 #:g210))) (funcall f (interpret-usec-bits usec-bits))))
Generate a defmacro form that transforms code like this:
(infix 'some-name)

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

Macro definition:
(defmacro INFIX ...)

Macroexpansion:
'some-name
Define a macro that eliminates this repetitive pattern:
(lambda* 'some-name)

Issue: Macro call that should be transformed by LAMBDA*

Macro definition:
(defmacro LAMBDA* ...)

Macroexpansion:
(lambda (quote some-name) (the t nil))
You are a Common Lisp macro expert. Given this code pattern:
(define-op (:- conjunctive-op :sql-op-name "-"))

Write a macro that addresses: 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 (--op (:include conjunctive-op (name "-")) (:constructor make---op (&rest expressions))))
You are a Common Lisp macro expert. Given this code pattern:
(bind (((:slots-read-only a (my-c c) (the-b b)) (make-instance 'metabang-bind-class-1 :a 1 :b 2 :c 3))) (list a the-b my-c))

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

Macro definition:
(defmacro bind ((&rest bindings) &body body)
  "Bind is a replacement for let*, destructuring-bind, multiple-value-bind and more. 

An example is probably the best way to describe its syntax:

    \(bind \(\(a 2\)
           \(\(b &rest args &key \(c 2\) &allow-other-keys\) '\(:a :c 5 :d 10 :e 54\)\)
           \(\(:values d e\) \(truncate 4.5\)\)
           \(\(:structure xxx- slot1 slot2\) \(make-xxx\)\)
           \(\(:flet name \(arg1 arg2\)\) \(+ arg1 arg2\)\)\)
         \(list a b c d e args\)\)

Simple bindings are as in let*. Destructuring is done if the first item
in a binding is a list. Multiple value binding is done if the first item
in a binding is a list and the first item in the list is ':values'. Other
forms have their own syntax. For example, :structure first has the conc
name and then slot names whereas :flet has the function name and a list
of arguments and then the function body (in an implicit progn)."
  (let (declarations)
    (loop while (and (consp (car body)) (eq (caar body) 'declare)) do
          (push (first body) declarations)
          (setf body (rest body)))
    (if bindings
	(let ((*all-declarations* (bind-expand-declarations (nreverse declarations))))
	  (prog1
	      (bind-macro-helper bindings body)
	    (check-for-unused-variable-declarations *all-declarations*)))
        `(locally
             ,@declarations
           ,@body))))

Macroexpansion:
(let* ((#:|values-170| (make-instance (quote metabang-bind-class-1) :a 1 :b 2 :c 3)) (a (slot-value #:|values-170| (quote a))) (my-c (slot-value #:|values-170| (quote c))) (the-b (slot-value #:|values-170| (quote b)))) (declare (ignorable #:|values-170|)) (progn (list a the-b my-c)))
Create a Common Lisp macro for the following transformation. Before code:
(define-alias nil
    (progn))

What needs to change: Macro call that should be transformed by DEFINE-ALIAS

Macro definition:
(defmacro DEFINE-ALIAS ...)

Macroexpansion:
(progn
 (macrolet ((thunk ()
              (let ((progn 'progn)))))
   (defun nil (progn) nil (thunk)))
 (define-compiler-macro nil
     (progn)
   nil
   `(let ,(list (list '#:progn124 progn))
      ,(let ((progn '#:progn124))))))
Create a Common Lisp macro for the following transformation. Before code:
(defsyntax nil)

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

Macro definition:
(defmacro defsyntax (name &body options)
  `(progn
     (setf (get ',name :options) ',options)
     (defvar ,name (defreadtable ,name ,@options))))

Macroexpansion:
(progn (setf (get 'nil :options) 'nil) (defvar nil (defreadtable nil)))
Define a macro that eliminates this repetitive pattern:
(dolist (quote some-name))

Issue: Macro call that should be transformed by DOLIST

Macro definition:
(defmacro DOLIST ...)

Macroexpansion:
(block nil
  (let ((#:list186
         (sb-kernel:the* (list :use-annotations t :source-form some-name)
                         some-name)))
    (tagbody
     #:start187
      (unless (endp #:list186)
        (let ((quote (car #:list186)))
          (declare (ignorable quote))
          (setq #:list186 (cdr #:list186))
          (tagbody))
        (go #:start187)))))
Write a Common Lisp macro to handle this code pattern:
(do-subclasses (itype index) (publish itype))

Problem: Macro call that should be transformed by do-subclasses

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

Macroexpansion:
(let ((#:klasses286 (all-subclasses (find-class (quote index))))) (loop for itype in #:klasses286 do (publish itype)))
Generate a defmacro form that transforms code like this:
(define-cruft %standard-readtable () "Return the standard readtable." #+ :sbcl+safe-standard-readtable sb-impl::*standard-readtable* #+ :common-lisp (copy-readtable nil))

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

Macro definition:
(defmacro define-cruft (name lambda-list &body (docstring . alternatives))
  (assert (typep docstring 'string) (docstring) "Docstring missing!")
  (assert (not (null alternatives)))
  `(progn
     (declaim (inline ,name))
     (defun ,name ,lambda-list ,docstring ,(first alternatives))))

Macroexpansion:
(progn (declaim (inline %standard-readtable)) (defun %standard-readtable nil "Return the standard readtable." (copy-readtable nil)))
Define a macro that eliminates this repetitive pattern:
(collect-min nil)

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

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

Macroexpansion:
(common-lisp:let* ((#:generator-273 (generator nil))
                   #:numbers-267
                   (#:number-269 nil))
  (declare (type generator #:generator-273))
  (tagbody
   #:ll-274
    (setq #:numbers-267 (next-in #:generator-273 (go end)))
    (if (or (null #:number-269) (> #:number-269 #:numbers-267))
        (setq #:number-269 #:numbers-267))
    (go #:ll-274)
   end)
  (if (null #:number-269)
      (setq #:number-269 nil))
  #:number-269)
You are a Common Lisp macro expert. Given this code pattern:
(keep-bops nil (progn))

Write a macro that addresses: Macro call that should be transformed by KEEP-BOPS

Macro definition:
(defmacro KEEP-BOPS ...)

Macroexpansion:
(eval-when (:load-toplevel :compile-toplevel :execute)
  (progn
   (init-binfix)
   (unless nil
     (setq *binfix*
             (delete nil
                     (mapcar
                      (lambda (bs)
                        (setq bs
                                (delete-if
                                 (lambda (b)
                                   (unless (member (car b) '(nil (progn)))
                                     (remprop (car b) 'properties)
                                     t))
                                 bs)))
                      *binfix*)))
     (assign-properties))))
You are a Common Lisp macro expert. Given this code pattern:
(dletf nil
  :key
  nil)

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

Macro definition:
(defmacro DLETF ...)

Macroexpansion:
(special-symbol-progv (with-symbol-access
                        (list))
    (list)
  (locally (declare (special)) :key nil))
You are a Common Lisp macro expert. Given this code pattern:
(with-properties nil
    nil)

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

Macro definition:
(defmacro WITH-PROPERTIES ...)

Macroexpansion:
(let ((#:g133 nil))
  (symbol-macrolet ()))
You are a Common Lisp macro expert. Given this code pattern:
(with-color (:gray :stream stream) (format/indent reporter stream description))

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

Macro definition:
(defmacro with-color ((color &rest args) &body body)
  (cond
    ((or (eq color :gray)
         (eq color :grey))
     `(if *enable-colors*
          (with-gray ,(or (getf args :stream) t) ,@body)
          (progn ,@body)))
    (T `(if *enable-colors*
            (if (or (eq ,color :gray)
                    (eq ,color :grey)
                    (eq ,color cl-colors:+gray+)
                    (eq ,color cl-colors:+grey+))
                (with-gray ,(or (getf args :stream) t) ,@body)
                (cl-ansi-text:with-color (,color ,@args) ,@body))
            (progn ,@body)))))

Macroexpansion:
(if *enable-colors* (with-gray stream (format/indent reporter stream description)) (progn (format/indent reporter stream description)))