j14i/cl-macros huggingface dataset:
You are a Common Lisp macro expert. Given this code pattern:
(when-let (x (opaque :ok)) (setf x (cons x x)) x)

Write a macro that addresses: Macro call that should be transformed by when-let

Macro definition:
(defmacro when-let (bindings &body forms)
    "Creates new variable bindings, and conditionally executes FORMS.

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, then FORMS are executed as an
implicit PROGN."
  (let* ((binding-list (if (and (consp bindings) (symbolp (car bindings)))
                           (list bindings)
                           bindings))
         (variables (mapcar #'car binding-list)))
    `(let ,binding-list
       (when (and ,@variables)
         ,@forms))))

Macroexpansion:
(let ((x (opaque :ok))) (when (and x) (setf x (cons x x)) x))
You are a Common Lisp macro expert. Given this code pattern:
(defgenerator some-numbers () (loop for i from 1 upto 3 do (yield i)) (dotimes (j 3) (yield (- 10 j))))

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

Macro definition:
(defmacro defgenerator (name arguments &body body)
  (multiple-value-bind (remaining-forms declarations doc-string)
      (alexandria:parse-body body :documentation t)
    `(defun ,name ,arguments
       ,doc-string
       ,@declarations
       (with-yield
	 ,@remaining-forms))))

Macroexpansion:
(defun some-numbers nil nil (with-yield (loop for i from 1 upto 3 do (yield i)) (dotimes (j 3) (yield (- 10 j)))))
Create a Common Lisp macro for the following transformation. Before code:
(def-neo4j-fun create-relationship (node-id to-node-id relationship-type properties) :post (:uri-spec (format nil "node/~A/relationships" node-id)) (:encode (list to-node-id relationship-type properties) :relationship) (:status-handlers (201 (decode-neo4j-json-output body)) (400 (error 'invalid-data-sent-error :uri uri :json json)) (404 (error 'node-not-found-error :uri uri))))

What needs to change: Macro call that should be transformed by def-neo4j-fun

Macro definition:
(defmacro def-neo4j-fun (name lambda-list method &rest args)
  `(progn
     (defun ,name (&key ,@lambda-list)
       (let ((uri ,(cadr (assoc :uri-spec args)))
             (json (encode-neo4j-json-payload ,@(aif (assoc :encode args)
                                                     (cdr it)
                                                     (list '() :string)))))
         (make-neo4j-request ,method uri json
                             (list ,@(mapcar (lambda (handler)
                                               `(list ,(car handler) (lambda (body uri json)
                                                                  ,(cadr handler))))
                                             (cdr (assoc :status-handlers args)))))))))

Macroexpansion:
(progn (defun create-relationship (&key node-id to-node-id relationship-type properties) (let ((uri (format nil "node/~A/relationships" node-id)) (json (encode-neo4j-json-payload (list to-node-id relationship-type properties) :relationship))) (make-neo4j-request :post uri json (list (list 201 (lambda (body uri json) (decode-neo4j-json-output body))) (list 400 (lambda (body uri json) (error (quote invalid-data-sent-error) :uri uri :json json))) (list 404 (lambda (body uri json) (error (quote node-not-found-error) :uri uri))))))))
Write a Common Lisp macro to handle this code pattern:
(def-slot-annotation optional (init-form) (unless (plist-member slot-options :initarg) (setf (getf slot-options :initarg) (make-keyword slot-name))) (unless (plist-member slot-options :initform) (setf (getf slot-options :initform) init-form)))

Problem: Macro call that should be transformed by def-slot-annotation

