j14i/cl-macros huggingface dataset:
You are a Common Lisp macro expert. Given this code pattern:
(defclause optimizing (form &key (test ''>) saving in) "Finds the optimum value of an expression across the iteration. Refer to the manual for details." (let* ((candidate (gensym "CANDIDATE-MAX")) (test-form `(funcall ,test ,candidate ,*iteration-variable*)) (saving (ensure-list saving)) (in (ensure-list in))) (when (not (= (length saving) (length in))) (error ":saving and :in have different lengths!")) (list* (make-simple-iteration :init form) (make-epilogue :form `(let ((,candidate ,form)) (when ,test-form (setf ,*iteration-variable* ,candidate ,@(loop :for x :in saving :for y :in in :collect y :collect x))))) (loop :for x :in saving :for y :in in :collect (make-simple-iteration :var y :init x)))))

Write a macro that addresses: 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 optimizing (form &key (test (quote (quote >))) saving in) "Finds the optimum value of an expression across the iteration. Refer to the manual for details." (let* ((candidate (gensym "CANDIDATE-MAX")) (test-form (sb-int:quasiquote (funcall #S(sb-impl::comma :expr test :kind 0) #S(sb-impl::comma :expr candidate :kind 0) #S(sb-impl::comma :expr *iteration-variable* :kind 0)))) (saving (ensure-list saving)) (in (ensure-list in))) (when (not (= (length saving) (length in))) (error ":saving and :in have different lengths!")) (list* (make-simple-iteration :init form) (make-epilogue :form (sb-int:quasiquote (let ((#S(sb-impl::comma :expr candidate :kind 0) #S(sb-impl::comma :expr form :kind 0))) (when #S(sb-impl::comma :expr test-form :kind 0) (setf #S(sb-impl::comma :expr *iteration-variable* :kind 0) #S(sb-impl::comma :expr candidate :kind 0) #S(sb-impl::comma :expr (loop :for x :in saving :for y :in in :collect y :collect x) :kind 2)))))) (loop :for x :in saving :for y :in in :collect (make-simple-iteration :var y :init x))))) (pushnew (quote optimizing) *clauses*))
Write a Common Lisp macro to handle this code pattern:
(with-html-string (:li :class nil "Hello"))

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 (:li :class nil "Hello")))
Create a Common Lisp macro for the following transformation. Before code:
(integer-reader 1)

What needs to change: Macro call that should be transformed by integer-reader

Macro definition:
(defmacro integer-reader (bytes)
  "Create a function to read integers from a binary stream."
  (let ((bits (* bytes 8)))
    (labels ((return-form (signed)
               (if signed
                   `(if (logbitp ,(1- bits) result)
                        (dpb result (byte ,(1- bits) 0) -1)
                        result)
                   `result))
             (generate-reader (signed)
               `(defun ,(integer-reader-name bytes signed) (socket)
                  (declare (type stream socket)
                           #.*optimize*)
                  ,(if (= bytes 1)
                       `(let ((result (the (unsigned-byte 8) (read-byte socket))))
                          (declare (type (unsigned-byte 8) result))
                          ,(return-form signed))
                       `(let ((result 0))
                          (declare (type (unsigned-byte ,bits) result))
                          ,@(loop :for byte :from (1- bytes) :downto 0
                                  :collect `(setf (ldb (byte 8 ,(* 8 byte))
                                                       result)
                                                  (the (unsigned-byte 8)
                                                       (read-byte socket))))
                          ,(return-form signed))))))
      `(progn
         ;; This causes weird errors on SBCL in some circumstances. Disabled for now.
         ;;         (declaim (inline ,(integer-reader-name bytes t)
         ;;                          ,(integer-reader-name bytes nil)))
         (declaim (ftype (function (t) (signed-byte ,bits))
                         ,(integer-reader-name bytes t)))
         ,(generate-reader t)
         (declaim (ftype (function (t) (unsigned-byte ,bits))
                         ,(integer-reader-name bytes nil)))
         ,(generate-reader nil)))))

Macroexpansion:
(progn (declaim (ftype (function (t) (signed-byte 8)) read-int1)) (defun read-int1 (socket) (declare (type stream socket) (optimize (speed 3) (safety 0) (space 1) (debug 1) (compilation-speed 0))) (let ((result (the (unsigned-byte 8) (read-byte socket)))) (declare (type (unsigned-byte 8) result)) (if (logbitp 7 result) (dpb result (byte 7 0) -1) result))) (declaim (ftype (function (t) (unsigned-byte 8)) read-uint1)) (defun read-uint1 (socket) (declare (type stream socket) (optimize (speed 3) (safety 0) (space 1) (debug 1) (compilation-speed 0))) (let ((result (the (unsigned-byte 8) (read-byte socket)))) (declare (type (unsigned-byte 8) result)) result)))
You are a Common Lisp macro expert. Given this code pattern:
(some-<>> nil (progn))

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

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

Macroexpansion:
(let* ((#:g132 nil))
  (if (null #:g132)
      nil
      (->> #:g132 (progn))))
Write a Common Lisp macro to handle this code pattern:
(define-custom-var (:real *real-handler*) (constantly 0) "Designator for a function of 1 string argument (real token).")

Problem: 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 (*real-handler* . :real)) *custom-vars* :test (function equal)) (defvar *real-handler* (constantly 0) "Designator for a function of 1 string argument (real token).")))
Write a Common Lisp macro to handle this code pattern:
(mapcar (lambda (f) `(function ,(force-first f))) bindings)

