j14i/cl-macros huggingface dataset:
You are a Common Lisp macro expert. Given this code pattern:
(defclause hash-entries-of (hash-table) "Iterates over the entries of a hash table. The iteration variables must be specified as (key value), for example: (for (lemma definitions) (hash-entries-of the-english-vocabulary))." (unless (and (listp *iteration-variable*) (= 2 (length *iteration-variable*))) (error "Invalid variable specification for hash-entry, expected (key value) but got ~S" *iteration-variable*)) (let ((iterator (gensym "HASH-TABLE-ITERATOR")) (test (gensym "TEST")) (key (car *iteration-variable*)) (value (cadr *iteration-variable*))) `(,(make-wrapper :function (lambda (body) `(with-hash-table-iterator (,iterator ,hash-table) ,body))) ,(make-iteration :bindings (list test key value) :initializations `((setf (values ,test ,key ,value) (,iterator))) :steps `((setf (values ,test ,key ,value) (,iterator))) :postconditions `((not (null ,test)))))))

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 hash-entries-of (hash-table) "Iterates over the entries of a hash table. The iteration variables must be specified as (key value), for example: (for (lemma definitions) (hash-entries-of the-english-vocabulary))." (unless (and (listp *iteration-variable*) (= 2 (length *iteration-variable*))) (error "Invalid variable specification for hash-entry, expected (key value) but got ~S" *iteration-variable*)) (let ((iterator (gensym "HASH-TABLE-ITERATOR")) (test (gensym "TEST")) (key (car *iteration-variable*)) (value (cadr *iteration-variable*))) (sb-int:quasiquote (#S(sb-impl::comma :expr (make-wrapper :function (lambda (body) (sb-int:quasiquote (with-hash-table-iterator (#S(sb-impl::comma :expr iterator :kind 0) #S(sb-impl::comma :expr hash-table :kind 0)) #S(sb-impl::comma :expr body :kind 0))))) :kind 0) #S(sb-impl::comma :expr (make-iteration :bindings (list test key value) :initializations (sb-int:quasiquote ((setf (values #S(sb-impl::comma :expr test :kind 0) #S(sb-impl::comma :expr key :kind 0) #S(sb-impl::comma :expr value :kind 0)) (#S(sb-impl::comma :expr iterator :kind 0))))) :steps (sb-int:quasiquote ((setf (values #S(sb-impl::comma :expr test :kind 0) #S(sb-impl::comma :expr key :kind 0) #S(sb-impl::comma :expr value :kind 0)) (#S(sb-impl::comma :expr iterator :kind 0))))) :postconditions (sb-int:quasiquote ((not (null #S(sb-impl::comma :expr test :kind 0)))))) :kind 0))))) (pushnew (quote hash-entries-of) *clauses*))
Create a Common Lisp macro for the following transformation. Before code:
(with-ps-gensyms nil
  (progn))

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

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

Macroexpansion:
(let* ()
  (progn))
Write a Common Lisp macro to handle this code pattern:
(define-test fixture :fix (*read-default-float-format*) (is = 0.0f0 (read-from-string "0.0")) (setf *read-default-float-format* 'double-float) (is = 0.0d0 (read-from-string "0.0")))

Problem: Macro call that should be transformed by define-test

Macro definition:
(defmacro define-test (name &body arguments-and-body)
  (destructuring-bind (nparent name) (if (listp name) name (list NIL name))
    (form-fiddle:with-body-options (body options parent home (test-class 'test) (compile-at :compile-time) defun) arguments-and-body
      (let ((body (remove 'define-test body :key (lambda (a) (when (listp a) (car a))) :test #'eql))
            (defs (remove 'define-test body :key (lambda (a) (when (listp a) (car a))) :test-not #'eql))
            (home-form (or home `(find-package ,(package-name *package*)))))
        (when (and parent nparent)
          (error "Cannot specify parent through name and through a keyword argument at the same time!"))
        `(let ((*package* (find-package ,(package-name *package*)))) ; Make sure package stays consistent throughout initialisation.
           (setf (find-test ',name ,home-form)
                 (ensure-test ',test-class
                              :name ',name
                              :home ,home-form
                              :tests (list ,@(loop for form in body
                                                   collect (ecase compile-at
                                                             (:compile-time `(lambda () ,form))
                                                             (:execute `(lambda () (call-compile ',form))))))
                              :parent ',(or parent nparent)
                              ,@(loop for option in options
                                      collect `',option)))
           ,@(loop for (def subname . body) in defs
                   collect `(,def (,name ,subname)
                              :home ,home
                              ,@body))
           ,@(when defun
               `((defun ,(if (stringp name) (read-symbol name) name) (&rest test-args)
                   (apply #'test (find-test ',name ,home-form) test-args))))
           ',name)))))

Macroexpansion:
(let ((*package* (find-package #A((9) base-char . "PARACHUTE")))) (setf (find-test (quote fixture) (find-package #A((9) base-char . "PARACHUTE"))) (ensure-test (quote test) :name (quote fixture) :home (find-package #A((9) base-char . "PARACHUTE")) :tests (list (lambda nil (is = 0.0 (read-from-string "0.0"))) (lambda nil (setf *read-default-float-format* (quote double-float))) (lambda nil (is = 0.0d0 (read-from-string "0.0")))) :parent (quote nil) (quote :fix) (quote (*read-default-float-format*)))) (quote fixture))
Generate a defmacro form that transforms code like this:
(f0
  nil)

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

Macro definition:
(defmacro F0 ...)

Macroexpansion:
(lambda () nil)
Create a Common Lisp macro for the following transformation. Before code:
(augment init-code init)

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

Macro definition:
(defmacro augment (var stuff)
  `(setf ,var (nconc ,var ,stuff)))

Macroexpansion:
(setf init-code (nconc init-code init))
Write a Common Lisp macro to handle this code pattern:
(finish (error "NOPE"))

Problem: Macro call that should be transformed by finish

Macro definition:
(defmacro finish (form &optional description &rest format-args)
  `(eval-in-context
    *context*
    (make-instance 'finishing-result
                   :expression '(finish ,form)
                   :body (lambda () ,form)
                   ,@(when description
                       `(:description (format NIL ,description ,@format-args))))))

Macroexpansion:
(eval-in-context *context* (make-instance (quote finishing-result) :expression (quote (finish (error "NOPE"))) :body (lambda nil (error "NOPE"))))
Create a Common Lisp macro for the following transformation. Before code:
(enable-quasi-quoted-list-syntax)

What needs to change: Macro call that should be transformed by ENABLE-QUASI-QUOTED-LIST-SYNTAX

Macro definition:
(defmacro ENABLE-QUASI-QUOTED-LIST-SYNTAX ...)

Macroexpansion:
(eval-when (:compile-toplevel :execute)
  (setf *readtable* (copy-readtable *readtable*))
  (set-quasi-quoted-list-syntax-in-readtable :start-character #\GRAVE_ACCENT
                                             :end-character nil
                                             :unquote-character #\COMMA
                                             :splice-character #\COMMERCIAL_AT
                                             :destructive-splice-character
                                             #\FULL_STOP
                                             :transformation-pipeline nil
                                             :dispatched-quasi-quote-name nil)
  (values))
Write a Common Lisp macro to handle this code pattern:
(alet 43 (slet it it))

Problem: Macro call that should be transformed by alet

Macro definition:
(defmacro alet (form &body body)
  "Binds the FORM to IT (via LET) in the scope of the BODY."
  `(anaphoric ignore-first ,form (progn ,@body)))

Macroexpansion:
(anaphoric ignore-first 43 (progn (slet it it)))
Generate a defmacro form that transforms code like this:
(*> +opt-fws+ #'ccontent)

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

Macro definition:
(defmacro *> (parser &rest parsers)
  "Combination of parsers yielding the result of the rightmost one."
  (let ((offset (gensym "*>-OFFSET")))
    `(lambda (,offset)
       ,(reduce (lambda (i p)
                  (let ((res  (gensym "*>-RES"))
                        (next (gensym "*>-NEXT")))
                    `(multiple-value-bind (,res ,next) ,i
                       (if (ok? ,res)
                           (funcall ,p ,next)
                           (fail ,next)))))
                parsers
                :initial-value `(funcall ,parser ,offset)))))

Macroexpansion:
(lambda (#:*>-offset143) (multiple-value-bind (#:*>-res144 #:*>-next145) (funcall +opt-fws+ #:*>-offset143) (if (ok? #:*>-res144) (funcall (function ccontent) #:*>-next145) (fail #:*>-next145))))
Write a Common Lisp macro to handle this code pattern:
(enable-version-syntax)

Problem: Macro call that should be transformed by enable-version-syntax

Macro definition:
(defmacro enable-version-syntax ()
  "Enable version reader syntax."
  `(eval-when (:compile-toplevel :load-toplevel :execute)
     (%enable-version-syntax)))

Macroexpansion:
(eval-when (:compile-toplevel :load-toplevel :execute) (%enable-version-syntax))
Create a Common Lisp macro for the following transformation. Before code:
(when body `(make-block ,body))

What needs to change: 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 body (sb-int:quasiquote (make-block #S(sb-impl::comma :expr body :kind 0))))
Generate a defmacro form that transforms code like this:
(skip "Not ready yet" (false T) (is = 5 6))

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

Macro definition:
(defmacro skip (desc &body tests)
  `(with-forced-status (:skipped ,@(if (listp desc) desc (list desc)))
     ,@tests))

Macroexpansion:
(with-forced-status (:skipped "Not ready yet") (false t) (is = 5 6))
Define a macro that eliminates this repetitive pattern:
;; Manual gensym creation is boilerplate-heavy
(defmacro with-temp (var &body body)
  (let ((g (gensym)))
    `(let ((,g ,var))
       ,@body)))
;; Every macro needs this pattern - repetitive and error-prone

Issue: Repeated gensym boilerplate in macro definitions — want automatic gensym creation from naming convention

Macro definition:
(defun g!-symbol-p (s)
  (and (symbolp s)
       (> (length (symbol-name s)) 2)
       (string= (symbol-name s)
                "G!"
                :start1 0
                :end1 2)))

(defmacro defmacro/g! (name args &rest body)
  (let ((syms (remove-duplicates
               (remove-if-not #'g!-symbol-p
                              (flatten body)))))
    (multiple-value-bind (body declarations docstring)
        (parse-body body :documentation t)
      `(defmacro ,name ,args
         ,@(when docstring
             (list docstring))
         ,@declarations
         (let ,(mapcar
                (lambda (s)
                  `(,s (gensym ,(subseq
                                 (symbol-name s)
                                 2))))
                syms)
           ,@body)))))

Macroexpansion:
;; Usage:
;; (defmacro/g! with-temp (g!var &body body)
;;   `(let ((,g!var ,g!var))
;;      ,@body))
;;
;; g!var is automatically gensym'd to #:VAR1234 at expansion time
;; No capture risk - gensym is uninterned
Create a Common Lisp macro for the following transformation. Before code:
(defcategory :warning (or :warning :error))

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

Macro definition:
(defmacro defcategory (category &optional expands-as set)
  `(defcategory-fn ',category ',expands-as ,set))

Macroexpansion:
(defcategory-fn (quote :warning) (quote (or :warning :error)) nil)
Create a Common Lisp macro for the following transformation. Before code:
(matrix-ctypecase nil)

What needs to change: Macro call that should be transformed by MATRIX-CTYPECASE

Macro definition:
(defmacro MATRIX-CTYPECASE ...)

Macroexpansion:
nil
You are a Common Lisp macro expert. Given this code pattern:
(do-generator-value-list (vars (apply #'multi-gen generators)) (apply #'yield (mapcar #'car vars)))

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

Macro definition:
(defmacro do-generator ((var &rest vars-and-generator) &body body)
  "Steps through the specified generator, binding the value it returns to var, then executing the body for each step. If multiple variables are specified and the generator returns multiple values, the extra values will be bound to the extra variables."
  (let ((g (gensym)))
    `(let ((,g ,(car (last vars-and-generator))))
       (loop 
	  do (if-generator ((,var ,@(butlast vars-and-generator)) ,g)
			   (progn
			     ,@body)
			   (return))))))

Macroexpansion:
(let ((#:g157 (apply (function multi-gen) generators))) (loop do (if-generator (vars #:g157) (progn (apply (function yield) (mapcar (function car) vars))) (return))))
Define a macro that eliminates this repetitive pattern:
(with-yield-binds (format nil "~A~:[~; IF NOT EXISTS~] ~A (~%~{ ~A~^,~%~}~%)" (sql-statement-name statement) (create-table-statement-if-not-exists statement) (yield (create-table-statement-table statement)) (mapcar #'yield (sql-composed-statement-children statement))))

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~:[~; IF NOT EXISTS~] ~A (~%~{ ~A~^,~%~}~%)" (sql-statement-name statement) (create-table-statement-if-not-exists statement) (yield (create-table-statement-table statement)) (mapcar (function yield) (sql-composed-statement-children statement)))) (loop for bind in (reverse *bind-values*) append bind)))
Write a Common Lisp macro to handle this code pattern:
(lambda* 'some-name)

Problem: Macro call that should be transformed by LAMBDA*

Macro definition:
(defmacro LAMBDA* ...)

Macroexpansion:
(lambda (quote some-name) (with-yield))
Create a Common Lisp macro for the following transformation. Before code:
(-> :tag-1 () ", concurrent")

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

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

Macroexpansion:
(atomically :tag-1 nil ", concurrent")
Write a Common Lisp macro to handle this code pattern:
(single-line-mode-p flags)

Problem: Macro call that should be transformed by single-line-mode-p

Macro definition:
(defmacro single-line-mode-p (flags)
  "Accessor macro to extract the third flag out of a three-element flag list."
  `(third ,flags))

Macroexpansion:
(third flags)
You are a Common Lisp macro expert. Given this code pattern:
(resolving
  nil
  nil)

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

Macro definition:
(defmacro RESOLVING ...)

Macroexpansion:
(resolve
  nil
  nil)
Write a Common Lisp macro to handle this code pattern:
(deferror "23503" foreign-key-violation integrity-violation)

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 foreign-key-violation (integrity-violation) nil) (setf (gethash "23503" *error-table*) (quote foreign-key-violation)))
Define a macro that eliminates this repetitive pattern:
(do-iterator 'some-name)

Issue: Macro call that should be transformed by DO-ITERATOR

Macro definition:
(defmacro DO-ITERATOR ...)

Macroexpansion:
(iterate-for-effects some-name (lambda (quote)))
Create a Common Lisp macro for the following transformation. Before code:
(with-mocks () (answer foo 3 (call-previous)) (is (eql 3 (foo))) (is (eq 'foo (foo))))

What needs to change: 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 3 (call-previous)) (is (eql 3 (foo))) (is (eq (quote foo) (foo)))) :recordp t)
Generate a defmacro form that transforms code like this:
(lret* ((y 1) (y 2)) (declare (ignorable y)) 3)

Pattern to recognize: 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* ((y 1) (y 2)) (declare (ignorable y)) 3)
Define a macro that eliminates this repetitive pattern:
(alist-bind (type size) form `((:array ,@(parse-type type (aval :tag type)) ,size)))

Issue: 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 ((#:alist236 form)) (let ((type (aval :type #:alist236)) (size (aval :size #:alist236))) (sb-int:quasiquote ((:array #S(sb-impl::comma :expr (parse-type type (aval :tag type)) :kind 2) #S(sb-impl::comma :expr size :kind 0))))))
Write a Common Lisp macro to handle this code pattern:
(defgenerator icount (n &optional (step 1)) "Make a generator that returns evenly spaced values starting with n. Step can be fractional. Eg: (counter 10) -> 10 11 12 13 14 ... (counter 2.5 0.5) -> 2.5 3.0 3.5 ..." (unless (numberp n) (error "n must be a number")) (unless (numberp step) (error "step must be a number")) (loop for i from n by step do (yield i)))

Problem: 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 icount (n &optional (step 1)) "Make a generator that returns evenly spaced values starting with n. Step can be fractional. Eg: (counter 10) -> 10 11 12 13 14 ... (counter 2.5 0.5) -> 2.5 3.0 3.5 ..." (with-yield (unless (numberp n) (error "n must be a number")) (unless (numberp step) (error "step must be a number")) (loop for i from n by step do (yield i))))
Write a Common Lisp macro to handle this code pattern:
(who-ps-html nil nil)

Problem: Macro call that should be transformed by WHO-PS-HTML

Macro definition:
(defmacro WHO-PS-HTML ...)

Macroexpansion:
(stringify nil nil)
Generate a defmacro form that transforms code like this:
(do-generator (g generator) (let ((currkey (funcall key g))) (if (funcall comp last currkey) (push g res) (progn (when res (yield last (nreverse res))) (setf last currkey) (setf res (cons g nil))))))

Pattern to recognize: Macro call that should be transformed by do-generator

Macro definition:
(defmacro do-generator ((var &rest vars-and-generator) &body body)
  "Steps through the specified generator, binding the value it returns to var, then executing the body for each step. If multiple variables are specified and the generator returns multiple values, the extra values will be bound to the extra variables."
  (let ((g (gensym)))
    `(let ((,g ,(car (last vars-and-generator))))
       (loop 
	  do (if-generator ((,var ,@(butlast vars-and-generator)) ,g)
			   (progn
			     ,@body)
			   (return))))))

Macroexpansion:
(let ((#:g162 generator)) (loop do (if-generator ((g) #:g162) (progn (let ((currkey (funcall key g))) (if (funcall comp last currkey) (push g res) (progn (when res (yield last (nreverse res))) (setf last currkey) (setf res (cons g nil)))))) (return))))
Generate a defmacro form that transforms code like this:
(draw scene (:path :d (path (move-to 100 400) (line-to-r 50 -25) (arc-to-r 25 25 -30 0 1 50 -25) (line-to-r 50 -25) (arc-to-r 25 50 -30 0 1 50 -25) (line-to-r 50 -25) (arc-to-r 25 75 -30 0 1 50 -25) (line-to-r 50 -25) (arc-to-r 25 100 -30 0 1 50 -25) (line-to-r 50 -25) (vertical-to-r 50))) :fill "none" :stroke "blue" :stroke-width 5)

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

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

Macroexpansion:
(let ((#:g161 (funcall (function make-svg-element) :path (append (list :d (path (move-to 100 400) (line-to-r 50 -25) (arc-to-r 25 25 -30 0 1 50 -25) (line-to-r 50 -25) (arc-to-r 25 50 -30 0 1 50 -25) (line-to-r 50 -25) (arc-to-r 25 75 -30 0 1 50 -25) (line-to-r 50 -25) (arc-to-r 25 100 -30 0 1 50 -25) (line-to-r 50 -25) (vertical-to-r 50))) (list :fill "none" :stroke "blue" :stroke-width 5))))) (add-element scene #:g161) #:g161)
Define a macro that eliminates this repetitive pattern:
(fgatherlet nil
  nil)

Issue: Macro call that should be transformed by FGATHERLET

Macro definition:
(defmacro FGATHERLET ...)

Macroexpansion:
(flet ()
  nil)
You are a Common Lisp macro expert. Given this code pattern:
(secase (car x) (:y (setf it :no)) (:x (setf it :yes)))

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

Macro definition:
(defmacro secase (keyform &body cases)
  "Like ECASE, except binds the keyform to IT (via SYMBOL-MACROLET) for the
scope of the cases. IT can be set with SETF."
  `(symbolic ecase ,keyform ,@cases))

Macroexpansion:
(symbolic ecase (car x) (:y (setf it :no)) (:x (setf it :yes)))
Generate a defmacro form that transforms code like this:
(c? (klin self))

Pattern to recognize: Macro call that should be transformed by c?

Macro definition:
(defmacro c? (&body body)
  `(make-c-dependent
    :code ',body
    :value-state :unevaluated
    :rule (c-lambda ,@body)))

Macroexpansion:
(make-c-dependent :code (quote ((klin self))) :value-state :unevaluated :rule (c-lambda (klin self)))