j14i/cl-macros huggingface dataset:
Write a Common Lisp macro to handle this code pattern:
(defclause generating (var iteration) "Lazy version of FOR. The user must call UPDATE or TRY-UPDATE in the body of the DO+ form in order to compute new values for the variable(s). Initialization, instead, is *always* performed eagerly." (make-generator :name (if (symbolp var) var (extract-variables var)) :clauses `(for ,var ,iteration)))

Problem: Macro call that should be transformed by defclause

Macro definition:
(defmacro defclause (name arglist &body body)
  "Same as cl:defmacro, but additionally records <name> in *clauses* as a known clause macro."
  `(progn
     (defmacro ,name ,arglist ,@body)
     (pushnew ',name *clauses*)))

Macroexpansion:
(progn (defmacro generating (var iteration) "Lazy version of FOR. The user must call UPDATE or TRY-UPDATE in the body of the DO+ form in order to compute new values for the variable(s). Initialization, instead, is *always* performed eagerly." (make-generator :name (if (symbolp var) var (extract-variables var)) :clauses (sb-int:quasiquote (for #S(sb-impl::comma :expr var :kind 0) #S(sb-impl::comma :expr iteration :kind 0))))) (pushnew (quote generating) *clauses*))
Define a macro that eliminates this repetitive pattern:
(with-mocks () (answer foo 1 2 3) (is (eql 1 (foo))) (is (eql 2 (foo))) (is (eql 3 (foo))) (is (eql 3 (foo))))

Issue: 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 (answer foo 1 2 3) (is (eql 1 (foo))) (is (eql 2 (foo))) (is (eql 3 (foo))) (is (eql 3 (foo)))) :recordp t)
Write a Common Lisp macro to handle this code pattern:
(dig nil)

Problem: Macro call that should be transformed by DIG

Macro definition:
(defmacro DIG ...)

Macroexpansion:
(dig 1 nil)
Generate a defmacro form that transforms code like this:
(some->> nil (progn))

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

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

Macroexpansion:
(let* ((#:|some122| nil) (#:|some122| (when #:|some122| (progn #:|some122|))))
  #:|some122|)
Generate a defmacro form that transforms code like this:
(alist-bind (tag name id) form (let (symbol-type) (cond ((string= tag ":struct") (setf tag :struct) (setf symbol-type :cstruct)) ((string= tag ":union") (setf tag :union) (setf symbol-type :cunion)) ((string= tag ":enum") (setf tag :enum) (setf symbol-type :cenum)) (t (error "Unknown tag for MAKE-RECORD-REF: ~S" tag))) `((,tag (,(if (and (string= name "") (> id 0)) nil (foreign-type-symbol name symbol-type *package*)) ,@(when (and (string= name "") (> id 0)) `(:id ,id)))))))

Pattern to recognize: Macro call that should be transformed by alist-bind

Macro definition:
(defmacro alist-bind ((&rest vars) alist &body body)
  "Inefficient but doesn't really matter here"
  (once-only (alist)
    `(let (,@(mapcar (lambda (x)
                       (if (consp x)
                           `(,(car x) (aval ,(cadr x) ,alist))
                           `(,x (aval ,(make-keyword x) ,alist))))
                     vars))
       ,@body)))

Macroexpansion:
(let ((#:alist233 form)) (let ((tag (aval :tag #:alist233)) (name (aval :name #:alist233)) (id (aval :id #:alist233))) (let (symbol-type) (cond ((string= tag ":struct") (setf tag :struct) (setf symbol-type :cstruct)) ((string= tag ":union") (setf tag :union) (setf symbol-type :cunion)) ((string= tag ":enum") (setf tag :enum) (setf symbol-type :cenum)) (t (error "Unknown tag for MAKE-RECORD-REF: ~S" tag))) (sb-int:quasiquote ((#S(sb-impl::comma :expr tag :kind 0) (#S(sb-impl::comma :expr (if (and (string= name "") (> id 0)) nil (foreign-type-symbol name symbol-type *package*)) :kind 0) #S(sb-impl::comma :expr (when (and (string= name "") (> id 0)) (sb-int:quasiquote (:id #S(sb-impl::comma :expr id :kind 0)))) :kind 2))))))))
You are a Common Lisp macro expert. Given this code pattern:
(enable-quasi-quoted-bivalent-to-binary-emitting-form-syntax nil)

Write a macro that addresses: Macro call that should be transformed by ENABLE-QUASI-QUOTED-BIVALENT-TO-BINARY-EMITTING-FORM-SYNTAX

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

Macroexpansion:
(eval-when (:compile-toplevel :execute)
  (setf *readtable* (copy-readtable *readtable*))
  (set-quasi-quoted-bivalent-to-binary-emitting-form-syntax-in-readtable nil
                                                                         :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
                                                                         "biv"
                                                                         :encoding
                                                                         *default-character-encoding*)
  (values))
You are a Common Lisp macro expert. Given this code pattern:
(min-of nil
  :key
  nil)

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

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

Macroexpansion:
(lc (nil :key nil) minimize)
Create a Common Lisp macro for the following transformation. Before code:
(define-custom-var (:real *real-handler*))

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 (*real-handler* . :real)) *custom-vars* :test (function equal)) (defvar *real-handler*)))
Create a Common Lisp macro for the following transformation. Before code:
(deferror "55P03" lock-not-available object-state-error)

What needs to change: 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 lock-not-available (object-state-error) nil) (setf (gethash "55P03" *error-table*) (quote lock-not-available)))
You are a Common Lisp macro expert. Given this code pattern:
(with-temp (d :directory t :debug (<= 1 *debug-prolog*)) (with-temp (input-file :tmpdir d :template "XXXXXX.prolog" :debug (<= 1 *debug-prolog*)) (with-open-file (s input-file :direction :output :if-does-not-exist :error) (dolist (r rules) (print-rule s r))) (run-command-with-debug-print `("swipl" "--quiet" "-l" ,input-file ,@args) :input input :output output :error error)))

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

Macro definition:
(defmacro with-temp ((var &key directory template (tmpdir "/tmp/") debug) &body body)
  "Create a temporary file, then remove the file by unwind-protect.
Most arguments are analogous to mktemp.
When DIRECTORY is non-nil, creates a directory instead.
DEBUG is a form.
When evaluated to non-nil, it does not remove the directory so that you can investigate what happened inside the directory.
It may be evaluated multiple times."
  (with-gensyms (command)
    `(let ((,var (uiop:run-program
                  (let ((,command (format nil "mktemp --tmpdir='~a' ~@[-d~*~] ~@[~a~]"
                                          ,tmpdir ,directory ,template)))
                    (when ,debug
                      (format *error-output* "~&; ~a~%" ,command))
                    ,command)
                  :output '(:string :stripped t))))
       (unwind-protect
            (progn ,@body)
         (if ,debug
             (format *error-output* "~&; not removing ~a for debugging~%" ,var)
             (uiop:run-program (format nil "rm -rf ~a" (namestring ,var)) :ignore-error-status t))))))

Macroexpansion:
(let ((d (uiop/run-program:run-program (let ((#:command175 (format nil "mktemp --tmpdir='~a' ~@[-d~*~] ~@[~a~]" "/tmp/" t nil))) (when (<= 1 *debug-prolog*) (format *error-output* "~&; ~a~%" #:command175)) #:command175) :output (quote (:string :stripped t))))) (unwind-protect (progn (with-temp (input-file :tmpdir d :template "XXXXXX.prolog" :debug (<= 1 *debug-prolog*)) (with-open-file (s input-file :direction :output :if-does-not-exist :error) (dolist (r rules) (print-rule s r))) (run-command-with-debug-print (sb-int:quasiquote ("swipl" "--quiet" "-l" #S(sb-impl::comma :expr input-file :kind 0) #S(sb-impl::comma :expr args :kind 2))) :input input :output output :error error))) (if (<= 1 *debug-prolog*) (format *error-output* "~&; not removing ~a for debugging~%" d) (uiop/run-program:run-program (format nil "rm -rf ~a" (namestring d)) :ignore-error-status t))))
Define a macro that eliminates this repetitive pattern:
(defpattern list (&rest args) (when args `(cons ,(car args) (list ,@(cdr args)))))

Issue: Macro call that should be transformed by defpattern

Macro definition:
(defmacro defpattern (name lambda-list &body body)
  "Defines a derived pattern specifier named NAME. This is analogous
to DEFTYPE.

Examples:

    ;; Defines a LIST pattern.
    (defpattern list (&rest args)
      (when args
        `(cons ,(car args) (list ,@(cdr args)))))"
  `(eval-when (:compile-toplevel :load-toplevel :execute)
     (setf (pattern-expand-function ',name) (lambda ,lambda-list ,@body))))

Macroexpansion:
(%defpattern list (quote &rest) (quote args) (lambda (when args (quasiquote (cons #S(sb-impl::comma :expr (car args) :kind 0) (list #S(sb-impl::comma :expr (cdr args) :kind 2)))))))
Generate a defmacro form that transforms code like this:
(when specifier `(specifier (make-nodelist ,specifier)))

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

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

Macroexpansion:
(if specifier (sb-int:quasiquote (specifier (make-nodelist #S(sb-impl::comma :expr specifier :kind 0)))))
Define a macro that eliminates this repetitive pattern:
(signal-syntax-error* (lexer-pos lexer) "Character missing after '\\c'")

Issue: Macro call that should be transformed by signal-syntax-error*

Macro definition:
(defmacro signal-syntax-error* (pos format-control &rest format-arguments)
  `(error 'ppcre-syntax-error
          :pos ,pos
          :format-control ,format-control
          :format-arguments (list ,@format-arguments)))

Macroexpansion:
(error (quote ppcre-syntax-error) :pos (lexer-pos lexer) :format-control "Character missing after '\\c'" :format-arguments (list))
Define a macro that eliminates this repetitive pattern:
(check-cursor-attached cluffer:line (cursor))

Issue: Macro call that should be transformed by check-cursor-attached

Macro definition:
(defmacro check-cursor-attached (name arguments)
  (let ((args (substitute '(cursor cluffer:cursor) 'cursor arguments)))
    `(defmethod ,name :before ,args
       (declare (ignore ,@(set-difference (remove 'cursor arguments)
                                          lambda-list-keywords)))
       (unless (cluffer:cursor-attached-p cursor)
         (error 'cluffer:cursor-detached)))))

Macroexpansion:
(defmethod cluffer:line :before ((cursor cluffer:cursor)) (declare (ignore)) (unless (cluffer:cursor-attached-p cursor) (error (quote cluffer:cursor-detached))))
You are a Common Lisp macro expert. Given this code pattern:
(alist-bind (name type bit-size bit-offset bit-alignment) field (let ((symbol (foreign-type-symbol name field-type *package*))) (list* symbol `(,@(parse-type type (aval :tag type)) ,@(when (eq field-type :cfield) `(:bit-size ,bit-size :bit-offset ,bit-offset :bit-alignment ,bit-alignment))))))

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

Macro definition:
(defmacro alist-bind ((&rest vars) alist &body body)
  "Inefficient but doesn't really matter here"
  (once-only (alist)
    `(let (,@(mapcar (lambda (x)
                       (if (consp x)
                           `(,(car x) (aval ,(cadr x) ,alist))
                           `(,x (aval ,(make-keyword x) ,alist))))
                     vars))
       ,@body)))

Macroexpansion:
(let ((#:alist240 field)) (let ((name (aval :name #:alist240)) (type (aval :type #:alist240)) (bit-size (aval :bit-size #:alist240)) (bit-offset (aval :bit-offset #:alist240)) (bit-alignment (aval :bit-alignment #:alist240))) (let ((symbol (foreign-type-symbol name field-type *package*))) (list* symbol (sb-int:quasiquote (#S(sb-impl::comma :expr (parse-type type (aval :tag type)) :kind 2) #S(sb-impl::comma :expr (when (eq field-type :cfield) (sb-int:quasiquote (:bit-size #S(sb-impl::comma :expr bit-size :kind 0) :bit-offset #S(sb-impl::comma :expr bit-offset :kind 0) :bit-alignment #S(sb-impl::comma :expr bit-alignment :kind 0)))) :kind 2)))))))
Write a Common Lisp macro to handle this code pattern:
(do+ (for x (in '(1 2 3 4))) (for z (previous y)) (for y (previous x)) (collect (list x y z)))

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 (for x (in (quote (1 2 3 4)))) (for z (previous y)) (for y (previous x)) (collect (list x y z)))
Write a Common Lisp macro to handle this code pattern:
(is-values (values 1 2 nil 3) '(1 2 nil 3))

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

Macro definition:
(defmacro is-values (got expected &rest args)
  `(is (multiple-value-list ,got) ,expected ,@args))

Macroexpansion:
(is (multiple-value-list (values 1 2 nil 3)) (quote (1 2 nil 3)))
Create a Common Lisp macro for the following transformation. Before code:
(lret ((out (make-array (array-dimensions array) :element-type element-type))) (map-into (%flatten out) fn (%flatten array)))

What needs to change: 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 ((out (make-array (array-dimensions array) :element-type element-type))) (map-into (%flatten out) fn (%flatten array)))
Create a Common Lisp macro for the following transformation. Before code:
(list-of 'some-name)

What needs to change: Macro call that should be transformed by LIST-OF

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

Macroexpansion:
(lc ('some-name) collect)
Write a Common Lisp macro to handle this code pattern:
(collect-sum nil (progn))

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

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

Macroexpansion:
(compiler-let ((*optimize-series-expressions* nil)) (collect-sum nil (progn)))
Generate a defmacro form that transforms code like this:
(append-at-end nil :key nil)

Pattern to recognize: Macro call that should be transformed by APPEND-AT-END

Macro definition:
(defmacro APPEND-AT-END ...)

Macroexpansion:
(dolist (#:a122 nil)
  (typecase #:a122
    (list (collect-at-end nil :key #:a122))
    (t
     (let ((c (cons #:a122 nil)))
       (when (null nil) (setf nil c))
       (unless (null :key) (setf (cdr :key) c))
       (setf :key (last c))))))
Define a macro that eliminates this repetitive pattern:
(defgenerator ifilter (predicate generator) "Emits only those items in generator that are true by predicate. The generator equivalent of remove-if-not" (do-generator (g generator) (when (funcall predicate g) (yield g))))

Issue: 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 ifilter (predicate generator) "Emits only those items in generator that are true by predicate. The generator equivalent of remove-if-not" (with-yield (do-generator (g generator) (when (funcall predicate g) (yield g)))))
Write a Common Lisp macro to handle this code pattern:
(define-custom-var (:array-type *json-array-type*) 'vector)

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 (*json-array-type* . :array-type)) *custom-vars* :test (function equal)) (defvar *json-array-type* (quote vector))))
You are a Common Lisp macro expert. Given this code pattern:
(dreletf nil
  :key
  nil)

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

Macro definition:
(defmacro DRELETF ...)

Macroexpansion:
(let ((#:symbol-store234
       (with-symbol-access
         (list))))
  (special-symbol-reprogv #:symbol-store234
      (list)
    (locally (declare (special)) :key nil)))
Define a macro that eliminates this repetitive pattern:
(newq nil (progn))

Issue: Macro call that should be transformed by NEWQ

Macro definition:
(defmacro NEWQ ...)

Macroexpansion:
(new 'nil (progn))
Write a Common Lisp macro to handle this code pattern:
(defclass/a dbi-driver () () (:documentation "Base class for DB driver."))

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

Macro definition:
(defmacro defclass/a (name superclasses slots &rest class-options)
  `(progn
     (defclass ,name ,superclasses ,slots ,@class-options)
     (deftype ,(intern (format nil "<~A>" (symbol-name name))) () ',name)
     (setf (find-class ',(intern (format nil "<~A>" (symbol-name name))))
           (find-class ',name))))

Macroexpansion:
(progn (defclass dbi-driver nil nil (:documentation "Base class for DB driver.")) (deftype <dbi-driver> nil (quote dbi-driver)) (setf (find-class (quote <dbi-driver>)) (find-class (quote dbi-driver))))
Create a Common Lisp macro for the following transformation. Before code:
(lambda-match
  'some-name)

What needs to change: Macro call that should be transformed by LAMBDA-MATCH

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

Macroexpansion:
(lambda (#:arg150)
  (match #:arg150
    'some-name))
Create a Common Lisp macro for the following transformation. Before code:
(with-access-values nil
    nil)

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

Macro definition:
(defmacro with-access-values ((&rest bindings) obj &body body)
  "A macro which binds local variables from accessed values on object
   according to bindings

   bindings: (local-symbol-and-access-key
              or (local-symbol access-key)
               ...)
   obj: the thing we are accessing data from
  "
  (flet ((key-for (it)
           (etypecase it
             (symbol `(quote ,it))
             ((or string keyword list) it))))
    (let* ((o (gensym "OBJ"))
           (expanded-bindings
             (iter (for b in (ensure-list bindings))
               (when (first-iteration-p)
                 (collect `(,o ,obj)))
               (typecase b
                 (null)
                 (list (collect `(,(first b) (access ,o ,(key-for (second b))))))
                 (symbol (collect `(,b (access ,o ,(key-for b)))))))))
      `(let* ,expanded-bindings
        ,@body))))

Macroexpansion:
(let* ())
You are a Common Lisp macro expert. Given this code pattern:
(collect-alist nil nil)

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

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

Macroexpansion:
(common-lisp:let* ((#:generator-430 (generator nil))
                   #:values-423
                   (#:generator-428 (generator nil))
                   #:keys-422
                   (#:alist-424 nil))
  (declare (type generator #:generator-430)
           (type generator #:generator-428)
           (type list #:alist-424))
  (tagbody
   #:ll-431
    (setq #:values-423 (next-in #:generator-430 (go end)))
    (setq #:keys-422 (next-in #:generator-428 (go end)))
    (setq #:alist-424 (cons (cons #:keys-422 #:values-423) #:alist-424))
    (go #:ll-431)
   end)
  #:alist-424)
You are a Common Lisp macro expert. Given this code pattern:
(declare-deprecated-operators nil nil)

Write a macro that addresses: Macro call that should be transformed by DECLARE-DEPRECATED-OPERATORS

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

Macroexpansion:
(eval-when (:compile-toplevel :load-toplevel :execute)
  (define-compiler-macro nil
      (&whole form &rest arguments)
    (declare (ignore arguments))
    (let ((where-from (or *compile-file-truename* *load-truename*)))
      (when *deprecation-warnings*
        (warn 'deprecation-warning :operator-name 'nil :source-file where-from
              :source-form form))
      (when where-from
        (pushnew where-from (gethash 'nil *deprecation-locations*) :test
                 #'equalp))
      form))
  (define-compiler-macro nil
      (&whole form &rest arguments)
    (declare (ignore arguments))
    (let ((where-from (or *compile-file-truename* *load-truename*)))
      (when *deprecation-warnings*
        (warn 'deprecation-warning :operator-name 'nil :source-file where-from
              :source-form form))
      (when where-from
        (pushnew where-from (gethash 'nil *deprecation-locations*) :test
                 #'equalp))
      form))
  (values))
Write a Common Lisp macro to handle this code pattern:
(log-message z z)

Problem: Macro call that should be transformed by log-message

Macro definition:
(defmacro log-message (category description &rest arguments)
  `(log-manager-message (log-manager) ,category ,description ,@arguments))

Macroexpansion:
(log-manager-message (log-manager) z z)