j14i/cl-macros huggingface dataset:
Generate a defmacro form that transforms code like this:
(with-html-string (:p :dataset (:duck (dolomphious) :fish 'fizzgigious :spoon "runcible")))

Pattern to recognize: 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 (:p :dataset (:duck (dolomphious) :fish (quote fizzgigious) :spoon "runcible"))))
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)
  "Cf. `lret'."
  `(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)))
Generate a defmacro form that transforms code like this:
(augment post-code `((setq ,extra-save-var ,var)))

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

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

Macroexpansion:
(setf post-code (nconc post-code (sb-int:quasiquote ((setq #S(sb-impl::comma :expr extra-save-var :kind 0) #S(sb-impl::comma :expr var :kind 0))))))
Create a Common Lisp macro for the following transformation. Before code:
(*> +period+ +any-digit+ +digits+)

What needs to change: 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 (#:*>-offset184) (multiple-value-bind (#:*>-res187 #:*>-next188) (multiple-value-bind (#:*>-res185 #:*>-next186) (funcall +period+ #:*>-offset184) (if (ok? #:*>-res185) (funcall +any-digit+ #:*>-next186) (fail #:*>-next186))) (if (ok? #:*>-res187) (funcall +digits+ #:*>-next188) (fail #:*>-next188))))
Define a macro that eliminates this repetitive pattern:
(with-env [assoc-list 'c])

Issue: Macro call that should be transformed by with-env

Macro definition:
(defmacro with-env (&body body)
  (let ((body-value (gensym)))
    `(let (,body-value)
       (defclass foo () ((a :initform 3)))
       (defmethod get-val ((object foo) &rest slot/s) (slot-value object (car slot/s)))
       (defmethod (setf get-val) (new-value (object foo) &rest slot/s)
         (setf (slot-value object (car slot/s)) new-value))
       (defstruct bar a)
       (setq ,body-value
             (let ((str (alexandria:copy-array "abcde"))
                   (vec (alexandria:copy-array #(a b c d e)))
                   (arr (alexandria:copy-array #2A((1 2 3)
                                                   (4 5 6))))
                   (list      (copy-list '(a b c d e)))
                   (ht        (eval (read-from-string "{'a 'b 'c 'd}")))
                   (ht-eq     (eval (read-from-string "{eq \"a\" 1
                                                    \"b\" 2}")))
                   (ht-equalp (eval (read-from-string "{equalp '(1 2 3) \"a\"
                                                               '(4 5 6) \"b\"}")))
                   (assoc-list (copy-tree '((a . 1) (b . 2))))
                   (plist      (copy-list '(:a 4 :c 5)))
                   (clos-object (make-instance 'foo))
                   (struct      (make-bar :a 3)))
               (declare (ignorable str vec arr list ht ht-eq ht-equalp
                                   assoc-list plist clos-object struct))
               ,@body))
       (setf (find-class 'foo nil) nil)
       (setf (find-class 'bar nil) nil)
       ,body-value))

Macroexpansion:
(let (#:g128) (defclass foo nil ((a :initform 3))) (defmethod get-val ((object foo) &rest slot/s) (slot-value object (car slot/s))) (defmethod (setf get-val) (new-value (object foo) &rest slot/s) (setf (slot-value object (car slot/s)) new-value)) (defstruct bar a) (setq #:g128 (let ((str (alexandria:copy-array "abcde")) (vec (alexandria:copy-array #(a b c d e))) (arr (alexandria:copy-array #2A((1 2 3) (4 5 6)))) (list (copy-list (quote (a b c d e)))) (ht (eval (read-from-string "{'a 'b 'c 'd}"))) (ht-eq (eval (read-from-string "{eq \"a\" 1
                                                    \"b\" 2}"))) (ht-equalp (eval (read-from-string "{equalp '(1 2 3) \"a\"
                                                               '(4 5 6) \"b\"}"))) (assoc-list (copy-tree (quote ((a . 1) (b . 2))))) (plist (copy-list (quote (:a 4 :c 5)))) (clos-object (make-instance (quote foo))) (struct (make-bar :a 3))) (declare (ignorable str vec arr list ht ht-eq ht-equalp assoc-list plist clos-object struct)) [assoc-list (quote c]))) (setf (find-class (quote foo) nil) nil) (setf (find-class (quote bar) nil) nil) #:g128)
Write a Common Lisp macro to handle this code pattern:
(define-test partially-correct (true "Happy") (is = (get-universal-time) 2962566000))

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 partially-correct) (find-package #A((9) base-char . "PARACHUTE"))) (ensure-test (quote test) :name (quote partially-correct) :home (find-package #A((9) base-char . "PARACHUTE")) :tests (list (lambda nil (true "Happy")) (lambda nil (is = (get-universal-time) 2962566000))) :parent (quote nil))) (quote partially-correct))
Create a Common Lisp macro for the following transformation. Before code:
(%destructure-defhook-args args (destructure-specialized-lambda-list descriptive-lambda-list vanilla-lambda-list type-list specialized-lambda-list (with-effective-qualifier generic-function qualifier (intern-hook generic-function hook-name type-list qualifier) `(progn (%defhook-fun ,hook-name ,vanilla-lambda-list ,@body) (%define-method-dispatch ,generic-function ,qualifier ,specialized-lambda-list)))))

What needs to change: Macro call that should be transformed by %destructure-defhook-args

Macro definition:
(defmacro %destructure-defhook-args (args &body body)
  (let ((args-sym (gensym)))
    `(let* ((,args-sym ,args)
            (qualifier
            (cond ((and (symbolp (car ,args-sym)) (not (null (car ,args-sym))))
                   (prog1 (car ,args-sym) (setf ,args-sym (cdr ,args-sym))))
                  (t :use-default))))
       (destructuring-bind (specialized-lambda-list &body body) ,args-sym
         ,@body))))

Macroexpansion:
(let* ((#:g122 args) (qualifier (cond ((and (symbolp (car #:g122)) (not (null (car #:g122)))) (prog1 (car #:g122) (setf #:g122 (cdr #:g122)))) (t :use-default)))) (destructuring-bind (specialized-lambda-list &body body) #:g122 (destructure-specialized-lambda-list descriptive-lambda-list vanilla-lambda-list type-list specialized-lambda-list (with-effective-qualifier generic-function qualifier (intern-hook generic-function hook-name type-list qualifier) (sb-int:quasiquote (progn (%defhook-fun #S(sb-impl::comma :expr hook-name :kind 0) #S(sb-impl::comma :expr vanilla-lambda-list :kind 0) #S(sb-impl::comma :expr body :kind 2)) (%define-method-dispatch #S(sb-impl::comma :expr generic-function :kind 0) #S(sb-impl::comma :expr qualifier :kind 0) #S(sb-impl::comma :expr specialized-lambda-list :kind 0))))))))
Write a Common Lisp macro to handle this code pattern:
(define-template nil :key nil)

Problem: Macro call that should be transformed by DEFINE-TEMPLATE

Macro definition:
(defmacro DEFINE-TEMPLATE ...)

Macroexpansion:
(defmacro define-nil (:key &optional (#:name128))
  (flet ((template-unfulfillable ()
           (error 'template-unfulfillable :template 'nil :arguments
                  (list :key))))
    (declare (ignorable (function template-unfulfillable)))
    (let ((body (progn)) (name (or #:name128 (compose-name #\SOLIDUS 'nil))))
      `(progn
        (declaim
         (ftype
          (function
           ,(loop with types = (declared-variable-types body)
                  for arg in (quote nil)
                  collect (or (second (assoc arg types)) (quote t)))
           ,(declared-return-type body))
          ,name)
         ,@(when (find (quote inline) (declarations body)) `((inline ,name))))
        (defun ,name ,'nil
          (declare (optimize speed (safety 0) (debug 0) (compilation-speed 0))
                   ,@(remove (quote inline) (declarations body)))
          ,@(remove-if #'declaration-p body))))))
Write a Common Lisp macro to handle this code pattern:
(define-fixture-restore function (symbol value) (setf (fdefinition symbol) value))

Problem: Macro call that should be transformed by define-fixture-restore

Macro definition:
(defmacro define-fixture-restore (name args &body body)
  `(progn (setf (gethash ',name *fixture-restores*)
                (lambda ,args ,@body))
          ',name))

Macroexpansion:
(progn (setf (gethash (quote function) *fixture-restores*) (lambda (symbol value) (setf (fdefinition symbol) value))) (quote function))
Write a Common Lisp macro to handle this code pattern:
(define-hook (:boot foreign-libraries (- most-positive-fixnum 10)) () (status 0 "Reloading foreign libraries.") (flet ((maybe-load (lib) (let ((lib (ensure-library lib)) #+sbcl(sb-ext:*muffled-warnings* 'style-warning)) (unless (or (library-open-p lib) (library-dont-open-p lib)) (status 1 "Loading foreign library ~a." lib) (open-library lib))))) (dolist (lib *foreign-libraries-to-reload*) (maybe-load lib))))

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

Macro definition:
(defmacro define-hook ((type name &optional (priority 0)) args &body body)
  (ecase type (:pre-load) (:load) (:build) (:deploy) (:boot) (:quit))
  (check-type name symbol)
  `(let ((,name (or (hook ,type ',name)
                    (make-instance 'hook :name ',name :type ,type))))
     (setf (hook-priority ,name) ,priority)
     (setf (hook-function ,name) (flet ((,name (&key ,@args &allow-other-keys)
                                          ,@body))
                                   #',name))
     (setf (hook ,type ',name) ,name)
     (setf (docstring ,name) ,(if (stringp (car body)) (car body)))
     ',name))

Macroexpansion:
(let ((foreign-libraries (or (hook :boot (quote foreign-libraries)) (make-instance (quote hook) :name (quote foreign-libraries) :type :boot)))) (setf (hook-priority foreign-libraries) (- most-positive-fixnum 10)) (setf (hook-function foreign-libraries) (flet ((foreign-libraries (&key &allow-other-keys) (status 0 "Reloading foreign libraries.") (flet ((maybe-load (lib) (let ((lib (ensure-library lib)) (sb-ext:*muffled-warnings* (quote style-warning))) (unless (or (library-open-p lib) (library-dont-open-p lib)) (status 1 "Loading foreign library ~a." lib) (open-library lib))))) (dolist (lib *foreign-libraries-to-reload*) (maybe-load lib))))) (function foreign-libraries))) (setf (hook :boot (quote foreign-libraries)) foreign-libraries) (setf (docstring foreign-libraries) nil) (quote foreign-libraries))
Create a Common Lisp macro for the following transformation. Before code:
(lambda* nil
  (progn))

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

Macro definition:
(defmacro LAMBDA* ...)

Macroexpansion:
(lambda () (the t (progn)))
Write a Common Lisp macro to handle this code pattern:
(collect-min 'some-name)

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

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

Macroexpansion:
(common-lisp:let* ((#:generator-320 (generator 'some-name))
                   #:numbers-314
                   (#:number-316 nil))
  (declare (type generator #:generator-320))
  (tagbody
   #:ll-321
    (setq #:numbers-314 (next-in #:generator-320 (go end)))
    (if (or (null #:number-316) (> #:number-316 #:numbers-314))
        (setq #:number-316 #:numbers-314))
    (go #:ll-321)
   end)
  (if (null #:number-316)
      (setq #:number-316 nil))
  #:number-316)
Create a Common Lisp macro for the following transformation. Before code:
(is = 5 6)

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

Macro definition:
(defmacro is (comp expected form &optional description &rest format-args)
  `(eval-in-context
    *context*
    (make-instance 'comparison-result
                   :expression '(is ,comp ,expected ,form)
                   :value-form ',form
                   :body (lambda () ,form)
                   :expected ,expected
                   :comparison ,(maybe-quote comp)
                   ,@(when description
                       `(:description (format NIL ,description ,@format-args))))))

Macroexpansion:
(eval-in-context *context* (make-instance (quote comparison-result) :expression (quote (is = 5 6)) :value-form (quote 6) :body (lambda nil 6) :expected 5 :comparison (quote =)))
Create a Common Lisp macro for the following transformation. Before code:
(defclause-driver (for var in-stream stream &optional using (reader '#'read)) "Forms in a stream (which will be closed at the end)" (top-level-check) (return-stream-driver-code var stream reader :stream generate))

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

Macro definition:
(defmacro defclause (clause-template &body body)
  (define-clause 'defun clause-template body nil))

Macroexpansion:
(eval-when (:compile-toplevel :load-toplevel :execute) (defun clause-for-in-stream-7 (&key ((:for var)) ((:in-stream stream)) ((:using reader) (quote (function read))) generate) "Forms in a stream (which will be closed at the end)" (top-level-check) (return-stream-driver-code var stream reader :stream generate)) (install-clause-info (quote (for :in-stream)) (quote (for :in-stream &optional :using)) (quote clause-for-in-stream-7) "Forms in a stream (which will be closed at the end)" t) (quote (for var in-stream stream &optional using (reader (quote (function read))))))
Define a macro that eliminates this repetitive pattern:
(defun/1 ungetc (c fd) (handler-case (progn (unread-char (code-char c) (fd-stream fd)) c) (error () (setf (ferror fd) EIO) EOF)))

Issue: Macro call that should be transformed by defun/1

Macro definition:
(defmacro defun/1 (name arglist &body body)
  "Lisp-1 defun; makes function pointers work."
  `(progn
     (defun ,name ,arglist
       (declare (optimize (speed 0) (debug 3)
                          ;; FIXME: Why do minor warnings result in load errors?
                          #+sbcl (sb-ext:inhibit-warnings 3)))
        
       ,@body)
     (defparameter ,name (vacietis.c:mkptr& (symbol-function ',name)))))

Macroexpansion:
(progn (defun ungetc (c fd) (declare (optimize (speed 0) (debug 3) (sb-ext:inhibit-warnings 3))) (handler-case (progn (unread-char (code-char c) (fd-stream fd)) c) (error nil (setf (ferror fd) eio) eof))) (defparameter ungetc (vacietis.c:mkptr& (symbol-function (quote ungetc)))))
You are a Common Lisp macro expert. Given this code pattern:
(with-yield
  nil
  :key
  nil)

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

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

Macroexpansion:
(isolate-cont
  (enable-yield
    nil
    nil
    :key
    nil))
Create a Common Lisp macro for the following transformation. Before code:
(aggregate-scope-progv *string-scope-variables* (aggregate-scope-progv *aggregate-scope-variables* (loop initially (funcall *beginning-of-string-handler*) for c = (read-json-string-char stream) while c do (funcall *string-char-handler* c) finally (return (funcall *end-of-string-handler*)))))

What needs to change: Macro call that should be transformed by aggregate-scope-progv

Macro definition:
(defmacro aggregate-scope-progv (variables &body body)
  "Establish a dynamic environment where all VARIABLES are freshly
bound (to their current values), and execute BODY in it, returning the
result."
  `(progv ,variables (mapcar #'symbol-value ,variables)
     ,@body))

Macroexpansion:
(progv *string-scope-variables* (mapcar (function symbol-value) *string-scope-variables*) (aggregate-scope-progv *aggregate-scope-variables* (loop initially (funcall *beginning-of-string-handler*) for c = (read-json-string-char stream) while c do (funcall *string-char-handler* c) finally (return (funcall *end-of-string-handler*)))))
Generate a defmacro form that transforms code like this:
(gatherlet nil)

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

Macro definition:
(defmacro GATHERLET ...)

Macroexpansion:
(common-lisp:let ())
Generate a defmacro form that transforms code like this:
(cond->
  'some-name)

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

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

Macroexpansion:
'some-name
Define a macro that eliminates this repetitive pattern:
(define-cruft %associate-name-with-readtable (name readtable) "Associate NAME with READTABLE for FIND-READTABLE to work." #+ :allegro (setf (excl:named-readtable (readtable-name-for-allegro name)) readtable) #+ :common-lisp (setf (gethash name *named-readtables*) readtable))

Issue: Macro call that should be transformed by define-cruft

Macro definition:
(defmacro define-cruft (name lambda-list &body (docstring . alternatives))
  (assert (typep docstring 'string) (docstring) "Docstring missing!")
  (assert (not (null alternatives)))
  `(progn
     (declaim (inline ,name))
     (defun ,name ,lambda-list ,docstring ,(first alternatives))))

Macroexpansion:
(progn (declaim (inline %associate-name-with-readtable)) (defun %associate-name-with-readtable (name readtable) "Associate NAME with READTABLE for FIND-READTABLE to work." (setf (gethash name *named-readtables*) readtable)))
You are a Common Lisp macro expert. Given this code pattern:
(defjs test_sum() (let ((l (make-array 1 2 3 4)) (sum 0)) (dolist (c l) (incf sum c)) (return sum)))

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

Macro definition:
(defmacro defjs (name args &body body)
  "Define client side javascript. Works like defun; body is in lisp, with parenscript
   additions, like return. So (defjs hello (x y) (return (+ x y))) defines an adder. 
   macro creates a lisp function which sends the javascript function over to the mongo 
   server to be evaluated. Result is processed and returned to the reader. 
   This will execute 10 times on the server :
   (mapcar (lambda (x) (hello 10 x)) (list 1 2 3 4 5 6 7 8 9 10))"
  `(let* ((js-body (parenscript:ps (lambda ,args ,@body))))
     (setf (gethash ',name *js-definitions*) js-body)
     (defun ,name ,args
       (get-element "retval" (car (docs (db.eval js-body ,@args)))))))

Macroexpansion:
(let* ((js-body (parenscript:ps (lambda nil (let ((l (make-array 1 2 3 4)) (sum 0)) (dolist (c l) (incf sum c)) (return sum)))))) (setf (gethash (quote test_sum) *js-definitions*) js-body) (defun test_sum nil (get-element "retval" (car (docs (db.eval js-body))))))
Write a Common Lisp macro to handle this code pattern:
(defclause (minimize expr &optional into var) "Minimize value of an expression" (return-extremum-code expr var 'min))

Problem: Macro call that should be transformed by defclause

Macro definition:
(defmacro defclause (clause-template &body body)
  (define-clause 'defun clause-template body nil))

Macroexpansion:
(eval-when (:compile-toplevel :load-toplevel :execute) (defun clause-minimize-13 (&key ((:minimize expr)) ((:into var))) "Minimize value of an expression" (return-extremum-code expr var (quote min))) (install-clause-info (quote (minimize)) (quote (minimize &optional :into)) (quote clause-minimize-13) "Minimize value of an expression" nil) (quote (minimize expr &optional into var)))
Generate a defmacro form that transforms code like this:
(with-packages-unlocked nil
  (progn))

Pattern to recognize: Macro call that should be transformed by WITH-PACKAGES-UNLOCKED

Macro definition:
(defmacro WITH-PACKAGES-UNLOCKED ...)

Macroexpansion:
(let ((#:|packages122| (locked-packages 'nil)))
  (unlock-packages #:|packages122|)
  (unwind-protect (progn) (lock-packages #:|packages122|)))
Create a Common Lisp macro for the following transformation. Before code:
(dlet* nil
  :key
  nil)

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

Macro definition:
(defmacro DLET* ...)

Macroexpansion:
(dynamic-let* nil
  :key
  nil)