j14i/cl-macros huggingface dataset:
Generate a defmacro form that transforms code like this:
(with-wcs-math-error-handling (ret (cos 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* ((#:g209 x) (#:g210 nil) (#:g211 (list #:g209))) (declare (ignorable #:g210) (type list #:g211) (dynamic-extent #:g211)) (catch (quote return-from-with-wcs-math-error-handling) (multiple-value-bind (ret) (call-with-wcs-math-error-handler (quote cos) #:g211) (flet ((check-wcs-math-result (&optional (ret ret) (arg-list #:g211)) (check-wcs-math-result ret arg-list))) (check-wcs-math-result)))))
Create a Common Lisp macro for the following transformation. Before code:
(dlet nil)

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

Macro definition:
(defmacro DLET ...)

Macroexpansion:
(dynamic-let nil)
Define a macro that eliminates this repetitive pattern:
(defmethod nil
  :key
  nil)

Issue: Macro call that should be transformed by DEFMETHOD

Macro definition:
(defmacro DEFMETHOD ...)

Macroexpansion:
(common-lisp:defmethod nil :key ())
Create a Common Lisp macro for the following transformation. Before code:
(xor nil nil 1 nil)

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

Macro definition:
(defmacro xor (&rest datums)
  "Evaluates its arguments one at a time, from left to right. If more than one
argument evaluates to a true value no further DATUMS are evaluated, and NIL is
returned as both primary and secondary value. If exactly one argument
evaluates to true, its value is returned as the primary value after all the
arguments have been evaluated, and T is returned as the secondary value. If no
arguments evaluate to true NIL is returned as primary, and T as secondary
value."
  (with-gensyms (xor tmp true)
    `(let (,tmp ,true)
       (declare (ignorable ,tmp))
       (block ,xor
         ,@(mapcar (lambda (datum)
                     `(if (setf ,tmp ,datum)
                          (if ,true
                              (return-from ,xor (values nil nil))
                              (setf ,true ,tmp))))
                   datums)
         (return-from ,xor (values ,true t))))))

Macroexpansion:
(let (#:tmp141 #:true142) (declare (ignorable #:tmp141)) (block #:xor140 (if (setf #:tmp141 nil) (if #:true142 (return-from #:xor140 (values nil nil)) (setf #:true142 #:tmp141))) (if (setf #:tmp141 nil) (if #:true142 (return-from #:xor140 (values nil nil)) (setf #:true142 #:tmp141))) (if (setf #:tmp141 1) (if #:true142 (return-from #:xor140 (values nil nil)) (setf #:true142 #:tmp141))) (if (setf #:tmp141 nil) (if #:true142 (return-from #:xor140 (values nil nil)) (setf #:true142 #:tmp141))) (return-from #:xor140 (values #:true142 t))))
Create a Common Lisp macro for the following transformation. Before code:
(defstruct*
  'some-name)

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

Macro definition:
(defmacro DEFSTRUCT* ...)

Macroexpansion:
(progn
 (defclass quote nil nil)
 (defun make-quote (&rest structure-ext.as-class::args)
   (apply #'make-instance 'quote structure-ext.as-class::args))
 (defgeneric copy-quote
     (structure-ext.as-class::arg))
 (defmethod copy-quote ((structure-ext.as-class::arg quote))
   (let ((structure-ext.as-class::obj
          (make-instance (class-of structure-ext.as-class::arg))))
     (dolist
         (structure-ext.as-class::slot
          (structure-ext.as-class::slots<=obj structure-ext.as-class::arg))
       (if (slot-boundp structure-ext.as-class::arg
                        structure-ext.as-class::slot)
           (setf (slot-value structure-ext.as-class::obj
                             structure-ext.as-class::slot)
                   (slot-value structure-ext.as-class::arg
                               structure-ext.as-class::slot))
           (slot-makunbound structure-ext.as-class::obj
                            structure-ext.as-class::slot)))
     structure-ext.as-class::obj))
 (defun quote-p (structure-ext.as-class::arg)
   (typep structure-ext.as-class::arg 'quote))
 'quote)
Write a Common Lisp macro to handle this code pattern:
(defclause summing-to (vars &optional result-processor) "Specifies an accumulation strategy with 0 as the default value and + as the accumulator function." `(accumulating-to ,vars :initially 0 :by #'+ :finally ,result-processor))

Problem: Macro call that should be transformed by defclause

Macro definition:
(defmacro defclause (name arglist &body body)
  "Same as cl:defmacro, but additionally records <name> in *clauses* as a known clause macro."
  `(progn
     (defmacro ,name ,arglist ,@body)
     (pushnew ',name *clauses*)))

Macroexpansion:
(progn (defmacro summing-to (vars &optional result-processor) "Specifies an accumulation strategy with 0 as the default value and + as the accumulator function." (sb-int:quasiquote (accumulating-to #S(sb-impl::comma :expr vars :kind 0) :initially 0 :by (function +) :finally #S(sb-impl::comma :expr result-processor :kind 0)))) (pushnew (quote summing-to) *clauses*))
Create a Common Lisp macro for the following transformation. Before code:
(fgathering nil
  (progn))

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

Macro definition:
(defmacro FGATHERING ...)

Macroexpansion:
(flet ()
  (progn)
  (values))
You are a Common Lisp macro expert. Given this code pattern:
(defcell a 0)

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

Macro definition:
(defmacro defcell (name value-form &environment env)
  "Define a global cell identified by NAME.

This macro defines a cell identified by NAME with its value computed
by VALUE-FORM. The value of the cell can be referenced by the symbol
NAME following the DEFCELL form.

If VALUE-FORM is a constant, by CONSTANTP, a mutable cell is defined
which can have its value set directly using SETF or SETQ on the symbol
NAME.

If VALUE-FORM is not a constant a computed cell is created. A computed
cell may reference one or more argument cells in VALUE-FORM or a
function called during the evaluation of VALUE-FORM.  When the values
of any of the argument cells change, the value of the computed cell is
recomputed by evaluating VALUE-FORM again. The referenced argument
cells are determined automatically when the VALUE-FORM is evaluated.

This macro creates a cell definition that is visible globally to all
forms unless it is lexically shadowed by a definition with the same
NAME using CELL-LET. Note that despite being visible globally, the
cell definition is still lexically scoped and not dynamically scoped
like global variables defined with DEFVAR or DEFPARAMETER."

  (if (constantp value-form env)
      `(define-mutable-cell% ,name ,value-form)
      `(define-computed-cell% ,name ,value-form)))

Macroexpansion:
(define-mutable-cell% a 0)
Create a Common Lisp macro for the following transformation. Before code:
(or 'some-name)

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

Macro definition:
(defmacro OR ...)

Macroexpansion:
(the t 'some-name)
Create a Common Lisp macro for the following transformation. Before code:
(with-package (package) (let ((nicks (package-nicknames package))) (unless (member nickname nicks :test #'string=) (rename-package package (package-name package) (cons nickname nicks)))))

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

Macro definition:
(defmacro with-package ((var &optional (package var)) &body body)
  `(let ((,var (ensure-package ,package)))
     ,@body))

Macroexpansion:
(let ((package (ensure-package package))) (let ((nicks (package-nicknames package))) (unless (member nickname nicks :test (function string=)) (rename-package package (package-name package) (cons nickname nicks)))))
Write a Common Lisp macro to handle this code pattern:
(collect-and nil)

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

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

Macroexpansion:
(common-lisp:let* ((#:generator-495 (generator nil)) #:bools-491 (#:bool-492 t))
  (declare (type generator #:generator-495))
  (tagbody
   #:ll-496
    (setq #:bools-491 (next-in #:generator-495 (go end)))
    (if (null (setq #:bool-492 #:bools-491))
        (go end))
    (go #:ll-496)
   end)
  #:bool-492)
Generate a defmacro form that transforms code like this:
(fgather-result 'some-name)

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

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

Macroexpansion:
('some-name nil t)
Generate a defmacro form that transforms code like this:
(define-method-combination% list)

Pattern to recognize: Macro call that should be transformed by define-method-combination%

Macro definition:
(defmacro define-method-combination% (name &rest args)
  "Define a method-combination for the static-dispatch system only.

   Arguments are of the same form as to CL:DEFINE-METHOD-COMBINATION."

  `(eval-when (:compile-toplevel :load-toplevel :execute)
     (setf
      (combination-function ',name)
      ,(match args
         ((or nil
              (list* (and (type symbol) (not nil)) _))

          (destructuring-bind (&key (operator name) (identity-with-one-argument nil))
              args

            `(method-combination-function-short ,name ,operator ,identity-with-one-argument)))

         (_
          `(method-combination-function ,name ,@args))))))

Macroexpansion:
(eval-when (:compile-toplevel :load-toplevel :execute) (setf (combination-function (quote list)) (method-combination-function-short list list nil)))
Create a Common Lisp macro for the following transformation. Before code:
(define-option-expander export (package &rest symbols) (export (mapcar #'(lambda (s) (intern (string s) package)) symbols) package))

What needs to change: Macro call that should be transformed by define-option-expander

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

Macroexpansion:
(defmethod expand-option ((#:type134 (eql :export)) package #:args133) (destructuring-bind (&rest symbols) #:args133 (export (mapcar (function (lambda (s) (intern (string s) package))) symbols) package)))
Generate a defmacro form that transforms code like this:
(define-simple-definition-resolver compiler-macro compiler-macro-function)

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 compiler-macro (compiler-macro #:package135) (when (ignore-errors (compiler-macro-function compiler-macro)) (list (make-instance (quote compiler-macro) :designator compiler-macro :package #:package135))))
You are a Common Lisp macro expert. Given this code pattern:
(iterate nil :key nil)

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

Macro definition:
(defmacro ITERATE ...)

Macroexpansion:
(progn (tagbody #:ll-255 ((lambda () :key nil)) (go #:ll-255)) nil)
You are a Common Lisp macro expert. Given this code pattern:
(defalias path:relative-p (pathname) cl-fad:pathname-relative-p)

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

Macro definition:
(defmacro defalias (name args realname)
  `(progn
     (defun ,name ,args
       ,(if (eql '&rest (first args))
            `(apply #',realname ,(second args))
            `(,realname ,@args)))
     (define-compiler-macro ,name (&rest args)
       (list* ',realname args))))

Macroexpansion:
(progn (defun path:relative-p (pathname) (pathname-relative-p pathname)) (define-compiler-macro path:relative-p (&rest args) (list* (quote pathname-relative-p) args)))
You are a Common Lisp macro expert. Given this code pattern:
(*> +any-crlf+ +skipws1+)

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

Macro definition:
(defmacro *> (parser &rest parsers)
  "Combination of parsers yielding the result of the rightmost one."
  (let ((offset (gensym "*>-OFFSET")))
    `(lambda (,offset)
       ,(reduce (lambda (i p)
                  (let ((res  (gensym "*>-RES"))
                        (next (gensym "*>-NEXT")))
                    `(multiple-value-bind (,res ,next) ,i
                       (if (ok? ,res)
                           (funcall ,p ,next)
                           (fail ,next)))))
                parsers
                :initial-value `(funcall ,parser ,offset)))))

Macroexpansion:
(lambda (#:*>-offset134) (multiple-value-bind (#:*>-res135 #:*>-next136) (funcall +any-crlf+ #:*>-offset134) (if (ok? #:*>-res135) (funcall +skipws1+ #:*>-next136) (fail #:*>-next136))))
Write a Common Lisp macro to handle this code pattern:
(with-decoder-simple-list-semantics (is (equalp '((:hello . "hej") (:hi . "tjena")) (decode-json-from-string input))) (is-false (decode-json-from-string " { } ")) (is-false (decode-json-from-string "{}")))

Problem: Macro call that should be transformed by with-decoder-simple-list-semantics

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

Macroexpansion:
(with-shadowed-custom-vars (set-decoder-simple-list-semantics) (is (equalp (quote ((:hello . "hej") (:hi . "tjena"))) (decode-json-from-string input))) (is-false (decode-json-from-string " { } ")) (is-false (decode-json-from-string "{}")))
Write a Common Lisp macro to handle this code pattern:
(define-method-combination% append :operator append :identity-with-one-argument t)

Problem: Macro call that should be transformed by define-method-combination%

Macro definition:
(defmacro define-method-combination% (name &rest args)
  "Define a method-combination for the static-dispatch system only.

   Arguments are of the same form as to CL:DEFINE-METHOD-COMBINATION."

  `(eval-when (:compile-toplevel :load-toplevel :execute)
     (setf
      (combination-function ',name)
      ,(match args
         ((or nil
              (list* (and (type symbol) (not nil)) _))

          (destructuring-bind (&key (operator name) (identity-with-one-argument nil))
              args

            `(method-combination-function-short ,name ,operator ,identity-with-one-argument)))

         (_
          `(method-combination-function ,name ,@args))))))

Macroexpansion:
(eval-when (:compile-toplevel :load-toplevel :execute) (setf (combination-function (quote append)) (method-combination-function-short append append t)))
Define a macro that eliminates this repetitive pattern:
(define-test bad-var (is eql a 'c))

Issue: Macro call that should be transformed by define-test

Macro definition:
(defmacro define-test (name &body arguments-and-body)
  (destructuring-bind (nparent name) (if (listp name) name (list NIL name))
    (form-fiddle:with-body-options (body options parent home (test-class 'test) (compile-at :compile-time) defun) arguments-and-body
      (let ((body (remove 'define-test body :key (lambda (a) (when (listp a) (car a))) :test #'eql))
            (defs (remove 'define-test body :key (lambda (a) (when (listp a) (car a))) :test-not #'eql))
            (home-form (or home `(find-package ,(package-name *package*)))))
        (when (and parent nparent)
          (error "Cannot specify parent through name and through a keyword argument at the same time!"))
        `(let ((*package* (find-package ,(package-name *package*)))) ; Make sure package stays consistent throughout initialisation.
           (setf (find-test ',name ,home-form)
                 (ensure-test ',test-class
                              :name ',name
                              :home ,home-form
                              :tests (list ,@(loop for form in body
                                                   collect (ecase compile-at
                                                             (:compile-time `(lambda () ,form))
                                                             (:execute `(lambda () (call-compile ',form))))))
                              :parent ',(or parent nparent)
                              ,@(loop for option in options
                                      collect `',option)))
           ,@(loop for (def subname . body) in defs
                   collect `(,def (,name ,subname)
                              :home ,home
                              ,@body))
           ,@(when defun
               `((defun ,(if (stringp name) (read-symbol name) name) (&rest test-args)
                   (apply #'test (find-test ',name ,home-form) test-args))))
           ',name)))))

Macroexpansion:
(let ((*package* (find-package #A((9) base-char . "PARACHUTE")))) (setf (find-test (quote bad-var) (find-package #A((9) base-char . "PARACHUTE"))) (ensure-test (quote test) :name (quote bad-var) :home (find-package #A((9) base-char . "PARACHUTE")) :tests (list (lambda nil (is eql a (quote c)))) :parent (quote nil))) (quote bad-var))
You are a Common Lisp macro expert. Given this code pattern:
(rte-case nil)

Write a macro that addresses: Macro call that should be transformed by RTE-CASE

Macro definition:
(defmacro RTE-CASE ...)

Macroexpansion:
(let ((#:rte169 nil))
  (typecase #:rte169
    ((not sequence) nil)
    (t
     (funcall
      (lambda (#:rte169)
        (declare (optimize (speed 3) (debug 0) (safety 0)))
        (block check
          (typecase #:rte169
            (list nil)
            (simple-vector
             (let ((i 0) (len (length #:rte169)))
               (declare (type (and unsigned-byte fixnum) i len)
                        (ignorable len))
               nil))
            (vector
             (let ((i 0) (len (length #:rte169)))
               (declare (type (and fixnum unsigned-byte) i len)
                        (ignorable len))
               nil))
            (sequence
             (let ((i 0) (len (sb-sequence:length #:rte169)))
               (declare (type (and fixnum unsigned-byte) i len)
                        (ignorable len))
               nil))
            (t nil))))
      #:rte169))))
Create a Common Lisp macro for the following transformation. Before code:
(dynamic-progv nil
    nil)

What needs to change: Macro call that should be transformed by DYNAMIC-PROGV

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

Macroexpansion:
(let* ((#:fixed-symbols235 nil)
       (#:fixed-bindings236 (compute-bindings #:fixed-symbols235 nil)))
  (dynamic-wind
    :proceed
    #:proceed237
    (progv #:fixed-symbols235 #:fixed-bindings236 (#:proceed237))))
Generate a defmacro form that transforms code like this:
(if-let ((x 2) (y x)) (+ x y) :oops)

Pattern to recognize: Macro call that should be transformed by if-let

Macro definition:
(defmacro if-let (bindings &body (then-form &optional else-form))
    "Creates new variable bindings, and conditionally executes either
THEN-FORM or ELSE-FORM. ELSE-FORM defaults to NIL.

BINDINGS must be either single binding of the form:

 (variable initial-form)

or a list of bindings of the form:

 ((variable-1 initial-form-1)
  (variable-2 initial-form-2)
  ...
  (variable-n initial-form-n))

All initial-forms are executed sequentially in the specified order. Then all
the variables are bound to the corresponding values.

If all variables were bound to true values, the THEN-FORM is executed with the
bindings in effect, otherwise the ELSE-FORM is executed with the bindings in
effect."
    (let* ((binding-list (if (and (consp bindings) (symbolp (car bindings)))
                             (list bindings)
                             bindings))
         (variables (mapcar #'car binding-list)))
    `(let ,binding-list
       (if (and ,@variables)
           ,then-form
           ,else-form))))

Macroexpansion:
(let ((x 2) (y x)) (if (and x y) (+ x y) :oops))
Write a Common Lisp macro to handle this code pattern:
(with-special-initargs nil
  :key
  nil)

Problem: Macro call that should be transformed by WITH-SPECIAL-INITARGS

Macro definition:
(defmacro WITH-SPECIAL-INITARGS ...)

Macroexpansion:
(funcall-with-special-initargs (list) (lambda () :key nil))
Create a Common Lisp macro for the following transformation. Before code:
(assert-values ("added foo = nil") (foo nil) (foo+1 nil) (bar 'nothing) (bar-1 'nothing))

What needs to change: Macro call that should be transformed by assert-values

Macro definition:
(defmacro assert-values ((desc) &body objects-and-values)
  `(progn
     (trc ,desc)
     ,@(loop for (obj val) in objects-and-values
	    collect `(assert (eql (value ,obj) ,val)))))

Macroexpansion:
(progn (trc "added foo = nil") (assert (eql (value foo) nil)) (assert (eql (value foo+1) nil)) (assert (eql (value bar) (quote nothing))) (assert (eql (value bar-1) (quote nothing))))
Generate a defmacro form that transforms code like this:
(->> 'some-name)

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

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

Macroexpansion:
'some-name
Generate a defmacro form that transforms code like this:
(define-simple-object-lookup function fdefinition)

Pattern to recognize: Macro call that should be transformed by define-simple-object-lookup

Macro definition:
(defmacro define-simple-object-lookup (class lookup-function &body body)
  `(defmethod object ((,class ,class))
     ,(if body
          `(let ((,(first lookup-function) ,class))
             ,@body)
          `(,lookup-function (designator ,class)))))

Macroexpansion:
(defmethod object ((function function)) (fdefinition (designator function)))
You are a Common Lisp macro expert. Given this code pattern:
(defun+ nil
    (progn))

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

Macro definition:
(defmacro DEFUN+ ...)

Macroexpansion:
(defun nil (#:g128) (let+ ((progn #:g128))))