j14i/cl-macros huggingface dataset:
You are a Common Lisp macro expert. Given this code pattern:
(with-env (setp 3 [assoc-list 'c]))

Write a macro that addresses: 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 (#:g135) (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 #:g135 (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)) (setp 3 [assoc-list (quote c])))) (setf (find-class (quote foo) nil) nil) (setf (find-class (quote bar) nil) nil) #:g135)
Generate a defmacro form that transforms code like this:
(with-table node hash depth (bitmap array bits index hit) (flet ((%insert (table) (%dict-insert table key value hash (1+ depth) test))) (let ((new-node (cond (hit (%insert (aref array index))) ((= depth 6) (make-instance 'dict-leaf :key key :value value)) (t (%insert (make-instance 'dict-table)))))) (make-instance 'dict-table :bitmap (logior bitmap (ash 1 bits)) :table (funcall (if hit #'vec-update #'vec-insert) array index new-node)))))

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

Macro definition:
(defmacro with-table (node hash depth
                      (bitmap array bits index hit)
                      &body body)
  "Bitshifting in HAMT tables"
  `(let* ((,bitmap (table-bitmap ,node))
          (,array (table-array ,node))
          (,bits (get-bits ,hash ,depth))
          (,index (get-index ,bits ,bitmap))
          (,hit (logbitp ,bits ,bitmap)))
     ,@body))

Macroexpansion:
(let* ((bitmap (table-bitmap node)) (array (table-array node)) (bits (get-bits hash depth)) (index (get-index bits bitmap)) (hit (logbitp bits bitmap))) (flet ((%insert (table) (%dict-insert table key value hash (1+ depth) test))) (let ((new-node (cond (hit (%insert (aref array index))) ((= depth 6) (make-instance (quote dict-leaf) :key key :value value)) (t (%insert (make-instance (quote dict-table))))))) (make-instance (quote dict-table) :bitmap (logior bitmap (ash 1 bits)) :table (funcall (if hit (function vec-update) (function vec-insert)) array index new-node)))))
You are a Common Lisp macro expert. Given this code pattern:
(with-mocks () (register-mock 'foo) (register-mock 'bar) (foo) (bar) (is (equal '((foo)) (invocations 'foo))))

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

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

Macroexpansion:
(call-with-mocks (lambda nil (register-mock (quote foo)) (register-mock (quote bar)) (foo) (bar) (is (equal (quote ((foo))) (invocations (quote foo))))) :recordp t)
Define a macro that eliminates this repetitive pattern:
(define-symbol-macro nil nil)

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

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

Macroexpansion:
(eval-when (:compile-toplevel :load-toplevel :execute)
  (sb-c::%define-symbol-macro 'nil 'nil (sb-c:source-location)))
Write a Common Lisp macro to handle this code pattern:
(defobject nil
    (progn))

Problem: Macro call that should be transformed by DEFOBJECT

Macro definition:
(defmacro DEFOBJECT ...)

Macroexpansion:
(let ((old (find-class 'nil nil)))
  (prog1
      (ensure-class 'nil :metaclass 'adhoc-class :direct-default-initargs
                    (list) :direct-superclasses '(progn object) :direct-slots
                    (list) :direct-descending-attributes 'nil)
    (when old (make-instances-obsolete old))))
Write a Common Lisp macro to handle this code pattern:
(check-cursor-attached (setf cluffer:cursor-position) (position cursor))

Problem: 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 (setf cluffer:cursor-position) :before (position (cursor cluffer:cursor)) (declare (ignore position)) (unless (cluffer:cursor-attached-p cursor) (error (quote cluffer:cursor-detached))))
Create a Common Lisp macro for the following transformation. Before code:
(with-additional-indent (reporter stream "~& ") (with-color (:cyan :stream stream) (with-additional-indent (reporter stream "- ") (let ((description (possible-report-description report))) (when description (format/indent reporter stream description)))) (terpri stream)))

What needs to change: 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 (:cyan :stream stream) (with-additional-indent (reporter stream "- ") (let ((description (possible-report-description report))) (when description (format/indent reporter stream description)))) (terpri stream))))
Write a Common Lisp macro to handle this code pattern:
(defun-compile-time cps-convert-let (bindings body declarations continuation types value? environment &optional new-bindings) (if (null bindings) `(let ,new-bindings ,@declarations ,(cps-convert-progn body continuation types value? environment)) (let* ((binding (first bindings)) (binding-variable (if (symbolp binding) binding (first binding))) (binding-form (if (and (consp binding) (= (length binding) 2)) (second binding) nil)) (dummy-argument (gensym "DUMMY-")) (other-arguments (gensym "OTHER-"))) (cps-convert binding-form `#'(lambda (&optional ,dummy-argument &rest ,other-arguments) (declare (magic) (ignore ,other-arguments)) ,(cps-convert-let (rest bindings) body declarations continuation types value? environment (cons (list binding-variable dummy-argument) new-bindings))) '() t environment))))

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 cps-convert-let (bindings body declarations continuation types value? environment &optional new-bindings) (if (null bindings) (sb-int:quasiquote (let #S(sb-impl::comma :expr new-bindings :kind 0) #S(sb-impl::comma :expr declarations :kind 2) #S(sb-impl::comma :expr (cps-convert-progn body continuation types value? environment) :kind 0))) (let* ((binding (first bindings)) (binding-variable (if (symbolp binding) binding (first binding))) (binding-form (if (and (consp binding) (= (length binding) 2)) (second binding) nil)) (dummy-argument (gensym "DUMMY-")) (other-arguments (gensym "OTHER-"))) (cps-convert binding-form (sb-int:quasiquote (function (lambda (&optional #S(sb-impl::comma :expr dummy-argument :kind 0) &rest #S(sb-impl::comma :expr other-arguments :kind 0)) (declare (magic) (ignore #S(sb-impl::comma :expr other-arguments :kind 0))) #S(sb-impl::comma :expr (cps-convert-let (rest bindings) body declarations continuation types value? environment (cons (list binding-variable dummy-argument) new-bindings)) :kind 0)))) (quote nil) t environment)))) (eval-when (:compile-toplevel) (compile (quote cps-convert-let))))
Define a macro that eliminates this repetitive pattern:
(with-yield-binds (format nil "(~A)" (yield (apply #'make-sql-splicing-list (sql-list-elements list)))))

Issue: 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)" (yield (apply (function make-sql-splicing-list) (sql-list-elements list))))) (loop for bind in (reverse *bind-values*) append bind)))
Generate a defmacro form that transforms code like this:
(deferror "42P05" duplicate-prepared-statement syntax-error-or-access-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 duplicate-prepared-statement (syntax-error-or-access-violation) nil) (setf (gethash "42P05" *error-table*) (quote duplicate-prepared-statement)))
Generate a defmacro form that transforms code like this:
(ensure-getf options :dynamic-extent dynamic-extent)

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

Macro definition:
(defmacro ensure-getf (place key &optional default)
  (once-only (key default)
    `(setf (getf ,place ,key) (getf ,place ,key ,default))))

Macroexpansion:
(let ((#:key175 :dynamic-extent) (#:default176 dynamic-extent)) (setf (getf options #:key175) (getf options #:key175 #:default176)))
Generate a defmacro form that transforms code like this:
(cond->> nil (progn))

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

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

Macroexpansion:
(let* ((#:|cond137| nil)
       (#:|cond137|
        (if progn
            #:|cond137|
            #:|cond137|)))
  #:|cond137|)
Write a Common Lisp macro to handle this code pattern:
(collect-last nil)

Problem: Macro call that should be transformed by COLLECT-LAST

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

Macroexpansion:
(common-lisp:let* ((#:generator-509 (generator nil))
                   #:items-503
                   (#:item-505 nil))
  (declare (type generator #:generator-509)
           (type (null-or t) #:item-505))
  (tagbody
   #:ll-510
    (setq #:items-503 (next-in #:generator-509 (go end)))
    (setq #:item-505 #:items-503)
    (go #:ll-510)
   end)
  #:item-505)
You are a Common Lisp macro expert. Given this code pattern:
(-> 'some-name)

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

Macro definition:
(defmacro -> ...)

Macroexpansion:
'some-name
Write a Common Lisp macro to handle this code pattern:
(deferror "22P01" floating-point-exception data-exception)

Problem: 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 floating-point-exception (data-exception) nil) (setf (gethash "22P01" *error-table*) (quote floating-point-exception)))
Write a Common Lisp macro to handle this code pattern:
(with-preprocessor-state-slots (state) (when if-section-skip-reason (return-from process-preprocessing-directive nil)) (let* ((identifier (pop-preprocessor-directive-token directive-token-list directive-symbol)) (next-token (first directive-token-list)) (function-like-p (token-equal-p next-token '|(|))) (cond (function-like-p (multiple-value-bind (identifier-list variadicp rest-token-list) (collect-function-like-macro-identifier-list directive-token-list directive-symbol) (add-local-preprocessor-macro state identifier (make-instance 'function-like-macro :name identifier :identifier-list identifier-list :variadicp variadicp :replacement-list rest-token-list)))) (t (unless (or (null directive-token-list) (eq next-token +whitespace-marker+)) (warn 'with-c-syntax-style-warning :message "C99 requires whitespace after the macro name.")) (add-local-preprocessor-macro state identifier (make-instance 'object-like-macro :name identifier :replacement-list directive-token-list)))))))

Problem: 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 (when if-section-skip-reason (return-from process-preprocessing-directive nil)) (let* ((identifier (pop-preprocessor-directive-token directive-token-list directive-symbol)) (next-token (first directive-token-list)) (function-like-p (token-equal-p next-token (quote |(|)))) (cond (function-like-p (multiple-value-bind (identifier-list variadicp rest-token-list) (collect-function-like-macro-identifier-list directive-token-list directive-symbol) (add-local-preprocessor-macro state identifier (make-instance (quote function-like-macro) :name identifier :identifier-list identifier-list :variadicp variadicp :replacement-list rest-token-list)))) (t (unless (or (null directive-token-list) (eq next-token +whitespace-marker+)) (warn (quote with-c-syntax-style-warning) :message "C99 requires whitespace after the macro name.")) (add-local-preprocessor-macro state identifier (make-instance (quote object-like-macro) :name identifier :replacement-list directive-token-list))))))
You are a Common Lisp macro expert. Given this code pattern:
(with-transaction conn (let ((cursor (make-cursor conn "SELECT * FROM person WHERE name = 'Trixie'"))) (execute cursor) (ok (null (fetch cursor))) (close-cursor cursor)))

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

Macro definition:
(defmacro with-transaction (conn &body body)
  "Start a transaction and commit at the end of this block. If the evaluation `body` is interrupted, the transaction is rolled back automatically."
  (let ((conn-var (gensym "CONN-VAR")))
    `(let ((,conn-var ,conn))
       (if (in-transaction ,conn-var)
           (with-savepoint ,conn-var ,@body)
           (%with-transaction ,conn-var ,@body)))))

Macroexpansion:
(let ((#:conn-var162 conn)) (if (in-transaction #:conn-var162) (with-savepoint #:conn-var162 (let ((cursor (make-cursor conn "SELECT * FROM person WHERE name = 'Trixie'"))) (execute cursor) (ok (null (fetch cursor))) (close-cursor cursor))) (%with-transaction #:conn-var162 (let ((cursor (make-cursor conn "SELECT * FROM person WHERE name = 'Trixie'"))) (execute cursor) (ok (null (fetch cursor))) (close-cursor cursor)))))
Write a Common Lisp macro to handle this code pattern:
(with-mapping-appender 'some-name)

Problem: Macro call that should be transformed by WITH-MAPPING-APPENDER

Macro definition:
(defmacro WITH-MAPPING-APPENDER ...)

Macroexpansion:
(let ((#:col129 (make-appender)))
  (map-aggregation (#:col129 (lambda some-name))
    (flet ((quote (&rest #:flet-args130) (apply #:col129 #:flet-args130))))))
Create a Common Lisp macro for the following transformation. Before code:
(with-unique-names (clauses next) `(prog (,clauses) ,next (push (do-parse-clause ,client ,region *index* ,read-name-p ,@args) ,clauses) (when (maybe-parse-token :keywords '(:and)) (go ,next)) (return (nreverse ,clauses))))

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

Macro definition:
(defmacro with-unique-names (names &body body)
  `(let ,(mapcar (lambda (sym)
                   `(,sym (gensym ,(symbol-name sym))))
                  names)
     ,@body))

Macroexpansion:
(let ((clauses (gensym #A((7) base-char . "CLAUSES"))) (next (gensym #A((4) base-char . "NEXT")))) (quasiquote (prog (#S(sb-impl::comma :expr clauses :kind 0)) #S(sb-impl::comma :expr next :kind 0) (push (do-parse-clause #S(sb-impl::comma :expr client :kind 0) #S(sb-impl::comma :expr region :kind 0) *index* #S(sb-impl::comma :expr read-name-p :kind 0) #S(sb-impl::comma :expr args :kind 2)) #S(sb-impl::comma :expr clauses :kind 0)) (when (maybe-parse-token :keywords (quote (:and))) (go #S(sb-impl::comma :expr next :kind 0))) (return (nreverse #S(sb-impl::comma :expr clauses :kind 0))))))
Write a Common Lisp macro to handle this code pattern:
(with-implicit-conversion 'some-name)

Problem: Macro call that should be transformed by WITH-IMPLICIT-CONVERSION

Macro definition:
(defmacro WITH-IMPLICIT-CONVERSION ...)

Macroexpansion:
(let ((*allow-implicit-conversion* (eql quote :allowed)))
  (block #:blockname132
    (handler-bind ((implicit-conversion-to-advisable-function
                    (lambda (#:c133)
                      (declare (ignore #:c133))
                      (return-from #:blockname132 nil))))
      (locally))))
Define a macro that eliminates this repetitive pattern:
(defun/1 fputc (c fd) (handler-case (progn (write-char (code-char c) (fd-stream fd)) c) (error () (setf (ferror fd) EIO) EOF)))

Issue: 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 fputc (c fd) (declare (optimize (speed 0) (debug 3) (sb-ext:inhibit-warnings 3))) (handler-case (progn (write-char (code-char c) (fd-stream fd)) c) (error nil (setf (ferror fd) eio) eof))) (defparameter fputc (vacietis.c:mkptr& (symbol-function (quote fputc)))))
Create a Common Lisp macro for the following transformation. Before code:
(use-syntax 'some-name)

What needs to change: Macro call that should be transformed by USE-SYNTAX

Macro definition:
(defmacro use-syntax (name)
  `(eval-when (:compile-toplevel :load-toplevel :execute)
     (%use-syntax ,name)))

Macroexpansion:
(eval-when (:compile-toplevel :load-toplevel :execute) (%use-syntax 'some-name))