j14i/cl-macros huggingface dataset:
Define a macro that eliminates this repetitive pattern:
(define-method-combination% nconc :operator nconc :identity-with-one-argument t)

Issue: Macro call that should be transformed by define-method-combination%

Macro definition:
(defmacro define-method-combination% (name &rest args)
  "Define a method-combination for the static-dispatch system only.

   Arguments are of the same form as to CL:DEFINE-METHOD-COMBINATION."

  `(eval-when (:compile-toplevel :load-toplevel :execute)
     (setf
      (combination-function ',name)
      ,(match args
         ((or nil
              (list* (and (type symbol) (not nil)) _))

          (destructuring-bind (&key (operator name) (identity-with-one-argument nil))
              args

            `(method-combination-function-short ,name ,operator ,identity-with-one-argument)))

         (_
          `(method-combination-function ,name ,@args))))))

Macroexpansion:
(eval-when (:compile-toplevel :load-toplevel :execute) (setf (combination-function (quote nconc)) (method-combination-function-short nconc nconc t)))
Generate a defmacro form that transforms code like this:
(define-modf-rewrite caadar (expr) `(car (cadar ,(second expr))))

Pattern to recognize: 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 caadar) *modf-rewrites*) (lambda (expr) (sb-int:quasiquote (car (cadar #S(sb-impl::comma :expr (second expr) :kind 0)))))))
You are a Common Lisp macro expert. Given this code pattern:
(with-reader-syntax (string) (is (string-equal "5.0d0" (er "(let ((a 5.0d0)) $a)"))))

Write a macro that addresses: Macro call that should be transformed by with-reader-syntax

Macro definition:
(defmacro with-reader-syntax (reader-macro-identifiers &body body)
  "This macro is only made for use by read-and-eval functionality,
and rather directed towards tests than users. So, do not export."
  (let ((identifiers (loop :for identifier :in reader-macro-identifiers
                           :collect `(quote ,identifier))))
    `(let ((*array-function*         'make-t-array-from-initial-contents)
           (*hash-table-function*    'alexandria:plist-hash-table)
           (*get-val-function*       'get-val)
           (*get-val-array-function* 'cl:aref)
           (*set-function*           'cl:remove-duplicates)
           (*alists-are-lists*       nil)
           (*plists-are-lists*       nil)
           (*readtable*             (%enable-reader-syntax *readtable* ,@identifiers)))
       ,@body)))

Macroexpansion:
(let ((*array-function* (quote make-t-array-from-initial-contents)) (*hash-table-function* (quote alexandria:plist-hash-table)) (*get-val-function* (quote get-val)) (*get-val-array-function* (quote aref)) (*set-function* (quote remove-duplicates)) (*alists-are-lists* nil) (*plists-are-lists* nil) (*readtable* (%enable-reader-syntax *readtable* (quote string)))) (is (string-equal "5.0d0" (er "(let ((a 5.0d0)) $a)"))))
You are a Common Lisp macro expert. Given this code pattern:
(lret () 1)

Write a macro that addresses: 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 nil 1)
Create a Common Lisp macro for the following transformation. Before code:
(with-mocks () (answer (foo 1) 42) (answer foo 23) (is (eql 42 (foo 1))))

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

Macro definition:
(defmacro with-mocks ((&key (recordp T)) &body body)
  "Execute BODY in a new mocking context.  Invocations will be recorded
if RECORDP is set (default true)."
  `(call-with-mocks
    (lambda () ,@body)
    :recordp ,recordp))

Macroexpansion:
(call-with-mocks (lambda nil (answer (foo 1) 42) (answer foo 23) (is (eql 42 (foo 1)))) :recordp t)
You are a Common Lisp macro expert. Given this code pattern:
(unwind-protect-case (aborted-p) (protected-form) (:always (perform-cleanup-if aborted-p)))

Write a macro that addresses: 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+122 t)) (unwind-protect (multiple-value-prog1 (protected-form) (setf #:flag+122 nil)) (let ((aborted-p #:flag+122)) (progn (perform-cleanup-if aborted-p)))))
Generate a defmacro form that transforms code like this:
(def-neo4j-fun cypher-query (statements) :post (:uri-spec "transaction/commit") (:encode statements :statements) (:status-handlers (200 (decode-neo4j-json-output body)) (404 (error 'node-not-found-error :uri uri))))

Pattern to recognize: 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 cypher-query (&key statements) (let ((uri "transaction/commit") (json (encode-neo4j-json-payload statements :statements))) (make-neo4j-request :post 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))))))))
Generate a defmacro form that transforms code like this:
(-> nil nil)

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

Macro definition:
(defmacro -> ...)

Macroexpansion:
(nil nil)
You are a Common Lisp macro expert. Given this code pattern:
(defannotation notinline* (name) (:alias notinline :inline t) "Shorthand for (DECLARE (NOTINLINE ...))." (let ((symbol (definition-form-symbol name)) (type (definition-form-type name))) (if (and symbol (member type '(defun defmethod))) `(progn (declaim (notinline ,symbol)) ,name) `(declare (notinline ,name)))))

Write a macro that addresses: 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 notinline*) (quote (:alias notinline :inline t))) (defmacro notinline* (name) "Shorthand for (DECLARE (NOTINLINE ...))." (let ((symbol (definition-form-symbol name)) (type (definition-form-type name))) (if (and symbol (member type (quote (defun defmethod)))) (sb-int:quasiquote (progn (declaim (notinline #S(sb-impl::comma :expr symbol :kind 0))) #S(sb-impl::comma :expr name :kind 0))) (sb-int:quasiquote (declare (notinline #S(sb-impl::comma :expr name :kind 0))))))))
Create a Common Lisp macro for the following transformation. Before code:
(*> +consume-ws-crlf+ +skipws1+)

What needs to change: 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 (#:*>-offset131) (multiple-value-bind (#:*>-res132 #:*>-next133) (funcall +consume-ws-crlf+ #:*>-offset131) (if (ok? #:*>-res132) (funcall +skipws1+ #:*>-next133) (fail #:*>-next133))))
Write a Common Lisp macro to handle this code pattern:
(dletf nil
  nil)

Problem: Macro call that should be transformed by DLETF

Macro definition:
(defmacro DLETF ...)

Macroexpansion:
(special-symbol-progv (with-symbol-access
                        (list))
    (list)
  (locally (declare (special)) nil))
Define a macro that eliminates this repetitive pattern:
(some->
  nil
  nil)

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

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

Macroexpansion:
(let* ((#:var169 nil)
       (#:var170
        (if #:var169
            (nil #:var169)
            nil)))
  #:var170)
Create a Common Lisp macro for the following transformation. Before code:
(ematch0 or1 ((list* 'or1 or-subpatterns) (list* 'or1 (mapcar (lambda (or-sp) `(and ,or-sp ,@guard1-patterns)) or-subpatterns))))

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

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

Macroexpansion:
(match0 or1 ((list* (quote or1) or-subpatterns) (list* (quote or1) (mapcar (lambda (or-sp) (sb-int:quasiquote (and #S(sb-impl::comma :expr or-sp :kind 0) #S(sb-impl::comma :expr guard1-patterns :kind 2)))) or-subpatterns))) (_ (error "level0 match error!")))
You are a Common Lisp macro expert. Given this code pattern:
(defclass/std computer (gadget) ((screen mouse keyboard :a :type string :with) (bluetooth touchpad :wi :std :unbound) (speaker microphone :r) (place :@@ :with-prefix :doc "Where it is" :r) (owner :static :std "Me" :w)))

Write a macro that addresses: Macro call that should be transformed by defclass/std

Macro definition:
(defmacro defclass/std (name direct-superclasses direct-slots &rest options
                        &environment env)
  "Shortcut macro to the DEFCLASS macro.

  (defclass/std example ()
    ((slot1 slot2 slot3)))

  expands to:

  (DEFCLASS EXAMPLE ()
    ((SLOT1 :ACCESSOR SLOT1 :INITARG :SLOT1 :INITFORM NIL)
    (SLOT2 :ACCESSOR SLOT2 :INITARG :SLOT2 :INITFORM NIL)
    (SLOT3 :ACCESSOR SLOT3 :INITARG :SLOT3 :INITFORM NIL)))

  Each slot definition accepts options:

    :std 1 => changes the :initform to 1. It can be :unbound.
    :with or :with-prefix => creates accessors with the class name as prefix.

  See the README for more.

  See also `class/std' and `print-object/std'.
  "
  `(defclass ,name ,direct-superclasses
     ,(process-slots env direct-slots name)
     ,@options))

Macroexpansion:
(defclass computer (gadget) ((screen :accessor computer-screen :type string) (mouse :accessor computer-mouse :type string) (keyboard :accessor computer-keyboard :type string) (bluetooth :writer bluetooth :initarg :bluetooth) (touchpad :writer touchpad :initarg :touchpad) (speaker :reader speaker :initform nil) (microphone :reader microphone :initform nil) (place :reader computer-place :initform nil :allocation :class :documentation "Where it is") (owner :writer owner :initform "Me" :allocation :class)))
Generate a defmacro form that transforms code like this:
(defpattern nil
    (progn))

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

Macro definition:
(defmacro DEFPATTERN ...)

Macroexpansion:
(eval-always
  (setf (get 'nil 'cl-match-pattern)
          (lambda (#:g133)
            (lett (progn)
                #:g133))))
Write a Common Lisp macro to handle this code pattern:
(fail 'happy)

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:
(eval-in-context *context* (make-instance (quote comparison-result) :expression (quote (fail (quote happy) error)) :value-form (quote (capture-error (quote happy))) :body (lambda nil (capture-error (quote happy) error)) :expected (quote error) :comparison (quote typep)))
You are a Common Lisp macro expert. Given this code pattern:
($map-reduce "foo" m r :out "testit" :query ($> "l" -900))

Write a macro that addresses: 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 "testit" "testit" (concatenate (quote string) "mr." "foo"))) (kv "verbose" t) (kv "limit" 0) (kv "keeptemp" nil) (kv "query" ($> "l" -900))))
Define a macro that eliminates this repetitive pattern:
(compile-time-report-wrap-failures)

Issue: Macro call that should be transformed by compile-time-report-wrap-failures

Macro definition:
(defmacro compile-time-report-wrap-failures ()
  (report-wrap-failures 'compile-time *error-output*))

Macroexpansion:
nil
You are a Common Lisp macro expert. Given this code pattern:
(define-declaration nil
    nil)

Write a macro that addresses: Macro call that should be transformed by DEFINE-DECLARATION

Macro definition:
(defmacro DEFINE-DECLARATION ...)

Macroexpansion:
(eval-when (:compile-toplevel :load-toplevel :execute)
  (proclaim '(declaration nil))
  (flet ((sb-cltl2::func ()
           ))
    (setf (sb-int:info :declaration :known 'nil)
            (lambda
                (sb-kernel:lexenv sb-cltl2::spec sb-cltl2::pd-vars
                 sb-cltl2::pd-fvars)
              (multiple-value-bind (sb-cltl2::kind sb-cltl2::data)
                  (sb-cltl2::func sb-cltl2::spec sb-kernel:lexenv)
                (sb-cltl2::update-lexenv-user-data sb-kernel:lexenv
                                                   sb-cltl2::kind
                                                   sb-cltl2::data
                                                   sb-cltl2::pd-vars
                                                   sb-cltl2::pd-fvars))))))
You are a Common Lisp macro expert. Given this code pattern:
;; Anonymous recursion requires explicit labels every time
(labels ((self (n)
           (if (> n 0)
             (cons n (self (- n 1)))
             nil)))
  #'self)

;; labels boilerplate obscures the recursive logic

Write a macro that addresses: Need anonymous recursion without writing labels boilerplate — want implicit 'self' for recursion

Macro definition:
(defmacro alambda (parms &body body)
  `(labels ((self ,parms ,@body))
     #'self))

Macroexpansion:
;; (alambda (n)
;;   (if (> n 0)
;;     (cons n (self (- n 1)))
;;     nil))
;; Expands to:
;; (LABELS ((SELF (N)
;;            (IF (> N 0)
;;              (CONS N (SELF (- N 1)))
;;              NIL)))
;;   #'SELF)
You are a Common Lisp macro expert. Given this code pattern:
(setf nil nil)

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

Macro definition:
(defmacro SETF ...)

Macroexpansion:
(setq nil nil)
Generate a defmacro form that transforms code like this:
(-> :g (a) (+ a 3))

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

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

Macroexpansion:
(atomically :g (a) (+ a 3))
Write a Common Lisp macro to handle this code pattern:
(defclause maximizing (form &key (test ''>) saving in) "Synonym for optimizing." `(optimizing ,form :test ,test :saving ,saving :in ,in))

Problem: Macro call that should be transformed by defclause

Macro definition:
(defmacro defclause (name arglist &body body)
  "Same as cl:defmacro, but additionally records <name> in *clauses* as a known clause macro."
  `(progn
     (defmacro ,name ,arglist ,@body)
     (pushnew ',name *clauses*)))

Macroexpansion:
(progn (defmacro maximizing (form &key (test (quote (quote >))) saving in) "Synonym for optimizing." (sb-int:quasiquote (optimizing #S(sb-impl::comma :expr form :kind 0) :test #S(sb-impl::comma :expr test :kind 0) :saving #S(sb-impl::comma :expr saving :kind 0) :in #S(sb-impl::comma :expr in :kind 0)))) (pushnew (quote maximizing) *clauses*))
Define a macro that eliminates this repetitive pattern:
(signal-syntax-error "Unknown token ~A in parse-tree." token)

Issue: 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 token ~A in parse-tree." token)
Generate a defmacro form that transforms code like this:
(some-> nil nil)

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

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

Macroexpansion:
(let* ((#:g142 nil))
  (if (null #:g142)
      nil
      (-> #:g142 nil)))
Generate a defmacro form that transforms code like this:
(drelet nil
  :key
  nil)

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

Macro definition:
(defmacro DRELET ...)

Macroexpansion:
(dynamic-relet nil
  :key
  nil)
Define a macro that eliminates this repetitive pattern:
(without-symbol-access
  nil)

Issue: Macro call that should be transformed by WITHOUT-SYMBOL-ACCESS

Macro definition:
(defmacro WITHOUT-SYMBOL-ACCESS ...)

Macroexpansion:
(let ((*symbol-access* nil))
  nil)
Define a macro that eliminates this repetitive pattern:
(cardinality-case 'some-name)

Issue: Macro call that should be transformed by CARDINALITY-CASE

Macro definition:
(defmacro CARDINALITY-CASE ...)

Macroexpansion:
(let ((#:cardinality131 'some-name))
  (typecase #:cardinality131))
Define a macro that eliminates this repetitive pattern:
(do-generator-value-list (vars (apply #'multi-gen (loop for g in gens collect (list g :fill-value fillspec)))) (apply #'yield (mapcar #'car vars)))

Issue: Macro call that should be transformed by do-generator-value-list

Macro definition:
(defmacro do-generator-value-list ((var generator) &body body)
  "Like do-generator, except all values emitted by the generator are placed in a list under the user defined variable."
  (let ((g (gensym)))
    `(let ((,g ,generator))
       (loop 
	  do (if-generator (,var ,g)
			   (progn ,@body)
			   (return))))))

Macroexpansion:
(let ((#:g180 (apply (function multi-gen) (loop for g in gens collect (list g :fill-value fillspec))))) (loop do (if-generator (vars #:g180) (progn (apply (function yield) (mapcar (function car) vars))) (return))))
Write a Common Lisp macro to handle this code pattern:
(make-obsolete mustache-render render "0.10.0")

Problem: Macro call that should be transformed by make-obsolete

Macro definition:
(defmacro make-obsolete (obsolete-name current-name when)
  `(defun ,obsolete-name (&rest args)
     ,(documentation current-name 'function)
     (warn 'deprecation-warning
           :name ',obsolete-name :replacement ',current-name :since ,when)
     (apply ',current-name args)))

Macroexpansion:
(defun mustache-render (&rest args) "Render TEMPLATE with optional CONTEXT to *OUTPUT-STREAM* or OUTPUT-STREAM" (warn (quote deprecation-warning) :name (quote mustache-render) :replacement (quote render) :since "0.10.0") (apply (quote render) args))
Define a macro that eliminates this repetitive pattern:
(assert-values ("baz w/o lookup") (baz 'no-lookup))

Issue: Macro call that should be transformed by assert-values

Macro definition:
(defmacro assert-values ((desc) &body objects-and-values)
  `(progn
     (trc ,desc)
     ,@(loop for (obj val) in objects-and-values
	    collect `(assert (eql (value ,obj) ,val)))))

Macroexpansion:
(progn (trc "baz w/o lookup") (assert (eql (value baz) (quote no-lookup))))