j14i/cl-macros huggingface dataset:
You are a Common Lisp macro expert. Given this code pattern:
;; Conditional logic with different variable bindings per branch
;; requires deeply nested lets inside each cond clause
(cond ((> x 0)
       (let ((order :ascending)
             (bound (sqrt x)))
         (process order bound)))
      ((< x 0)
       (let ((order :descending)
             (bound (sqrt (- x))))
         (process order bound)))
      (t
       (let ((order :zero)
             (bound 0))
         (process order bound))))

;; Repetitive: same body structure, different bindings per branch

Write a macro that addresses: Cond with per-branch variable bindings leads to duplicated body code — want shared body with branch-specific bindings

Macro definition:
(defmacro condlet (clauses &body body)
  (let ((bodfn (gensym))
        (vars (mapcar #'(lambda (v) (cons v (gensym)))
                      (remove-duplicates
                        (mapcar #'car
                                (mappend #'cdr clauses))))))
    `(labels ((,bodfn ,(mapcar #'car vars)
                 ,@body))
       (cond ,@(mapcar #'(lambda (cl)
                           (condlet-clause vars cl bodfn))
                       clauses)))))

Macroexpansion:
;; (condlet (((= x 0) (order :zero)  (bound 0))
;;           ((> x 0) (order :ascending) (bound (sqrt x)))
;;           ((< x 0) (order :descending) (bound (sqrt (- x)))))
;;   (process order bound))
;;
;; Each cond clause specifies test + bindings.
;; The body (process order bound) is shared across all clauses.
;; Variables from ALL clauses are recognized and gensym'd.
Define a macro that eliminates this repetitive pattern:
(with-hamt dict (:test test :hash hash :table table) (flet ((%insert (table key value) (%dict-insert table key value (funcall hash key) 0 test))) (make-instance 'hash-dict :test test :hash hash :table (labels ((f (table args) (if args (let ((key (car args)) (value (cadr args))) (f (%insert table key value) (cddr args))) table))) (f table args)))))

Issue: Macro call that should be transformed by with-hamt

Macro definition:
(defmacro with-hamt (hamt (&key test hash table) &body body)
  "Accessing HAMT slots"
  `(with-accessors ((,test hamt-test)
                    (,hash hamt-hash)
                    (,table hamt-table))
       ,hamt
     ,@body))

Macroexpansion:
(with-accessors ((test hamt-test) (hash hamt-hash) (table hamt-table)) dict (flet ((%insert (table key value) (%dict-insert table key value (funcall hash key) 0 test))) (make-instance (quote hash-dict) :test test :hash hash :table (labels ((f (table args) (if args (let ((key (car args)) (value (cadr args))) (f (%insert table key value) (cddr args))) table))) (f table args)))))
Define a macro that eliminates this repetitive pattern:
(lret* () 1)

Issue: Macro call that should be transformed by lret*

Macro definition:
(defmacro lret* ((&rest bindings) &body body)
  "Cf. `lret'."
  `(lret-aux let* ,bindings
     ,@body))

Macroexpansion:
(lret-aux let* nil 1)
Write a Common Lisp macro to handle this code pattern:
(dynamic-let* nil
  nil)

Problem: Macro call that should be transformed by DYNAMIC-LET*

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

Macroexpansion:
(progn nil)
You are a Common Lisp macro expert. Given this code pattern:
(defproto nil)

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

Macro definition:
(defmacro DEFPROTO ...)

Macroexpansion:
(progn
 (declaim (special nil))
 (eval-when (:compile-toplevel))
 (setf (symbol-value 'nil)
         (ensure-object (when (boundp 'nil) (symbol-value 'nil)) (list)
                        :properties (list) :nickname 'nil)))
Write a Common Lisp macro to handle this code pattern:
(or nil nil)

Problem: Macro call that should be transformed by OR

Macro definition:
(defmacro OR ...)

Macroexpansion:
(let ((#:g201 nil))
  (if #:g201
      #:g201
      nil))
Define a macro that eliminates this repetitive pattern:
(with-shadowed-custom-vars (let ((tricky-json "{\"start_XPos\":98,\"start_YPos\":4}") (*json-symbols-package* (find-package :keyword))) (set-decoder-simple-list-semantics) (is (equal '((:START--*X-POS . 98) (:START--*Y-POS . 4)) (decode-json-from-string tricky-json)))))

Issue: Macro call that should be transformed by with-shadowed-custom-vars

Macro definition:
(defmacro with-shadowed-custom-vars (&body body)
  `(let ,(loop for (var) in *custom-vars*
            collect `(,var (if (boundp ',var) ,var)))
     ,@body))

Macroexpansion:
(let ((*aggregate-scope-variables* (if (boundp (quote *aggregate-scope-variables*)) *aggregate-scope-variables*)) (*string-scope-variables* (if (boundp (quote *string-scope-variables*)) *string-scope-variables*)) (*array-scope-variables* (if (boundp (quote *array-scope-variables*)) *array-scope-variables*)) (*object-scope-variables* (if (boundp (quote *object-scope-variables*)) *object-scope-variables*)) (*internal-decoder* (if (boundp (quote *internal-decoder*)) *internal-decoder*)) (*end-of-object-handler* (if (boundp (quote *end-of-object-handler*)) *end-of-object-handler*)) (*object-value-handler* (if (boundp (quote *object-value-handler*)) *object-value-handler*)) (*object-key-handler* (if (boundp (quote *object-key-handler*)) *object-key-handler*)) (*beginning-of-object-handler* (if (boundp (quote *beginning-of-object-handler*)) *beginning-of-object-handler*)) (*json-array-type* (if (boundp (quote *json-array-type*)) *json-array-type*)) (*end-of-array-handler* (if (boundp (quote *end-of-array-handler*)) *end-of-array-handler*)) (*array-member-handler* (if (boundp (quote *array-member-handler*)) *array-member-handler*)) (*beginning-of-array-handler* (if (boundp (quote *beginning-of-array-handler*)) *beginning-of-array-handler*)) (*end-of-string-handler* (if (boundp (quote *end-of-string-handler*)) *end-of-string-handler*)) (*string-char-handler* (if (boundp (quote *string-char-handler*)) *string-char-handler*)) (*beginning-of-string-handler* (if (boundp (quote *beginning-of-string-handler*)) *beginning-of-string-handler*)) (*boolean-handler* (if (boundp (quote *boolean-handler*)) *boolean-handler*)) (*real-handler* (if (boundp (quote *real-handler*)) *real-handler*)) (*integer-handler* (if (boundp (quote *integer-handler*)) *integer-handler*))) (let ((tricky-json "{\"start_XPos\":98,\"start_YPos\":4}") (*json-symbols-package* (find-package :keyword))) (set-decoder-simple-list-semantics) (is (equal (quote ((:start--*x-pos . 98) (:start--*y-pos . 4))) (decode-json-from-string tricky-json)))))
Write a Common Lisp macro to handle this code pattern:
(with nil
  (progn))

Problem: Macro call that should be transformed by WITH

Macro definition:
(defmacro WITH ...)

Macroexpansion:
(progn)
You are a Common Lisp macro expert. Given this code pattern:
(ok t)

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

Macro definition:
(defmacro ok (test &optional desc)
  (with-gensyms (duration result)
    (once-only (test desc)
      `(with-catching-errors (:expected T :description ,desc)
         (with-duration ((,duration ,result) ,test)
           (test ,result t ,desc
                 :duration ,duration
                 :test-fn (lambda (x y)
                            (eq (not (null x)) y))
                 :got-form ,test))))))

Macroexpansion:
(let ((#:test142 t) (#:desc143 nil)) (with-catching-errors (:expected t :description #:desc143) (with-duration ((#:duration140 #:result141) #:test142) (test #:result141 t #:desc143 :duration #:duration140 :test-fn (lambda (x y) (eq (not (null x)) y)) :got-form #:test142))))
Define a macro that eliminates this repetitive pattern:
(->> nil (progn))

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

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

Macroexpansion:
(progn nil)
Create a Common Lisp macro for the following transformation. Before code:
(collect-max nil)

What needs to change: Macro call that should be transformed by COLLECT-MAX

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

Macroexpansion:
(common-lisp:let* ((#:generator-340 (generator nil))
                   #:numbers-334
                   (#:number-336 nil))
  (declare (type generator #:generator-340))
  (tagbody
   #:ll-341
    (setq #:numbers-334 (next-in #:generator-340 (go end)))
    (if (or (null #:number-336) (< #:number-336 #:numbers-334))
        (setq #:number-336 #:numbers-334))
    (go #:ll-341)
   end)
  (if (null #:number-336)
      (setq #:number-336 nil))
  #:number-336)
Generate a defmacro form that transforms code like this:
(all-of nil)

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

Macro definition:
(defmacro ALL-OF ...)

Macroexpansion:
(lc (nil) always)
Define a macro that eliminates this repetitive pattern:
(quasiquote-unexpand-1 #-quasiquote-strict-append 'unquote-splicing #+quasiquote-strict-append 'x-unquote (car (last x)))

Issue: Macro call that should be transformed by quasiquote

Macro definition:
(defmacro quasiquote (x) (quasiquote-expand x))

Macroexpansion:
(quasiquote-unexpand-1 (quote unquote-splicing) (car (last x)))
Define a macro that eliminates this repetitive pattern:
(pop-preprocessor-directive-token token-list directive-symbol)

Issue: Macro call that should be transformed by pop-preprocessor-directive-token

Macro definition:
(defmacro pop-preprocessor-directive-token (token-list directive-name &key (errorp t))
  "Pops the next token in TOKEN-LIST ignoring `+whitespace-marker+'"
  (with-gensyms (head_)
    `(let ((,head_
             (check-and-pop-pp-directive-token-1 ,token-list ,directive-name ,errorp)))
       (if (eq +whitespace-marker+ ,head_)
           (check-and-pop-pp-directive-token-1 ,token-list ,directive-name ,errorp)
           ,head_))))

Macroexpansion:
(let ((#:head_264 (check-and-pop-pp-directive-token-1 token-list directive-symbol t))) (if (eq +whitespace-marker+ #:head_264) (check-and-pop-pp-directive-token-1 token-list directive-symbol t) #:head_264))
Write a Common Lisp macro to handle this code pattern:
(define-op (:+ conjunctive-op))

Problem: Macro call that should be transformed by define-op

Macro definition:
(defmacro define-op ((op-name struct-type &key sql-op-name include-slots (package (find-package '#:sxql/operator))) &body body)
  (check-type op-name symbol)
  (let ((struct-name (intern (concatenate 'string (symbol-name op-name) #.(string :-op)) package)))
    `(defstruct (,struct-name (:include ,struct-type
                               (name ,(or sql-op-name
                                          (with-output-to-string (s)
                                            (loop for c across (symbol-name op-name)
                                                  if (char= c #\-)
                                                    do (write-char #\Space s)
                                                  else
                                                    do (write-char c s)))))
                               ,@include-slots)
                              (:constructor ,(intern (concatenate 'string
                                                                  #.(string :make-)
                                                                  (symbol-name op-name)
                                                                  #.(string :-op))
                                                     package)
                                  ,(ecase struct-type
                                     ((unary-op
                                       unary-splicing-op
                                       unary-postfix-op) '(var))
                                     ((infix-op
                                       infix-splicing-op
                                       infix-list-op) '(left right))
                                     (conjunctive-op '(&rest expressions)))))
       ,@body)))

Macroexpansion:
(defstruct (+-op (:include conjunctive-op (name "+")) (:constructor make-+-op (&rest expressions))))
Define a macro that eliminates this repetitive pattern:
(inext-or-error nil)

Issue: Macro call that should be transformed by INEXT-OR-ERROR

Macro definition:
(defmacro INEXT-OR-ERROR ...)

Macroexpansion:
(let ((vals (multiple-value-list (funcall (i-coro nil) nil))))
  (if (not vals)
      (error 'stop-iteration)
      (values (car vals) t)))
You are a Common Lisp macro expert. Given this code pattern:
(def-neo4j-fun add-to-index ((type :node) name key value object-id) :post (:uri-spec (format nil "index/~A/~A" (string-downcase (symbol-name type)) name)) (:encode (list (list (cons :uri object-id) (case type (:node :node-url) (:relationship :relationship-url))) (list (cons :key key)) (list (cons :value value))) :object) (:status-handlers (201 (decode-neo4j-json-output body))))

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 add-to-index (&key (type :node) name key value object-id) (let ((uri (format nil "index/~A/~A" (string-downcase (symbol-name type)) name)) (json (encode-neo4j-json-payload (list (list (cons :uri object-id) (case type (:node :node-url) (:relationship :relationship-url))) (list (cons :key key)) (list (cons :value value))) :object))) (make-neo4j-request :post uri json (list (list 201 (lambda (body uri json) (decode-neo4j-json-output body))))))))
Generate a defmacro form that transforms code like this:
(*> +opt-fws+ +sliding-quoted-pairs+)

Pattern to recognize: 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 (#:*>-offset149) (multiple-value-bind (#:*>-res150 #:*>-next151) (funcall +opt-fws+ #:*>-offset149) (if (ok? #:*>-res150) (funcall +sliding-quoted-pairs+ #:*>-next151) (fail #:*>-next151))))
Define a macro that eliminates this repetitive pattern:
(resolve
  nil
  :key
  nil)

Issue: Macro call that should be transformed by RESOLVE

Macro definition:
(defmacro RESOLVE ...)

Macroexpansion:
(locally
 (declare)
 (multiple-value-bind (#:assignment153 #:unified-p154)
     (type-unify 'nil 'nil (list))
   (assert #:unified-p154 nil 'simple-type-error :format-control
           "gtypes failed to unify to the actual types:~% ~a~%    against~% ~a"
           :format-arguments (list 'nil (list)))
   (let ()
     (declare (ignorable))
     nil
     :key
     nil)))
Generate a defmacro form that transforms code like this:
(define-template nil (progn))

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

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

Macroexpansion:
(defmacro define-nil (&optional (#:name127))
  (flet ((template-unfulfillable ()
           (error 'template-unfulfillable :template 'nil :arguments (list))))
    (declare (ignorable (function template-unfulfillable)))
    (let ((body (progn)) (name (or #:name127 (compose-name #\SOLIDUS 'nil))))
      `(progn
        (declaim
         (ftype
          (function
           ,(loop with types = (declared-variable-types body)
                  for arg in (quote (progn))
                  collect (or (second (assoc arg types)) (quote t)))
           ,(declared-return-type body))
          ,name)
         ,@(when (find (quote inline) (declarations body)) `((inline ,name))))
        (defun ,name ,'(progn)
          (declare (optimize speed (safety 0) (debug 0) (compilation-speed 0))
                   ,@(remove (quote inline) (declarations body)))
          ,@(remove-if #'declaration-p body))))))
Generate a defmacro form that transforms code like this:
(as->* nil)

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

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

Macroexpansion:
(as-> nil)
Write a Common Lisp macro to handle this code pattern:
(defclass/std default () ((with-std)))

Problem: 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 default nil ((with-std :accessor with-std :initarg :with-std :initform nil)))
Create a Common Lisp macro for the following transformation. Before code:
(inext-noexit nil)

What needs to change: Macro call that should be transformed by INEXT-NOEXIT

Macro definition:
(defmacro INEXT-NOEXIT ...)

Macroexpansion:
(let ((vals (multiple-value-list (funcall (i-coro nil) nil))))
  (if (not vals)
      (values nil nil)
      (values (car vals) t)))
Generate a defmacro form that transforms code like this:
(make-obsolete mustache-render-to-string render* "0.10.0")

Pattern to recognize: 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-to-string (&rest args) #A((48) base-char . "Render TEMPLATE with optional CONTEXT to string.") (warn (quote deprecation-warning) :name (quote mustache-render-to-string) :replacement (quote render*) :since "0.10.0") (apply (quote render*) args))
Create a Common Lisp macro for the following transformation. Before code:
(undefmessage nil)

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

Macro definition:
(defmacro UNDEFMESSAGE ...)

Macroexpansion:
(fmakunbound 'nil)
Write a Common Lisp macro to handle this code pattern:
(with-assert-observers ("deleting bar" bar bar-1 baz) (store-remove :bar store))

Problem: Macro call that should be transformed by with-assert-observers

Macro definition:
(defmacro with-assert-observers ((desc &rest asserted-observers) &body body)  
  `(let ((*observers* nil))
     (trc ,desc " -- checking observers")
     ,@body
     (let ((superfluous-observers (loop for run in *observers* if (not (member run (list ,@asserted-observers))) collect run))
	   (failed-observers (loop for asserted in (list ,@asserted-observers) if (not (member asserted *observers*)) collect asserted)))
       (trc "called observers on" *observers* :superflous superfluous-observers :failed failed-observers)
       (assert (not superfluous-observers))
       (assert (not failed-observers)))))

Macroexpansion:
(let ((*observers* nil)) (trc "deleting bar" " -- checking observers") (store-remove :bar store) (let ((superfluous-observers (loop for run in *observers* if (not (member run (list bar bar-1 baz))) collect run)) (failed-observers (loop for asserted in (list bar bar-1 baz) if (not (member asserted *observers*)) collect asserted))) (trc "called observers on" *observers* :superflous superfluous-observers :failed failed-observers) (assert (not superfluous-observers)) (assert (not failed-observers))))
You are a Common Lisp macro expert. Given this code pattern:
(do-matches (s e regex target-string count :start start :end end) (incf count))

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

Macro definition:
(defmacro do-matches ((match-start match-end regex
                                   target-string
                                   &optional result-form
                                   &key start end)
                      &body body)
  "Iterates over TARGET-STRING and tries to match REGEX as often as
possible evaluating BODY with MATCH-START and MATCH-END bound to the
start/end positions of each match in turn.  After the last match,
returns RESULT-FORM if provided or NIL otherwise.  An implicit block
named NIL surrounds DO-MATCHES; RETURN may be used to terminate the
loop immediately.  If REGEX matches an empty string the scan is
continued one position behind this match.  BODY may start with
declarations."
  ;; this is a simplified form of DO-SCANS - we just provide two dummy
  ;; vars and ignore them
  (with-unique-names (reg-starts reg-ends)
    `(do-scans (,match-start ,match-end
                ,reg-starts ,reg-ends
                ,regex ,target-string
                ,result-form
                :start ,start :end ,end)
      ,@body)))

Macroexpansion:
(do-scans (s e #:reg-starts137 #:reg-ends138 regex target-string count :start start :end end) (incf count))
You are a Common Lisp macro expert. Given this code pattern:
(incf nil)

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

Macro definition:
(defmacro INCF ...)

Macroexpansion:
(setq nil (+ 1 nil))
You are a Common Lisp macro expert. Given this code pattern:
(with-html-string (:p (values "foo") "bar" "baz"))

Write a macro that addresses: 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 (:p (values "foo") "bar" "baz")))
Generate a defmacro form that transforms code like this:
(ematch0 accessor ((list 'function name) name) ((list 'quote name) name) (_ (error "[access] 1st arg is not a function designator")))

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

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

Macroexpansion:
(match0 accessor ((list (quote function) name) name) ((list (quote quote) name) name) (_ (error "[access] 1st arg is not a function designator")) (_ (error "level0 match error!")))
Create a Common Lisp macro for the following transformation. Before code:
(defmethod nil)

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

Macro definition:
(defmacro DEFMETHOD ...)

Macroexpansion:
(common-lisp:defmethod nil)
Write a Common Lisp macro to handle this code pattern:
(case 'some-name)

Problem: Macro call that should be transformed by CASE

Macro definition:
(defmacro CASE ...)

Macroexpansion:
(let ((#:g196 'some-name))
  (declare (ignorable #:g196))
  (cond))
Create a Common Lisp macro for the following transformation. Before code:
(all-of nil
  (progn))

What needs to change: Macro call that should be transformed by ALL-OF

Macro definition:
(defmacro ALL-OF ...)

Macroexpansion:
(lc (nil (progn)) always)