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

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

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

Macroexpansion:
(let* ((#:var176 nil)
       (#:var177
        (if #:var176
            (nil #:var176)
            nil)))
  #:var177)
Generate a defmacro form that transforms code like this:
(action (:after node-abstraction) #'handle-pop-hoist-point)

Pattern to recognize: 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-abstraction) (function handle-pop-hoist-point))
Write a Common Lisp macro to handle this code pattern:
(whichever a b c)

Problem: Macro call that should be transformed by whichever

Macro definition:
(defmacro whichever (&rest possibilities &environment env)
  "Evaluates exactly one of POSSIBILITIES, chosen at random."
  (setf possibilities (mapcar (lambda (p) (macroexpand p env)) possibilities))
  (let ((length (length possibilities)))
    (cond
      ((= 1 length)
       (first possibilities))
      ((every #'constantp possibilities)
       `(svref (load-time-value (vector ,@possibilities)) 
               (random ,length)))
      (T
       (labels ((expand (possibilities position random-number)
                  (if (null (cdr possibilities))
                      (car possibilities)
                      (let* ((length (length possibilities))
                             (half (truncate length 2))
                             (second-half (nthcdr half possibilities))
                             (first-half (butlast possibilities (- length half))))
                        `(if (< ,random-number ,(+ position half))
                             ,(expand first-half position random-number)
                             ,(expand second-half (+ position half) random-number))))))
         (with-gensyms (random-number)
           `(let ((,random-number (random ,length)))
              ,(expand possibilities 0 random-number))))))))

Macroexpansion:
(let ((#:random-number136 (random 3))) (if (< #:random-number136 1) a (if (< #:random-number136 2) b c)))
You are a Common Lisp macro expert. Given this code pattern:
(with-cache ("foo" :expire 2 :store storage) 1)

Write a macro that addresses: 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 ((#:key247 "foo") (#:store248 storage) (#:expire249 2)) (multiple-value-bind (#:value250 #:exists-p251) (getcache #:key247 #:store248) (if #:exists-p251 #:value250 (let ((#:value250 (progn 1))) (setcache #:key247 #:value250 #:store248 :expire #:expire249) #:value250))))
Generate a defmacro form that transforms code like this:
(do-generator (item generator) (funcall function item))

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

Macro definition:
(defmacro do-generator ((var &rest vars-and-generator) &body body)
  "Steps through the specified generator, binding the value it returns to var, then executing the body for each step. If multiple variables are specified and the generator returns multiple values, the extra values will be bound to the extra variables."
  (let ((g (gensym)))
    `(let ((,g ,(car (last vars-and-generator))))
       (loop 
	  do (if-generator ((,var ,@(butlast vars-and-generator)) ,g)
			   (progn
			     ,@body)
			   (return))))))

Macroexpansion:
(let ((#:g168 generator)) (loop do (if-generator ((item) #:g168) (progn (funcall function item)) (return))))
Create a Common Lisp macro for the following transformation. Before code:
(with-effective-qualifier generic-function qualifier (intern-hook generic-function hook-name type-list qualifier) `(progn (%defhook-fun ,hook-name ,vanilla-lambda-list ,@body) (%define-method-dispatch ,generic-function ,qualifier ,specialized-lambda-list)))

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

Macro definition:
(defmacro with-effective-qualifier (gf-name qualifier &body body)
  "take generic function and a symbol bound to a qualifier and mask that symbol with the effective qualifier.

The effective qualifier is the default qualifier for the given generic function should there be one defined by
a define-hook-generic form."
  `(let ((,qualifier
          (effective-qualifier ,gf-name ,qualifier)))
     ,@body))

Macroexpansion:
(let ((qualifier (effective-qualifier generic-function qualifier))) (intern-hook generic-function hook-name type-list qualifier) (sb-int:quasiquote (progn (%defhook-fun #S(sb-impl::comma :expr hook-name :kind 0) #S(sb-impl::comma :expr vanilla-lambda-list :kind 0) #S(sb-impl::comma :expr body :kind 2)) (%define-method-dispatch #S(sb-impl::comma :expr generic-function :kind 0) #S(sb-impl::comma :expr qualifier :kind 0) #S(sb-impl::comma :expr specialized-lambda-list :kind 0)))))
Write a Common Lisp macro to handle this code pattern:
(with-current-source-form 'some-name)

Problem: Macro call that should be transformed by WITH-CURRENT-SOURCE-FORM

Macro definition:
(defmacro WITH-CURRENT-SOURCE-FORM ...)

Macroexpansion:
(sb-ext:with-current-source-form 'some-name)
You are a Common Lisp macro expert. Given this code pattern:
(resolving
  'some-name)

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

Macro definition:
(defmacro RESOLVING ...)

Macroexpansion:
(resolve
  'some-name)
Define a macro that eliminates this repetitive pattern:
(producing nil (progn))

Issue: Macro call that should be transformed by PRODUCING

Macro definition:
(defmacro PRODUCING ...)

Macroexpansion:
(non-opt-producing nil
    (progn))
You are a Common Lisp macro expert. Given this code pattern:
(some-> nil nil)

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

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

Macroexpansion:
(let* ((#:|some126| nil) (#:|some126| (when #:|some126| (nil #:|some126|))))
  #:|some126|)
Create a Common Lisp macro for the following transformation. Before code:
(dynamic-let nil)

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

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

Macroexpansion:
(let ()
  (dynamic-wind
    :proceed
    #:g192
    (let ()
      (declare (special))
      (#:g192))))
Create a Common Lisp macro for the following transformation. Before code:
(awhen (incf x) (+ 1 it))

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

Macro definition:
(defmacro awhen (test &body body)
  "Like WHEN, except binds the result of the test to IT (via LET) for the scope
of the body."
  `(anaphoric when ,test ,@body))

Macroexpansion:
(let ((it (incf x))) (when it (+ 1 it)))
Write a Common Lisp macro to handle this code pattern:
(def-neo4j-fun get-node-relationships (node-id direction types) :get (:uri-spec (format nil "node/~A/relationships/~A/~{~A~^\\&~}" node-id (cond ((null direction) "all") ((symbolp direction) (string-downcase (symbol-name direction))) (t direction)) types)) (:status-handlers (200 (decode-neo4j-json-output body)) (404 (error 'node-not-found-error :uri uri))))

Problem: 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 get-node-relationships (&key node-id direction types) (let ((uri (format nil "node/~A/relationships/~A/~{~A~^\\&~}" node-id (cond ((null direction) "all") ((symbolp direction) (string-downcase (symbol-name direction))) (t direction)) types)) (json (encode-neo4j-json-payload nil :string))) (make-neo4j-request :get uri json (list (list 200 (lambda (body uri json) (decode-neo4j-json-output body))) (list 404 (lambda (body uri json) (error (quote node-not-found-error) :uri uri))))))))
Define a macro that eliminates this repetitive pattern:
(compile-$flavor-$methods 'some-name)

Issue: Macro call that should be transformed by COMPILE-$FLAVOR-$METHODS

Macro definition:
(defmacro COMPILE-$FLAVOR-$METHODS ...)

Macroexpansion:
(eval-when (:load-toplevel) (combine-class-methods 'some-name))
Write a Common Lisp macro to handle this code pattern:
(gen-lambda-with-sticky-stop () (multiple-value-bind (res signal) (funcall source) (if signal res (sticky-stop))))

Problem: Macro call that should be transformed by gen-lambda

Macro definition:
(defmacro gen-lambda (params &body rest)
  "Version of lambda that wraps the anonymous function in an instance of the basic-generator class. This allows the lambda to be identified as a generator by its type. Basic-generator objects are derived from funcallable-standard-class, therefore they can be called as functions."
  `(let ((values-handler (create-values-handler)))
     (declare (ignorable values-handler))
     (make-instance 
      'basic-generator 
      :function (lambda ,params ,@rest))))

Macroexpansion:
(make-instance (quote basic-generator) :function (sticky-stop-lambda nil (multiple-value-bind (res signal) (funcall source) (if signal res (sticky-stop)))))
Create a Common Lisp macro for the following transformation. Before code:
(with-atomic-updates 'with-atomic-updates)

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

Macro definition:
(defmacro with-atomic-updates ((&rest variables) &body body)
  ;;Self-binding is necessary to avoid losing the previous value
  `(with-atomic-updates* ,variables (let ,(mapcar (lambda (var) (list var var)) variables)) ,@body))

Macroexpansion:
(with-atomic-updates* (quote with-atomic-updates) (let ((quote quote) (with-atomic-updates with-atomic-updates))))
You are a Common Lisp macro expert. Given this code pattern:
(ct-flet nil)

Write a macro that addresses: Macro call that should be transformed by CT-FLET

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

Macroexpansion:
(cond (*within-captured-dynenv* (progn))
      (t
       (error
        "No macrodynamic environment has been captured to establish CT-FLET bindings.")))
Generate a defmacro form that transforms code like this:
(with-dot nil)

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

Macro definition:
(defmacro with-dot (() &body body)
  `(progn ,@(replace-dot-calls body)))

Macroexpansion:
(progn)
Generate a defmacro form that transforms code like this:
(c? (/ (len self) 2))

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 ((/ (len self) 2))) :value-state :unevaluated :rule (c-lambda (/ (len self) 2)))
You are a Common Lisp macro expert. Given this code pattern:
(with-wcs-math-error-handling (ret (ffloor x)) (check-wcs-math-result))

Write a macro that addresses: 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* ((#:g245 x) (#:g246 nil) (#:g247 (list #:g245))) (declare (ignorable #:g246) (type list #:g247) (dynamic-extent #:g247)) (catch (quote return-from-with-wcs-math-error-handling) (multiple-value-bind (ret) (call-with-wcs-math-error-handler (quote ffloor) #:g247) (flet ((check-wcs-math-result (&optional (ret ret) (arg-list #:g247)) (check-wcs-math-result ret arg-list))) (check-wcs-math-result)))))
Define a macro that eliminates this repetitive pattern:
(do-readtable (char readtable) (set-syntax-from-char char #\A readtable))

Issue: Macro call that should be transformed by do-readtable

Macro definition:
(defmacro do-readtable ((entry-designator readtable &optional result)
                        &body body)
  "Iterate through a readtable's macro characters, and dispatch macro characters."
  (destructuring-bind (char &optional reader-fn non-terminating-p disp? table)
      (if (symbolp entry-designator)
          (list entry-designator)
          entry-designator)
    (let ((iter (gensym "ITER+"))
          (more? (gensym "MORE?+"))
          (rt (gensym "READTABLE+")))
      `(let ((,rt ,readtable))
         (with-readtable-iterator (,iter ,rt)
           (loop
             (multiple-value-bind (,more?
                                   ,char
                                   ,@(when reader-fn (list reader-fn))
                                   ,@(when disp? (list disp?))
                                   ,@(when table (list table)))
                 (,iter)
               (unless ,more? (return ,result))
               (let ,(when non-terminating-p
                       ;; FIXME: N-T-P should be incorporated in iterators.
                       `((,non-terminating-p
                          (nth-value 1 (get-macro-character ,char ,rt)))))
                 ,@body))))))))

Macroexpansion:
(let ((#:readtable+143 readtable)) (with-readtable-iterator (#:iter+141 #:readtable+143) (loop (multiple-value-bind (#:more?+142 char) (#:iter+141) (unless #:more?+142 (return nil)) (let nil (set-syntax-from-char char #\LATIN_CAPITAL_LETTER_A readtable))))))
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:
(progn nil)
Define a macro that eliminates this repetitive pattern:
(ematch0 more-patterns (nil nil) ((list* _ subpattern more-patterns) (append (%variables subpattern) (%variables-more-patterns more-patterns))))

Issue: Macro call that should be transformed by ematch0

Macro definition:
(defmacro ematch0 (what &body clauses)
  `(match0 ,what
     ,@clauses
     (_ (error "level0 match error!"))))

Macroexpansion:
(match0 more-patterns (nil nil) ((list* _ subpattern more-patterns) (append (%variables subpattern) (%variables-more-patterns more-patterns))) (_ (error "level0 match error!")))
Create a Common Lisp macro for the following transformation. Before code:
(ct-let* nil
  nil)

What needs to change: Macro call that should be transformed by CT-LET*

Macro definition:
(defmacro CT-LET* ...)

Macroexpansion:
(cond (*within-captured-dynenv* (progn nil))
      (t
       (error
        "No macrodynamic environment has been captured to establish CT-LET* bindings.")))
Write a Common Lisp macro to handle this code pattern:
(check-cursor-attached cluffer:buffer (cursor))

Problem: Macro call that should be transformed by check-cursor-attached

Macro definition:
(defmacro check-cursor-attached (name arguments)
  (let ((args (substitute '(cursor cluffer:cursor) 'cursor arguments)))
    `(defmethod ,name :before ,args
       (declare (ignore ,@(set-difference (remove 'cursor arguments)
                                          lambda-list-keywords)))
       (unless (cluffer:cursor-attached-p cursor)
         (error 'cluffer:cursor-detached)))))

Macroexpansion:
(defmethod cluffer:buffer :before ((cursor cluffer:cursor)) (declare (ignore)) (unless (cluffer:cursor-attached-p cursor) (error (quote cluffer:cursor-detached))))
You are a Common Lisp macro expert. Given this code pattern:
(make-method-function-call (function-name info) args `(#'call-next-method ,(and next-method t)))

Write a macro that addresses: Macro call that should be transformed by make-method

Macro definition:
(defmacro make-method (form)
  `(cl:make-method ,form))

Macroexpansion:
(make-method-function-call (function-name info) args (sb-int:quasiquote ((function call-next-method) #S(sb-impl::comma :expr (and next-method t) :kind 0))))
Create a Common Lisp macro for the following transformation. Before code:
(defsynonym until :until)

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

Macro definition:
(defmacro defsynonym (symbol synonym)
  "Set SYNONYM for a SYMBOL. "
  `(eval-always
     (setf (get ',symbol 'synonym) ',synonym)))

Macroexpansion:
(eval-always (setf (get (quote until) (quote synonym)) (quote :until)))
Create a Common Lisp macro for the following transformation. Before code:
(defvar-unbound *start-char* "Bound to the opening outer delimiter while parsing a string.")

What needs to change: Macro call that should be transformed by defvar-unbound

Macro definition:
(defmacro defvar-unbound (variable-name documentation)
  "Like DEFVAR, but the variable will be unbound rather than getting
an initial value.  This is useful for variables which should have no
global value but might have a dynamically bound value."
  ;; stolen from comp.lang.lisp article <k7727i3s.fsf@comcast.net> by
  ;; "prunesquallor@comcast.net"
  `(eval-when (:load-toplevel :compile-toplevel :execute)
    (defvar ,variable-name)
    (setf (documentation ',variable-name 'variable)
            ,documentation)))

Macroexpansion:
(eval-when (:load-toplevel :compile-toplevel :execute) (defvar *start-char*) (setf (documentation (quote *start-char*) (quote variable)) "Bound to the opening outer delimiter while parsing a string."))
Write a Common Lisp macro to handle this code pattern:
(defannotation inline* (name) (:alias inline :inline t) "Shorthand for (DECLARE (INLINE ...))." (let ((symbol (definition-form-symbol name)) (type (definition-form-type name))) (if (and symbol (member type '(defun defmethod))) `(progn (declaim (inline ,symbol)) ,name) `(declare (inline ,name)))))

Problem: 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 inline*) (quote (:alias inline :inline t))) (defmacro inline* (name) "Shorthand for (DECLARE (INLINE ...))." (let ((symbol (definition-form-symbol name)) (type (definition-form-type name))) (if (and symbol (member type (quote (defun defmethod)))) (sb-int:quasiquote (progn (declaim (inline #S(sb-impl::comma :expr symbol :kind 0))) #S(sb-impl::comma :expr name :kind 0))) (sb-int:quasiquote (declare (inline #S(sb-impl::comma :expr name :kind 0))))))))
Write a Common Lisp macro to handle this code pattern:
(ensure-gethash x table 42)

Problem: Macro call that should be transformed by ensure-gethash

Macro definition:
(defmacro ensure-gethash (key hash-table &optional default)
  "Like GETHASH, but if KEY is not found in the HASH-TABLE saves the DEFAULT
under key before returning it. Secondary return value is true if key was
already in the table."
  (once-only (key hash-table)
    (with-unique-names (value presentp)
      `(multiple-value-bind (,value ,presentp) (gethash ,key ,hash-table)
         (if ,presentp
             (values ,value ,presentp)
             (values (setf (gethash ,key ,hash-table) ,default) nil))))))

Macroexpansion:
(let ((#:n-key-159 x) (#:n-hash-table-160 table)) (multiple-value-bind (#:value161 #:foundp162) (gethash #:n-key-159 #:n-hash-table-160) (if #:foundp162 (values #:value161 t) (values (setf (gethash #:n-key-159 #:n-hash-table-160) 42) nil))))
You are a Common Lisp macro expert. Given this code pattern:
(builder (:static :path (lambda (path-info) (when (starts-with-subseq "/static/" path-info) (subseq path-info #.(length "/static")))) :root (asdf:system-relative-pathname :lack #P"data/")) (lambda (env) (declare (ignore env)) `(200 (:content-type "text/plain") ("ok"))))

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

Macro definition:
(defmacro builder (&rest app-or-middlewares)
  (let ((middlewares (butlast app-or-middlewares)))
    `(reduce #'funcall
             (remove-if
              #'null
              (list
               ,@(loop for mw in middlewares
                       when mw
                         collect (convert-to-middleware-form mw))))
             :initial-value (to-app ,(car (last app-or-middlewares)))
             :from-end t)))

Macroexpansion:
(reduce (function funcall) (remove-if (function null) (list (lambda (#:app230) (funcall (find-middleware :static) #:app230 :path (lambda (path-info) (when (starts-with-subseq "/static/" path-info) (subseq path-info 7))) :root (asdf/system:system-relative-pathname :lack #P"data/"))))) :initial-value (to-app (lambda (env) (declare (ignore env)) (sb-int:quasiquote (200 (:content-type "text/plain") ("ok"))))) :from-end t)