j14i/cl-macros huggingface dataset:
You are a Common Lisp macro expert. Given this code pattern:
(collect-nconc 'some-name)

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

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

Macroexpansion:
(common-lisp:let* ((#:generator-574 (generator 'some-name))
                   #:items-569
                   (#:lst-570 nil)
                   (#:list-571 nil))
  (declare (type generator #:generator-574)
           (type list #:lst-570)
           (type list #:list-571))
  (tagbody
   #:ll-575
    (setq #:items-569 (next-in #:generator-574 (go end)))
    (when #:items-569
      (when #:list-571 (setf (cdr (last #:list-571)) #:items-569))
      (setq #:list-571 #:items-569)
      (when (null #:lst-570) (setq #:lst-570 #:items-569)))
    (go #:ll-575)
   end)
  #:lst-570)
Write a Common Lisp macro to handle this code pattern:
(cond-<>>
  nil
  :key
  nil)

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

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

Macroexpansion:
(let* ((#:var159 nil)
       (#:var160
        (if :key
            (-<>>
              #:var159)
            #:var159))
       (#:var161
        (if nil
            (-<>>
              #:var160)
            #:var160)))
  #:var161)
Create a Common Lisp macro for the following transformation. Before code:
(with-standard-readtable)

What needs to change: Macro call that should be transformed by WITH-STANDARD-READTABLE

Macro definition:
(defmacro WITH-STANDARD-READTABLE ...)

Macroexpansion:
(bind ((*readtable* (with-standard-io-syntax (copy-readtable *readtable*)))))
Generate a defmacro form that transforms code like this:
(~> (-> (one) :ignore-invariant t () (increment)) (-> :one :ignore-invariant t () (increment)) (-> :one :ignore-invariant t () (increment)))

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

Macro definition:
(defmacro ~> (&rest body)
  "See flow:concurrently"
  `(concurrently ,@body))

Macroexpansion:
(concurrently (-> (one) :ignore-invariant t nil (increment)) (-> :one :ignore-invariant t nil (increment)) (-> :one :ignore-invariant t nil (increment)))
Define a macro that eliminates this repetitive pattern:
(defun-compile-time walk-multiple-value-call (map-function reduce-function screamer? partial? nested? form environment) (unless (null (rest (last form))) (error "Improper MULTIPLE-VALUE-CALL: ~S" form)) (unless (>= (length form) 2) (error "MULTIPLE-VALUE-CALL must have at least one argument, a FUNCTION: ~S" form)) (if reduce-function (funcall reduce-function (funcall map-function form 'multiple-value-call) (reduce reduce-function (mapcar #'(lambda (subform) (walk map-function reduce-function screamer? partial? nested? subform environment)) (rest form)))) (funcall map-function form 'multiple-value-call)))

Issue: Macro call that should be transformed by defun-compile-time

Macro definition:
(defmacro defun-compile-time (function-name lambda-list &body body)
  `(eval-when (:compile-toplevel :load-toplevel :execute)
     (cl:defun ,function-name ,lambda-list ,@body)
     (eval-when (:compile-toplevel) (compile ',function-name))))

Macroexpansion:
(eval-when (:compile-toplevel :load-toplevel :execute) (common-lisp:defun walk-multiple-value-call (map-function reduce-function screamer? partial? nested? form environment) (unless (null (rest (last form))) (error "Improper MULTIPLE-VALUE-CALL: ~S" form)) (unless (>= (length form) 2) (error "MULTIPLE-VALUE-CALL must have at least one argument, a FUNCTION: ~S" form)) (if reduce-function (funcall reduce-function (funcall map-function form (quote multiple-value-call)) (reduce reduce-function (mapcar (function (lambda (subform) (walk map-function reduce-function screamer? partial? nested? subform environment))) (rest form)))) (funcall map-function form (quote multiple-value-call)))) (eval-when (:compile-toplevel) (compile (quote walk-multiple-value-call))))
You are a Common Lisp macro expert. Given this code pattern:
(aggregate-scope-progv *aggregate-scope-variables* (funcall *beginning-of-array-handler*) (multiple-value-bind (type token) (peek-json-token stream) (if (and (eql type :punct) (char= token #\])) (progn (read-json-token stream) (return-from decode-json-array (funcall *end-of-array-handler*))) (funcall *array-member-handler* (funcall *internal-decoder* stream)))) (loop (multiple-value-bind (type token) (read-json-token stream) (if (eql type :punct) (case token (#\] (return-from decode-json-array (funcall *end-of-array-handler*))) (#\, (setq token nil)))) (if token (json-syntax-error stream "Token out of place in Array on JSON input: `~A'" token))) (funcall *array-member-handler* (funcall *internal-decoder* stream))))

Write a macro that addresses: 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 *aggregate-scope-variables* (mapcar (function symbol-value) *aggregate-scope-variables*) (funcall *beginning-of-array-handler*) (multiple-value-bind (type token) (peek-json-token stream) (if (and (eql type :punct) (char= token #\RIGHT_SQUARE_BRACKET)) (progn (read-json-token stream) (return-from decode-json-array (funcall *end-of-array-handler*))) (funcall *array-member-handler* (funcall *internal-decoder* stream)))) (loop (multiple-value-bind (type token) (read-json-token stream) (if (eql type :punct) (case token (#\RIGHT_SQUARE_BRACKET (return-from decode-json-array (funcall *end-of-array-handler*))) (#\COMMA (setq token nil)))) (if token (json-syntax-error stream "Token out of place in Array on JSON input: `~A'" token))) (funcall *array-member-handler* (funcall *internal-decoder* stream))))
Define a macro that eliminates this repetitive pattern:
;; Manual destructuring from sequences is verbose
(let ((lst (compute-list)))
  (let ((a (elt lst 0))
        (b (elt lst 1))
        (c (subseq lst 2)))
    (process a b c)))

;; Nested structures are even worse:
(let ((tree (compute-tree)))
  (let ((x (elt tree 0))
        (inner (elt tree 1)))
    (let ((y (elt inner 0))
          (z (elt inner 1)))
      (compute x y z))))

Issue: Manual sequence destructuring with elt/subseq is error-prone — want pattern-based destructuring like ML/Haskell

Macro definition:
(defmacro dbind (pat seq &body body)
  (let ((gseq (gensym)))
    `(let ((,gseq ,seq))
       ,(dbind-ex (destruc pat gseq #'atom) body))))

Macroexpansion:
;; (dbind (a b &rest c) (compute-list)
;;   (process a b c))
;;
;; (dbind (x (y z)) (compute-tree)
;;   (compute x y z))
;;
;; Handles nested patterns, &rest, &body.
;; Works on any sequence (list, vector, string).
;; The pattern literal describes the shape of the data.
You are a Common Lisp macro expert. Given this code pattern:
(as-> nil nil)

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

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

Macroexpansion:
(let* ((nil nil))
  nil)
Create a Common Lisp macro for the following transformation. Before code:
(define-op (:when infix-op))

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

Macro definition:
(defmacro define-op ((op-name struct-type &key sql-op-name include-slots (package (find-package '#:sxql/operator))) &body body)
  (check-type op-name symbol)
  (let ((struct-name (intern (concatenate 'string (symbol-name op-name) #.(string :-op)) package)))
    `(defstruct (,struct-name (:include ,struct-type
                               (name ,(or sql-op-name
                                          (with-output-to-string (s)
                                            (loop for c across (symbol-name op-name)
                                                  if (char= c #\-)
                                                    do (write-char #\Space s)
                                                  else
                                                    do (write-char c s)))))
                               ,@include-slots)
                              (:constructor ,(intern (concatenate 'string
                                                                  #.(string :make-)
                                                                  (symbol-name op-name)
                                                                  #.(string :-op))
                                                     package)
                                  ,(ecase struct-type
                                     ((unary-op
                                       unary-splicing-op
                                       unary-postfix-op) '(var))
                                     ((infix-op
                                       infix-splicing-op
                                       infix-list-op) '(left right))
                                     (conjunctive-op '(&rest expressions)))))
       ,@body)))

Macroexpansion:
(defstruct (when-op (:include infix-op (name "WHEN")) (:constructor make-when-op (left right))))
Generate a defmacro form that transforms code like this:
(defstore example (a &optional (b 0) &key (c (the integer (init-c a b)))))

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

Macro definition:
(defmacro defstore (store-name store-lambda-list &body body &environment env)
  (let* ((store-class-name (second (find :store-class body :key #'first)))
         (store-class (etypecase store-class-name
                        (null (find-class 'standard-store))
                        (symbol (find-class store-class-name))))
         (form (apply #'defstore-using-class store-class store-name store-lambda-list
                      :environment env
                      (mapcan #'(lambda (item)
                                  (cond ((eql (first item) :store-class)
                                         `(:store-class ',store-class-name))
                                        ((and (member (first item) '(:documentation :specialization-class)))
                                         (if (= 2 (length item))
                                             item
                                             (error "Invalid store definition option: ~W." item)))
                                        (t
                                         (list (first item) (rest item)))))
                              body))))
    `(eval-when (:compile-toplevel :load-toplevel :execute)
       ,form)))

Macroexpansion:
(eval-when (:compile-toplevel :load-toplevel :execute) (progn (defun a-init-function152 (a b #:b?169) (declare (ignorable a b #:b?169)) (the integer (init-c a b))) (ensure-store (quote example) (quote (a &optional (b 0 #:b?169) &key (c (the integer (a-init-function152 a b #:b?169)) #:c?170))))))
Create a Common Lisp macro for the following transformation. Before code:
(with-yield-binds (format nil "ELSE ~A" (with-table-name nil (yield (else-op-var op)))))

What needs to change: 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 "ELSE ~A" (with-table-name nil (yield (else-op-var op))))) (loop for bind in (reverse *bind-values*) append bind)))
You are a Common Lisp macro expert. Given this code pattern:
(true 1)

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

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

Macroexpansion:
(eval-in-context *context* (make-instance (quote comparison-result) :expression (quote (true 1)) :value-form (quote 1) :body (lambda nil 1) :expected (quote t) :comparison (quote geq)))
Define a macro that eliminates this repetitive pattern:
(define-simple-type-map package cl:package)

Issue: Macro call that should be transformed by define-simple-type-map

Macro definition:
(defmacro define-simple-type-map (class type)
  `(defmethod type ((,class ,class))
     ',type))

Macroexpansion:
(defmethod type ((package package)) (quote common-lisp:package))
Define a macro that eliminates this repetitive pattern:
(with-standard-definer-options 'some-name)

Issue: Macro call that should be transformed by WITH-STANDARD-DEFINER-OPTIONS

Macro definition:
(defmacro WITH-STANDARD-DEFINER-OPTIONS ...)

Macroexpansion:
`(progn
  ,@(when (getf -options- :export)
      `((eval-when (:compile-toplevel :load-toplevel :execute)
          (export ','some-name)))))
Write a Common Lisp macro to handle this code pattern:
(defclass/a dbd-postgres-connection (dbi-connection) ((%modified-row-count :type (or null fixnum) :initform nil) (%deallocation-queue :type list :initform nil)))

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 dbd-postgres-connection (dbi-connection) ((%modified-row-count :type (or null fixnum) :initform nil) (%deallocation-queue :type list :initform nil))) (deftype <dbd-postgres-connection> nil (quote dbd-postgres-connection)) (setf (find-class (quote <dbd-postgres-connection>)) (find-class (quote dbd-postgres-connection))))
Write a Common Lisp macro to handle this code pattern:
(define-simple-clause until (form) `(when ,form (end-for)))

Problem: Macro call that should be transformed by define-simple-clause

Macro definition:
(defmacro define-simple-clause (name args &body body)
  (multiple-value-bind (args outer-let inner-let result-let) (compute-binding-parts NIL NIL args)
    `(define-direct-clause ,name ,(rest args)
       (let ,outer-let
         (values* `(let* ,(list
                           ,@result-let)
                     (declare (ignorable ,,@(mapcar #'delist outer-let))))
                  (let ,inner-let
                    (declare (ignorable ,@(mapcar #'delist inner-let)))
                    ,@body))))))

Macroexpansion:
(define-direct-clause until (form) (let nil (values* (sb-int:quasiquote (let* #S(sb-impl::comma :expr (list) :kind 0) (declare (ignorable)))) (let nil (declare (ignorable)) (sb-int:quasiquote (when #S(sb-impl::comma :expr form :kind 0) (end-for)))))))
You are a Common Lisp macro expert. Given this code pattern:
(swhen x (setf it :oops))

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

Macro definition:
(defmacro swhen (test &body body)
  "Like WHEN, except binds the test form to IT (via SYMBOL-MACROLET) for the
scope of the body. IT can be set with SETF."
  `(symbolic when ,test ,@body))

Macroexpansion:
(symbolic when x (setf it :oops))
Write a Common Lisp macro to handle this code pattern:
(advisable-lambda nil
  nil)

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

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

Macroexpansion:
(make-instance 'advisable-function :main #'(lambda () nil) :arguments 'nil
               :dispatcher-generator
               #'(lambda (#:fobj124)
                   #'(lambda ()
                       #A((29) base-char . "Advisable function dispatcher")
                       (let ((#:fixed125 (append)))
                         (apply-before #:fobj124 #:fixed125)
                         (multiple-value-prog1
                             (apply-around #:fobj124 #:fixed125)
                           (apply-after #:fobj124 #:fixed125))))))
You are a Common Lisp macro expert. Given this code pattern:
(-> :g (v) (put v) nil)

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

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

Macroexpansion:
(atomically :g (v) (put v) nil)
Generate a defmacro form that transforms code like this:
(collect-stream nil nil)

Pattern to recognize: Macro call that should be transformed by COLLECT-STREAM

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

Macroexpansion:
(common-lisp:let* ((#:generator-475 (generator nil)) #:items-470)
  (declare (type generator #:generator-475))
  (tagbody
   #:ll-476
    (setq #:items-470 (next-in #:generator-475 (go end)))
    (common-lisp:funcall #'print #:items-470 nil)
    (go #:ll-476)
   end)
  nil)
Write a Common Lisp macro to handle this code pattern:
(with-inactive-layers nil)

Problem: Macro call that should be transformed by WITH-INACTIVE-LAYERS

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

Macroexpansion:
(progn)
Generate a defmacro form that transforms code like this:
(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 `(,*xsb* "--nobanner" "--quietload" "--noprompt" "-e" ,(format nil "consult('~a')." input-file) ,@args) :input input :output output :error error)))

Pattern to recognize: 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 ((#:command177 (format nil "mktemp --tmpdir='~a' ~@[-d~*~] ~@[~a~]" "/tmp/" t nil))) (when (<= 1 *debug-prolog*) (format *error-output* "~&; ~a~%" #:command177)) #:command177) :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 (#S(sb-impl::comma :expr *xsb* :kind 0) "--nobanner" "--quietload" "--noprompt" "-e" #S(sb-impl::comma :expr (format nil "consult('~a')." 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:
(dletf* nil)

Issue: Macro call that should be transformed by DLETF*

Macro definition:
(defmacro DLETF* ...)

Macroexpansion:
(progn)
Write a Common Lisp macro to handle this code pattern:
(with-access nil
    (progn))

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

Macro definition:
(defmacro with-access ((&rest keys) val-form &body body)
  "Similar to with-accessors except using the access functions"
  (let* ((gval (gensym "val"))
     (forms
      (iter (for k in keys)
        (for (k-to k-from) = (if (listp k) k (list k k)))
        (collect `(,k-to (access ,gval ',k-from))))))
    `(let ((,gval ,val-form))
       (declare (ignorable ,gval))
       (symbol-macrolet (,@forms)
     ,@body
     ))))

Macroexpansion:
(let ((#:|val242| (progn)))
  (declare (ignorable #:|val242|))
  (symbol-macrolet ()))
Generate a defmacro form that transforms code like this:
(f_
  nil
  (progn))

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

Macro definition:
(defmacro F_ ...)

Macroexpansion:
(lambda (_) nil (progn))
Generate a defmacro form that transforms code like this:
(log-message <manager> <category> <desctiption> <arguments...>)

Pattern to recognize: 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) <manager> <category> <desctiption> <arguments...>)
You are a Common Lisp macro expert. Given this code pattern:
(dynamic-let* nil
  (progn))

Write a macro that addresses: Macro call that should be transformed by DYNAMIC-LET*

Macro definition:
(defmacro DYNAMIC-LET* ...)

Macroexpansion:
(progn (progn))
Write a Common Lisp macro to handle this code pattern:
(define-custom-var (:integer *integer-handler*))

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 (*integer-handler* . :integer)) *custom-vars* :test (function equal)) (defvar *integer-handler*)))
Write a Common Lisp macro to handle this code pattern:
(deferror "08001" sqlclient-unable-to-establish-sqlconnection)

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 sqlclient-unable-to-establish-sqlconnection (database-error) nil) (setf (gethash "08001" *error-table*) (quote sqlclient-unable-to-establish-sqlconnection)))
You are a Common Lisp macro expert. Given this code pattern:
(-<>> (diamond-wand init (cddr exp) t))

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

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

Macroexpansion:
(diamond-wand init (cddr exp) t)
You are a Common Lisp macro expert. Given this code pattern:
(psetq)

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

Macro definition:
(defmacro PSETQ ...)

Macroexpansion:
nil
Generate a defmacro form that transforms code like this:
($ "name" ($/ "[_]*.mr." "i"))

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

Macro definition:
(defmacro $ (&rest args)
  `(kv ,@args))

Macroexpansion:
(kv "name" ($/ "[_]*.mr." "i"))