Macro definition:
(defmacro def-slot-annotation (name args &body body)
  (with-gensyms (slot-specifier)
    `(defannotation ,name ,(append args (list slot-specifier))
         (:inline t :arity ,(1+ (length args)))
       (destructuring-bind (slot-name . slot-options)
           (if (consp ,slot-specifier)
               ,slot-specifier
               (list ,slot-specifier))
         ,@body
         (cons slot-name slot-options)))))

Macroexpansion:
(defannotation optional (init-form #:slot-specifier122) (:inline t :arity 2) (destructuring-bind (slot-name . slot-options) (if (consp #:slot-specifier122) #:slot-specifier122 (list #:slot-specifier122)) (unless (plist-member slot-options :initarg) (setf (getf slot-options :initarg) (make-keyword slot-name))) (unless (plist-member slot-options :initform) (setf (getf slot-options :initform) init-form)) (cons slot-name slot-options)))
Define a macro that eliminates this repetitive pattern:
(f_
  nil)

Issue: Macro call that should be transformed by F_

Macro definition:
(defmacro F_ ...)

Macroexpansion:
(lambda (_) nil)
Create a Common Lisp macro for the following transformation. Before code:
(action (:traverse node-let) #'propagate-constants-node-let)

What needs to change: 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 :traverse) (quote node-let) (function propagate-constants-node-let))
Create a Common Lisp macro for the following transformation. Before code:
(lret ((x 1) (y (make-array 1))) (setf (aref y 0) x))

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

Macro definition:
(defmacro lret ((&rest bindings) &body body)
  "Return the initial value of the last binding in BINDINGS. The idea
is to create something, initialize it, and then return it.

    (lret ((x 1)
           (y (make-array 1)))
      (setf (aref y 0) x))
    => #(1)

Note that the value returned is the value initially bound. Subsequent
assignments are ignored.

    (lret ((x 1))
      (setf x 2))
    => 1

Furthermore, on Lisps that support it, the variable may be made
read-only, making assignment a compiler-time error.

`lret' may seem trivial, but it fufills the highest purpose a macro
can: it eliminates a whole class of bugs (initializing an object, but
forgetting to return it).

Cf. `aprog1' in Anaphora."
  `(lret-aux let ,bindings
     ,@body))

Macroexpansion:
(lret-aux let ((x 1) (y (make-array 1))) (setf (aref y 0) x))
You are a Common Lisp macro expert. Given this code pattern:
(make-stream-method pp-xml-value (s (value float) &optional colon-p at-p) (declare (ignore colon-p at-p)) (if (< (- (abs value) *precision-epsilon*) 0.00000001) (format s "0") (format s "~v$" *float-format-precision* value)))

Write a macro that addresses: 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 float) &optional colon-p at-p) (declare (ignore colon-p at-p)) (if (< (- (abs value) *precision-epsilon*) 1.0e-8) (format s "0") (format s "~v$" *float-format-precision* value))))
Create a Common Lisp macro for the following transformation. Before code:
(is equal "A" (string :a))

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

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

