j14i/cl-macros huggingface dataset:
Write a Common Lisp macro to handle this code pattern:
(binary-reader ((usec-bits uint 8) (days int 4) (months int 4)) (funcall f months days (interpret-usec-bits usec-bits)))

Problem: Macro call that should be transformed by binary-reader

Macro definition:
(defmacro binary-reader (fields &body value)
  "A slightly convoluted macro for defining interpreter functions. It
allows two forms. The first is to pass a single type identifier, in
which case a value of this type will be read and returned directly.
The second is to pass a list of lists containing names and types, and
then a body. In this case the names will be bound to values read from
the socket and interpreted as the given types, and then the body will
be run in the resulting environment. If the last field is of type
bytes, string, or uint2s, all remaining data will be read and
interpreted as an array of the given type."
  (let ((stream-name (gensym))
        (size-name (gensym))
        (length-used 0))
    (flet ((read-type (type &optional modifier)
             (ecase type
               (bytes `(read-bytes ,stream-name (- ,size-name ,length-used)))
               (string `(enc-read-string ,stream-name
                                         :byte-length (- ,size-name ,length-used)))
               (uint2s `(let* ((size (/ (- ,size-name ,length-used) 2))
                               (result
                                 (make-array size
                                             :element-type '(unsigned-byte 16)
                                             :initial-element 0)))
                          (dotimes (i size)
                            (setf (elt result i) (read-uint2 ,stream-name)))
                          result))
               (int (assert (integerp modifier))
                (incf length-used modifier)
                `(,(integer-reader-name modifier t) ,stream-name))
               (uint (assert (integerp modifier))
                (incf length-used modifier)
                `(,(integer-reader-name modifier nil) ,stream-name)))))
      `(lambda (,stream-name ,size-name)
         (declare (type stream ,stream-name)
                  (type integer ,size-name)
                  (ignorable ,size-name))
         ,(if (consp fields)
              (progn
                `(let ,(loop :for field :in fields
                            :collect `(,(first field)
                                       ,(apply #'read-type (cdr field))))
                  ,@value))
              (read-type fields (car value)))))))

Macroexpansion:
(lambda (#:g208 #:g209) (declare (type stream #:g208) (type integer #:g209) (ignorable #:g209)) (let ((usec-bits (read-uint8 #:g208)) (days (read-int4 #:g208)) (months (read-int4 #:g208))) (funcall f months days (interpret-usec-bits usec-bits))))
You are a Common Lisp macro expert. Given this code pattern:
(with-dynenv 'some-name)

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

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

Macroexpansion:
(multiple-value-bind (#:var-expansion138 #:var-expanded-p139)
    (macroexpand-1 'var-space 'some-name)
  (multiple-value-bind (#:fun-expansion140 #:fun-expanded-p141)
      (macroexpand-1 'fun-space 'some-name)
    (let ((*var-space* (when #:var-expanded-p139 #:var-expansion138))
          (*fun-space* (when #:fun-expanded-p141 #:fun-expansion140))
          (*within-captured-dynenv* t)))))
You are a Common Lisp macro expert. Given this code pattern:
(do+ (for k (in '(a b c d e))) (for x (across #(1 2 3 4) :index index)) (returning (list x k :index index)))

Write a macro that addresses: 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 k (in (quote (a b c d e)))) (for x (across #(1 2 3 4) :index index)) (returning (list x k :index index)))
Create a Common Lisp macro for the following transformation. Before code:
(bind (((:flet doit (x)) (declare (type fixnum x)) (setf x (* 2 x)) (setf x (+ x 3)) x)) (ensure-same (doit 1) 5) (ensure-same (doit 2) 7))

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

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

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

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

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

Macroexpansion:
(flet ((doit (x) (declare (type fixnum x)) (progn (setf x (* 2 x)) (setf x (+ x 3)) x))) (progn (ensure-same (doit 1) 5) (ensure-same (doit 2) 7)))
Define a macro that eliminates this repetitive pattern:
(action (:after node-lisp node bound-variables) (loop :for (_ . name) :in (node-lisp-vars node) :when (and (member name variables :test #'eq) (not (member name bound-variables :test #'eq))) :do (setf escaped? t)) (values))

Issue: Macro call that should be transformed by action

Macro definition:
(defmacro action ((when type &rest args) &body body)
  "Construct an action block, turning `body` into a lambda function
accepting `args` if `args` are provided. If there are no `args`, then
`body` is assumed to be a function object and is used directly with
`when` and `type` to create an `action` instance. Otherwise, the first
argument in `args` is declared to be a node of type `type`, and the
`args` and `body` are used to generate a lambda function."
  (check-type when keyword)
  (check-type type symbol)
  (assert (subtypep type 'node))
  (assert (or (not (endp args)) (= 1 (length body))))
  (if (endp args)
      `(make-action ',when ',type ,@body)
      `(make-action ',when ',type
                    (lambda (,@args)
                      (declare (type ,type ,(first args)))
                      ,@body))))

Macroexpansion:
(make-action (quote :after) (quote node-lisp) (lambda (node bound-variables) (declare (type node-lisp node)) (loop :for (_ . name) :in (node-lisp-vars node) :when (and (member name variables :test (function eq)) (not (member name bound-variables :test (function eq)))) :do (setf escaped? t)) (values)))
Define a macro that eliminates this repetitive pattern:
(define EOF -1)

Issue: Macro call that should be transformed by define

Macro definition:
(defmacro define (name value &rest docstring)
  "Like a #define but also visible to Lisp code."
  `(progn
     (eval-when (:compile-toplevel :load-toplevel :execute)
       (defvar ,(pp-defines *package*) (make-hash-table))
       (setf (gethash ',name ,(pp-defines *package*)) ,(prin1-to-string value)))
     (defparameter ,name ,value ,@docstring)))

Macroexpansion:
(progn (eval-when (:compile-toplevel :load-toplevel :execute) (defvar *preprocessor-defines* (make-hash-table)) (setf (gethash (quote eof) *preprocessor-defines*) #A((2) base-char . "-1"))) (defparameter eof -1))
Write a Common Lisp macro to handle this code pattern:
(do+ (returning 1) (terminate))

Problem: 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 (returning 1) (terminate))
Generate a defmacro form that transforms code like this:
(with-took-usec took-usec (exec-query (connection-handle conn) sql))

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

Macro definition:
(defmacro with-took-usec (var &body body)
  (let ((before (gensym "BEFORE")))
    `(let ((,before (get-internal-real-time)))
       (multiple-value-prog1 (progn ,@body)
         (setf ,var (ceiling
                      (* (- (get-internal-real-time) ,before)
                         #.(/ 1000000 internal-time-units-per-second))))))))

Macroexpansion:
(multiple-value-bind (#:before-unixtime167 #:before-usec168) (sb-ext:get-time-of-day) (multiple-value-prog1 (progn (exec-query (connection-handle conn) sql)) (multiple-value-bind (#:after-unixtime169 #:after-usec170) (sb-ext:get-time-of-day) (setf took-usec (+ (* (- #:after-unixtime169 #:before-unixtime167) 1000000) (- #:after-usec170 #:before-usec168))))))
Define a macro that eliminates this repetitive pattern:
(dynamic-wind
  nil)

Issue: Macro call that should be transformed by DYNAMIC-WIND

Macro definition:
(defmacro DYNAMIC-WIND ...)

Macroexpansion:
(flet ((#:dynamic-wind-thunk216 (#:proceed-thunk217)
         (macrolet ((proceed (&body #:proceed-body218)
                      `(if ,'#:proceed-thunk217
                           (funcall (the function ,'#:proceed-thunk217))
                           (progn ,@#:proceed-body218))))
           nil)))
  (declare (inline #:dynamic-wind-thunk216))
  (let ((*dynamic-wind-stack*
         (cons #'#:dynamic-wind-thunk216 *dynamic-wind-stack*)))
    (#:dynamic-wind-thunk216 nil)))
Generate a defmacro form that transforms code like this:
(whichever 1 2 3)

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

Macro definition:
(defmacro whichever (&rest possibilities &environment env)
  "Evaluates exactly one of POSSIBILITIES, chosen at random."
  (setf possibilities (mapcar (lambda (p) (macroexpand p env)) possibilities))
  (let ((length (length possibilities)))
    (cond
      ((= 1 length)
       (first possibilities))
      ((every #'constantp possibilities)
       `(svref (load-time-value (vector ,@possibilities)) 
               (random ,length)))
      (T
       (labels ((expand (possibilities position random-number)
                  (if (null (cdr possibilities))
                      (car possibilities)
                      (let* ((length (length possibilities))
                             (half (truncate length 2))
                             (second-half (nthcdr half possibilities))
                             (first-half (butlast possibilities (- length half))))
                        `(if (< ,random-number ,(+ position half))
                             ,(expand first-half position random-number)
                             ,(expand second-half (+ position half) random-number))))))
         (with-gensyms (random-number)
           `(let ((,random-number (random ,length)))
              ,(expand possibilities 0 random-number))))))))

Macroexpansion:
(svref (load-time-value (vector 1 2 3)) (random 3))
Create a Common Lisp macro for the following transformation. Before code:
(declare-deprecated-operators)

What needs to change: Macro call that should be transformed by DECLARE-DEPRECATED-OPERATORS

Macro definition:
(defmacro DECLARE-DEPRECATED-OPERATORS ...)

Macroexpansion:
(eval-when (:compile-toplevel :load-toplevel :execute) (values))
Define a macro that eliminates this repetitive pattern:
(enable-quasi-quoted-string-to-string-emitting-form-syntax 'some-name)

Issue: Macro call that should be transformed by ENABLE-QUASI-QUOTED-STRING-TO-STRING-EMITTING-FORM-SYNTAX

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

Macroexpansion:
(eval-when (:compile-toplevel :execute)
  (setf *readtable* (copy-readtable *readtable*))
  (set-quasi-quoted-string-to-string-emitting-form-syntax-in-readtable
   'some-name :with-inline-emitting nil :declarations 'nil :start-character nil
   :end-character nil :unquote-character #\COMMA :splice-character
   #\COMMERCIAL_AT :destructive-splice-character #\FULL_STOP
   :dispatched-quasi-quote-name "str")
  (values))
Define a macro that eliminates this repetitive pattern:
(with-yield-binds (format nil "WHEN ~A THEN ~A" (with-table-name nil (yield (when-op-left op))) (with-table-name nil (yield (when-op-right op)))))

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 "WHEN ~A THEN ~A" (with-table-name nil (yield (when-op-left op))) (with-table-name nil (yield (when-op-right op))))) (loop for bind in (reverse *bind-values*) append bind)))
Generate a defmacro form that transforms code like this:
(define-method-combination% or :operator or :identity-with-one-argument t)

Pattern to recognize: Macro call that should be transformed by define-method-combination%

Macro definition:
(defmacro define-method-combination% (name &rest args)
  "Define a method-combination for the static-dispatch system only.

   Arguments are of the same form as to CL:DEFINE-METHOD-COMBINATION."

  `(eval-when (:compile-toplevel :load-toplevel :execute)
     (setf
      (combination-function ',name)
      ,(match args
         ((or nil
              (list* (and (type symbol) (not nil)) _))

          (destructuring-bind (&key (operator name) (identity-with-one-argument nil))
              args

            `(method-combination-function-short ,name ,operator ,identity-with-one-argument)))

         (_
          `(method-combination-function ,name ,@args))))))

Macroexpansion:
(eval-when (:compile-toplevel :load-toplevel :execute) (setf (combination-function (quote or)) (method-combination-function-short or or t)))
Define a macro that eliminates this repetitive pattern:
(c-assert (eq :quiesced (c-state c)) () "Cell ~a of dead model ~a not quiesced. Was not-to-be shadowed by a primary method? Use :before instead." c self)

Issue: Macro call that should be transformed by c-assert

Macro definition:
(defmacro c-assert (assertion &optional places fmt$ &rest fmt-args)
  (declare (ignorable assertion places fmt$ fmt-args))
   #+(or)`(progn) 
  `(unless *stop*
     (unless ,assertion
       ,(if fmt$
            `(c-break ,fmt$ ,@fmt-args)
          `(c-break "failed assertion: ~a" ',assertion)))))

Macroexpansion:
(unless *stop* (unless (eq :quiesced (c-state c)) (c-break "Cell ~a of dead model ~a not quiesced. Was not-to-be shadowed by a primary method? Use :before instead." c self)))
Generate a defmacro form that transforms code like this:
(defmacro/ps nil
    (progn))

Pattern to recognize: Macro call that should be transformed by DEFMACRO/PS

Macro definition:
(defmacro DEFMACRO/PS ...)

Macroexpansion:
(progn (defmacro nil (progn)) (import-macros-from-lisp 'nil))
Generate a defmacro form that transforms code like this:
(def-neo4j-fun delete-index ((type :node) name) :delete (:uri-spec (format nil "index/~A/~A" (string-downcase (symbol-name type)) name)) (:status-handlers (204 (values t body)) (404 (error 'index-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 delete-index (&key (type :node) name) (let ((uri (format nil "index/~A/~A" (string-downcase (symbol-name type)) name)) (json (encode-neo4j-json-payload nil :string))) (make-neo4j-request :delete uri json (list (list 204 (lambda (body uri json) (values t body))) (list 404 (lambda (body uri json) (error (quote index-not-found-error) :uri uri))))))))
Create a Common Lisp macro for the following transformation. Before code:
(do-immutable-map (name type env) (declare (ignore name)) (setf out (append (type-variables type) out)))

What needs to change: Macro call that should be transformed by do-immutable-map

Macro definition:
(defmacro do-immutable-map ((key value map &optional result) &body body)
  "Iterate over MAP in ascending key order, binding KEY and VALUE."
  `(avl:do-avl (,key ,value (immutable-map-data ,map) ,result)
     ,@body))

Macroexpansion:
(avl:do-avl (name type (immutable-map-data env) nil) (declare (ignore name)) (setf out (append (type-variables type) out)))
Write a Common Lisp macro to handle this code pattern:
(some-<>> (diamond-wand init (cddr exp) t t))

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

Macro definition:
(defmacro some-<>> (init &body exps) (diamond-wand init exps t t))

Macroexpansion:
(block #:g128 (diamond-wand init (cddr exp) t t))
Write a Common Lisp macro to handle this code pattern:
(is-type 1 'string)

Problem: Macro call that should be transformed by is-type

Macro definition:
(defmacro is-type (got expected-type &optional desc)
  (with-gensyms (duration result)
    (once-only (desc expected-type)
      `(with-catching-errors (:description ,desc :expected ,expected-type)
         (with-duration ((,duration ,result) ,got)
           (test ,result ,expected-type ,desc
                 :duration ,duration
                 :got-form ',got
                 :test-fn #'typep
                 :report-expected-label "be a type of"))))))

Macroexpansion:
(let ((#:desc207 nil) (#:expected-type208 (quote string))) (with-catching-errors (:description #:desc207 :expected #:expected-type208) (with-duration ((#:duration205 #:result206) 1) (test #:result206 #:expected-type208 #:desc207 :duration #:duration205 :got-form (quote 1) :test-fn (function typep) :report-expected-label "be a type of"))))
Create a Common Lisp macro for the following transformation. Before code:
(as-> nil (progn))

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

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

Macroexpansion:
(let* (((progn) nil))
  (progn))
Generate a defmacro form that transforms code like this:
(with-active-layers nil
  nil)

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

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

Macroexpansion:
(progn nil)
Create a Common Lisp macro for the following transformation. Before code:
(odig 'some-name)

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

Macro definition:
(defmacro ODIG ...)

Macroexpansion:
(odig 1 'some-name)
You are a Common Lisp macro expert. Given this code pattern:
(deferror "42723" duplicate-function syntax-error-or-access-violation)

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

Macro definition:
(defmacro deferror (code typename &optional (superclass 'database-error))
  `(progn (define-condition ,typename (,superclass) ())
          (setf (gethash ,code *error-table*) ',typename)))

Macroexpansion:
(progn (define-condition duplicate-function (syntax-error-or-access-violation) nil) (setf (gethash "42723" *error-table*) (quote duplicate-function)))
You are a Common Lisp macro expert. Given this code pattern:
(flow-lambda-macro (flow-context) `(dispatch-concurrently ,flow-context ,flow-list))

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

Macro definition:
(defmacro flow-lambda-macro ((flow-context) &body body)
  `(with-gensyms (,flow-context)
     `(%flow-lambda (,,flow-context)
        ,,@body)))

Macroexpansion:
(with-gensyms (flow-context) (sb-int:quasiquote (%flow-lambda (#S(sb-impl::comma :expr flow-context :kind 0)) #S(sb-impl::comma :expr (sb-int:quasiquote (dispatch-concurrently #S(sb-impl::comma :expr flow-context :kind 0) #S(sb-impl::comma :expr flow-list :kind 0))) :kind 0))))
Generate a defmacro form that transforms code like this:
(or nil :key nil)

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

Macro definition:
(defmacro OR ...)

Macroexpansion:
(let ((#:g203 nil))
  (if #:g203
      #:g203
      (let ((#:g204 :key))
        (if #:g204
            #:g204
            nil))))
You are a Common Lisp macro expert. Given this code pattern:
(min-of nil
  (progn))

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

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

Macroexpansion:
(lc (nil (progn)) minimize)
Write a Common Lisp macro to handle this code pattern:
(defclass/std prefix () ((without-prefix :with)))

Problem: Macro call that should be transformed by defclass/std

Macro definition:
(defmacro defclass/std (name direct-superclasses direct-slots &rest options
                        &environment env)
  "Shortcut macro to the DEFCLASS macro.

  (defclass/std example ()
    ((slot1 slot2 slot3)))

  expands to:

  (DEFCLASS EXAMPLE ()
    ((SLOT1 :ACCESSOR SLOT1 :INITARG :SLOT1 :INITFORM NIL)
    (SLOT2 :ACCESSOR SLOT2 :INITARG :SLOT2 :INITFORM NIL)
    (SLOT3 :ACCESSOR SLOT3 :INITARG :SLOT3 :INITFORM NIL)))

  Each slot definition accepts options:

    :std 1 => changes the :initform to 1. It can be :unbound.
    :with or :with-prefix => creates accessors with the class name as prefix.

  See the README for more.

  See also `class/std' and `print-object/std'.
  "
  `(defclass ,name ,direct-superclasses
     ,(process-slots env direct-slots name)
     ,@options))

Macroexpansion:
(defclass prefix nil ((without-prefix :accessor prefix-without-prefix :initarg :without-prefix :initform nil)))
Generate a defmacro form that transforms code like this:
(define-error body-block-empty () (form-name) "In varjo it is not valid to have a ~s with an empty body." form-name)

Pattern to recognize: 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 body-block-empty (:error-type varjo-error :prefix "Varjo") (form-name) "In varjo it is not valid to have a ~s with an empty body." form-name)
Generate a defmacro form that transforms code like this:
(ematch0 parsed1 ((list slot pattern) `((,(find-reader slot type) ,it) ,pattern)))

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

Macro definition:
(defmacro ematch0 (what &body clauses)
  `(match0 ,what
     ,@clauses
     (_ (error "level0 match error!"))))

Macroexpansion:
(match0 parsed1 ((list slot pattern) (sb-int:quasiquote ((#S(sb-impl::comma :expr (find-reader slot type) :kind 0) #S(sb-impl::comma :expr it :kind 0)) #S(sb-impl::comma :expr pattern :kind 0)))) (_ (error "level0 match error!")))