j14i/cl-macros huggingface dataset:
Define a macro that eliminates this repetitive pattern:
(with-foreign-pointer-as-string (s 100) (sprintf s "%.0f" :double (* pi 100d0)))

Issue: Macro call that should be transformed by with-foreign-pointer

Macro definition:
(defmacro with-foreign-pointer ((var size &optional size-var) &body body)
  "Bind 'var to 'size bytes of foreign memory during 'body.  The
  pointer in 'var is invalid beyond the dynamic extent of 'body, and
  may be stack-allocated if supported by the implementation.  If
  'size-var is supplied, it will be bound to 'size during 'body."
  (unless size-var
    (setf size-var (gensym (symbol-name '#:size))))
  ;; If the size is constant we can stack-allocate.
  (cond ((constantp size)
         (let ((alien-var (gensym (symbol-name '#:alien))))
           `(with-alien ((,alien-var (array (unsigned 8) ,(eval size))))
             (let ((,size-var ,size)
                   (,var (alien-sap ,alien-var)))
               (declare (ignorable ,size-var))
               ,@body))))
        (t
         `(let ((,size-var ,size))
            (alien:with-bytes (,var ,size-var)
              ,@body)))))

Macroexpansion:
(with-foreign-pointer-as-string (s 100) (sprintf s "%.0f" :double (* pi 100.0d0)))
Write a Common Lisp macro to handle this code pattern:
(ignore-errors)

Problem: Macro call that should be transformed by IGNORE-ERRORS

Macro definition:
(defmacro IGNORE-ERRORS ...)

Macroexpansion:
(handler-case (progn) (error (condition) (values nil condition)))
Write a Common Lisp macro to handle this code pattern:
(defcategory :notice (or :notice :warning))

Problem: 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 :notice) (quote (or :notice :warning)) nil)
Write a Common Lisp macro to handle this code pattern:
(define-templated-dispatch nil
    nil)

Problem: Macro call that should be transformed by DEFINE-TEMPLATED-DISPATCH

Macro definition:
(defmacro DEFINE-TEMPLATED-DISPATCH ...)

Macroexpansion:
(define-type-dispatch nil
    nil)
Write a Common Lisp macro to handle this code pattern:
(with-additional-indent (reporter stream "~& ") (with-color (:white :stream stream) (format/indent reporter stream (slot-value report 'description))) (terpri stream))

Problem: Macro call that should be transformed by with-additional-indent

Macro definition:
(defmacro with-additional-indent ((reporter stream control-string &rest format-arguments) &body body)
  (declare (ignorable reporter stream control-string))
  (let* ((need-new-line (ppcre:scan "^~&" control-string))
         (string (apply #'format nil control-string format-arguments))
         (increment (length string)))
    `(with-slots (indent-space) reporter
       (let* ((first-line-indent (indent indent-space))
              (*additional-indent* ,(if need-new-line
                                        increment
                                        `(+ *additional-indent*
                                            ,increment))))
         (declare (ignorable first-line-indent))
         ,(if need-new-line
              `(progn (fresh-line stream)
                      (write-string first-line-indent ,stream)
                      ;; because we just started a new line, we
                      ;; should use format/indent to write string
                      ;; taking into account a main indentation level
                      (format/indent ,reporter ,stream ,string))
              ;; otherwise, just output our prefix
              `(write-string ,string ,stream))
       
       
         ,@body))))

Macroexpansion:
(with-slots (indent-space) reporter (let* ((first-line-indent (indent indent-space)) (*additional-indent* 1)) (declare (ignorable first-line-indent)) (progn (fresh-line stream) (write-string first-line-indent stream) (format/indent reporter stream #A((1) base-char . " "))) (with-color (:white :stream stream) (format/indent reporter stream (slot-value report (quote description)))) (terpri stream)))
Write a Common Lisp macro to handle this code pattern:
($ "$min" ($ "value-1" 600))

Problem: Macro call that should be transformed by $

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

Macroexpansion:
(kv "$min" ($ "value-1" 600))
Define a macro that eliminates this repetitive pattern:
(defclause while (condition) "Same as (until (not <condition>))." (make-termination :condition `(not ,condition)))

Issue: 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 while (condition) "Same as (until (not <condition>))." (make-termination :condition (sb-int:quasiquote (not #S(sb-impl::comma :expr condition :kind 0))))) (pushnew (quote while) *clauses*))
You are a Common Lisp macro expert. Given this code pattern:
(builder :backtrace (lambda (env) (declare (ignore env)) (error 'test-error)))

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

Macro definition:
(defmacro builder (&rest app-or-middlewares)
  (let ((middlewares (butlast app-or-middlewares)))
    `(reduce #'funcall
             (remove-if
              #'null
              (list
               ,@(loop for mw in middlewares
                       when mw
                         collect (convert-to-middleware-form mw))))
             :initial-value (to-app ,(car (last app-or-middlewares)))
             :from-end t)))

Macroexpansion:
(reduce (function funcall) (remove-if (function null) (list (find-middleware :backtrace))) :initial-value (to-app (lambda (env) (declare (ignore env)) (error (quote test-error)))) :from-end t)
Write a Common Lisp macro to handle this code pattern:
(when-let* ((x t) (y (consp x)) (z (error "OOPS"))) t)

Problem: Macro call that should be transformed by when-let*

Macro definition:
(defmacro when-let* (bindings &body body)
  "Creates new variable bindings, and conditionally executes BODY.

BINDINGS must be either single binding of the form:

 (variable initial-form)

or a list of bindings of the form:

 ((variable-1 initial-form-1)
  (variable-2 initial-form-2)
  ...
  (variable-n initial-form-n))

Each INITIAL-FORM is executed in turn, and the variable bound to the
corresponding value. INITIAL-FORM expressions can refer to variables
previously bound by the WHEN-LET*.

Execution of WHEN-LET* stops immediately if any INITIAL-FORM evaluates to NIL.
If all INITIAL-FORMs evaluate to true, then BODY is executed as an implicit
PROGN."
  (let ((binding-list (if (and (consp bindings) (symbolp (car bindings)))
                          (list bindings)
                          bindings)))
    (labels ((bind (bindings body)
               (if bindings
                   `(let (,(car bindings))
                      (when ,(caar bindings)
                        ,(bind (cdr bindings) body)))
                   `(progn ,@body))))
      (bind binding-list body))))

Macroexpansion:
(let ((x t)) (when x (let ((y (consp x))) (when y (let ((z (error "OOPS"))) (when z (progn t)))))))
You are a Common Lisp macro expert. Given this code pattern:
(match nil (progn))

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

Macro definition:
(defmacro MATCH ...)

Macroexpansion:
(block #:match127
  (let (progn)
    (when (and (setft progn nil)) (return-from #:match127 nil))))
Define a macro that eliminates this repetitive pattern:
($ ($ "$min" ($ "value-1" 600)) ($ "$max" ($ "value-1" 610)) ($ "query" ($ nil nil)))

Issue: Macro call that should be transformed by $

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

Macroexpansion:
(kv ($ "$min" ($ "value-1" 600)) ($ "$max" ($ "value-1" 610)) ($ "query" ($ nil nil)))
Define a macro that eliminates this repetitive pattern:
(with-properties nil
    (progn))

Issue: Macro call that should be transformed by WITH-PROPERTIES

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

Macroexpansion:
(let ((#:g134 (progn)))
  (symbol-macrolet ()))
Write a Common Lisp macro to handle this code pattern:
(ps-to-stream 'some-name)

Problem: Macro call that should be transformed by PS-TO-STREAM

Macro definition:
(defmacro PS-TO-STREAM ...)

Macroexpansion:
(let ((*parenscript-stream* 'some-name))
  (write-string "" *parenscript-stream*))
You are a Common Lisp macro expert. Given this code pattern:
(when-let* (x y) (1+ x))

Write a macro that addresses: Macro call that should be transformed by when-let*

Macro definition:
(defmacro when-let* (bindings &body body)
  "Creates new variable bindings, and conditionally executes BODY.

BINDINGS must be either single binding of the form:

 (variable initial-form)

or a list of bindings of the form:

 ((variable-1 initial-form-1)
  (variable-2 initial-form-2)
  ...
  (variable-n initial-form-n))

Each INITIAL-FORM is executed in turn, and the variable bound to the
corresponding value. INITIAL-FORM expressions can refer to variables
previously bound by the WHEN-LET*.

Execution of WHEN-LET* stops immediately if any INITIAL-FORM evaluates to NIL.
If all INITIAL-FORMs evaluate to true, then BODY is executed as an implicit
PROGN."
  (let ((binding-list (if (and (consp bindings) (symbolp (car bindings)))
                          (list bindings)
                          bindings)))
    (labels ((bind (bindings body)
               (if bindings
                   `(let (,(car bindings))
                      (when ,(caar bindings)
                        ,(bind (cdr bindings) body)))
                   `(progn ,@body))))
      (bind binding-list body))))

Macroexpansion:
(let ((x y)) (when x (progn (1+ x))))
Define a macro that eliminates this repetitive pattern:
(define-class nil
    :key
    nil)

Issue: Macro call that should be transformed by DEFINE-CLASS

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

Macroexpansion:
(progn (defclass nil :key nil))
Write a Common Lisp macro to handle this code pattern:
(f0
  nil
  nil)

Problem: Macro call that should be transformed by F0

Macro definition:
(defmacro F0 ...)

Macroexpansion:
(lambda () nil nil)
Create a Common Lisp macro for the following transformation. Before code:
(define-op (:> 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 (>-op (:include infix-op (name ">")) (:constructor make->-op (left right))))
You are a Common Lisp macro expert. Given this code pattern:
(unless nil (progn))

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

Macro definition:
(defmacro UNLESS ...)

Macroexpansion:
(if nil
    nil
    (progn))
Generate a defmacro form that transforms code like this:
(mapping)

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

Macro definition:
(defmacro MAPPING ...)

Macroexpansion:
(mapping-mac)
Generate a defmacro form that transforms code like this:
(list-of nil
  (progn))

Pattern to recognize: Macro call that should be transformed by LIST-OF

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

Macroexpansion:
(lc (nil (progn)) collect)
You are a Common Lisp macro expert. Given this code pattern:
(define-shared-method nil
    nil)

Write a macro that addresses: Macro call that should be transformed by DEFINE-SHARED-METHOD

Macro definition:
(defmacro DEFINE-SHARED-METHOD ...)

Macroexpansion:
(define-incongruent-method incongruent-methods.methods::nil
    nil)
Define a macro that eliminates this repetitive pattern:
(define-simple-definition-resolver global (designator) (eq :global (sb-cltl2:variable-information designator)))

Issue: Macro call that should be transformed by define-simple-definition-resolver

Macro definition:
(defmacro define-simple-definition-resolver (class lookup-function &body body)
  (let ((package (gensym "PACKAGE")))
    `(define-definition-resolver ,class (,class ,package)
       (when (ignore-errors ,(if body
                                 `(let ((,(first lookup-function) ,class))
                                    ,@body)
                                 `(,lookup-function ,class)))
         (list (make-instance ',class :designator ,class :package ,package))))))

Macroexpansion:
(define-definition-resolver global (global #:package147) (when (ignore-errors (let ((designator global)) (eq :global (sb-cltl2:variable-information designator)))) (list (make-instance (quote global) :designator global :package #:package147))))
You are a Common Lisp macro expert. Given this code pattern:
(match ARG (PATTERN THEN) (otherwise ELSE))

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

Macro definition:
(defmacro match (arg &body clauses)
  "Matches ARG with CLAUSES. CLAUSES is a list of the form of (PATTERN
. BODY) where PATTERN is a pattern specifier and BODY is an implicit
progn. If ARG matches some PATTERN, `match` then evaluates
the corresponding BODY and returns the evaluated value.  If no pattern matches,
then returns NIL.

Evaluating a form (FAIL) in the clause body causes the latest pattern
matching to fail. For example,

    (match 1
      (x (if (eql x 1)
             (fail)
             x))
      (_ 'ok))

returns OK, because the form (FAIL) in the first clause is
evaluated.

If BODY starts with the symbols WHEN or UNLESS, then the next form
will be used to introduce (FAIL). That is,

    (match list ((list x) when (oddp x) x))
    (match list ((list x) unless (evenp x) x))

will be translated to

    (match list ((list x) (if (oddp x) x (fail))))
    (match list ((list x) (if (evenp x) (fail) x)))

Examples:

    (match 1 (1 1))
    => 1
    (match 1 (2 2))
    => 2
    (match 1 (x x))
    => 1
    (match (list 1 2 3)
      (list x y z) (+ x y z))
    => 6"
  (compile-match-1 arg clauses nil))

Macroexpansion:
(%or (%or (let ((pattern arg)) then) else (fail)) nil)
Write a Common Lisp macro to handle this code pattern:
(macroexpand-convention (form) (if (consp form) (expand-export-slots-using-head (first form) form) form))

Problem: Macro call that should be transformed by macroexpand-convention

Macro definition:
(defmacro macroexpand-convention ((original-form) &body body)
  "Executes BODY as like `progn' and return the result as the first
value.  As the second value, returns a boolean whether the result is
not same with ORIGINAL-FORM or not.
This macro is designed to follow the `macroexpand' convention."
  `(multiple-value-bind (result expanded-p)
       (progn ,@body)
     (values result
             (or expanded-p
                 (not (eq result ,original-form))))))

Macroexpansion:
(multiple-value-bind (result expanded-p) (progn (if (consp form) (expand-export-slots-using-head (first form) form) form)) (values result (or expanded-p (not (eq result form)))))
Generate a defmacro form that transforms code like this:
(define-column-type string (&optional length) (if length `(:varchar ,length) :text))

Pattern to recognize: Macro call that should be transformed by define-column-type

Macro definition:
(defmacro define-column-type (type-symbol lambda-list &body body)
  (let ((type (gensym "TYPE"))
        (args (gensym "ARGS")))
    `(defmethod cltype-to-dbtype ((,type (eql ',type-symbol)) &rest ,args)
       (declare (ignore ,type))
       (destructuring-bind ,lambda-list ,args
         ,@body))))

Macroexpansion:
(defmethod cltype-to-dbtype ((#:type222 (eql (quote string))) &rest #:args223) (declare (ignore #:type222)) (destructuring-bind (&optional length) #:args223 (if length (sb-int:quasiquote (:varchar #S(sb-impl::comma :expr length :kind 0))) :text)))
You are a Common Lisp macro expert. Given this code pattern:
(define-simple-documentation-lookup special-operator cl:function)

Write a macro that addresses: Macro call that should be transformed by define-simple-documentation-lookup

Macro definition:
(defmacro define-simple-documentation-lookup (class documentation-type)
  `(defmethod documentation ((,class ,class))
     ,(if (eql documentation-type T)
          `(cl:documentation (object ,class) 'T)
          `(cl:documentation (designator ,class) ',documentation-type))))

Macroexpansion:
(defmethod documentation ((special-operator special-operator)) (common-lisp:documentation (designator special-operator) (quote common-lisp:function)))
Write a Common Lisp macro to handle this code pattern:
(when (typep (car evaluated) 'node) (setf asts (append asts evaluated)))

Problem: 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 (typep (car evaluated) (quote node)) (setf asts (append asts evaluated)))
Create a Common Lisp macro for the following transformation. Before code:
(ensure-getf options :type type)

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

Macro definition:
(defmacro ensure-getf (place key &optional default)
  (once-only (key default)
    `(setf (getf ,place ,key) (getf ,place ,key ,default))))

Macroexpansion:
(let ((#:key169 :type) (#:default170 type)) (setf (getf options #:key169) (getf options #:key169 #:default170)))
You are a Common Lisp macro expert. Given this code pattern:
(define-simple-type-map type cl:type)

Write a macro that addresses: 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 ((type type)) (quote common-lisp:type))
You are a Common Lisp macro expert. Given this code pattern:
;; Sorting multiple places requires manual compare-and-swap
(when (> b a) (rotatef a b))
(when (> c a) (rotatef a c))
(when (> c b) (rotatef b c))
;; This is a sorting network but manually written - error-prone
;; For more than 3 elements, the network is complex

Write a macro that addresses: Sorting multiple values in-place requires compare-and-swap networks — want automatic sorting network generation

Macro definition:
(defun build-batcher-sn (n)
  (let* (network
         (tee (ceiling (log n 2)))
         (p (ash 1 (- tee 1))))
    (loop while (> p 0) do
      (let ((q (ash 1 (- tee 1)))
            (r 0)
            (d p))
        (loop while (> d 0) do
          (loop for i from 0 to (- n d 1) do
            (if (= (logand i p) r)
              (push (list i (+ i d))
                    network)))
          (setf d (- q p)
                q (ash q -1)
                r p)))
      (setf p (ash p -1)))
    (nreverse network)))

(defmacro! sortf (comparator &rest places)
  (if places
    `(tagbody
       ,@(mapcar
           #`(let ((,g!a #1=,(nth (car a1) places))
                   (,g!b #2=,(nth (cadr a1) places)))
               (if (,comparator ,g!b ,g!a)
                 (setf #1# ,g!b
                       #2# ,g!a)))
           (build-batcher-sn (length places))))))

Macroexpansion:
;; (sortf string< a b c d e)
;; Generates a Batcher sorting network of compare-and-swap operations
;; Each pair is: (let ((#:ga (nth 0 places)) (#:gb (nth 3 places)))
;;                (if (string< #:gb #:ga) (setf #1# #:gb #2# #:ga)))
;; All within a tagbody for compiler optimization
You are a Common Lisp macro expert. Given this code pattern:
(the nil (progn))

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

Macro definition:
(defmacro THE ...)

Macroexpansion:
(send self nil (progn))
Write a Common Lisp macro to handle this code pattern:
(bind (((:struct metabang-bind-test-1- a c) (make-metabang-bind-test-1 :a 1 :b 2 :c 3))) (list a c))

Problem: Macro call that should be transformed by bind

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

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

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

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

Macroexpansion:
(let* ((#:|values-188| (make-metabang-bind-test-1 :a 1 :b 2 :c 3)) (a (metabang-bind-test-1-a #:|values-188|)) (c (metabang-bind-test-1-c #:|values-188|))) (declare (ignorable #:|values-188|)) (progn (list a c)))
Create a Common Lisp macro for the following transformation. Before code:
(enable-quasiquote-2.0)

What needs to change: Macro call that should be transformed by ENABLE-QUASIQUOTE-2.0

Macro definition:
(defmacro ENABLE-QUASIQUOTE-2.0 ...)

Macroexpansion:
(eval-when (:compile-toplevel :load-toplevel :execute) (%enable-quasiquote-2.0))