Problem: Macro call that should be transformed by m

Macro definition:
(defmacro m (form &environment *env*)
  (e form))

Macroexpansion:
(mapcar (lambda (f) (sb-int:quasiquote (function #S(sb-impl::comma :expr (force-first f) :kind 0)))) bindings)
You are a Common Lisp macro expert. Given this code pattern:
(ensure-gethash (car tail) table (cadr tail))

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

Macro definition:
(defmacro ensure-gethash (key hash-table &optional default)
  "Like GETHASH, but if KEY is not found in the HASH-TABLE saves the DEFAULT
under key before returning it. Secondary return value is true if key was
already in the table."
  (once-only (key hash-table)
    (with-unique-names (value presentp)
      `(multiple-value-bind (,value ,presentp) (gethash ,key ,hash-table)
         (if ,presentp
             (values ,value ,presentp)
             (values (setf (gethash ,key ,hash-table) ,default) nil))))))

Macroexpansion:
(let ((#:n-key-155 (car tail)) (#:n-hash-table-156 table)) (multiple-value-bind (#:value157 #:foundp158) (gethash #:n-key-155 #:n-hash-table-156) (if #:foundp158 (values #:value157 t) (values (setf (gethash #:n-key-155 #:n-hash-table-156) (cadr tail)) nil))))
Generate a defmacro form that transforms code like this:
(make-name-transformer nil :key nil)

Pattern to recognize: Macro call that should be transformed by MAKE-NAME-TRANSFORMER

Macro definition:
(defmacro MAKE-NAME-TRANSFORMER ...)

Macroexpansion:
(lambda (name definition)
  (declare (ignorable definition))
  (concatenate-symbol nil :key nil))
Define a macro that eliminates this repetitive pattern:
(cond->>
  nil
  nil)

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

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

Macroexpansion:
(let* ((#:var162 nil)
       (#:var163
        (if nil
            (->>
              #:var162)
            #:var162)))
  #:var163)
Create a Common Lisp macro for the following transformation. Before code:
(auto-permute-typecase nil
  (progn))

What needs to change: Macro call that should be transformed by AUTO-PERMUTE-TYPECASE

Macro definition:
(defmacro AUTO-PERMUTE-TYPECASE ...)

Macroexpansion:
(typecase nil (progn))
Define a macro that eliminates this repetitive pattern:
(with-effective-qualifier generic-function qualifier (destructure-specialized-lambda-list descriptive-lambda-list vanilla-lambda-list type-list specialized-lambda-list `(%lay-method-base-for-dispatch ,generic-function ,qualifier ,type-list ,descriptive-lambda-list ,@body)))

Issue: Macro call that should be transformed by with-effective-qualifier

Macro definition:
(defmacro with-effective-qualifier (gf-name qualifier &body body)
  "take generic function and a symbol bound to a qualifier and mask that symbol with the effective qualifier.

The effective qualifier is the default qualifier for the given generic function should there be one defined by
a define-hook-generic form."
  `(let ((,qualifier
          (effective-qualifier ,gf-name ,qualifier)))
     ,@body))

Macroexpansion:
(let ((qualifier (effective-qualifier generic-function qualifier))) (destructure-specialized-lambda-list descriptive-lambda-list vanilla-lambda-list type-list specialized-lambda-list (sb-int:quasiquote (%lay-method-base-for-dispatch #S(sb-impl::comma :expr generic-function :kind 0) #S(sb-impl::comma :expr qualifier :kind 0) #S(sb-impl::comma :expr type-list :kind 0) #S(sb-impl::comma :expr descriptive-lambda-list :kind 0) #S(sb-impl::comma :expr body :kind 2)))))
You are a Common Lisp macro expert. Given this code pattern:
(with-reader-syntax (get-val array hash-table) (with-output-to-string (*error-output*) (is (char= #\a (er "(with-env [str 0])"))) (is (eq 'a (er "(with-env [vec 0])"))) (is (= 3 (er "(with-env [arr 0 2])"))) (is (eq 'd (er "(with-env [list 3])"))) (is (eq 'b (er "(with-env [ht 'a])"))) (is (eq nil (er "(with-env [ht-eq (string (alexandria:copy-array \"a\"))])"))) (is (equal "b" (er "(with-env [ht-equalp (copy-list '(4 5 6))])"))) (is (= 1 (er "(with-env [assoc-list 'a])"))) (is (eq nil (er "(with-env [assoc-list 'c])"))) (is (= 5 (er "(with-env [plist :c])"))) (is (eq nil (er "(with-env [plist :e])"))) (is (eq 3 (er "(with-env [clos-object 'a])"))) (is (eq 3 (er "(with-env [struct 'a])")))))

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

Macro definition:
(defmacro with-reader-syntax (reader-macro-identifiers &body body)
  "This macro is only made for use by read-and-eval functionality,
and rather directed towards tests than users. So, do not export."
  (let ((identifiers (loop :for identifier :in reader-macro-identifiers
                           :collect `(quote ,identifier))))
    `(let ((*array-function*         'make-t-array-from-initial-contents)
           (*hash-table-function*    'alexandria:plist-hash-table)
           (*get-val-function*       'get-val)
           (*get-val-array-function* 'cl:aref)
           (*set-function*           'cl:remove-duplicates)
           (*alists-are-lists*       nil)
           (*plists-are-lists*       nil)
           (*readtable*             (%enable-reader-syntax *readtable* ,@identifiers)))
       ,@body)))

Macroexpansion:
(let ((*array-function* (quote make-t-array-from-initial-contents)) (*hash-table-function* (quote alexandria:plist-hash-table)) (*get-val-function* (quote get-val)) (*get-val-array-function* (quote aref)) (*set-function* (quote remove-duplicates)) (*alists-are-lists* nil) (*plists-are-lists* nil) (*readtable* (%enable-reader-syntax *readtable* (quote get-val) (quote array) (quote hash-table)))) (with-output-to-string (*error-output*) (is (char= #\LATIN_SMALL_LETTER_A (er "(with-env [str 0])"))) (is (eq (quote a) (er "(with-env [vec 0])"))) (is (= 3 (er "(with-env [arr 0 2])"))) (is (eq (quote d) (er "(with-env [list 3])"))) (is (eq (quote b) (er "(with-env [ht 'a])"))) (is (eq nil (er "(with-env [ht-eq (string (alexandria:copy-array \"a\"))])"))) (is (equal "b" (er "(with-env [ht-equalp (copy-list '(4 5 6))])"))) (is (= 1 (er "(with-env [assoc-list 'a])"))) (is (eq nil (er "(with-env [assoc-list 'c])"))) (is (= 5 (er "(with-env [plist :c])"))) (is (eq nil (er "(with-env [plist :e])"))) (is (eq 3 (er "(with-env [clos-object 'a])"))) (is (eq 3 (er "(with-env [struct 'a])")))))
Generate a defmacro form that transforms code like this:
(assert-values ("changed foo = 1") (foo 1) (foo+1 2) (bar 'nothing) (bar-1 'nothing))

Pattern to recognize: Macro call that should be transformed by assert-values

Macro definition:
(defmacro assert-values ((desc) &body objects-and-values)
  `(progn
     (trc ,desc)
     ,@(loop for (obj val) in objects-and-values
	    collect `(assert (eql (value ,obj) ,val)))))

Macroexpansion:
(progn (trc "changed foo = 1") (assert (eql (value foo) 1)) (assert (eql (value foo+1) 2)) (assert (eql (value bar) (quote nothing))) (assert (eql (value bar-1) (quote nothing))))
Define a macro that eliminates this repetitive pattern:
(define-simple-definition-resolver source-transform (designator) (cond ((and (listp designator) (eql 'cl:setf (car designator))) (sb-int:info :function :source-transform (second designator))) ((symbolp designator) (sb-int:info :function :source-transform designator))))

Issue: Macro call that should be transformed by define-simple-definition-resolver

Macro definition:
(defmacro define-simple-definition-resolver (class lookup-function &body body)
  (let ((package (gensym "PACKAGE")))
    `(define-definition-resolver ,class (,class ,package)
       (when (ignore-errors ,(if body
                                 `(let ((,(first lookup-function) ,class))
                                    ,@body)
                                 `(,lookup-function ,class)))
         (list (make-instance ',class :designator ,class :package ,package))))))

Macroexpansion:
(define-definition-resolver source-transform (source-transform #:package149) (when (ignore-errors (let ((designator source-transform)) (cond ((and (listp designator) (eql (quote setf) (car designator))) (sb-int:info :function :source-transform (second designator))) ((symbolp designator) (sb-int:info :function :source-transform designator))))) (list (make-instance (quote source-transform) :designator source-transform :package #:package149))))
Write a Common Lisp macro to handle this code pattern:
(with-rules 'some-name)

Problem: Macro call that should be transformed by WITH-RULES

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

Macroexpansion:
(dolist ('some-name (alexandria:hash-table-keys cl-rules.core::*rules*)))
Create a Common Lisp macro for the following transformation. Before code:
(deftag ul* (body attrs &key &allow-other-keys) "<ul> with every form (except <li>) in BODY auto-wrapped into a <li>." `(:ul ,@attrs ,@(loop for form in body when (and (listp form) (eq :li (first form))) collect form else collect `(:li ,form))))

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

Macro definition:
(defmacro deftag (name (body attrs-var &rest ll) &body tag)
  "Define NAME as a tag.
If NAME is not a keyword, it will also be defined as a macro with an
implicit `with-html'."
  (let ((definer
          (if (keywordp name)
              'deftag/keyword
              'deftag/macro)))
    `(,definer ,name (,body ,attrs-var ,@ll) ,@tag)))

Macroexpansion:
(deftag/macro ul* (body attrs &key &allow-other-keys) "<ul> with every form (except <li>) in BODY auto-wrapped into a <li>." (sb-int:quasiquote (:ul #S(sb-impl::comma :expr attrs :kind 2) #S(sb-impl::comma :expr (loop for form in body when (and (listp form) (eq :li (first form))) collect form else collect (sb-int:quasiquote (:li #S(sb-impl::comma :expr form :kind 0)))) :kind 2))))
Write a Common Lisp macro to handle this code pattern:
(lambda-coro
  nil)

Problem: Macro call that should be transformed by LAMBDA-CORO

Macro definition:
(defmacro LAMBDA-CORO ...)

Macroexpansion:
(progn
 (defcoroutine #:name125
     (#:arg126)
   (macrolet ((yield (form)
                (let ((g!-it (gensym "IT")))
                  `(progn
                    (let ((,g!-it ,form))
                      (cl-coroutine:yield ,g!-it))
                    ,'#:arg126)))
              (last-yield-value ()
                '#:arg126))
     nil
     (coexit!)))
 (make-coroutine '#:name125))
Define a macro that eliminates this repetitive pattern:
(next-ffi)

Issue: Macro call that should be transformed by next-ffi

Macro definition:
(defmacro next-ffi ()
  (with-gensyms (next)
    `(let ((,next (cadr fields)))
       (foreign-to-ffi
        (and ,next (foreign-type ,next))
        (cdr names)
        (cdr params)
        (cdr fields)
        body))))

Macroexpansion:
(let ((#:next192 (cadr fields))) (foreign-to-ffi (and #:next192 (foreign-type #:next192)) (cdr names) (cdr params) (cdr fields) body))
Write a Common Lisp macro to handle this code pattern:
(signal-reader-error "Incomplete regex comment starting with '(#'")

Problem: Macro call that should be transformed by signal-reader-error

Macro definition:
(defmacro signal-reader-error (format-control &rest format-arguments)
  "Like ERROR but signals a SIMPLE-READER-ERROR for the stream
*STREAM*."
  `(error 'simple-reader-error
          :stream *stream*
          :format-control ,format-control
          :format-arguments (list ,@format-arguments)))

Macroexpansion:
(error (quote simple-reader-error) :stream *stream* :format-control "Incomplete regex comment starting with '(#'" :format-arguments (list))
You are a Common Lisp macro expert. Given this code pattern:
(some-<>
  'some-name)

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

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

Macroexpansion:
'some-name
Create a Common Lisp macro for the following transformation. Before code:
(gen-lambda-with-sticky-stop () (let ((res (funcall source-func))) (if (funcall predicate res) res (sticky-stop))))

What needs to change: Macro call that should be transformed by gen-lambda

Macro definition:
(defmacro gen-lambda (params &body rest)
  "Version of lambda that wraps the anonymous function in an instance of the basic-generator class. This allows the lambda to be identified as a generator by its type. Basic-generator objects are derived from funcallable-standard-class, therefore they can be called as functions."
  `(let ((values-handler (create-values-handler)))
     (declare (ignorable values-handler))
     (make-instance 
      'basic-generator 
      :function (lambda ,params ,@rest))))

Macroexpansion:
(make-instance (quote basic-generator) :function (sticky-stop-lambda nil (let ((res (funcall source-func))) (if (funcall predicate res) res (sticky-stop)))))
Generate a defmacro form that transforms code like this:
(lambda* nil
  :key
  nil)

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

Macro definition:
(defmacro LAMBDA* ...)

Macroexpansion:
(lambda ()
  (with-yield
    :key
    nil))
Write a Common Lisp macro to handle this code pattern:
(lret* ((offset (- length (length vec))) (element-type (array-element-type vec)) (out (make-array length :element-type element-type))) (replace out vec :start1 offset) (loop for i from 0 below offset by pad-len do (replace out pad :start1 i :end1 offset)))

Problem: Macro call that should be transformed by lret

Macro definition:
(defmacro lret ((&rest bindings) &body body)
  "Return the initial value of the last binding in BINDINGS. The idea
is to create something, initialize it, and then return it.

    (lret ((x 1)
           (y (make-array 1)))
      (setf (aref y 0) x))
    => #(1)

Note that the value returned is the value initially bound. Subsequent
assignments are ignored.

    (lret ((x 1))
      (setf x 2))
    => 1

Furthermore, on Lisps that support it, the variable may be made
read-only, making assignment a compiler-time error.

`lret' may seem trivial, but it fufills the highest purpose a macro
can: it eliminates a whole class of bugs (initializing an object, but
forgetting to return it).

Cf. `aprog1' in Anaphora."
  `(lret-aux let ,bindings
     ,@body))

Macroexpansion:
(lret-aux let* ((offset (- length (length vec))) (element-type (array-element-type vec)) (out (make-array length :element-type element-type))) (replace out vec :start1 offset) (loop for i from 0 below offset by pad-len do (replace out pad :start1 i :end1 offset)))
Define a macro that eliminates this repetitive pattern:
(with-dot nil
  :key
  nil)

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

Macro definition:
(defmacro with-dot (() &body body)
  `(progn ,@(replace-dot-calls body)))

Macroexpansion:
(progn :key nil)
Define a macro that eliminates this repetitive pattern:
(defgeneric nil :key nil)

Issue: Macro call that should be transformed by DEFGENERIC

Macro definition:
(defmacro DEFGENERIC ...)

Macroexpansion:
(common-lisp:defgeneric nil
    :key
  nil)
Write a Common Lisp macro to handle this code pattern:
(deferror "22003" numeric-value-out-of-range 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 numeric-value-out-of-range (data-exception) nil) (setf (gethash "22003" *error-table*) (quote numeric-value-out-of-range)))
Write a Common Lisp macro to handle this code pattern:
(none-of nil
  (progn))

Problem: Macro call that should be transformed by NONE-OF

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

Macroexpansion:
(lc (nil (progn)) never)
Write a Common Lisp macro to handle this code pattern:
(deferror "40003" statement-completion-unknown transaction-rollback)

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 statement-completion-unknown (transaction-rollback) nil) (setf (gethash "40003" *error-table*) (quote statement-completion-unknown)))