j14i/cl-macros huggingface dataset:
Write a Common Lisp macro to handle this code pattern:
(with-cache ((list x y z)) (if (<= x y) z (tak (tak/with-cache (1- x) y z) (tak/with-cache (1- y) z x) (tak/with-cache (1- z) x y))))

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 ((#:key227 (list x y z)) (#:store228 nil) (#:expire229 nil)) (multiple-value-bind (#:value230 #:exists-p231) (getcache #:key227 #:store228) (if #:exists-p231 #:value230 (let ((#:value230 (progn (if (<= x y) z (tak (tak/with-cache (1- x) y z) (tak/with-cache (1- y) z x) (tak/with-cache (1- z) x y)))))) (setcache #:key227 #:value230 #:store228 :expire #:expire229) #:value230))))
Create a Common Lisp macro for the following transformation. Before code:
(signal-syntax-error "Unknown flag token ~A." token)

What needs to change: Macro call that should be transformed by signal-syntax-error

Macro definition:
(defmacro signal-syntax-error (format-control &rest format-arguments)
  `(signal-syntax-error* nil ,format-control ,@format-arguments))

Macroexpansion:
(signal-syntax-error* nil "Unknown flag token ~A." token)
Write a Common Lisp macro to handle this code pattern:
(defreply nil
    :key
  nil)

Problem: Macro call that should be transformed by DEFREPLY

Macro definition:
(defmacro DEFREPLY ...)

Macroexpansion:
(progn
 (eval-when (:compile-toplevel)
   (unless (fboundp 'nil)
     (warn 'automatic-message-creation :message-name 'nil)
     (ensure-message 'nil :lambda-list 'nil)))
 (ensure-reply 'nil :qualifiers '(:key) :lambda-list 'nil :participants (list)
               :documentation nil :function
               (lambda (#:args144 #:next-replies145 &rest #:more-args147)
                 (declare
                  (ignorable #:args144 #:next-replies145 #:more-args147))
                 (flet ((next-reply-p ()
                          (not (null #:next-replies145)))
                        (call-next-reply (&rest args)
                          (if (null #:next-replies145)
                              (apply 'no-next-reply
                                     (getf #:more-args147 :message)
                                     (getf #:more-args147 :reply)
                                     (or args #:args144))
                              (apply (reply-function (car #:next-replies145))
                                     (or args #:args144)
                                     (cdr #:next-replies145) #:more-args147))))
                   (declare
                    (ignorable (function next-reply-p)
                     (function call-next-reply)))
                   (flet ((#:reply-function146 ()
                            (declare (ignorable))
                            (block nil)))
                     (declare (inline #:reply-function146))
                     (apply #'#:reply-function146 #:args144))))))
Generate a defmacro form that transforms code like this:
(define-class-method nil
    :key
  nil)

Pattern to recognize: Macro call that should be transformed by DEFINE-CLASS-METHOD

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

Macroexpansion:
(progn
 (define-incongruent-method nil
     :key
   nil)
 (eval-when (:compile-toplevel :load-toplevel :execute)
   (add-class-principal-method 'nil ':key)))
Define a macro that eliminates this repetitive pattern:
(as-> nil
    :key
  nil)

Issue: Macro call that should be transformed by AS->

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

Macroexpansion:
(let* ((:key nil) (:key (nil)))
  :key)
Create a Common Lisp macro for the following transformation. Before code:
(defobject 'some-name)

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

Macro definition:
(defmacro DEFOBJECT ...)

Macroexpansion:
(object :parents (list quote some-name) :properties (list))
Define a macro that eliminates this repetitive pattern:
(iterate)

Issue: Macro call that should be transformed by ITERATE

Macro definition:
(defmacro ITERATE ...)

Macroexpansion:
(iter)
You are a Common Lisp macro expert. Given this code pattern:
(defsynonym never :never)

Write a macro that addresses: 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 never) (quote synonym)) (quote :never)))
Write a Common Lisp macro to handle this code pattern:
(define-simple-definition-resolver macro macro-function)

Problem: 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 macro (macro #:package134) (when (ignore-errors (macro-function macro)) (list (make-instance (quote macro) :designator macro :package #:package134))))
Define a macro that eliminates this repetitive pattern:
(define-option-expander shadow (package &rest symbols) (shadow symbols package))

Issue: Macro call that should be transformed by define-option-expander

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

Macroexpansion:
(defmethod expand-option ((#:type128 (eql :shadow)) package #:args127) (destructuring-bind (&rest symbols) #:args127 (shadow symbols package)))
Create a Common Lisp macro for the following transformation. Before code:
(lambda-ematch0 ((list* var options) `(type ,(getf options :type) ,var)))

What needs to change: Macro call that should be transformed by lambda-ematch0

Macro definition:
(defmacro lambda-ematch0 (&body clauses)
  (alexandria:with-gensyms (arg)
    `(lambda (,arg)
       (ematch0 ,arg
         ,@clauses))))

Macroexpansion:
(lambda (#:arg167) (ematch0 #:arg167 ((list* var options) (sb-int:quasiquote (type #S(sb-impl::comma :expr (getf options :type) :kind 0) #S(sb-impl::comma :expr var :kind 0))))))
Create a Common Lisp macro for the following transformation. Before code:
(define-modf-rewrite cdadar (expr) `(cdr (cadar ,(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 cdadar) *modf-rewrites*) (lambda (expr) (sb-int:quasiquote (cdr (cadar #S(sb-impl::comma :expr (second expr) :kind 0)))))))
Create a Common Lisp macro for the following transformation. Before code:
(lambda-match
  nil
  :key
  nil)

What needs to change: Macro call that should be transformed by LAMBDA-MATCH

Macro definition:
(defmacro LAMBDA-MATCH ...)

Macroexpansion:
(lambda (#:arg149)
  (match #:arg149
    nil
    :key
    nil))
Create a Common Lisp macro for the following transformation. Before code:
(receive (x) (values) x)

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

Macro definition:
(defmacro receive (formals expr &body body)
  "Stricter version of `multiple-value-bind'.

Use `receive' when you want to enforce that EXPR should return a
certain number of values, or a minimum number of values.

If FORMALS is a proper list, then EXPR must return exactly as many
values -- no more and no less -- as there are variables in FORMALS.

If FORMALS is an improper list (VARS . REST), then EXPR must return at
least as many values as there are VARS, and any further values are
bound, as a list, to REST.

Lastly, if FORMALS is a symbol, bind that symbol to all the values
returned by EXPR, as if by `multiple-value-list'.

From Scheme (SRFI-8)."
  ;; It's probably not worth stack-allocating the thunk.
  (cond ((null formals)
         `(multiple-value-call
              (lambda ()
                ,@body)
            ,expr))
        ((atom formals)
         ;; This could also be written:
         #+(or) `(let ((,formals (multiple-value-list ,expr)))
                   ,@body)
         ;; But I want it to be possible to declare FORMALS to have
         ;; dynamic extent, and most Lisps support that for &rest
         ;; lists.
         `(multiple-value-call
              (lambda (&rest ,formals)
                ,@body)
            ,expr))
        ((proper-list-p formals)
         (when (intersection formals lambda-list-keywords)
           (error "Lambda list keywords in formals: ~a" formals))
         `(multiple-value-call
              (lambda ,formals
                ,@body)
            ,expr))
        (t (let* ((last (last formals))
                  (vars (append (butlast formals)
                                (list (car last))))
                  (rest (cdr last)))
             (when (intersection (cons rest vars) lambda-list-keywords)
               (error "Lambda list keywords in formals: ~a" formals))
             `(multiple-value-call
                  (lambda (,@vars &rest ,rest)
                    ,@body)
                ,expr)))))

Macroexpansion:
(multiple-value-call (lambda (x) x) (values))
Define a macro that eliminates this repetitive pattern:
(do+ (for x (to 5)) (generating y (in #(0 1))) (collect (list x y)) (when (oddp x) (is (eql (try-update y :on-error (lambda (value cond) (setf error cond) value)) y))) (when error (multiple-value-bind (value success?) (try-update y) (is (eql value y)) (is (null success?)))))

Issue: 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 (for x (to 5)) (generating y (in #(0 1))) (collect (list x y)) (when (oddp x) (is (eql (try-update y :on-error (lambda (value cond) (setf error cond) value)) y))) (when error (multiple-value-bind (value success?) (try-update y) (is (eql value y)) (is (null success?)))))
Write a Common Lisp macro to handle this code pattern:
(def-neo4j-fun list-indexes ((type :node)) :get (:uri-spec (format nil "index/~A" (string-downcase (symbol-name type)))) (:status-handlers (200 (decode-neo4j-json-output body))))

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 list-indexes (&key (type :node)) (let ((uri (format nil "index/~A" (string-downcase (symbol-name type)))) (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))))))))
Write a Common Lisp macro to handle this code pattern:
(defiter nil
    (progn))

Problem: Macro call that should be transformed by DEFITER

Macro definition:
(defmacro DEFITER ...)

Macroexpansion:
(defun nil (progn) (make-instance 'iterator :coro (lambda-coro)))
Create a Common Lisp macro for the following transformation. Before code:
(define-templated-dispatch nil
    :key
  nil)

What needs to change: Macro call that should be transformed by DEFINE-TEMPLATED-DISPATCH

Macro definition:
(defmacro DEFINE-TEMPLATED-DISPATCH ...)

Macroexpansion:
(define-type-dispatch nil
    :key)
Define a macro that eliminates this repetitive pattern:
(caching-types)

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 ()))))))))
Create a Common Lisp macro for the following transformation. Before code:
(-<>>
  'some-name)

What needs to change: Macro call that should be transformed by -<>>

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

Macroexpansion:
'some-name
Create a Common Lisp macro for the following transformation. Before code:
(->*
  nil
  (progn))

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

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

Macroexpansion:
(let* ((#:var192 (progn)) (#:var193 (nil #:var192)))
  #:var193)
You are a Common Lisp macro expert. Given this code pattern:
(define-modf-rewrite cdar (expr) `(cdr (car ,(second 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 cdar) *modf-rewrites*) (lambda (expr) (sb-int:quasiquote (cdr (car #S(sb-impl::comma :expr (second expr) :kind 0)))))))
You are a Common Lisp macro expert. Given this code pattern:
(defstore example (object))

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

Macro definition:
(defmacro defstore (store-name store-lambda-list &body body &environment env)
  (let* ((store-class-name (second (find :store-class body :key #'first)))
         (store-class (etypecase store-class-name
                        (null (find-class 'standard-store))
                        (symbol (find-class store-class-name))))
         (form (apply #'defstore-using-class store-class store-name store-lambda-list
                      :environment env
                      (mapcan #'(lambda (item)
                                  (cond ((eql (first item) :store-class)
                                         `(:store-class ',store-class-name))
                                        ((and (member (first item) '(:documentation :specialization-class)))
                                         (if (= 2 (length item))
                                             item
                                             (error "Invalid store definition option: ~W." item)))
                                        (t
                                         (list (first item) (rest item)))))
                              body))))
    `(eval-when (:compile-toplevel :load-toplevel :execute)
       ,form)))

Macroexpansion:
(eval-when (:compile-toplevel :load-toplevel :execute) (progn (ensure-store (quote example) (quote (object)))))
Write a Common Lisp macro to handle this code pattern:
(some->)

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

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

Macroexpansion:
nil
You are a Common Lisp macro expert. Given this code pattern:
(with-packages-unlocked 'some-name)

Write a macro that addresses: Macro call that should be transformed by WITH-PACKAGES-UNLOCKED

Macro definition:
(defmacro WITH-PACKAGES-UNLOCKED ...)

Macroexpansion:
(let ((#:|packages124| (locked-packages ''some-name)))
  (unlock-packages #:|packages124|)
  (unwind-protect (lock-packages #:|packages124|)))
Write a Common Lisp macro to handle this code pattern:
(answer foo 42)

Problem: Macro call that should be transformed by answer

Macro definition:
(defmacro answer (call &body forms)
  (let ((name (if (listp call) (car call) call))
        (sym (gensym)))
    `(if-called
      ',name
      (let ((,sym (fdefinition ',name)))
        (declare (ignorable ,sym))
        (let ((times 0))
          (lambda (&rest args)
            (declare (ignorable args))
            ,(let ((cases
                     `(case (prog1 times (incf times))
                        ,.(loop
                            for i from 0
                            for (form . rest) on forms
                            collect `(,(if rest i T) ,form)))))
               (if (listp call)
                   `(trivia:match args
                     ((list . ,(cdr call)) ,cases)
                     (_ (unhandled)))
                   cases))))))))

Macroexpansion:
(if-called (quote foo) (let ((#:g162 (fdefinition (quote foo)))) (declare (ignorable #:g162)) (let ((times 0)) (lambda (&rest args) (declare (ignorable args)) (case (prog1 times (incf times)) (t 42))))))
You are a Common Lisp macro expert. Given this code pattern:
(defvar-compile-time *tagbody-tags* '() "This must be globally NIL.")

Write a macro that addresses: Macro call that should be transformed by defvar-compile-time

Macro definition:
(defmacro defvar-compile-time (name &optional initial-value documentation)
  `(eval-when (:compile-toplevel :load-toplevel :execute)
     (defvar ,name ,initial-value ,documentation)))

Macroexpansion:
(eval-when (:compile-toplevel :load-toplevel :execute) (defvar *tagbody-tags* (quote nil) "This must be globally NIL."))
Write a Common Lisp macro to handle this code pattern:
(f 'some-name)

Problem: Macro call that should be transformed by F

Macro definition:
(defmacro F ...)

Macroexpansion:
(lambda (quote some-name))
Create a Common Lisp macro for the following transformation. Before code:
(bdd-typecase 'some-name)

What needs to change: Macro call that should be transformed by BDD-TYPECASE

Macro definition:
(defmacro BDD-TYPECASE ...)

Macroexpansion:
((lambda (#:obj165)
   (declare (ignorable #:obj165))
   (block #:block166 (tagbody)))
 'some-name)
You are a Common Lisp macro expert. Given this code pattern:
(collect-hash nil (progn))

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

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

Macroexpansion:
(common-lisp:let* ((#:out-149 (make-hash-table)))
  (common-lisp:let ((#:generator-153 (generator (progn)))
                    #:values-145
                    (#:generator-151 (generator nil))
                    #:keys-144)
    (declare (type generator #:generator-153)
             (type generator #:generator-151))
    (tagbody
     #:ll-154
      (setq #:values-145 (next-in #:generator-153 (go end)))
      (setq #:keys-144 (next-in #:generator-151 (go end)))
      (setf (gethash #:keys-144 #:out-149) #:values-145)
      (go #:ll-154)
     end)
    #:out-149))
Define a macro that eliminates this repetitive pattern:
(define-error unknown-type-spec () (type-spec) "Could not find the correct type for type-spec ~s~@[ ~a~]~%~a" type-spec (when (typep type-spec 'v-type) (format nil "~%It seems we recieved a type object instead of type spec")) (let ((found (find-alternative-types-for-spec type-spec))) (if found (format nil "~%Perhaps you meant one of these types?:~%~(~{~s~%~}~)" found) "")))

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

Macro definition:
(defmacro define-error (name (&key (error-type 'varjo-error) (prefix "Varjo"))
                            (&rest args) error-string &body body)
  `(defcondition ,name (:error-type ,error-type :prefix ,prefix) ,args
       ,error-string ,@body))

Macroexpansion:
(defcondition unknown-type-spec (:error-type varjo-error :prefix "Varjo") (type-spec) "Could not find the correct type for type-spec ~s~@[ ~a~]~%~a" type-spec (when (typep type-spec (quote v-type)) (format nil "~%It seems we recieved a type object instead of type spec")) (let ((found (find-alternative-types-for-spec type-spec))) (if found (format nil "~%Perhaps you meant one of these types?:~%~(~{~s~%~}~)" found) "")))
Generate a defmacro form that transforms code like this:
(def-dynenv-macro nil
    nil)

Pattern to recognize: Macro call that should be transformed by DEF-DYNENV-MACRO

Macro definition:
(defmacro DEF-DYNENV-MACRO ...)

Macroexpansion:
(defmacro nil (&environment #:env174) (with-dynenv #:env174))
You are a Common Lisp macro expert. Given this code pattern:
(deferror "08007" transaction-resolution-unknown)

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

Macro definition:
(defmacro deferror (code typename &optional (superclass 'database-error))
  `(progn (define-condition ,typename (,superclass) ())
          (setf (gethash ,code *error-table*) ',typename)))

Macroexpansion:
(progn (define-condition transaction-resolution-unknown (database-error) nil) (setf (gethash "08007" *error-table*) (quote transaction-resolution-unknown)))
Write a Common Lisp macro to handle this code pattern:
(failure NIL)

Problem: Macro call that should be transformed by fail

Macro definition:
(defmacro fail (form &optional (type 'error) description &rest format-args)
  `(eval-in-context
    *context*
    (make-instance 'comparison-result
                   :expression '(fail ,form ,type)
                   :value-form '(capture-error ,form)
                   :body (lambda () (capture-error ,form ,(maybe-unquote type)))
                   :expected ',(maybe-unquote type)
                   :comparison 'typep
                   ,@(when description
                       `(:description (format NIL ,description ,@format-args))))))

Macroexpansion:
(failure nil)
Define a macro that eliminates this repetitive pattern:
(flow-lambda-macro (flow-context) `(flet ((,test-fu () ,live-test-form)) (dispatch-repeatedly ,flow-context #',test-fu ,flow-list)))

Issue: Macro call that should be transformed by flow-lambda-macro

Macro definition:
(defmacro flow-lambda-macro ((flow-context) &body body)
  `(with-gensyms (,flow-context)
     `(%flow-lambda (,,flow-context)
        ,,@body)))

Macroexpansion:
(with-gensyms (flow-context) (sb-int:quasiquote (%flow-lambda (#S(sb-impl::comma :expr flow-context :kind 0)) #S(sb-impl::comma :expr (sb-int:quasiquote (flet ((#S(sb-impl::comma :expr test-fu :kind 0) nil #S(sb-impl::comma :expr live-test-form :kind 0))) (dispatch-repeatedly #S(sb-impl::comma :expr flow-context :kind 0) (function #S(sb-impl::comma :expr test-fu :kind 0)) #S(sb-impl::comma :expr flow-list :kind 0)))) :kind 0))))