j14i/cl-macros huggingface dataset:
Generate a defmacro form that transforms code like this:
(letrec* ((f (constantly t)) (a (funcall f))) (is-true a))

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

Macro definition:
(defmacro letrec ((&rest bindings) &body body)
  "Recursive LET.
The idea is that functions created in BINDINGS can close over one
another, and themselves.

Note that `letrec' only binds variables: it can define recursive
functions, but can't bind them as functions. (But see `fbindrec'.)"
  `(letrec-with psetq ,bindings
     ,@body))

Macroexpansion:
(letrec-with setq ((f (constantly t)) (a (funcall f))) (is-true a))
Write a Common Lisp macro to handle this code pattern:
(with-env [assoc-list 'a])

Problem: Macro call that should be transformed by with-env

Macro definition:
(defmacro with-env (&body body)
  (let ((body-value (gensym)))
    `(let (,body-value)
       (defclass foo () ((a :initform 3)))
       (defmethod get-val ((object foo) &rest slot/s) (slot-value object (car slot/s)))
       (defmethod (setf get-val) (new-value (object foo) &rest slot/s)
         (setf (slot-value object (car slot/s)) new-value))
       (defstruct bar a)
       (setq ,body-value
             (let ((str (alexandria:copy-array "abcde"))
                   (vec (alexandria:copy-array #(a b c d e)))
                   (arr (alexandria:copy-array #2A((1 2 3)
                                                   (4 5 6))))
                   (list      (copy-list '(a b c d e)))
                   (ht        (eval (read-from-string "{'a 'b 'c 'd}")))
                   (ht-eq     (eval (read-from-string "{eq \"a\" 1
                                                    \"b\" 2}")))
                   (ht-equalp (eval (read-from-string "{equalp '(1 2 3) \"a\"
                                                               '(4 5 6) \"b\"}")))
                   (assoc-list (copy-tree '((a . 1) (b . 2))))
                   (plist      (copy-list '(:a 4 :c 5)))
                   (clos-object (make-instance 'foo))
                   (struct      (make-bar :a 3)))
               (declare (ignorable str vec arr list ht ht-eq ht-equalp
                                   assoc-list plist clos-object struct))
               ,@body))
       (setf (find-class 'foo nil) nil)
       (setf (find-class 'bar nil) nil)
       ,body-value))

Macroexpansion:
(let (#:g127) (defclass foo nil ((a :initform 3))) (defmethod get-val ((object foo) &rest slot/s) (slot-value object (car slot/s))) (defmethod (setf get-val) (new-value (object foo) &rest slot/s) (setf (slot-value object (car slot/s)) new-value)) (defstruct bar a) (setq #:g127 (let ((str (alexandria:copy-array "abcde")) (vec (alexandria:copy-array #(a b c d e))) (arr (alexandria:copy-array #2A((1 2 3) (4 5 6)))) (list (copy-list (quote (a b c d e)))) (ht (eval (read-from-string "{'a 'b 'c 'd}"))) (ht-eq (eval (read-from-string "{eq \"a\" 1
                                                    \"b\" 2}"))) (ht-equalp (eval (read-from-string "{equalp '(1 2 3) \"a\"
                                                               '(4 5 6) \"b\"}"))) (assoc-list (copy-tree (quote ((a . 1) (b . 2))))) (plist (copy-list (quote (:a 4 :c 5)))) (clos-object (make-instance (quote foo))) (struct (make-bar :a 3))) (declare (ignorable str vec arr list ht ht-eq ht-equalp assoc-list plist clos-object struct)) [assoc-list (quote a]))) (setf (find-class (quote foo) nil) nil) (setf (find-class (quote bar) nil) nil) #:g127)
You are a Common Lisp macro expert. Given this code pattern:
(with-unbuilder 'some-name)

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

Macro definition:
(defmacro WITH-UNBUILDER ...)

Macroexpansion:
(flet ((with-builder-thunk (quote)
         ))
  (declare (dynamic-extent (function with-builder-thunk)))
  (call-with-unbuilder some-name #'with-builder-thunk))
You are a Common Lisp macro expert. Given this code pattern:
(when (and (first first-statement) (eql (first parent-node) 'compound-statement) (eql (- level (first curr-level)) 2)) (let ((count (length nodes))) (setf (first first-statement) nil) (setf (first statement-count) (max count (first statement-count)))))

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

Macro definition:
(defmacro when (test &body forms)
  `(if ,test
	   ,(cl:if (cadr forms)
			   `(progn ,@forms)
			   (car forms))))

Macroexpansion:
(if (and (first first-statement) (eql (first parent-node) (quote compound-statement)) (eql (- level (first curr-level)) 2)) (let ((count (length nodes))) (setf (first first-statement) nil) (setf (first statement-count) (max count (first statement-count)))))
Create a Common Lisp macro for the following transformation. Before code:
(defun-speedy read-until-crlf*2 (stream) (with-fast-output (buf) (tagbody read-cr (loop for byte of-type (or (unsigned-byte 8) null) = (read-byte stream nil nil) if byte do (fast-write-byte byte buf) else do (go eof) until (= byte (char-code #\Return))) read-lf (let ((next-byte (read-byte stream nil nil))) (unless next-byte (go eof)) (locally (declare (type (unsigned-byte 8) next-byte)) (cond ((= next-byte (char-code #\Newline)) (fast-write-byte next-byte buf) (go read-cr2)) ((= next-byte (char-code #\Return)) (fast-write-byte next-byte buf) (go read-lf)) (T (fast-write-byte next-byte buf) (go read-cr))))) read-cr2 (let ((next-byte (read-byte stream nil nil))) (unless next-byte (go eof)) (locally (declare (type (unsigned-byte 8) next-byte)) (cond ((= next-byte (char-code #\Return)) (fast-write-byte next-byte buf) (go read-lf2)) (T (fast-write-byte next-byte buf) (go read-cr))))) read-lf2 (let ((next-byte (read-byte stream nil nil))) (unless next-byte (go eof)) (locally (declare (type (unsigned-byte 8) next-byte)) (cond ((= next-byte (char-code #\Newline)) (fast-write-byte next-byte buf)) ((= next-byte (char-code #\Return)) (fast-write-byte next-byte buf) (go read-lf)) (T (fast-write-byte next-byte buf) (go read-cr))))) eof)))

What needs to change: Macro call that should be transformed by defun-speedy

Macro definition:
(defmacro defun-speedy (name lambda-list &body body)
  `(progn
     (declaim (notinline ,name))
     (defun ,name ,lambda-list
       ,*speedy-declaration*
       ,@body)))

Macroexpansion:
(progn (declaim (notinline read-until-crlf*2)) (defun read-until-crlf*2 (stream) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0))) (with-fast-output (buf) (tagbody read-cr (loop for byte of-type (or (unsigned-byte 8) null) = (read-byte stream nil nil) if byte do (fast-write-byte byte buf) else do (go eof) until (= byte (char-code #\Return))) read-lf (let ((next-byte (read-byte stream nil nil))) (unless next-byte (go eof)) (locally (declare (type (unsigned-byte 8) next-byte)) (cond ((= next-byte (char-code #\Newline)) (fast-write-byte next-byte buf) (go read-cr2)) ((= next-byte (char-code #\Return)) (fast-write-byte next-byte buf) (go read-lf)) (t (fast-write-byte next-byte buf) (go read-cr))))) read-cr2 (let ((next-byte (read-byte stream nil nil))) (unless next-byte (go eof)) (locally (declare (type (unsigned-byte 8) next-byte)) (cond ((= next-byte (char-code #\Return)) (fast-write-byte next-byte buf) (go read-lf2)) (t (fast-write-byte next-byte buf) (go read-cr))))) read-lf2 (let ((next-byte (read-byte stream nil nil))) (unless next-byte (go eof)) (locally (declare (type (unsigned-byte 8) next-byte)) (cond ((= next-byte (char-code #\Newline)) (fast-write-byte next-byte buf)) ((= next-byte (char-code #\Return)) (fast-write-byte next-byte buf) (go read-lf)) (t (fast-write-byte next-byte buf) (go read-cr))))) eof))))
Write a Common Lisp macro to handle this code pattern:
(f nil)

Problem: Macro call that should be transformed by F

Macro definition:
(defmacro F ...)

Macroexpansion:
(lambda ())
Generate a defmacro form that transforms code like this:
(define-custom-var (:object-value *object-value-handler*) (constantly t) "Designator for a function of 1 arbitrary argument (decoded member value of Object).")

Pattern to recognize: Macro call that should be transformed by define-custom-var

Macro definition:
(defmacro define-custom-var ((key name) &rest other-args)
  `(eval-when (:compile-toplevel :load-toplevel :execute)
     (progn (pushnew '(,name . ,key) *custom-vars* :test #'equal)
            (defvar ,name ,@other-args))))

Macroexpansion:
(eval-when (:compile-toplevel :load-toplevel :execute) (progn (pushnew (quote (*object-value-handler* . :object-value)) *custom-vars* :test (function equal)) (defvar *object-value-handler* (constantly t) "Designator for a function of 1 arbitrary argument (decoded member value of Object).")))
Create a Common Lisp macro for the following transformation. Before code:
(defclass/a dbd-null-connection (cl-dbi:dbi-connection) ())

What needs to change: Macro call that should be transformed by defclass/a

Macro definition:
(defmacro defclass/a (name superclasses slots &rest class-options)
  `(progn
     (defclass ,name ,superclasses ,slots ,@class-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 (defclass dbd-null-connection (dbi.driver:dbi-connection) nil) (deftype <dbd-null-connection> nil (quote dbd-null-connection)) (setf (find-class (quote <dbd-null-connection>)) (find-class (quote dbd-null-connection))))
Write a Common Lisp macro to handle this code pattern:
(producing)

Problem: Macro call that should be transformed by PRODUCING

Macro definition:
(defmacro PRODUCING ...)

Macroexpansion:
(non-opt-producing)
Generate a defmacro form that transforms code like this:
(do+ (for x (in '(1 2 3 4))) (for y (previous x)) (for z (previous y)) (collect (list x y z)))

Pattern to recognize: 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 (in (quote (1 2 3 4)))) (for y (previous x)) (for z (previous y)) (collect (list x y z)))
Write a Common Lisp macro to handle this code pattern:
(defun-compile-time indirect-callees (function-name) (indirect-callees-internal (callees function-name) '()))

Problem: Macro call that should be transformed by defun-compile-time

Macro definition:
(defmacro defun-compile-time (function-name lambda-list &body body)
  `(eval-when (:compile-toplevel :load-toplevel :execute)
     (cl:defun ,function-name ,lambda-list ,@body)
     (eval-when (:compile-toplevel) (compile ',function-name))))

Macroexpansion:
(eval-when (:compile-toplevel :load-toplevel :execute) (common-lisp:defun indirect-callees (function-name) (indirect-callees-internal (callees function-name) (quote nil))) (eval-when (:compile-toplevel) (compile (quote indirect-callees))))
Define a macro that eliminates this repetitive pattern:
(define-alias-binding reduce reducing)

Issue: Macro call that should be transformed by define-alias-binding

Macro definition:
(defmacro define-alias-binding (name referenced-binding-name)
  `(progn (setf (binding ',name) ',referenced-binding-name)
          ',name))

Macroexpansion:
(progn (setf (binding (quote reduce)) (quote reducing)) (quote reduce))
Create a Common Lisp macro for the following transformation. Before code:
(check-cursor-attached cluffer:beginning-of-line (cursor))

What needs to change: 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:beginning-of-line :before ((cursor cluffer:cursor)) (declare (ignore)) (unless (cluffer:cursor-attached-p cursor) (error (quote cluffer:cursor-detached))))
You are a Common Lisp macro expert. Given this code pattern:
(enable-quasi-quoted-string-syntax)

Write a macro that addresses: Macro call that should be transformed by ENABLE-QUASI-QUOTED-STRING-SYNTAX

Macro definition:
(defmacro ENABLE-QUASI-QUOTED-STRING-SYNTAX ...)

Macroexpansion:
(eval-when (:compile-toplevel :execute)
  (setf *readtable* (copy-readtable *readtable*))
  (set-quasi-quoted-string-syntax-in-readtable :start-character nil
                                               :end-character nil
                                               :unquote-character #\COMMA
                                               :splice-character
                                               #\COMMERCIAL_AT
                                               :destructive-splice-character
                                               #\FULL_STOP
                                               :dispatched-quasi-quote-name
                                               "str" :transformation-pipeline
                                               nil)
  (values))
Define a macro that eliminates this repetitive pattern:
(with-collectors 'some-name)

Issue: Macro call that should be transformed by WITH-COLLECTORS

Macro definition:
(defmacro WITH-COLLECTORS ...)

Macroexpansion:
(with-collector (quote)
  (with-collectors (some-name)))
Write a Common Lisp macro to handle this code pattern:
(defclause being (form &key (then form)) "Assigns to the iteration variable a value computed by evaluating FORM on each iteration, including the first. Optionally, the variable can be updated evaluating a differen form (the value of the `then' parameter). Examples: (for x (being (random))), (for y (being 'quiet :then (if (> x 0.5) 'angry 'quiet)))." (make-simple-iteration :init form :step then))

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 being (form &key (then form)) "Assigns to the iteration variable a value computed by evaluating FORM on each iteration, including the first. Optionally, the variable can be updated evaluating a differen form (the value of the `then' parameter). Examples: (for x (being (random))), (for y (being 'quiet :then (if (> x 0.5) 'angry 'quiet)))." (make-simple-iteration :init form :step then)) (pushnew (quote being) *clauses*))
You are a Common Lisp macro expert. Given this code pattern:
(->> (v) (flow-gen v))

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

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

Macroexpansion:
(dynamically (v) (flow-gen v))
Generate a defmacro form that transforms code like this:
(define-custom-var (:beginning-of-array *beginning-of-array-handler*) (constantly t) "Designator for a function of no arguments (called at encountering an opening bracket for an Array).")

Pattern to recognize: Macro call that should be transformed by define-custom-var

Macro definition:
(defmacro define-custom-var ((key name) &rest other-args)
  `(eval-when (:compile-toplevel :load-toplevel :execute)
     (progn (pushnew '(,name . ,key) *custom-vars* :test #'equal)
            (defvar ,name ,@other-args))))

Macroexpansion:
(eval-when (:compile-toplevel :load-toplevel :execute) (progn (pushnew (quote (*beginning-of-array-handler* . :beginning-of-array)) *custom-vars* :test (function equal)) (defvar *beginning-of-array-handler* (constantly t) "Designator for a function of no arguments (called at encountering an opening bracket for an Array).")))
You are a Common Lisp macro expert. Given this code pattern:
(with-preprocessor-state-slots (state) (let ((i-state (pop include-stack))) (unless (eql if-section-stack (saved-include-state-if-section-stack i-state)) (error 'preprocess-error :format-control "#if section does not end in included file ~A" :format-arguments (list file-pathname))) (setf *package* (saved-include-state-package i-state) *readtable* (saved-include-state-readtable i-state) ) i-state))

Write a macro that addresses: Macro call that should be transformed by with-preprocessor-state-slots

Macro definition:
(defmacro with-preprocessor-state-slots ((state) &body body)
  `(with-accessors ((file-pathname pp-state-file-pathname)
                    (token-list pp-state-token-list)
                    (result-list pp-state-result-list)
                    (line-number pp-state-line-number)
                    (tokens-in-line pp-state-tokens-in-line)
                    (macro-alist pp-state-macro-alist)
                    (if-section-stack pp-state-if-section-stack)
                    (if-section-skip-reason pp-state-if-section-skip-reason)
                    (include-stack pp-state-include-stack))
       ,state
     ,@body))

Macroexpansion:
(with-accessors ((file-pathname pp-state-file-pathname) (token-list pp-state-token-list) (result-list pp-state-result-list) (line-number pp-state-line-number) (tokens-in-line pp-state-tokens-in-line) (macro-alist pp-state-macro-alist) (if-section-stack pp-state-if-section-stack) (if-section-skip-reason pp-state-if-section-skip-reason) (include-stack pp-state-include-stack)) state (let ((i-state (pop include-stack))) (unless (eql if-section-stack (saved-include-state-if-section-stack i-state)) (error (quote preprocess-error) :format-control "#if section does not end in included file ~A" :format-arguments (list file-pathname))) (setf *package* (saved-include-state-package i-state) *readtable* (saved-include-state-readtable i-state)) i-state))
Write a Common Lisp macro to handle this code pattern:
(dynenv-macrolet nil
  (progn))

Problem: Macro call that should be transformed by DYNENV-MACROLET

Macro definition:
(defmacro DYNENV-MACROLET ...)

Macroexpansion:
(macrolet ()
  (progn))
Write a Common Lisp macro to handle this code pattern:
(*> +any-space+ +skip-all-space+ +pairs+)

Problem: 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 (#:*>-offset254) (multiple-value-bind (#:*>-res257 #:*>-next258) (multiple-value-bind (#:*>-res255 #:*>-next256) (funcall +any-space+ #:*>-offset254) (if (ok? #:*>-res255) (funcall +skip-all-space+ #:*>-next256) (fail #:*>-next256))) (if (ok? #:*>-res257) (funcall +pairs+ #:*>-next258) (fail #:*>-next258))))
Write a Common Lisp macro to handle this code pattern:
(-<>> nil (progn))

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

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

Macroexpansion:
(->> nil (progn))
Define a macro that eliminates this repetitive pattern:
(define-direct-binding when (var test sub-binding &rest args) (multiple-value-bind (init body value) (apply (binding sub-binding) var args) (values init `(when ,test ,body) value)))

Issue: Macro call that should be transformed by define-direct-binding

Macro definition:
(defmacro define-direct-binding (name args &body body)
  (let ((env (or (lambda-fiddle:environment-lambda-var args) (gensym "ENVIRONMENT"))))
    `(progn (setf (binding ',name)
                  (lambda ,(lambda-fiddle:remove-environment-part args)
                    (let ((,env *environment*))
                      (declare (ignorable ,env))
                      ,@body)))
            ',name)))

Macroexpansion:
(progn (setf (binding (quote when)) (lambda (var test sub-binding &rest args) (let ((#:environment125 *environment*)) (declare (ignorable #:environment125)) (multiple-value-bind (init body value) (apply (binding sub-binding) var args) (values init (sb-int:quasiquote (when #S(sb-impl::comma :expr test :kind 0) #S(sb-impl::comma :expr body :kind 0))) value))))) (quote when))
Create a Common Lisp macro for the following transformation. Before code:
(define-modf-function getf 2 (new-val plist key) (let ((new-plist (copy-list plist))) (setf (getf new-plist key) new-val) new-plist))

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

Macro definition:
(defmacro define-modf-function (name nth-arg (new-val &rest args) &body body)
  "Define a new modf function.  It inverts NAME forms by modifying the NTH-ARG
term of the arguments of the place form in the MODF macro."
  ;; Side effect in a macro, I know.  How can you do this via EVAL-WHEN if I
  ;; want it to run even if not a toplevel macro?
  (setf (gethash name *modf-nth-arg*)
        nth-arg)
  `(progn
     (eval-when (:compile-toplevel :load-toplevel :execute)
       (setf (gethash ',name *modf-nth-arg*)
             ,nth-arg))
     (defun ,(intern (modf-name name) :modf) (,new-val ,@args)
       ,@body)))

Macroexpansion:
(progn (eval-when (:compile-toplevel :load-toplevel :execute) (setf (gethash (quote getf) *modf-nth-arg*) 2)) (defun |BUILDER:COMMON-LISP:GETF| (new-val plist key) (let ((new-plist (copy-list plist))) (setf (getf new-plist key) new-val) new-plist)))
Generate a defmacro form that transforms code like this:
(define-modf-rewrite cdaddr (expr) `(cdr (caddr ,(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 cdaddr) *modf-rewrites*) (lambda (expr) (sb-int:quasiquote (cdr (caddr #S(sb-impl::comma :expr (second expr) :kind 0)))))))
Define a macro that eliminates this repetitive pattern:
(with-flow-function-macro (body-fu lambda-list body) `(dispatch-dynamically ,flow-context #',body-fu))

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

Macro definition:
(defmacro with-flow-function-macro ((fu-name fu-lambda-list fu-body) &body body)
  `(with-gensyms (,fu-name)
     `(%with-flow-function (,,fu-name ,,fu-lambda-list ,@,fu-body)
        ,,@body)))

Macroexpansion:
(with-gensyms (body-fu) (sb-int:quasiquote (%with-flow-function (#S(sb-impl::comma :expr body-fu :kind 0) #S(sb-impl::comma :expr lambda-list :kind 0) #S(sb-impl::comma :expr body :kind 2)) #S(sb-impl::comma :expr (sb-int:quasiquote (dispatch-dynamically #S(sb-impl::comma :expr flow-context :kind 0) (function #S(sb-impl::comma :expr body-fu :kind 0)))) :kind 0))))
Define a macro that eliminates this repetitive pattern:
(is = 5 5)

Issue: Macro call that should be transformed by is

Macro definition:
(defmacro is (comp expected form &optional description &rest format-args)
  `(eval-in-context
    *context*
    (make-instance 'comparison-result
                   :expression '(is ,comp ,expected ,form)
                   :value-form ',form
                   :body (lambda () ,form)
                   :expected ,expected
                   :comparison ,(maybe-quote comp)
                   ,@(when description
                       `(:description (format NIL ,description ,@format-args))))))

Macroexpansion:
(eval-in-context *context* (make-instance (quote comparison-result) :expression (quote (is = 5 5)) :value-form (quote 5) :body (lambda nil 5) :expected 5 :comparison (quote =)))