j14i/cl-macros huggingface dataset:
Write a Common Lisp macro to handle this code pattern:
(emit nil)

Problem: Macro call that should be transformed by EMIT

Macro definition:
(defmacro EMIT ...)

Macroexpansion:
(let ((#:ast181 nil))
  (progn
   (assert (typep #:ast181 'delayed-emitting) nil
           "Something went awry around the quasi quoted stuff, EMIT got a ~S."
           #:ast181)
   (funcall #:ast181)))
Define a macro that eliminates this repetitive pattern:
(define-custom-var (:array-type *json-array-type*) 'vector "The Lisp sequence type to which JSON Arrays are to be coerced.")

Issue: 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 (*json-array-type* . :array-type)) *custom-vars* :test (function equal)) (defvar *json-array-type* (quote vector) "The Lisp sequence type to which JSON Arrays are to be coerced.")))
You are a Common Lisp macro expert. Given this code pattern:
(define-modf-rewrite funcall (expr) (cons (cadadr expr) (cddr expr)))

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

Macro definition:
(defmacro define-modf-rewrite (name (expr) &body body)
  "Define a new rewrite rule.  If a form starting with NAME is encountered, call
the defined function to return a form that we can deal with (i.e. one defined
via DEFINE-MODF-EXPANDER, DEFINE-MODF-FUNCTION, and DEFINE-MODF-METHOD)."
  `(eval-when (:compile-toplevel :load-toplevel :execute)
     (setf (gethash ',name *modf-rewrites*)
           (lambda (,expr)
             ,@body))))

Macroexpansion:
(eval-when (:compile-toplevel :load-toplevel :execute) (setf (gethash (quote funcall) *modf-rewrites*) (lambda (expr) (cons (cadadr expr) (cddr expr)))))
Generate a defmacro form that transforms code like this:
(c? (when (< (depth self) 4) (loop repeat (1+ (depth self)) collecting (make-kid 'bftree :depth (1+ (depth self))))))

Pattern to recognize: Macro call that should be transformed by c?

Macro definition:
(defmacro c? (&body body)
  `(make-c-dependent
    :code ',body
    :value-state :unevaluated
    :rule (c-lambda ,@body)))

Macroexpansion:
(make-c-dependent :code (quote ((when (< (depth self) 4) (loop repeat (1+ (depth self)) collecting (make-kid (quote bftree) :depth (1+ (depth self))))))) :value-state :unevaluated :rule (c-lambda (when (< (depth self) 4) (loop repeat (1+ (depth self)) collecting (make-kid (quote bftree) :depth (1+ (depth self)))))))
Create a Common Lisp macro for the following transformation. Before code:
(do-generators ((a (repeat 2)) (:list b '(4 5 6)) (c (list->generator '(8 9)) :fill-value 30)) (print (* a (+ b c))))

What needs to change: Macro call that should be transformed by do-generators

Macro definition:
(defmacro do-generators (genspecs &body body)
  "Simultaneously iterate through multiple generators at once. By default 
do-generators terminates when the shortest generator ends, but individual 
generators can be padded out with the :fill-value keyword. Do-generators can 
also iterate over lists in parallel with generators. To use lists, start the genspec with the :list keyword. Eg:
  (do-generators ((a (repeat 2))
			 (:list b '(4 5 6))
			 (c (list->generator '(8 9)) :fill-value 30))
	   (print (* a (+ b c))))
24 
28 
72 
NIL"
  (let ((genspecs (mapcar #'proc-list-spec genspecs))
	(genr (gensym))
	(data (gensym))
	(sig (gensym)))
    (multiple-value-bind (varnames specs)
	(process-genspecs genspecs)
      
      `(let ((,genr (multi-gen ,@specs)))
	 (loop do
	   (destructuring-bind (,sig . ,data) 
	       (multiple-value-list (next-generator-value ,genr))
	     (unless ,sig
	       (return))
	     ,(bind-clause data varnames body)))))))

Macroexpansion:
(let ((#:g126 (multi-gen (repeat 2) (list->generator (quote (4 5 6))) (list (list->generator (quote (8 9))) :fill-value 30)))) (loop do (destructuring-bind (#:g128 . #:g127) (multiple-value-list (next-generator-value #:g126)) (unless #:g128 (return)) (let ((a (elt (elt #:g127 0) 0)) (b (elt (elt #:g127 1) 0)) (c (elt (elt #:g127 2) 0))) (print (* a (+ b c)))))))
Create a Common Lisp macro for the following transformation. Before code:
(with-yield
  nil)

What needs to change: Macro call that should be transformed by WITH-YIELD

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

Macroexpansion:
(isolate-cont
  (enable-yield
    nil
    nil))
Write a Common Lisp macro to handle this code pattern:
(defmacro/ps nil
    :key
  nil)

Problem: Macro call that should be transformed by DEFMACRO/PS

Macro definition:
(defmacro DEFMACRO/PS ...)

Macroexpansion:
(progn (defmacro nil :key nil) (import-macros-from-lisp 'nil))
You are a Common Lisp macro expert. Given this code pattern:
(ψ nil (progn))

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

Macro definition:
(defmacro Ψ ...)

Macroexpansion:
(mapcar (λ (progn)) nil)
Generate a defmacro form that transforms code like this:
(defconstant +newline+ (make-string 1 :initial-element #\Newline) "Used for indentation.")

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

Macro definition:
(defmacro defconstant (name value &optional doc)
  "Make sure VALUE is evaluated only once \(to appease SBCL & clasp)."
  `(cl:defconstant ,name (if (boundp ',name) (symbol-value ',name) ,value)
     ,@(when doc (list doc))))

Macroexpansion:
(eval-when (:compile-toplevel :load-toplevel :execute) (sb-impl::%defconstant (quote +newline+) (make-string 1 :initial-element #\Newline) (sb-c:source-location) (quote "Used for indentation.")))
Write a Common Lisp macro to handle this code pattern:
(when (not (slot-value (node-slot parameters) 'nodes)) (format stream "void"))

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 (not (slot-value (node-slot parameters) (quote nodes))) (format stream "void"))
You are a Common Lisp macro expert. Given this code pattern:
(do+ (with (x 1)) (terminate nil x))

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

Macro definition:
(defmacro do+ (&body body)
  "High-level, extensible iteration construct. Refer to the manual for syntax and semantics."
  `(do+/internal nil ,@body))

Macroexpansion:
(do+/internal nil (with (x 1)) (terminate nil x))
Generate a defmacro form that transforms code like this:
(with-output-to-file (output to :element-type element-type :if-exists if-to-exists) (copy-stream input output :element-type element-type :finish-output finish-output))

Pattern to recognize: Macro call that should be transformed by with-output-to-file

Macro definition:
(defmacro with-output-to-file ((stream-name file-name &rest args
                                            &key (direction nil direction-p)
                                            &allow-other-keys)
			       &body body)
  "Evaluate BODY with STREAM-NAME to an output stream on the file
FILE-NAME. ARGS is sent as is to the call to OPEN except EXTERNAL-FORMAT,
which is only sent to WITH-OPEN-FILE when it's not NIL."
  (declare (ignore direction))
  (when direction-p
    (error "Can't specify :DIRECTION for WITH-OUTPUT-TO-FILE."))
  `(with-open-file* (,stream-name ,file-name :direction :output ,@args)
     ,@body))

Macroexpansion:
(with-open-file* (output to :direction :output :element-type element-type :if-exists if-to-exists) (copy-stream input output :element-type element-type :finish-output finish-output))
Create a Common Lisp macro for the following transformation. Before code:
(with-foreign-pointer-as-string ((buf buf-size) 255) (foreign-funcall "snprintf" :pointer buf :int buf-size :string "%d %f #x%x!" :int 666 :double (coerce pi 'double-float) :unsigned-int #xcafebabe :void))

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

Macro definition:
(defmacro with-foreign-pointer ((var size &optional size-var) &body body)
  "Bind 'var to 'size bytes of foreign memory during 'body.  The
  pointer in 'var is invalid beyond the dynamic extent of 'body, and
  may be stack-allocated if supported by the implementation.  If
  'size-var is supplied, it will be bound to 'size during 'body."
  (unless size-var
    (setf size-var (gensym (symbol-name '#:size))))
  ;; If the size is constant we can stack-allocate.
  (cond ((constantp size)
         (let ((alien-var (gensym (symbol-name '#:alien))))
           `(with-alien ((,alien-var (array (unsigned 8) ,(eval size))))
             (let ((,size-var ,size)
                   (,var (alien-sap ,alien-var)))
               (declare (ignorable ,size-var))
               ,@body))))
        (t
         `(let ((,size-var ,size))
            (alien:with-bytes (,var ,size-var)
              ,@body)))))

Macroexpansion:
(with-foreign-pointer-as-string ((buf buf-size) 255) (foreign-funcall "snprintf" :pointer buf :int buf-size :string "%d %f #x%x!" :int 666 :double (coerce pi (quote double-float)) :unsigned-int 3405691582 :void))
Create a Common Lisp macro for the following transformation. Before code:
(define-alist-cache content-type-cache)

What needs to change: Macro call that should be transformed by define-alist-cache

Macro definition:
(defmacro define-alist-cache (cache-name)
  (let ((var (intern (format nil "*~A*" cache-name))))
  `(progn
     (defvar ,var)
     (defun ,(intern (format nil "LOOKUP-IN-~A" cache-name)) (elt)
       (when (boundp ',var)
         (alexandria:assoc-value ,var elt)))
     (defun (setf ,(intern (format nil "LOOKUP-IN-~A" cache-name))) (val elt)
       (when (boundp ',var)
         (setf (alexandria:assoc-value ,var elt) val))
       val))))

Macroexpansion:
(progn (defvar *content-type-cache*) (defun lookup-in-content-type-cache (elt) (when (boundp (quote *content-type-cache*)) (assoc-value *content-type-cache* elt))) (defun (setf lookup-in-content-type-cache) (val elt) (when (boundp (quote *content-type-cache*)) (setf (assoc-value *content-type-cache* elt) val)) val))
You are a Common Lisp macro expert. Given this code pattern:
(with-cached-reader-conditionals
  nil
  :key
  nil)

Write a macro that addresses: Macro call that should be transformed by WITH-CACHED-READER-CONDITIONALS

Macro definition:
(defmacro WITH-CACHED-READER-CONDITIONALS ...)

Macroexpansion:
(call-with-cached-reader-conditionals (lambda () nil :key nil))
Define a macro that eliminates this repetitive pattern:
(action (:before node-direct-application node new-subs) (when (find (node-direct-application-rator node) subs :key #'ast-substitution-from) (util:coalton-bug "Failure to apply ast substitution on variable ~A to node-direct-application" (node-direct-application-rator node))) (alexandria:when-let ((res (find (node-direct-application-rator node) new-subs :key #'ast-substitution-from))) (make-node-direct-application :type (node-type node) :properties (node-properties node) :rator-type (node-direct-application-rator-type node) :rator (node-variable-value (ast-substitution-to res)) :rands (node-direct-application-rands node) :keyword-rands (node-direct-application-keyword-rands node))))

Issue: Macro call that should be transformed by action

Macro definition:
(defmacro action ((when type &rest args) &body body)
  "Construct an action block, turning `body` into a lambda function
accepting `args` if `args` are provided. If there are no `args`, then
`body` is assumed to be a function object and is used directly with
`when` and `type` to create an `action` instance. Otherwise, the first
argument in `args` is declared to be a node of type `type`, and the
`args` and `body` are used to generate a lambda function."
  (check-type when keyword)
  (check-type type symbol)
  (assert (subtypep type 'node))
  (assert (or (not (endp args)) (= 1 (length body))))
  (if (endp args)
      `(make-action ',when ',type ,@body)
      `(make-action ',when ',type
                    (lambda (,@args)
                      (declare (type ,type ,(first args)))
                      ,@body))))

Macroexpansion:
(make-action (quote :before) (quote node-direct-application) (lambda (node new-subs) (declare (type node-direct-application node)) (when (find (node-direct-application-rator node) subs :key (function ast-substitution-from)) (util:coalton-bug "Failure to apply ast substitution on variable ~A to node-direct-application" (node-direct-application-rator node))) (alexandria:when-let ((res (find (node-direct-application-rator node) new-subs :key (function ast-substitution-from)))) (make-node-direct-application :type (node-type node) :properties (node-properties node) :rator-type (node-direct-application-rator-type node) :rator (node-variable-value (ast-substitution-to res)) :rands (node-direct-application-rands node) :keyword-rands (node-direct-application-keyword-rands node)))))
Create a Common Lisp macro for the following transformation. Before code:
(make-stream-method pp-xml-value (s value &optional colon-p at-p) (declare (ignore colon-p at-p)) (format s "~A" value))

What needs to change: Macro call that should be transformed by make-stream-method

Macro definition:
(defmacro make-stream-method (name (s &rest args) &body body)
  `(progn
     (defmethod ,name ((,s stream) ,@args)
       ,@body)
     #+abcl
     (defmethod ,name ((,s xp::xp-structure) ,@args)
       ,@body)))

Macroexpansion:
(progn (defmethod pp-xml-value ((s stream) value &optional colon-p at-p) (declare (ignore colon-p at-p)) (format s "~A" value)))
Write a Common Lisp macro to handle this code pattern:
(with-cache ("none" :expire 2 :store storage) (error "SHOULD BE ERROR"))

Problem: Macro call that should be transformed by with-cache

Macro definition:
(defmacro with-cache ((key &key store expire) &body body)
  "If a cache indicated by KEY exists, this just returns the cache
value without evaluating BODY. Otherwise, this evaluates BODY and
stores the evaluated value into STORE with KEY and EXPIRE. KEY is a
form that an evaluated value indicates the cache key.

Example:

    (defun f (x)
      (with-cache (x *store*)
        (very-complex-computation x)))"
  (once-only (key store expire)
    (with-gensyms (value exists-p)
      `(multiple-value-bind (,value ,exists-p)
           (getcache ,key ,store)
         (if ,exists-p
             ,value
             (let ((,value (progn ,@body)))
               (setcache ,key ,value ,store :expire ,expire)
               ,value))))))

Macroexpansion:
(let ((#:key262 "none") (#:store263 storage) (#:expire264 2)) (multiple-value-bind (#:value265 #:exists-p266) (getcache #:key262 #:store263) (if #:exists-p266 #:value265 (let ((#:value265 (progn (error "SHOULD BE ERROR")))) (setcache #:key262 #:value265 #:store263 :expire #:expire264) #:value265))))
Generate a defmacro form that transforms code like this:
(define-custom-var (:end-of-array *end-of-array-handler*))

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 (*end-of-array-handler* . :end-of-array)) *custom-vars* :test (function equal)) (defvar *end-of-array-handler*)))
Generate a defmacro form that transforms code like this:
(if-it (mismatch prefix string :test test :start2 start) (= it (length prefix)) t)

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

Macro definition:
(defmacro if-it (test then &optional else)
  "Like IF. IT is bound to TEST."
  `(let ((it ,test))
     (if it ,then ,else)))

Macroexpansion:
(let ((it (mismatch prefix string :test test :start2 start))) (if it (= it (length prefix)) t))
Write a Common Lisp macro to handle this code pattern:
(with-decoder-simple-list-semantics (let ((good-symbols "{\"car\":1,\"cdr\":2}") (bad-symbols "{\"could-be\":1,\"a-denial-of-service-attack\":2}") (*json-symbols-package* (find-package :cl)) (*identifier-name-to-key* #'safe-json-intern)) (is (equal '((car . 1) (cdr . 2)) (decode-json-from-string good-symbols))) (signals unknown-symbol-error (decode-json-from-string bad-symbols))))

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) (let ((good-symbols "{\"car\":1,\"cdr\":2}") (bad-symbols "{\"could-be\":1,\"a-denial-of-service-attack\":2}") (*json-symbols-package* (find-package :cl)) (*identifier-name-to-key* (function safe-json-intern))) (is (equal (quote ((car . 1) (cdr . 2))) (decode-json-from-string good-symbols))) (signals unknown-symbol-error (decode-json-from-string bad-symbols))))
Create a Common Lisp macro for the following transformation. Before code:
(letrec ((x 1) (y (lambda () y))) (is (functionp y)) (is (functionp (funcall y))) (is (numberp x)))

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

Macro definition:
(defmacro letrec ((&rest bindings) &body body)
  "Recursive LET.
The idea is that functions created in BINDINGS can close over one
another, and themselves.

Note that `letrec' only binds variables: it can define recursive
functions, but can't bind them as functions. (But see `fbindrec'.)"
  `(letrec-with psetq ,bindings
     ,@body))

Macroexpansion:
(letrec-with psetq ((x 1) (y (lambda nil y))) (is (functionp y)) (is (functionp (funcall y))) (is (numberp x)))
Write a Common Lisp macro to handle this code pattern:
(declare-deprecated-operators nil)

Problem: 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))
  (values))
Define a macro that eliminates this repetitive pattern:
(defjsmacro nil :key nil)

Issue: Macro call that should be transformed by DEFJSMACRO

Macro definition:
(defmacro DEFJSMACRO ...)

Macroexpansion:
(defpsmacro nil
    :key
  nil)
Create a Common Lisp macro for the following transformation. Before code:
(define-modf-rewrite seventh (expr) `(caddr (cddddr ,(second expr))))

What needs to change: 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 seventh) *modf-rewrites*) (lambda (expr) (sb-int:quasiquote (caddr (cddddr #S(sb-impl::comma :expr (second expr) :kind 0)))))))
Define a macro that eliminates this repetitive pattern:
(*> (string "!!!") (take-until (char #\')))

Issue: 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 (#:*>-offset122) (multiple-value-bind (#:*>-res123 #:*>-next124) (funcall (string "!!!") #:*>-offset122) (if (ok? #:*>-res123) (funcall (take-until (char #\APOSTROPHE)) #:*>-next124) (fail #:*>-next124))))
You are a Common Lisp macro expert. Given this code pattern:
(dlet nil
  nil)

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

Macro definition:
(defmacro DLET ...)

Macroexpansion:
(dynamic-let nil
  nil)
Define a macro that eliminates this repetitive pattern:
(with-rules nil
  (progn))

Issue: Macro call that should be transformed by WITH-RULES

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

Macroexpansion:
(dolist (nil (alexandria:hash-table-keys cl-rules.core::*rules*)) (progn))
You are a Common Lisp macro expert. Given this code pattern:
(when (node-slot initializer) (make-proxy initializer initializer))

Write a macro that addresses: 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 (node-slot initializer) (make-proxy initializer initializer))