j14i/cl-macros huggingface dataset:
Write a Common Lisp macro to handle this code pattern:
(define-ps-symbol-macro nil (progn))

Problem: Macro call that should be transformed by DEFINE-PS-SYMBOL-MACRO

Macro definition:
(defmacro DEFINE-PS-SYMBOL-MACRO ...)

Macroexpansion:
(progn
 nil
 (eval-when (:compile-toplevel :load-toplevel :execute)
   (setf (gethash 'nil *symbol-macro-toplevel*)
           (lambda (form) (declare (ignore form)) '(progn)))))
Write a Common Lisp macro to handle this code pattern:
(inext-noexit nil (progn))

Problem: Macro call that should be transformed by INEXT-NOEXIT

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

Macroexpansion:
(let ((vals (multiple-value-list (funcall (i-coro nil) (progn)))))
  (if (not vals)
      (values nil nil)
      (values (car vals) t)))
Create a Common Lisp macro for the following transformation. Before code:
(defun* nil
    :key
  nil)

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

Macro definition:
(defmacro DEFUN* ...)

Macroexpansion:
(defun nil :key
  (with-yield
    nil))
Define a macro that eliminates this repetitive pattern:
(with-ps-gensyms nil
  nil)

Issue: Macro call that should be transformed by WITH-PS-GENSYMS

Macro definition:
(defmacro WITH-PS-GENSYMS ...)

Macroexpansion:
(let* ()
  nil)
Generate a defmacro form that transforms code like this:
(dynamic-let* nil
  :key
  nil)

Pattern to recognize: Macro call that should be transformed by DYNAMIC-LET*

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

Macroexpansion:
(progn :key nil)
You are a Common Lisp macro expert. Given this code pattern:
(with-context (context) (funcall result (lambda (result) (funcall responder (process-response this result)))))

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

Macro definition:
(defmacro with-context ((context) &body body)
  `(let* ((*context* ,context)
          (*request* (context :request))
          (*response* (context :response))
          (*session* (context :session)))
     ,@body))

Macroexpansion:
(let* ((*context* context) (*request* (context :request)) (*response* (context :response)) (*session* (context :session))) (funcall result (lambda (result) (funcall responder (process-response this result)))))
Create a Common Lisp macro for the following transformation. Before code:
(defun/1 fclose (fd) (close (fd-stream fd)) (when (tmp-file fd) (delete-file (tmp-file fd)) (setf (tmp-file fd) nil)) 0)

What needs to change: Macro call that should be transformed by defun/1

Macro definition:
(defmacro defun/1 (name arglist &body body)
  "Lisp-1 defun; makes function pointers work."
  `(progn
     (defun ,name ,arglist
       (declare (optimize (speed 0) (debug 3)
                          ;; FIXME: Why do minor warnings result in load errors?
                          #+sbcl (sb-ext:inhibit-warnings 3)))
        
       ,@body)
     (defparameter ,name (vacietis.c:mkptr& (symbol-function ',name)))))

Macroexpansion:
(progn (defun fclose (fd) (declare (optimize (speed 0) (debug 3) (sb-ext:inhibit-warnings 3))) (close (fd-stream fd)) (when (tmp-file fd) (delete-file (tmp-file fd)) (setf (tmp-file fd) nil)) 0) (defparameter fclose (vacietis.c:mkptr& (symbol-function (quote fclose)))))
Generate a defmacro form that transforms code like this:
(deferror "23514" check-violation integrity-violation)

Pattern to recognize: 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 check-violation (integrity-violation) nil) (setf (gethash "23514" *error-table*) (quote check-violation)))
You are a Common Lisp macro expert. Given this code pattern:
(define-fixture-capture macro (symbol) (when (and (macro-function symbol) (not (locked-package-p (symbol-package symbol)))) (values (macro-function symbol) T)))

Write a macro that addresses: Macro call that should be transformed by define-fixture-capture

Macro definition:
(defmacro define-fixture-capture (name args &body body)
  `(progn (setf (gethash ',name *fixture-captures*)
                (lambda ,args ,@body))
          ',name))

Macroexpansion:
(progn (setf (gethash (quote macro) *fixture-captures*) (lambda (symbol) (when (and (macro-function symbol) (not (locked-package-p (symbol-package symbol)))) (values (macro-function symbol) t)))) (quote macro))
Create a Common Lisp macro for the following transformation. Before code:
(xor nil nil 1 2)

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

Macro definition:
(defmacro xor (&rest datums)
  "Evaluates its arguments one at a time, from left to right. If more than one
argument evaluates to a true value no further DATUMS are evaluated, and NIL is
returned as both primary and secondary value. If exactly one argument
evaluates to true, its value is returned as the primary value after all the
arguments have been evaluated, and T is returned as the secondary value. If no
arguments evaluate to true NIL is returned as primary, and T as secondary
value."
  (with-gensyms (xor tmp true)
    `(let (,tmp ,true)
       (declare (ignorable ,tmp))
       (block ,xor
         ,@(mapcar (lambda (datum)
                     `(if (setf ,tmp ,datum)
                          (if ,true
                              (return-from ,xor (values nil nil))
                              (setf ,true ,tmp))))
                   datums)
         (return-from ,xor (values ,true t))))))

Macroexpansion:
(let (#:tmp144 #:true145) (declare (ignorable #:tmp144)) (block #:xor143 (if (setf #:tmp144 nil) (if #:true145 (return-from #:xor143 (values nil nil)) (setf #:true145 #:tmp144))) (if (setf #:tmp144 nil) (if #:true145 (return-from #:xor143 (values nil nil)) (setf #:true145 #:tmp144))) (if (setf #:tmp144 1) (if #:true145 (return-from #:xor143 (values nil nil)) (setf #:true145 #:tmp144))) (if (setf #:tmp144 2) (if #:true145 (return-from #:xor143 (values nil nil)) (setf #:true145 #:tmp144))) (return-from #:xor143 (values #:true145 t))))
Create a Common Lisp macro for the following transformation. Before code:
(defgenerator groupby (generator &key (key #'identity) (comp #'eq)) "Groups the items from generator by the results of the key func. Each item emitted by groupby will be a pair: the key value, followed by a list of items that produced the key value when passed to the key function. Note: groupby does NOT sort the source generator. In other words it will only group matching items that are adjacent. To get SQL style GROUP BY functionality, sort the source generator before passing it to groupby. Eg: (groupby (list->generator '(A A A A B B B C C))) -> (A (A A A A)) (B (B B B)) ..." (let ((last (gensym)) (res nil)) (do-generator (g generator) (let ((currkey (funcall key g))) (if (funcall comp last currkey) (push g res) (progn (when res (yield last (nreverse res))) (setf last currkey) (setf res (cons g nil))))))))

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

Macro definition:
(defmacro defgenerator (name arguments &body body)
  (multiple-value-bind (remaining-forms declarations doc-string)
      (alexandria:parse-body body :documentation t)
    `(defun ,name ,arguments
       ,doc-string
       ,@declarations
       (with-yield
	 ,@remaining-forms))))

Macroexpansion:
(defun groupby (generator &key (key (function identity)) (comp (function eq))) "Groups the items from generator by the results of the key func. Each item emitted by groupby will be a pair: the key value, followed by a list of items that produced the key value when passed to the key function. Note: groupby does NOT sort the source generator. In other words it will only group matching items that are adjacent. To get SQL style GROUP BY functionality, sort the source generator before passing it to groupby. Eg: (groupby (list->generator '(A A A A B B B C C))) -> (A (A A A A)) (B (B B B)) ..." (with-yield (let ((last (gensym)) (res nil)) (do-generator (g generator) (let ((currkey (funcall key g))) (if (funcall comp last currkey) (push g res) (progn (when res (yield last (nreverse res))) (setf last currkey) (setf res (cons g nil)))))))))
Define a macro that eliminates this repetitive pattern:
(draw group (:circle :cx (+ x depth 1) :cy (1- (+ y depth)) :r (/ w 3)) :stroke "none" :fill "black")

Issue: Macro call that should be transformed by draw

Macro definition:
(defmacro draw (scene (shape &rest params) &rest opts)
  (let ((element (gensym)))
    `(let ((,element (funcall #'make-svg-element ,shape (append (list ,@params) (list ,@opts)))))
       (add-element ,scene ,element)
       ,element)))

Macroexpansion:
(let ((#:g157 (funcall (function make-svg-element) :circle (append (list :cx (+ x depth 1) :cy (1- (+ y depth)) :r (/ w 3)) (list :stroke "none" :fill "black"))))) (add-element group #:g157) #:g157)
Create a Common Lisp macro for the following transformation. Before code:
(send nil)

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

Macro definition:
(defmacro SEND ...)

Macroexpansion:
nil
Generate a defmacro form that transforms code like this:
(def-neo4j-fun get-relationship (relationship-id) :get (:uri-spec (format nil "relationship/~A" relationship-id)) (:status-handlers (200 (decode-neo4j-json-output body)) (404 (error 'relationship-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 get-relationship (&key relationship-id) (let ((uri (format nil "relationship/~A" relationship-id)) (json (encode-neo4j-json-payload nil :string))) (make-neo4j-request :get uri json (list (list 200 (lambda (body uri json) (decode-neo4j-json-output body))) (list 404 (lambda (body uri json) (error (quote relationship-not-found-error) :uri uri))))))))
Define a macro that eliminates this repetitive pattern:
(with-gensyms (random-number) `(let ((,random-number (random ,length))) ,(expand possibilities 0 random-number)))

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

Macro definition:
(defmacro with-gensyms (names &body forms)
  "Binds a set of variables to gensyms and evaluates the implicit progn FORMS.

Each element within NAMES is either a symbol SYMBOL or a pair (SYMBOL
STRING-DESIGNATOR). Bare symbols are equivalent to the pair (SYMBOL SYMBOL).

Each pair (SYMBOL STRING-DESIGNATOR) specifies that the variable named by SYMBOL
should be bound to a symbol constructed using GENSYM with the string designated
by STRING-DESIGNATOR being its first argument."
  `(let ,(mapcar (lambda (name)
                   (multiple-value-bind (symbol string)
                       (etypecase name
                         (symbol
                          (values name (symbol-name name)))
                         ((cons symbol (cons string-designator null))
                          (values (first name) (string (second name)))))
                     `(,symbol (gensym ,string))))
                 names)
     ,@forms))

Macroexpansion:
(let ((random-number (gensym #A((13) base-char . "RANDOM-NUMBER")))) (sb-int:quasiquote (let ((#S(sb-impl::comma :expr random-number :kind 0) (random #S(sb-impl::comma :expr length :kind 0)))) #S(sb-impl::comma :expr (expand possibilities 0 random-number) :kind 0))))
Create a Common Lisp macro for the following transformation. Before code:
(define-custom-var (:beginning-of-object *beginning-of-object-handler*) (constantly t) "Designator for a function of no arguments (called at encountering an opening brace for an Object).")

What needs to change: 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-object-handler* . :beginning-of-object)) *custom-vars* :test (function equal)) (defvar *beginning-of-object-handler* (constantly t) "Designator for a function of no arguments (called at encountering an opening brace for an Object).")))
Create a Common Lisp macro for the following transformation. Before code:
(with-color (:white :stream stream) (format/indent reporter stream (slot-value report 'description)))

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

Macro definition:
(defmacro with-color ((color &rest args) &body body)
  (cond
    ((or (eq color :gray)
         (eq color :grey))
     `(if *enable-colors*
          (with-gray ,(or (getf args :stream) t) ,@body)
          (progn ,@body)))
    (T `(if *enable-colors*
            (if (or (eq ,color :gray)
                    (eq ,color :grey)
                    (eq ,color cl-colors:+gray+)
                    (eq ,color cl-colors:+grey+))
                (with-gray ,(or (getf args :stream) t) ,@body)
                (cl-ansi-text:with-color (,color ,@args) ,@body))
            (progn ,@body)))))

Macroexpansion:
(if *enable-colors* (if (or (eq :white :gray) (eq :white :grey) (eq :white +gray+) (eq :white +grey+)) (with-gray stream (format/indent reporter stream (slot-value report (quote description)))) (cl-ansi-text:with-color (:white :stream stream) (format/indent reporter stream (slot-value report (quote description))))) (progn (format/indent reporter stream (slot-value report (quote description)))))
Define a macro that eliminates this repetitive pattern:
(-> :g (b) (+ b 6))

Issue: Macro call that should be transformed by ->

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

Macroexpansion:
(atomically :g (b) (+ b 6))
Define a macro that eliminates this repetitive pattern:
(define-error could-not-find-any (:error-type varjo-critical-error) (name) "No function, macro or compiler-macro called '~a' could be found in this environment" name)

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 could-not-find-any (:error-type varjo-critical-error :prefix "Varjo") (name) "No function, macro or compiler-macro called '~a' could be found in this environment" name)
Write a Common Lisp macro to handle this code pattern:
(dflet ((foo/inline () 42)) (is (eql 42 (foo/inline))))

Problem: Macro call that should be transformed by dflet

Macro definition:
(defmacro dflet ((&rest definitions) &body body)
  "Like FLET, but dynamically sets the FDEFINITIONS during the duration of
the BODY."
  `(progf
       ',(mapcar #'car definitions)
       (list
        ,.(mapcar (lambda (definition)
                    `(lambda ,(cadr definition)
                       ,@(cddr definition)))
                  definitions))
     ,@body))

Macroexpansion:
(progf (quote (foo/inline)) (list (lambda nil 42)) (is (eql 42 (foo/inline))))
Create a Common Lisp macro for the following transformation. Before code:
(with-attributes nil
    nil)

What needs to change: Macro call that should be transformed by WITH-ATTRIBUTES

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

Macroexpansion:
(let ((#:unit160 nil))
  (symbol-macrolet ()))
You are a Common Lisp macro expert. Given this code pattern:
(caching-types
  'some-name)

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

Macro definition:
(defmacro CACHING-TYPES ...)

Macroexpansion:
(call-with-disjoint-hash
 (lambda ()
   (call-with-subtype-hash
    (lambda ()
      (call-with-equiv-hash
       (lambda () (call-with-subtypep-cache (lambda () 'some-name))))))))
Define a macro that eliminates this repetitive pattern:
(caching-types
  nil
  nil)

Issue: Macro call that should be transformed by CACHING-TYPES

Macro definition:
(defmacro CACHING-TYPES ...)

Macroexpansion:
(call-with-disjoint-hash
 (lambda ()
   (call-with-subtype-hash
    (lambda ()
      (call-with-equiv-hash
       (lambda () (call-with-subtypep-cache (lambda () nil nil))))))))
You are a Common Lisp macro expert. Given this code pattern:
(special-symbol-progv nil
    :key
  nil)

Write a macro that addresses: Macro call that should be transformed by SPECIAL-SYMBOL-PROGV

Macro definition:
(defmacro SPECIAL-SYMBOL-PROGV ...)

Macroexpansion:
(let (#:symbol-list180)
  (tagbody
   #:retry181
    (setq #:symbol-list180 nil)
    (unless (every #'special-symbol-p #:symbol-list180)
      (cerror "Retry to rebind the place(s)."
              "Attempt at rebinding one or more non-special places: ~S" 'nil)
      (go #:retry181)))
  (dynamic-progv #:symbol-list180
      :key
    nil))
Create a Common Lisp macro for the following transformation. Before code:
(defsynonym initially :initially)

What needs to change: 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 initially) (quote synonym)) (quote :initially)))
Generate a defmacro form that transforms code like this:
(define-element-maker :marker "marker" '(:id))

Pattern to recognize: Macro call that should be transformed by define-element-maker

Macro definition:
(defmacro define-element-maker (element name required-attributes)
  `(progn
     (defmethod assert-required-attributes ((element (eql ,element)) attributes)
       (declare (ignore element))
       (unless (evenp (length attributes))
         (warn "attribute list may be missing data: ~A" attributes))
       (let ((missing (set-difference ,required-attributes attributes)))
	 (when missing
	   (error 'missing-attributes :message (format nil "~A missing attributes: ~{~A~^ ~}" ,element missing)))))
     (defmethod make-svg-element ((element (eql ,element)) attributes)
       (when *check-required-attributes*
         (assert-required-attributes element attributes))
       (make-instance 'svg-element :name ,name :attributes attributes))))

Macroexpansion:
(progn (defmethod assert-required-attributes ((element (eql :marker)) attributes) (declare (ignore element)) (unless (evenp (length attributes)) (warn "attribute list may be missing data: ~A" attributes)) (let ((missing (set-difference (quote (:id)) attributes))) (when missing (error (quote missing-attributes) :message (format nil "~A missing attributes: ~{~A~^ ~}" :marker missing))))) (defmethod make-svg-element ((element (eql :marker)) attributes) (when *check-required-attributes* (assert-required-attributes element attributes)) (make-instance (quote svg-element) :name "marker" :attributes attributes)))
Generate a defmacro form that transforms code like this:
(defmethod* nil)

Pattern to recognize: Macro call that should be transformed by DEFMETHOD*

Macro definition:
(defmacro DEFMETHOD* ...)

Macroexpansion:
(let* ((#:nil123 (ensure-generic*-function 'nil))
       (temp-method (defmethod #:nil122))
       (actual-gf
        (ensure-generic*-function 'nil :lambda-list
                                  (sb-mop:generic-function-lambda-list
                                   (symbol-function '#:nil122))
                                  :special-variables 'nil))
       (actual-method
        (add-method* #:nil123
                     (make-instance 'method* :special-variables (list)
                                    :qualifiers 'nil :specializers
                                    (sb-mop:method-specializers temp-method)
                                    :lambda-list
                                    (sb-mop:method-lambda-list temp-method)
                                    :documentation
                                    (documentation temp-method t) :function
                                    (sb-mop:method-function temp-method)))))
  (declare (ignorable #:nil123)
           (ignore actual-gf))
  (setf (documentation actual-method t) (documentation temp-method t))
  actual-method)
Define a macro that eliminates this repetitive pattern:
(with-prepared-query query (conn sql) (and (dbi:fetch-all (execute-with-retry query binds) :format :plist) t))

Issue: Macro call that should be transformed by with-prepared-query

Macro definition:
(defmacro with-prepared-query (query (conn sql &key use-prepare-cached) &body body)
  `(call-with-prepared-query ,conn ,sql (lambda (,query) ,@body) :use-prepare-cached ,use-prepare-cached))

Macroexpansion:
(call-with-prepared-query conn sql (lambda (query) (and (dbi.driver:fetch-all (execute-with-retry query binds) :format :plist) t)) :use-prepare-cached nil)
Generate a defmacro form that transforms code like this:
;; Manual gensym binding is verbose
(let ((g1 (gensym))
      (g2 (gensym))
      (g3 (gensym)))
  `(let ((,g1 ,x)
         (,g2 ,y))
     (f ,g1 ,g2 ,g3)))
;; The let-bindings for gensyms obscure the macro logic

Pattern to recognize: Manual gensym creation with let-bindings is verbose — want concise declaration of gensym-intended symbols

Macro definition:
(defmacro with-gensyms (syms &body body)
  `(let ,(mapcar #'(lambda (s)
                     `(,s (gensym)))
                 syms)
     ,@body))

Macroexpansion:
;; (with-gensyms (g1 g2 g3)
;;   `(let ((,g1 ,x)
;;          (,g2 ,y))
;;      (f ,g1 ,g2 ,g3)))
;; Expands to:
;; (LET ((G1 (GENSYM)) (G2 (GENSYM)) (G3 (GENSYM)))
;;   `(LET ((,G1 ,X) (,G2 ,Y)) (F ,G1 ,G2 ,G3)))
;;
;; Much cleaner than manual gensym let-bindings
Create a Common Lisp macro for the following transformation. Before code:
(with-html-string (:div.some-class (:pre "verbatim line one verbatim line two") (:p "Some following stuff")))

What needs to change: 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 (:div.some-class (:pre "verbatim line one verbatim line two") (:p "Some following stuff"))))
Define a macro that eliminates this repetitive pattern:
(define-custom-var (:end-of-string *end-of-string-handler*) (constantly "") "Designator for a function of no arguments (called at encountering a closing quote for a String).")

Issue: 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 (*end-of-string-handler* . :end-of-string)) *custom-vars* :test (function equal)) (defvar *end-of-string-handler* (constantly "") "Designator for a function of no arguments (called at encountering a closing quote for a String).")))