j14i/cl-macros huggingface dataset:
Write a Common Lisp macro to handle this code pattern:
(bind (((:flet doit (x)) (setf x (* 2 x)) (setf x (+ x 3)) x)) (ensure-same (doit 1) 5) (ensure-same (doit 2) 7))

Problem: Macro call that should be transformed by bind

Macro definition:
(defmacro bind ((&rest bindings) &body body)
  "Bind is a replacement for let*, destructuring-bind, multiple-value-bind and more. 

An example is probably the best way to describe its syntax:

    \(bind \(\(a 2\)
           \(\(b &rest args &key \(c 2\) &allow-other-keys\) '\(:a :c 5 :d 10 :e 54\)\)
           \(\(:values d e\) \(truncate 4.5\)\)
           \(\(:structure xxx- slot1 slot2\) \(make-xxx\)\)
           \(\(:flet name \(arg1 arg2\)\) \(+ arg1 arg2\)\)\)
         \(list a b c d e args\)\)

Simple bindings are as in let*. Destructuring is done if the first item
in a binding is a list. Multiple value binding is done if the first item
in a binding is a list and the first item in the list is ':values'. Other
forms have their own syntax. For example, :structure first has the conc
name and then slot names whereas :flet has the function name and a list
of arguments and then the function body (in an implicit progn)."
  (let (declarations)
    (loop while (and (consp (car body)) (eq (caar body) 'declare)) do
          (push (first body) declarations)
          (setf body (rest body)))
    (if bindings
	(let ((*all-declarations* (bind-expand-declarations (nreverse declarations))))
	  (prog1
	      (bind-macro-helper bindings body)
	    (check-for-unused-variable-declarations *all-declarations*)))
        `(locally
             ,@declarations
           ,@body))))

Macroexpansion:
(flet ((doit (x) (progn (setf x (* 2 x)) (setf x (+ x 3)) x))) (progn (ensure-same (doit 1) 5) (ensure-same (doit 2) 7)))
Generate a defmacro form that transforms code like this:
(iterate:display-iterate-clauses)

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

Macro definition:
(defmacro iterate (&body body)
  "Jonathan Amsterdam's powerful iteration facility"
  `(iter .,body))

Macroexpansion:
(display-iterate-clauses)
Generate a defmacro form that transforms code like this:
(define-modf-rewrite eighth (expr) `(cadddr (cddddr ,(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 eighth) *modf-rewrites*) (lambda (expr) (sb-int:quasiquote (cadddr (cddddr #S(sb-impl::comma :expr (second expr) :kind 0)))))))
Write a Common Lisp macro to handle this code pattern:
(defsynonym search :find)

Problem: 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 search) (quote synonym)) (quote :find)))
Define a macro that eliminates this repetitive pattern:
(make-window-or-instance nil :key nil)

Issue: Macro call that should be transformed by MAKE-WINDOW-OR-INSTANCE

Macro definition:
(defmacro MAKE-WINDOW-OR-INSTANCE ...)

Macroexpansion:
(make-$instance nil :key nil)
Write a Common Lisp macro to handle this code pattern:
(with-additional-indent (reporter stream "~& ") (with-color (:red :stream stream) (with-additional-indent (reporter stream "× ") (let ((description (possible-report-description report)) (duration (slot-value report 'duration))) (when description (format/indent reporter stream description)) (when duration (format stream " ") (print-duration stream duration (slot-value report 'slow-threshold)))) (when (slot-value report 'description) (format/indent reporter stream (concatenate 'string "~&" (report-expected-line report))))) (terpri stream)))

Problem: Macro call that should be transformed by with-additional-indent

Macro definition:
(defmacro with-additional-indent ((reporter stream control-string &rest format-arguments) &body body)
  (declare (ignorable reporter stream control-string))
  (let* ((need-new-line (ppcre:scan "^~&" control-string))
         (string (apply #'format nil control-string format-arguments))
         (increment (length string)))
    `(with-slots (indent-space) reporter
       (let* ((first-line-indent (indent indent-space))
              (*additional-indent* ,(if need-new-line
                                        increment
                                        `(+ *additional-indent*
                                            ,increment))))
         (declare (ignorable first-line-indent))
         ,(if need-new-line
              `(progn (fresh-line stream)
                      (write-string first-line-indent ,stream)
                      ;; because we just started a new line, we
                      ;; should use format/indent to write string
                      ;; taking into account a main indentation level
                      (format/indent ,reporter ,stream ,string))
              ;; otherwise, just output our prefix
              `(write-string ,string ,stream))
       
       
         ,@body))))

Macroexpansion:
(with-slots (indent-space) reporter (let* ((first-line-indent (indent indent-space)) (*additional-indent* 1)) (declare (ignorable first-line-indent)) (progn (fresh-line stream) (write-string first-line-indent stream) (format/indent reporter stream #A((1) base-char . " "))) (with-color (:red :stream stream) (with-additional-indent (reporter stream "× ") (let ((description (possible-report-description report)) (duration (slot-value report (quote duration)))) (when description (format/indent reporter stream description)) (when duration (format stream " ") (print-duration stream duration (slot-value report (quote slow-threshold))))) (when (slot-value report (quote description)) (format/indent reporter stream (concatenate (quote string) "~&" (report-expected-line report))))) (terpri stream))))
Generate a defmacro form that transforms code like this:
;; Depth-first search with manual backtracking
(defun search (node)
  (if (goal-p node)
      node
      (let ((children (expand node)))
        (when children
          (let ((result (search (car children))))
            (if result
                result
                (when (cdr children)
                  (search (cadr children)))))))))
;; Manual backtracking is error-prone and obscures the search logic

Pattern to recognize: Search/backtracking algorithms require manual state management — want implicit backtracking via nondeterministic choice

Macro definition:
(defparameter *paths* nil)
(defconstant failsym '@)

(defmacro choose (&rest choices)
  (if choices
      `(progn
         ,@(mapcar #'(lambda (c)
                       `(push #'(lambda () ,c) *paths*))
                   (reverse (cdr choices)))
         ,(car choices))
      '(fail)))

(defmacro choose-bind (var choices &body body)
  `(cb #'(lambda (,var) ,@body) ,choices))

(defun cb (fn choices)
  (if choices
     (progn
       (if (cdr choices)
           (push #'(lambda () (cb fn (cdr choices)))
                 *paths*))
       (funcall fn (car choices)))
     (fail)))

(defun fail ()
  (if *paths*
      (funcall (pop *paths*))
      failsym))

Macroexpansion:
;; (defun search (node)
;;   (if (goal-p node)
;;     node
;;     (let ((child (choose (expand node))))
;;       (search child))))
;;
;; choose pushes alternatives onto *paths*, executes the first.
;; When fail is called, it pops the next alternative and retries.
;; The backtracking is implicit - code reads like depth-first search.
;;
;; (choose-bind x '(1 2 3 4 5)
;;   (when (evenp x) (return x)))
;; => 2 (first even value)
You are a Common Lisp macro expert. Given this code pattern:
(defjs reduce7(k vals) (let ((sum 0) (index 0)) (dolist (c vals) (if (= index 3) (return c) (progn (incf index 1) (incf sum c)))) (return sum)))

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

Macro definition:
(defmacro defjs (name args &body body)
  "Define client side javascript. Works like defun; body is in lisp, with parenscript
   additions, like return. So (defjs hello (x y) (return (+ x y))) defines an adder. 
   macro creates a lisp function which sends the javascript function over to the mongo 
   server to be evaluated. Result is processed and returned to the reader. 
   This will execute 10 times on the server :
   (mapcar (lambda (x) (hello 10 x)) (list 1 2 3 4 5 6 7 8 9 10))"
  `(let* ((js-body (parenscript:ps (lambda ,args ,@body))))
     (setf (gethash ',name *js-definitions*) js-body)
     (defun ,name ,args
       (get-element "retval" (car (docs (db.eval js-body ,@args)))))))

Macroexpansion:
(let* ((js-body (parenscript:ps (lambda (k vals) (let ((sum 0) (index 0)) (dolist (c vals) (if (= index 3) (return c) (progn (incf index 1) (incf sum c)))) (return sum)))))) (setf (gethash (quote reduce7) *js-definitions*) js-body) (defun reduce7 (k vals) (get-element "retval" (car (docs (db.eval js-body k vals))))))
Define a macro that eliminates this repetitive pattern:
(defparameter* nil :key nil)

Issue: Macro call that should be transformed by DEFPARAMETER*

Macro definition:
(defmacro DEFPARAMETER* ...)

Macroexpansion:
(defvar/param defparameter nil :key nil)
Define a macro that eliminates this repetitive pattern:
(define-error loop-will-never-halt () (test-code test-obj) "The loop is using the following code as it's test.~%~a~%~%This will only ever result in a ~a which means the loop will never halt" test-code (type->type-spec (primary-type test-obj)))

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 loop-will-never-halt (:error-type varjo-error :prefix "Varjo") (test-code test-obj) "The loop is using the following code as it's test.~%~a~%~%This will only ever result in a ~a which means the loop will never halt" test-code (type->type-spec (primary-type test-obj)))
Write a Common Lisp macro to handle this code pattern:
(with-unique-js-names nil :key nil)

Problem: Macro call that should be transformed by WITH-UNIQUE-JS-NAMES

Macro definition:
(defmacro WITH-UNIQUE-JS-NAMES ...)

Macroexpansion:
(with-ps-gensyms nil
  :key
  nil)
Generate a defmacro form that transforms code like this:
(with-inactive-layers 'some-name)

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

Macro definition:
(defmacro WITH-INACTIVE-LAYERS ...)

Macroexpansion:
(dynamic-wind
  :proceed
  #:proceed211
  (%with-inactive-layers 'some-name
    (#:proceed211)))
Write a Common Lisp macro to handle this code pattern:
(with-standard-readtable
  'some-name)

Problem: Macro call that should be transformed by WITH-STANDARD-READTABLE

Macro definition:
(defmacro WITH-STANDARD-READTABLE ...)

Macroexpansion:
(bind ((*readtable* (with-standard-io-syntax (copy-readtable *readtable*))))
  'some-name)
Write a Common Lisp macro to handle this code pattern:
(with-html-string (:input :type "password" :name "password" :class "form-control" :id "password" :required t))

Problem: 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 (:input :type "password" :name "password" :class "form-control" :id "password" :required t)))
Write a Common Lisp macro to handle this code pattern:
(with-yield-binds (format nil "(~A ~A ~A)" (f (infix-op-left op)) (sql-op-name op) (f (infix-op-right op))))

Problem: Macro call that should be transformed by with-yield-binds

Macro definition:
(defmacro with-yield-binds (&body body)
  `(let ((*bind-values* nil)
         (*use-global-bind-values* t))
     (values
      (progn ,@body)
      (loop for bind in (reverse *bind-values*)
            append bind))))

Macroexpansion:
(let ((*bind-values* nil) (*use-global-bind-values* t)) (values (progn (format nil "(~A ~A ~A)" (f (infix-op-left op)) (sql-op-name op) (f (infix-op-right op)))) (loop for bind in (reverse *bind-values*) append bind)))
Generate a defmacro form that transforms code like this:
(mapping nil)

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

Macro definition:
(defmacro MAPPING ...)

Macroexpansion:
(mapping-mac nil)
You are a Common Lisp macro expert. Given this code pattern:
(deferror "57P02" crash-shutdown server-shutdown)

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 crash-shutdown (server-shutdown) nil) (setf (gethash "57P02" *error-table*) (quote crash-shutdown)))
Generate a defmacro form that transforms code like this:
(defsynonym as :for)

Pattern to recognize: 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 as) (quote synonym)) (quote :for)))
Create a Common Lisp macro for the following transformation. Before code:
(define-cruft %get-macro-character (char rt) "Ensure ANSI behaviour for GET-MACRO-CHARACTER." #+ :allegro (let ((fn (get-macro-character char rt))) (cond ((not fn) nil) ((function= fn #'excl::read-token) nil) (t fn))) #+ :cmucl (let ((fn (get-macro-character char rt))) (cond ((not fn) nil) ((function= fn #'lisp::read-token) nil) (t fn))) #+ :common-lisp (get-macro-character char rt))

What needs to change: Macro call that should be transformed by define-cruft

Macro definition:
(defmacro define-cruft (name lambda-list &body (docstring . alternatives))
  (assert (typep docstring 'string) (docstring) "Docstring missing!")
  (assert (not (null alternatives)))
  `(progn
     (declaim (inline ,name))
     (defun ,name ,lambda-list ,docstring ,(first alternatives))))

Macroexpansion:
(progn (declaim (inline %get-macro-character)) (defun %get-macro-character (char rt) "Ensure ANSI behaviour for GET-MACRO-CHARACTER." (get-macro-character char rt)))
Write a Common Lisp macro to handle this code pattern:
(finishes (signals error (error "an error")))

Problem: Macro call that should be transformed by finishes

Macro definition:
(defmacro finishes (&body body)
  "Generates a pass if BODY executes to normal completion. In
other words if body does signal, return-from or throw this test
fails."
  `(unwind-protect-case () (progn ,@body)
     (:normal (add-result 'test-passed :test-expr ',body))
     (:abort (process-failure ',body "Test didn't finish"))))

Macroexpansion:
(unwind-protect-case nil (progn (signals error (error "an error"))) (:normal (add-result (quote test-passed) :test-expr (quote ((signals error (error "an error")))))) (:abort (process-failure (quote ((signals error (error "an error")))) "Test didn't finish")))
Create a Common Lisp macro for the following transformation. Before code:
(do-generator (g generator) (yield g) (incf count) (when (= count n) (yield 'generator-stop)))

What needs to change: 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 ((#:g167 generator)) (loop do (if-generator ((g) #:g167) (progn (yield g) (incf count) (when (= count n) (yield (quote generator-stop)))) (return))))
Create a Common Lisp macro for the following transformation. Before code:
(define-method-combination% + :operator + :identity-with-one-argument t)

What needs to change: 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 +)) (method-combination-function-short + + t)))
Define a macro that eliminates this repetitive pattern:
(def-bop nil)

Issue: Macro call that should be transformed by DEF-BOP

Macro definition:
(defmacro DEF-BOP ...)

Macroexpansion:
t
Generate a defmacro form that transforms code like this:
(once-only* args (let ((else `(cerror "Continue." 'match-error :values (list ,@args) :patterns ',(mapcar #'car clauses)))) (compile-match args clauses else)))

Pattern to recognize: Macro call that should be transformed by once-only*

Macro definition:
(defmacro once-only* (symbol &body body)
  (with-unique-names (form var vars bindings)
    `(let (,vars ,bindings)
       (dolist (,form ,symbol)
         (if (symbolp ,form)
             (push ,form ,vars)
             (let ((,var (gensym "VAR")))
               (push ,var ,vars)
               (push (list ,var ,form) ,bindings))))
       (setq ,vars (nreverse ,vars)
             ,bindings (nreverse ,bindings))
       (if ,bindings
           `(let ,,bindings
              ;(declare (ignorable ,@(mapcar #'car ,bindings)))
              ,(let ((,symbol ,vars))
                 ,@body))
           (progn ,@body)))))

Macroexpansion:
(let (#:vars170 #:bindings171) (dolist (#:form168 args) (if (symbolp #:form168) (push #:form168 #:vars170) (let ((#:var169 (gensym "VAR"))) (push #:var169 #:vars170) (push (list #:var169 #:form168) #:bindings171)))) (setq #:vars170 (nreverse #:vars170) #:bindings171 (nreverse #:bindings171)) (if #:bindings171 (sb-int:quasiquote (let #S(sb-impl::comma :expr #:bindings171 :kind 0) #S(sb-impl::comma :expr (let ((args #:vars170)) (let ((else (sb-int:quasiquote (cerror "Continue." (quote match-error) :values (list #S(sb-impl::comma :expr args :kind 2)) :patterns (quote #S(sb-impl::comma :expr (mapcar (function car) clauses) :kind 0)))))) (compile-match args clauses else))) :kind 0))) (progn (let ((else (sb-int:quasiquote (cerror "Continue." (quote match-error) :values (list #S(sb-impl::comma :expr args :kind 2)) :patterns (quote #S(sb-impl::comma :expr (mapcar (function car) clauses) :kind 0)))))) (compile-match args clauses else)))))
Create a Common Lisp macro for the following transformation. Before code:
(some->
  'some-name)

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

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

Macroexpansion:
'some-name
Generate a defmacro form that transforms code like this:
(check-cursor-attached cluffer:split-line (cursor))

Pattern to recognize: 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:split-line :before ((cursor cluffer:cursor)) (declare (ignore)) (unless (cluffer:cursor-attached-p cursor) (error (quote cluffer:cursor-detached))))
Define a macro that eliminates this repetitive pattern:
(appending 'some-name)

Issue: Macro call that should be transformed by APPENDING

Macro definition:
(defmacro APPENDING ...)

Macroexpansion:
(with-appender-output (output)
  (dolist (quote (alexandria:ensure-list some-name))
    (restart-case (output (progn))
      (skip nil "Skip this element"))))
You are a Common Lisp macro expert. Given this code pattern:
(define-condition/a dbi-warning (simple-warning) () (:documentation "For important warnings like data truncation, etc."))

Write a macro that addresses: Macro call that should be transformed by define-condition/a

Macro definition:
(defmacro define-condition/a (name parent-types slots &body options)
  `(progn
     (define-condition ,name ,parent-types ,slots ,@options)
     (deftype ,(intern (format nil "<~A>" (symbol-name name))) () ',name)
     (setf (find-class ',(intern (format nil "<~A>" (symbol-name name))))
           (find-class ',name))))

Macroexpansion:
(progn (define-condition dbi-warning (simple-warning) nil (:documentation "For important warnings like data truncation, etc.")) (deftype <dbi-warning> nil (quote dbi-warning)) (setf (find-class (quote <dbi-warning>)) (find-class (quote dbi-warning))))
You are a Common Lisp macro expert. Given this code pattern:
(augment init-code (do-extra-save-var-hack var save-info-list code-list))

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

Macro definition:
(defmacro augment (var stuff)
  `(setf ,var (nconc ,var ,stuff)))

Macroexpansion:
(setf init-code (nconc init-code (do-extra-save-var-hack var save-info-list code-list)))
Write a Common Lisp macro to handle this code pattern:
(once-only* args (compile-match args clauses nil))

Problem: Macro call that should be transformed by once-only*

Macro definition:
(defmacro once-only* (symbol &body body)
  (with-unique-names (form var vars bindings)
    `(let (,vars ,bindings)
       (dolist (,form ,symbol)
         (if (symbolp ,form)
             (push ,form ,vars)
             (let ((,var (gensym "VAR")))
               (push ,var ,vars)
               (push (list ,var ,form) ,bindings))))
       (setq ,vars (nreverse ,vars)
             ,bindings (nreverse ,bindings))
       (if ,bindings
           `(let ,,bindings
              ;(declare (ignorable ,@(mapcar #'car ,bindings)))
              ,(let ((,symbol ,vars))
                 ,@body))
           (progn ,@body)))))

Macroexpansion:
(let (#:vars162 #:bindings163) (dolist (#:form160 args) (if (symbolp #:form160) (push #:form160 #:vars162) (let ((#:var161 (gensym "VAR"))) (push #:var161 #:vars162) (push (list #:var161 #:form160) #:bindings163)))) (setq #:vars162 (nreverse #:vars162) #:bindings163 (nreverse #:bindings163)) (if #:bindings163 (sb-int:quasiquote (let #S(sb-impl::comma :expr #:bindings163 :kind 0) #S(sb-impl::comma :expr (let ((args #:vars162)) (compile-match args clauses nil)) :kind 0))) (progn (compile-match args clauses nil))))