Macroexpansion:
(eval-in-context *context* (make-instance (quote comparison-result) :expression (quote (is equal "A" (string :a))) :value-form (quote (string :a)) :body (lambda nil (string :a)) :expected "A" :comparison (quote equal)))
Create a Common Lisp macro for the following transformation. Before code:
(when (typep (car evaluated) 'node) (setf asts evaluated))

What needs to change: 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 (typep (car evaluated) (quote node)) (setf asts evaluated))
Write a Common Lisp macro to handle this code pattern:
(when (eql (top-info) 'destructor) (format stream "~~"))

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 (top-info) (quote destructor)) (format stream "~~"))
Define a macro that eliminates this repetitive pattern:
(define-layered-class nil)

Issue: Macro call that should be transformed by DEFINE-LAYERED-CLASS

Macro definition:
(defmacro DEFINE-LAYERED-CLASS ...)

Macroexpansion:
(defclass nil nil nil (:metaclass layered-class) (:in-layer . t))
Create a Common Lisp macro for the following transformation. Before code:
(with-unique-names (body) (let ((body `(tagbody ,@(prologue-forms body-clause) ,@(step-intro-forms body-clause t) ,@(step-outro-forms body-clause t) ,body ,@(body-forms body-clause) ,@(step-intro-forms body-clause nil) ,@(step-outro-forms body-clause nil) (go ,body) ,*epilogue-tag* ,@(epilogue-forms body-clause) (return-from ,*loop-name* ,*accumulation-variable*))) (afterword (afterword-forms body-clause))) (if afterword `((unwind-protect ,body ,@afterword)) `(,body))))

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

Macro definition:
(defmacro with-unique-names (names &body body)
  `(let ,(mapcar (lambda (sym)
                   `(,sym (gensym ,(symbol-name sym))))
                  names)
     ,@body))

Macroexpansion:
(let ((body (gensym #A((4) base-char . "BODY")))) (let ((body (quasiquote (tagbody #S(sb-impl::comma :expr (prologue-forms body-clause) :kind 2) #S(sb-impl::comma :expr (step-intro-forms body-clause t) :kind 2) #S(sb-impl::comma :expr (step-outro-forms body-clause t) :kind 2) #S(sb-impl::comma :expr body :kind 0) #S(sb-impl::comma :expr (body-forms body-clause) :kind 2) #S(sb-impl::comma :expr (step-intro-forms body-clause nil) :kind 2) #S(sb-impl::comma :expr (step-outro-forms body-clause nil) :kind 2) (go #S(sb-impl::comma :expr body :kind 0)) #S(sb-impl::comma :expr *epilogue-tag* :kind 0) #S(sb-impl::comma :expr (epilogue-forms body-clause) :kind 2) (return-from #S(sb-impl::comma :expr *loop-name* :kind 0) #S(sb-impl::comma :expr *accumulation-variable* :kind 0))))) (afterword (afterword-forms body-clause))) (if afterword (quasiquote ((unwind-protect #S(sb-impl::comma :expr body :kind 0) #S(sb-impl::comma :expr afterword :kind 2)))) (quasiquote (#S(sb-impl::comma :expr body :kind 0))))))
Generate a defmacro form that transforms code like this:
(macroexpand-convention (form) (if (consp form) (expand-export-form-using-head (first form) form) form))

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

Macro definition:
(defmacro macroexpand-convention ((original-form) &body body)
  "Executes BODY as like `progn' and return the result as the first
value.  As the second value, returns a boolean whether the result is
not same with ORIGINAL-FORM or not.
This macro is designed to follow the `macroexpand' convention."
  `(multiple-value-bind (result expanded-p)
       (progn ,@body)
     (values result
             (or expanded-p
                 (not (eq result ,original-form))))))

Macroexpansion:
(multiple-value-bind (result expanded-p) (progn (if (consp form) (expand-export-form-using-head (first form) form) form)) (values result (or expanded-p (not (eq result form)))))
Create a Common Lisp macro for the following transformation. Before code:
(in-package nil)

What needs to change: Macro call that should be transformed by IN-PACKAGE

Macro definition:
(defmacro IN-PACKAGE ...)

Macroexpansion:
(eval-when (:compile-toplevel :load-toplevel :execute)
  (setq *package*
          (sb-int:find-undeleted-package-or-lose #A((3) base-char . "NIL"))))
Create a Common Lisp macro for the following transformation. Before code:
(sif (list 1 2 3) (sif (car it) (setf it 'a) :foo))

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

Macro definition:
(defmacro sif (test then &optional else)
  "Like IF, except binds the test form to IT (via SYMBOL-MACROLET) for
the scope of the then and else expressions. IT can be set with SETF"
  `(symbolic if ,test ,then ,else))

Macroexpansion:
(symbolic if (list 1 2 3) (sif (car it) (setf it (quote a)) :foo) nil)
You are a Common Lisp macro expert. Given this code pattern:
(when (eql (info-size) 0) (format stream "~&"))

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 (eql (info-size) 0) (format stream "~&"))
Write a Common Lisp macro to handle this code pattern:
(doseq (item seq) (accumulate collector item))

Problem: Macro call that should be transformed by doseq

Macro definition:
(defmacro doseq (name/seq &body body)
  "Iterate over the elements of a single sequence SEQUENCE.

   Same as DO-SEQUENCES but for the special case of iterating over a
   single sequence.

   The macro arguments can be in one of the following two forms:

    1. (NAME (ELEMENT SEQUENCE &REST ARGS) &BODY BODY)

    2. ((ELEMENT SEQUENCE &REST ARGS) &BODY BODY)

   NAME is the block name, NIL if not given.

   ELEMENT is the variable to which each element of the sequence is
   bound.

   SEQUENCE is the sequence, with ARGS being the remaining arguments
   passed to the ITERATOR function.

   BODY is the list of forms evaluated on each iteration."

  (let-if ((name name/seq)
           (seq (first body) name/seq)
           (body (rest body) body))
      (symbolp name/seq)

    (destructuring-bind (element sequence &rest args) seq
      `(do-sequences ,name
         ((,element ,sequence ,@args))
         ,@body))))

Macroexpansion:
(do-sequences nil ((item seq)) (accumulate collector item))
You are a Common Lisp macro expert. Given this code pattern:
(do-files (file (find-theme theme) "tmpl") (compile-template :common-lisp-backend file))

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

Macro definition:
(defmacro do-files ((var path &optional extension) &body body)
  "For each file under PATH, run BODY. If EXTENSION is provided, only run
BODY on files that match the given extension."
  (alexandria:with-gensyms (extension-p)
    `(flet ((,extension-p (file)
              (string= (pathname-type file) ,extension)))
       (cl-fad:walk-directory ,path (lambda (,var) ,@body)
                              :follow-symlinks nil
                              :test (if ,extension
                                        #',extension-p
                                        (constantly t))))))

Macroexpansion:
(flet ((#:extension-p288 (file) (string= (pathname-type file) "tmpl"))) (cl-fad:walk-directory (find-theme theme) (lambda (file) (compile-template :common-lisp-backend file)) :follow-symlinks nil :test (if "tmpl" (function #:extension-p288) (constantly t))))
Create a Common Lisp macro for the following transformation. Before code:
(define-shared-method nil
    (progn))

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

Macro definition:
(defmacro DEFINE-SHARED-METHOD ...)

Macroexpansion:
(define-incongruent-method incongruent-methods.methods::nil
    (progn))
Create a Common Lisp macro for the following transformation. Before code:
(with-html-string (:div (:section (:h2 (:p "hello")))))

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

Macro definition:
(defmacro with-html (&body body &environment env)
  "Interpret BODY as HTML. Consult README.txt for the syntax."
  `(let ((*html* (ensure-html-stream *html*)))
     ,(if (and (null (cdr body)) (atom (car body)))
          (car body)
          `(progn ,@(parse-html body env)))))

Macroexpansion:
(with-output-to-string (*html*) (with-html (:div (:section (:h2 (:p "hello"))))))
Write a Common Lisp macro to handle this code pattern:
(action (:after node-variable) #'propagate-constants-node-variable)

Problem: 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 :after) (quote node-variable) (function propagate-constants-node-variable))
Define a macro that eliminates this repetitive pattern:
(unwind-protect-case (aborted-p) (random 42) (:always (setq result aborted-p)))

Issue: Macro call that should be transformed by unwind-protect-case

Macro definition:
(defmacro unwind-protect-case ((&optional abort-flag) protected-form &body clauses)
  "Like CL:UNWIND-PROTECT, but you can specify the circumstances that
the cleanup CLAUSES are run.

  clauses ::= (:NORMAL form*)* | (:ABORT form*)* | (:ALWAYS form*)*

Clauses can be given in any order, and more than one clause can be
given for each circumstance. The clauses whose denoted circumstance
occured, are executed in the order the clauses appear.

ABORT-FLAG is the name of a variable that will be bound to T in
CLAUSES if the PROTECTED-FORM aborted preemptively, and to NIL
otherwise.

Examples:

  (unwind-protect-case ()
       (protected-form)
     (:normal (format t \"This is only evaluated if PROTECTED-FORM executed normally.~%\"))
     (:abort  (format t \"This is only evaluated if PROTECTED-FORM aborted preemptively.~%\"))
     (:always (format t \"This is evaluated in either case.~%\")))

  (unwind-protect-case (aborted-p)
       (protected-form)
     (:always (perform-cleanup-if aborted-p)))
"
  (check-type abort-flag (or null symbol))
  (let ((gflag (gensym "FLAG+")))
    `(let ((,gflag t))
       (unwind-protect (multiple-value-prog1 ,protected-form (setf ,gflag nil))
	 (let ,(and abort-flag `((,abort-flag ,gflag)))
	   ,@(loop for (cleanup-kind . forms) in clauses
		   collect (ecase cleanup-kind
			     (:normal `(when (not ,gflag) ,@forms))
			     (:abort  `(when ,gflag ,@forms))
			     (:always `(progn ,@forms)))))))))

Macroexpansion:
(let ((#:flag+127 t)) (unwind-protect (multiple-value-prog1 (random 42) (setf #:flag+127 nil)) (let ((aborted-p #:flag+127)) (progn (setq result aborted-p)))))
Write a Common Lisp macro to handle this code pattern:
(make-name-transformer nil nil)

Problem: Macro call that should be transformed by MAKE-NAME-TRANSFORMER

Macro definition:
(defmacro MAKE-NAME-TRANSFORMER ...)

Macroexpansion:
(lambda (name definition)
  (declare (ignorable definition))
  (concatenate-symbol nil nil))
Create a Common Lisp macro for the following transformation. Before code:
(define-simple-definition-resolver constant designator-constant-p)

What needs to change: 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 constant (constant #:package140) (when (ignore-errors (designator-constant-p constant)) (list (make-instance (quote constant) :designator constant :package #:package140))))
Write a Common Lisp macro to handle this code pattern:
(with-timeout (time-limit test) (loop for test in (tests test) do (funcall test)))

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

Macro definition:
(defmacro with-timeout (timeout &body body)
  #+(and clisp mt)
  `(mt:with-timeout (,timeout (error 'timeout))
     ,@body)
  #+(or allegro cmucl)
  `(mp:with-timeout (,timeout (error 'timeout))
     ,@body)
  #+sbcl
  `(sb-ext:with-timeout ,timeout
     ,@body)
  #-(or allegro (and clisp mt) cmucl sbcl)
  `(progn
     ,@body))

Macroexpansion:
(sb-ext:with-timeout (time-limit test) (loop for test in (tests test) do (funcall test)))
Define a macro that eliminates this repetitive pattern:
(ps-html nil :key nil)

Issue: Macro call that should be transformed by PS-HTML

Macro definition:
(defmacro PS-HTML ...)

Macroexpansion:
(stringify nil #A((11) base-char . "<key></key>") nil)
You are a Common Lisp macro expert. Given this code pattern:
(nlet nil
    (progn))

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

Macro definition:
(defmacro NLET ...)

Macroexpansion:
(let* ((progn nil)))
Generate a defmacro form that transforms code like this:
(define-accumulation-binding counting ((var 0) form) (declare (type (integer 0) var)) `(when ,form (incf ,var)))

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

Macro definition:
(defmacro define-accumulation-binding (name (var &rest args) &body body)
  `(define-form-binding ,name (,var ,@args)
     ,@(form-fiddle:lambda-declarations `(lambda () ,@body))
     (values
      (progn ,@(form-fiddle:lambda-forms `(lambda () ,@body)))
      (delist var))))

Macroexpansion:
(define-form-binding counting ((var 0) form) (declare (type (integer 0) var)) (values (progn (sb-int:quasiquote (when #S(sb-impl::comma :expr form :kind 0) (incf #S(sb-impl::comma :expr var :kind 0))))) (delist var)))
Generate a defmacro form that transforms code like this:
(ct-flet nil
  nil)

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

Macro definition:
(defmacro CT-FLET ...)

Macroexpansion:
(cond (*within-captured-dynenv* (progn nil))
      (t
       (error
        "No macrodynamic environment has been captured to establish CT-FLET bindings.")))