j14i/cl-macros huggingface dataset:
You are a Common Lisp macro expert. Given this code pattern:
(def-neo4j-fun del-node-property (node-id property) :delete (:uri-spec (format nil "node/~A/properties/~A" node-id (if (symbolp property) (string-downcase (symbol-name property)) property))) (:status-handlers (204 (values t body)) (404 (error 'node-not-found-error :uri uri)) (409 (error 'unable-to-delete-node-error :uri uri))))

Write a macro that addresses: 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 del-node-property (&key node-id property) (let ((uri (format nil "node/~A/properties/~A" node-id (if (symbolp property) (string-downcase (symbol-name property)) property))) (json (encode-neo4j-json-payload nil :string))) (make-neo4j-request :delete uri json (list (list 204 (lambda (body uri json) (values t body))) (list 404 (lambda (body uri json) (error (quote node-not-found-error) :uri uri))) (list 409 (lambda (body uri json) (error (quote unable-to-delete-node-error) :uri uri))))))))
Define a macro that eliminates this repetitive pattern:
(*> +underscore+ +digit-chunks+)

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 (#:*>-offset242) (multiple-value-bind (#:*>-res243 #:*>-next244) (funcall +underscore+ #:*>-offset242) (if (ok? #:*>-res243) (funcall +digit-chunks+ #:*>-next244) (fail #:*>-next244))))
You are a Common Lisp macro expert. Given this code pattern:
(with-decoder-simple-list-semantics (let* ((error (eq output-value :error)) (expected (cond ((eq output-value :error) nil) (t (with-guessing-encoder (encode-json-to-string output-value))))) (input-encoded (with-guessing-encoder (encode-json-to-string input-value))) (result (handler-bind ((error #'(lambda (x) (invoke-restart 'json-rpc:send-error (format nil "~a" x) 999)))) (json-rpc:invoke-rpc (format nil "{~@[~*\"jsonrpc\":\"2.0\",~]\"method\":\"fooA\",\"params\":[~a],\"id\":999}" (json-rpc-2-p) input-encoded))))) (if error (let ((res (decode-json-from-string result))) (is (and (null (cdr (assoc :result res))) (cdr (assoc :error res))))) (is (string= result (format nil "{~@[~*\"jsonrpc\":\"2.0\",~]\"result\":~a,~@[~*\"error\":null,~]\"id\":999}" (json-rpc-2-p) expected (not (json-rpc-2-p))))))))

Write a macro that addresses: 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* ((error (eq output-value :error)) (expected (cond ((eq output-value :error) nil) (t (with-guessing-encoder (encode-json-to-string output-value))))) (input-encoded (with-guessing-encoder (encode-json-to-string input-value))) (result (handler-bind ((error (function (lambda (x) (invoke-restart (quote json-rpc:send-error) (format nil "~a" x) 999))))) (json-rpc:invoke-rpc (format nil "{~@[~*\"jsonrpc\":\"2.0\",~]\"method\":\"fooA\",\"params\":[~a],\"id\":999}" (json-rpc-2-p) input-encoded))))) (if error (let ((res (decode-json-from-string result))) (is (and (null (cdr (assoc :result res))) (cdr (assoc :error res))))) (is (string= result (format nil "{~@[~*\"jsonrpc\":\"2.0\",~]\"result\":~a,~@[~*\"error\":null,~]\"id\":999}" (json-rpc-2-p) expected (not (json-rpc-2-p))))))))
Generate a defmacro form that transforms code like this:
(lret ((x 1)) (setf x 2))

Pattern to recognize: 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)) (setf x 2))
Create a Common Lisp macro for the following transformation. Before code:
(with-html-string (:html (:head (:link #p"styles.css" :type "text/css"))))

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 (:html (:head (:link #P"styles.css" :type "text/css")))))
Generate a defmacro form that transforms code like this:
($map-reduce "foo" m r :query ($> "l" -9))

Pattern to recognize: Macro call that should be transformed by $map-reduce

Macro definition:
(defmacro $map-reduce (collection map reduce &key (query nil) (limit 0) (out nil) 
		       (keeptemp nil) (finalize nil) (verbose t))
  "Run map reduce on the mongo server. map and reduce are either the names of the 
javascript functions, created with defjs or defsrvjs or are function definitions in javascript.
The keywords refer to option available for map reduce in mongo. This returns a result summary document.
When using :keeptemp t without specificing :out the collection is mr.<collection> "
    `(db.find "$cmd" (kv (kv "mapreduce" ,collection) 
			 (kv "map"    (or (jsdef ,map) ',map))
			 (kv "reduce" (or (jsdef ,reduce) ',reduce))
			 (when ,finalize (kv "finalize" (jsdef ,finalize)))
			 (kv "out"      (if ,out ,out (concatenate 'string "mr." ,collection))) 
			 (kv "verbose"  ,verbose)
			 (kv "limit"    ,limit)
			 (kv "keeptemp" ,keeptemp)
			 (kv "query"    ,query))))

Macroexpansion:
(db.find "$cmd" (kv (kv "mapreduce" "foo") (kv "map" (or (jsdef m) (quote m))) (kv "reduce" (or (jsdef r) (quote r))) (when nil (kv "finalize" (jsdef nil))) (kv "out" (if nil nil (concatenate (quote string) "mr." "foo"))) (kv "verbose" t) (kv "limit" 0) (kv "keeptemp" nil) (kv "query" ($> "l" -9))))
Generate a defmacro form that transforms code like this:
(defgeneric* nil nil)

Pattern to recognize: Macro call that should be transformed by DEFGENERIC*

Macro definition:
(defmacro DEFGENERIC* ...)

Macroexpansion:
(ensure-generic*-function 'nil :name 'nil :lambda-list 'nil)
Create a Common Lisp macro for the following transformation. Before code:
(with-wcs-math-error-handling (ret (tan x)) (check-wcs-math-result))

What needs to change: 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* ((#:g215 x) (#:g216 nil) (#:g217 (list #:g215))) (declare (ignorable #:g216) (type list #:g217) (dynamic-extent #:g217)) (catch (quote return-from-with-wcs-math-error-handling) (multiple-value-bind (ret) (call-with-wcs-math-error-handler (quote tan) #:g217) (flet ((check-wcs-math-result (&optional (ret ret) (arg-list #:g217)) (check-wcs-math-result ret arg-list))) (check-wcs-math-result)))))
Write a Common Lisp macro to handle this code pattern:
(with-transaction *db* (do-sql *db* "INSERT INTO person (id, name) VALUES (4, 'meymao')"))

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

Macro definition:
(defmacro with-transaction (conn &body body)
  "Start a transaction and commit at the end of this block. If the evaluation `body` is interrupted, the transaction is rolled back automatically."
  (let ((conn-var (gensym "CONN-VAR")))
    `(let ((,conn-var ,conn))
       (if (in-transaction ,conn-var)
           (with-savepoint ,conn-var ,@body)
           (%with-transaction ,conn-var ,@body)))))

Macroexpansion:
(let ((#:conn-var160 *db*)) (if (in-transaction #:conn-var160) (with-savepoint #:conn-var160 (do-sql *db* "INSERT INTO person (id, name) VALUES (4, 'meymao')")) (%with-transaction #:conn-var160 (do-sql *db* "INSERT INTO person (id, name) VALUES (4, 'meymao')"))))
Define a macro that eliminates this repetitive pattern:
(-> :g () 3)

Issue: Macro call that should be transformed by ->

Macro definition:
(defmacro -> (invariant &body args)
  "See flow:atomically"
  `(atomically ,invariant ,@args))

Macroexpansion:
(atomically :g nil 3)
Define a macro that eliminates this repetitive pattern:
(defalias path:rm-r (pathname) cl-fad:delete-directory-and-files)

Issue: 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:rm-r (pathname) (delete-directory-and-files pathname)) (define-compiler-macro path:rm-r (&rest args) (list* (quote delete-directory-and-files) args)))
Create a Common Lisp macro for the following transformation. Before code:
(let1 x 1 (list y z))

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

Macro definition:
(defmacro let1 (var expr &body body)
  "Bind VAR, immutably, to EXPR and evaluate BODY.

This may be pronounced with equal propriety as \"let-one\" or
\"let-once\"."
  `(let ((,var ,expr))
     (with-read-only-vars (,var)
       ,@body)))

Macroexpansion:
(let ((x 1)) (with-read-only-vars (x) (list y z)))
Generate a defmacro form that transforms code like this:
(define-binary-op-mapping-definer define-binary-ops `(progn (declaim (inline ,op)) (defun ,op (x y) (,cl x y))))

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

Macro definition:
(defmacro define (name value &rest docstring)
  "Like a #define but also visible to Lisp code."
  `(progn
     (eval-when (:compile-toplevel :load-toplevel :execute)
       (defvar ,(pp-defines *package*) (make-hash-table))
       (setf (gethash ',name ,(pp-defines *package*)) ,(prin1-to-string value)))
     (defparameter ,name ,value ,@docstring)))

Macroexpansion:
(defmacro define-binary-ops (&rest map) (sb-int:quasiquote (progn #S(sb-impl::comma :expr (loop for (vacietis cl) on map by (function cddr) collect (let ((op (find-symbol (symbol-name vacietis) (quote #:vacietis.c)))) (sb-int:quasiquote (progn (declaim (inline #S(sb-impl::comma :expr op :kind 0))) (defun #S(sb-impl::comma :expr op :kind 0) (x y) (#S(sb-impl::comma :expr cl :kind 0) x y)))))) :kind 2))))
Generate a defmacro form that transforms code like this:
(cond-> nil :key nil)

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

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

Macroexpansion:
(let* ((#:g139 nil))
  (if :key
      (-> #:g139 nil)
      #:g139))
You are a Common Lisp macro expert. Given this code pattern:
(some-> 'some-name)

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

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

Macroexpansion:
(let* ((#:|some129| 'some-name))
  #:|some129|)
You are a Common Lisp macro expert. Given this code pattern:
(c-assert (listp new-kids) () "New kids value for ~a not listp: ~a ~a" self (type-of new-kids) new-kids)

Write a macro that addresses: Macro call that should be transformed by c-assert

Macro definition:
(defmacro c-assert (assertion &optional places fmt$ &rest fmt-args)
  (declare (ignorable assertion places fmt$ fmt-args))
   #+(or)`(progn) 
  `(unless *stop*
     (unless ,assertion
       ,(if fmt$
            `(c-break ,fmt$ ,@fmt-args)
          `(c-break "failed assertion: ~a" ',assertion)))))

Macroexpansion:
(unless *stop* (unless (listp new-kids) (c-break "New kids value for ~a not listp: ~a ~a" self (type-of new-kids) new-kids)))
You are a Common Lisp macro expert. Given this code pattern:
(action (:after node-variable node bound-variables) (let ((name (node-variable-value node))) (unless (member name bound-variables :test #'eq) (alexandria:when-let ((target (alias-substitution-target name aliases))) (copy-node target (node-type node))))))

Write a macro that addresses: 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) (lambda (node bound-variables) (declare (type node-variable node)) (let ((name (node-variable-value node))) (unless (member name bound-variables :test (function eq)) (alexandria:when-let ((target (alias-substitution-target name aliases))) (copy-node target (node-type node)))))))
You are a Common Lisp macro expert. Given this code pattern:
(collect-sum 'some-name)

Write a macro that addresses: Macro call that should be transformed by COLLECT-SUM

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

Macroexpansion:
(common-lisp:let* ((#:generator-242 (generator 'some-name))
                   #:numbers-238
                   (#:sum-239 0))
  (declare (type generator #:generator-242)
           (type number #:sum-239))
  (tagbody
   #:ll-243
    (setq #:numbers-238 (next-in #:generator-242 (go end)))
    (setq #:sum-239 (+ #:sum-239 #:numbers-238))
    (go #:ll-243)
   end)
  #:sum-239)
Define a macro that eliminates this repetitive pattern:
(defannotation export* (definition-form) (:alias export) "Export the definition symbol of DEFINITION-FORM." (let ((name (definition-form-symbol definition-form))) (if name `(progn (export ',name) ,definition-form) definition-form)))

Issue: Macro call that should be transformed by defannotation

Macro definition:
(defmacro defannotation (name lambda-list options &body body)
  `(progn
     (set-annotation-options ',name ',options)
     (defmacro ,name ,lambda-list ,@body)))

Macroexpansion:
(progn (set-annotation-options (quote export*) (quote (:alias export))) (defmacro export* (definition-form) "Export the definition symbol of DEFINITION-FORM." (let ((name (definition-form-symbol definition-form))) (if name (sb-int:quasiquote (progn (export (quote #S(sb-impl::comma :expr name :kind 0))) #S(sb-impl::comma :expr definition-form :kind 0))) definition-form))))
Create a Common Lisp macro for the following transformation. Before code:
(lret* ((element-type (array-element-type vec)) (out (make-array length :element-type element-type))) (replace out vec) (fill out pad :start (length vec)) out)

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* ((element-type (array-element-type vec)) (out (make-array length :element-type element-type))) (replace out vec) (fill out pad :start (length vec)) out)
Create a Common Lisp macro for the following transformation. Before code:
(when-it (remove-if-not #'internal-variable? (free-variables form)) (clause-error "The variable~p ~{~A~^, ~} ~:[is~;are~] bound in a context ~ internal to the Iterate form.~% This part of the clause will be moved outside ~ the body of the loop, so it must not contain anything that depends on the body." (length it) it (rest it)))

What needs to change: Macro call that should be transformed by when-it

Macro definition:
(defmacro when-it (test &body body)
  "Like WHEN. IT is bound to TEST."
  `(let ((it ,test))
     (when it
       ,@body)))

Macroexpansion:
(let ((it (remove-if-not (function internal-variable?) (free-variables form)))) (when it (clause-error "The variable~p ~{~A~^, ~} ~:[is~;are~] bound in a context ~ internal to the Iterate form.~% This part of the clause will be moved outside ~ the body of the loop, so it must not contain anything that depends on the body." (length it) it (rest it))))
Define a macro that eliminates this repetitive pattern:
(caching-types
  nil)

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

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

Macroexpansion:
(call-with-disjoint-hash
 (lambda ()
   (call-with-subtype-hash
    (lambda ()
      (call-with-equiv-hash
       (lambda () (call-with-subtypep-cache (lambda () nil))))))))
Write a Common Lisp macro to handle this code pattern:
(with-color (color :stream stream) (format stream "(~Dms)" duration))

Problem: 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* (if (or (eq color :gray) (eq color :grey) (eq color +gray+) (eq color +grey+)) (with-gray stream (format stream "(~Dms)" duration)) (cl-ansi-text:with-color (color :stream stream) (format stream "(~Dms)" duration))) (progn (format stream "(~Dms)" duration)))
Define a macro that eliminates this repetitive pattern:
(with-dynenv nil
  (progn))

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

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

Macroexpansion:
(multiple-value-bind (#:var-expansion130 #:var-expanded-p131)
    (macroexpand-1 'var-space nil)
  (multiple-value-bind (#:fun-expansion132 #:fun-expanded-p133)
      (macroexpand-1 'fun-space nil)
    (let ((*var-space* (when #:var-expanded-p131 #:var-expansion130))
          (*fun-space* (when #:fun-expanded-p133 #:fun-expansion132))
          (*within-captured-dynenv* t))
      (progn))))
You are a Common Lisp macro expert. Given this code pattern:
(when (oddp (length rest)) (error "Set operator with odd number of elements: ~a" rest))

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 (oddp (length rest)) (error "Set operator with odd number of elements: ~a" rest))
You are a Common Lisp macro expert. Given this code pattern:
(dreletf nil
  (progn))

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

Macro definition:
(defmacro DRELETF ...)

Macroexpansion:
(let ((#:symbol-store233
       (with-symbol-access
         (list))))
  (special-symbol-reprogv #:symbol-store233
      (list)
    (locally (declare (special)) (progn))))
Define a macro that eliminates this repetitive pattern:
(some-<>> nil)

Issue: Macro call that should be transformed by SOME-<>>

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

Macroexpansion:
(let* ((#:g130 nil))
  #:g130)