j14i/cl-macros huggingface dataset:
Generate a defmacro form that transforms code like this:
(doseq (elem sequence :from-end from-end :start start :end end) (when (funcall test (funcall key elem)) (incf count)))

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

Macro definition:
(defmacro doseq (name/seq &body body)
  "Iterate over the elements of a single sequence SEQUENCE.

   Same as DO-SEQUENCES but for the special case of iterating over a
   single sequence.

   The macro arguments can be in one of the following two forms:

    1. (NAME (ELEMENT SEQUENCE &REST ARGS) &BODY BODY)

    2. ((ELEMENT SEQUENCE &REST ARGS) &BODY BODY)

   NAME is the block name, NIL if not given.

   ELEMENT is the variable to which each element of the sequence is
   bound.

   SEQUENCE is the sequence, with ARGS being the remaining arguments
   passed to the ITERATOR function.

   BODY is the list of forms evaluated on each iteration."

  (let-if ((name name/seq)
           (seq (first body) name/seq)
           (body (rest body) body))
      (symbolp name/seq)

    (destructuring-bind (element sequence &rest args) seq
      `(do-sequences ,name
         ((,element ,sequence ,@args))
         ,@body))))

Macroexpansion:
(do-sequences nil ((elem sequence :from-end from-end :start start :end end)) (when (funcall test (funcall key elem)) (incf count)))
Define a macro that eliminates this repetitive pattern:
(once-only* args (let ((else `(error 'match-error :values (list ,@args) :patterns ',(mapcar #'car clauses)))) (compile-match args clauses else)))

Issue: Macro call that should be transformed by once-only*

Macro definition:
(defmacro once-only* (symbol &body body)
  (with-unique-names (form var vars bindings)
    `(let (,vars ,bindings)
       (dolist (,form ,symbol)
         (if (symbolp ,form)
             (push ,form ,vars)
             (let ((,var (gensym "VAR")))
               (push ,var ,vars)
               (push (list ,var ,form) ,bindings))))
       (setq ,vars (nreverse ,vars)
             ,bindings (nreverse ,bindings))
       (if ,bindings
           `(let ,,bindings
              ;(declare (ignorable ,@(mapcar #'car ,bindings)))
              ,(let ((,symbol ,vars))
                 ,@body))
           (progn ,@body)))))

Macroexpansion:
(let (#:vars166 #:bindings167) (dolist (#:form164 args) (if (symbolp #:form164) (push #:form164 #:vars166) (let ((#:var165 (gensym "VAR"))) (push #:var165 #:vars166) (push (list #:var165 #:form164) #:bindings167)))) (setq #:vars166 (nreverse #:vars166) #:bindings167 (nreverse #:bindings167)) (if #:bindings167 (sb-int:quasiquote (let #S(sb-impl::comma :expr #:bindings167 :kind 0) #S(sb-impl::comma :expr (let ((args #:vars166)) (let ((else (sb-int:quasiquote (error (quote match-error) :values (list #S(sb-impl::comma :expr args :kind 2)) :patterns (quote #S(sb-impl::comma :expr (mapcar (function car) clauses) :kind 0)))))) (compile-match args clauses else))) :kind 0))) (progn (let ((else (sb-int:quasiquote (error (quote match-error) :values (list #S(sb-impl::comma :expr args :kind 2)) :patterns (quote #S(sb-impl::comma :expr (mapcar (function car) clauses) :kind 0)))))) (compile-match args clauses else)))))
You are a Common Lisp macro expert. Given this code pattern:
(keep-bops 'some-name)

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

Macro definition:
(defmacro KEEP-BOPS ...)

Macroexpansion:
(eval-when (:load-toplevel :compile-toplevel :execute)
  (progn
   (init-binfix)
   (unless nil
     (setq *binfix*
             (delete nil
                     (mapcar
                      (lambda (bs)
                        (setq bs
                                (delete-if
                                 (lambda (b)
                                   (unless (member (car b) '('some-name))
                                     (remprop (car b) 'properties)
                                     t))
                                 bs)))
                      *binfix*)))
     (assign-properties))))
You are a Common Lisp macro expert. Given this code pattern:
(f_n)

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

Macro definition:
(defmacro F_N ...)

Macroexpansion:
(lambda (&rest _))
Write a Common Lisp macro to handle this code pattern:
($+ result)

Problem: Macro call that should be transformed by $+

Macro definition:
(defmacro $+ (arg &rest args)
  `(construct-$+- +1 ,arg ,@args))

Macroexpansion:
(construct-$+- 1 result)
Define a macro that eliminates this repetitive pattern:
(min-of nil)

Issue: Macro call that should be transformed by MIN-OF

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

Macroexpansion:
(lc (nil) minimize)
Define a macro that eliminates this repetitive pattern:
(secase (car x) (:y (setf it :no)))

Issue: 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)))
Generate a defmacro form that transforms code like this:
(define-op (:= infix-op))

Pattern to recognize: 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))))
Define a macro that eliminates this repetitive pattern:
(-<>
  'some-name)

Issue: Macro call that should be transformed by -<>

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

Macroexpansion:
'some-name
You are a Common Lisp macro expert. Given this code pattern:
(bind ((obj (make-instance 'metabang-bind-class-2 :a 1 :b 2 :c 3 :d 4 :e 5)) ((:writable-accessors (my-a a) (my-c c) (d the-d)) obj)) (setf my-a 42) (list d my-c my-a (a obj)))

Write a macro that addresses: 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* ((obj (make-instance (quote metabang-bind-class-2) :a 1 :b 2 :c 3 :d 4 :e 5)) (#:|values-177| obj)) (declare (ignorable #:|values-177|)) (with-accessors ((my-a a) (my-c c) (d the-d)) #:|values-177| (progn (setf my-a 42) (list d my-c my-a (a obj)))))
You are a Common Lisp macro expert. Given this code pattern:
(ƒ→ nil :key nil)

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

Macro definition:
(defmacro Ƒ→ ...)

Macroexpansion:
(defn nil :key (&optional α)
      (let ((α (or α t)))
        (cond)))
Create a Common Lisp macro for the following transformation. Before code:
(cond-<>
  nil
  :key
  nil)

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

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

Macroexpansion:
(let* ((#:var138 nil)
       (#:var139
        (if :key
            (-<>
              #:var138)
            #:var138))
       (#:var140
        (if nil
            (-<>
              #:var139)
            #:var139)))
  #:var140)
Generate a defmacro form that transforms code like this:
(lret* ((type `(integer ,start (,end))) (len (- end start)) (vector (make-array len :element-type type))) (nlet lp ((i 0) (n start)) (declare (type array-index i n)) (if (= i len) vector (progn (setf (aref vector i) n) (lp (1+ i) (1+ n))))))

Pattern to recognize: 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* ((type (sb-int:quasiquote (integer #S(sb-impl::comma :expr start :kind 0) (#S(sb-impl::comma :expr end :kind 0))))) (len (- end start)) (vector (make-array len :element-type type))) (nlet lp ((i 0) (n start)) (declare (type array-index i n)) (if (= i len) vector (progn (setf (aref vector i) n) (lp (1+ i) (1+ n))))))
Write a Common Lisp macro to handle this code pattern:
(letmatch nil
    :key
  nil)

Problem: Macro call that should be transformed by LETMATCH

Macro definition:
(defmacro LETMATCH ...)

Macroexpansion:
(ifmatch (nil :key nil (error "LETMATCH:  mismatch.")))
Create a Common Lisp macro for the following transformation. Before code:
(match list ((list x) when (oddp x) x))

What needs to change: 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 (%if (consp list) (let ((#:g140 (car list)) (#:g141 (cdr list))) (declare (ignorable #:g140 #:g141)) (%if (%equals #:g141 nil) (%or (let ((x #:g140)) (if (oddp x) x (fail))) (fail)) (fail))) (fail)) nil)
Create a Common Lisp macro for the following transformation. Before code:
(defclass/std unknown () ((slot :unknown keywords :without-values)))

What needs to change: Macro call that should be transformed by defclass/std

Macro definition:
(defmacro defclass/std (name direct-superclasses direct-slots &rest options
                        &environment env)
  "Shortcut macro to the DEFCLASS macro.

  (defclass/std example ()
    ((slot1 slot2 slot3)))

  expands to:

  (DEFCLASS EXAMPLE ()
    ((SLOT1 :ACCESSOR SLOT1 :INITARG :SLOT1 :INITFORM NIL)
    (SLOT2 :ACCESSOR SLOT2 :INITARG :SLOT2 :INITFORM NIL)
    (SLOT3 :ACCESSOR SLOT3 :INITARG :SLOT3 :INITFORM NIL)))

  Each slot definition accepts options:

    :std 1 => changes the :initform to 1. It can be :unbound.
    :with or :with-prefix => creates accessors with the class name as prefix.

  See the README for more.

  See also `class/std' and `print-object/std'.
  "
  `(defclass ,name ,direct-superclasses
     ,(process-slots env direct-slots name)
     ,@options))

Macroexpansion:
(defclass unknown nil ((slot :accessor slot :initarg :slot :initform nil :unknown keywords :without-values)))
Write a Common Lisp macro to handle this code pattern:
(when (eql (top-sign) 'skip-first-funcall) (pop-sign))

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 (eql (top-sign) (quote skip-first-funcall)) (pop-sign))
Create a Common Lisp macro for the following transformation. Before code:
(without-symbol-access
  nil
  (progn))

What needs to change: Macro call that should be transformed by WITHOUT-SYMBOL-ACCESS

Macro definition:
(defmacro WITHOUT-SYMBOL-ACCESS ...)

Macroexpansion:
(let ((*symbol-access* nil))
  nil
  (progn))
Define a macro that eliminates this repetitive pattern:
(defsynonym repeat :repeat)

Issue: Macro call that should be transformed by defsynonym

Macro definition:
(defmacro defsynonym (symbol synonym)
  "Set SYNONYM for a SYMBOL. "
  `(eval-always
     (setf (get ',symbol 'synonym) ',synonym)))

Macroexpansion:
(eval-always (setf (get (quote repeat) (quote synonym)) (quote :repeat)))
Generate a defmacro form that transforms code like this:
(defun-compile-time screamer-error (header &rest args) (apply #'error (concatenate 'string header "~2%There are eight types of nondeterministic contexts: 1. the body of a function defined with SCREAMER::DEFUN 2. the body of a FOR-EFFECTS macro invocation 3. the body of an ALL-VALUES macro invocation 4. the first argument of a ONE-VALUE macro invocation 5. the body of a PRINT-VALUES macro invocation 6. the second argument of an ITH-VALUE macro invocation 7. the body of a POSSIBLY? macro invocation 8. the body of a NECESSARILY? macro invocation. Note that the default forms of &OPTIONAL and &KEY arguments and the initialization forms of &AUX variables are always deterministic contexts even though they may appear inside a SCREAMER::DEFUN.") args))

Pattern to recognize: 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 screamer-error (header &rest args) (apply (function error) (concatenate (quote string) header "~2%There are eight types of nondeterministic contexts: 1. the body of a function defined with SCREAMER::DEFUN 2. the body of a FOR-EFFECTS macro invocation 3. the body of an ALL-VALUES macro invocation 4. the first argument of a ONE-VALUE macro invocation 5. the body of a PRINT-VALUES macro invocation 6. the second argument of an ITH-VALUE macro invocation 7. the body of a POSSIBLY? macro invocation 8. the body of a NECESSARILY? macro invocation. Note that the default forms of &OPTIONAL and &KEY arguments and the initialization forms of &AUX variables are always deterministic contexts even though they may appear inside a SCREAMER::DEFUN.") args)) (eval-when (:compile-toplevel) (compile (quote screamer-error))))
Generate a defmacro form that transforms code like this:
(dynamic-progv nil
    (progn))

Pattern to recognize: Macro call that should be transformed by DYNAMIC-PROGV

Macro definition:
(defmacro DYNAMIC-PROGV ...)

Macroexpansion:
(let* ((#:fixed-symbols238 nil)
       (#:fixed-bindings239 (compute-bindings #:fixed-symbols238 (progn))))
  (dynamic-wind
    :proceed
    #:proceed240
    (progv #:fixed-symbols238 #:fixed-bindings239 (#:proceed240))))
Write a Common Lisp macro to handle this code pattern:
(->* nil nil)

Problem: Macro call that should be transformed by ->*

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

Macroexpansion:
(-> nil nil)
Write a Common Lisp macro to handle this code pattern:
(receive () (values 1))

Problem: Macro call that should be transformed by receive

Macro definition:
(defmacro receive (formals expr &body body)
  "Stricter version of `multiple-value-bind'.

Use `receive' when you want to enforce that EXPR should return a
certain number of values, or a minimum number of values.

If FORMALS is a proper list, then EXPR must return exactly as many
values -- no more and no less -- as there are variables in FORMALS.

If FORMALS is an improper list (VARS . REST), then EXPR must return at
least as many values as there are VARS, and any further values are
bound, as a list, to REST.

Lastly, if FORMALS is a symbol, bind that symbol to all the values
returned by EXPR, as if by `multiple-value-list'.

From Scheme (SRFI-8)."
  ;; It's probably not worth stack-allocating the thunk.
  (cond ((null formals)
         `(multiple-value-call
              (lambda ()
                ,@body)
            ,expr))
        ((atom formals)
         ;; This could also be written:
         #+(or) `(let ((,formals (multiple-value-list ,expr)))
                   ,@body)
         ;; But I want it to be possible to declare FORMALS to have
         ;; dynamic extent, and most Lisps support that for &rest
         ;; lists.
         `(multiple-value-call
              (lambda (&rest ,formals)
                ,@body)
            ,expr))
        ((proper-list-p formals)
         (when (intersection formals lambda-list-keywords)
           (error "Lambda list keywords in formals: ~a" formals))
         `(multiple-value-call
              (lambda ,formals
                ,@body)
            ,expr))
        (t (let* ((last (last formals))
                  (vars (append (butlast formals)
                                (list (car last))))
                  (rest (cdr last)))
             (when (intersection (cons rest vars) lambda-list-keywords)
               (error "Lambda list keywords in formals: ~a" formals))
             `(multiple-value-call
                  (lambda (,@vars &rest ,rest)
                    ,@body)
                ,expr)))))

Macroexpansion:
(multiple-value-call (lambda nil) (values 1))
You are a Common Lisp macro expert. Given this code pattern:
(-> :g () (put 1) 2)

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 nil (put 1) 2)
Write a Common Lisp macro to handle this code pattern:
(destructuring-methods nil
    nil)

Problem: Macro call that should be transformed by DESTRUCTURING-METHODS

Macro definition:
(defmacro DESTRUCTURING-METHODS ...)

Macroexpansion:
(let ((#:g131 nil))
  (typecase #:g131 ((not list) nil)))
Generate a defmacro form that transforms code like this:
(some-<> 'some-name)

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

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

Macroexpansion:
(let* ((#:g124 'some-name))
  #:g124)
Write a Common Lisp macro to handle this code pattern:
(defhandler function (function name) `(list ',function ,(if (function-name-p name) `',name (e name))))

Problem: Macro call that should be transformed by defhandler

Macro definition:
(defmacro defhandler (symbol lambda-list &body body)
  (let ((syms (force-list symbol)))
    (let ((func (intern (format nil "~A~A" 'hander- (first syms)))))
      `(progn
         (defun ,func ,lambda-list
           ,@body)
         (setf
          ,@(loop for sym in syms
               collect `(gethash ',sym *form-handler*)
               collect `',func))))))

Macroexpansion:
(progn (defun hander-function (function name) (sb-int:quasiquote (list (quote #S(sb-impl::comma :expr function :kind 0)) #S(sb-impl::comma :expr (if (function-name-p name) (sb-int:quasiquote (quote #S(sb-impl::comma :expr name :kind 0))) (e name)) :kind 0)))) (setf (gethash (quote function) *form-handler*) (quote hander-function)))
You are a Common Lisp macro expert. Given this code pattern:
(with-active-layers nil
  :key
  nil)

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

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

Macroexpansion:
(progn :key nil)
You are a Common Lisp macro expert. Given this code pattern:
(define-element-maker :linear-gradient "linearGradient" '(:id :x1 :y1 :x2 :y2))

Write a macro that addresses: Macro call that should be transformed by define-element-maker

Macro definition:
(defmacro define-element-maker (element name required-attributes)
  `(progn
     (defmethod assert-required-attributes ((element (eql ,element)) attributes)
       (declare (ignore element))
       (unless (evenp (length attributes))
         (warn "attribute list may be missing data: ~A" attributes))
       (let ((missing (set-difference ,required-attributes attributes)))
	 (when missing
	   (error 'missing-attributes :message (format nil "~A missing attributes: ~{~A~^ ~}" ,element missing)))))
     (defmethod make-svg-element ((element (eql ,element)) attributes)
       (when *check-required-attributes*
         (assert-required-attributes element attributes))
       (make-instance 'svg-element :name ,name :attributes attributes))))

Macroexpansion:
(progn (defmethod assert-required-attributes ((element (eql :linear-gradient)) attributes) (declare (ignore element)) (unless (evenp (length attributes)) (warn "attribute list may be missing data: ~A" attributes)) (let ((missing (set-difference (quote (:id :x1 :y1 :x2 :y2)) attributes))) (when missing (error (quote missing-attributes) :message (format nil "~A missing attributes: ~{~A~^ ~}" :linear-gradient missing))))) (defmethod make-svg-element ((element (eql :linear-gradient)) attributes) (when *check-required-attributes* (assert-required-attributes element attributes)) (make-instance (quote svg-element) :name "linearGradient" :attributes attributes)))
Generate a defmacro form that transforms code like this:
(enable-string-quote-syntax)

Pattern to recognize: Macro call that should be transformed by ENABLE-STRING-QUOTE-SYNTAX

Macro definition:
(defmacro ENABLE-STRING-QUOTE-SYNTAX ...)

Macroexpansion:
(eval-when (:compile-toplevel :execute)
  (setf *readtable* (copy-readtable *readtable*))
  (set-string-quote-syntax-in-readtable :start-character
                                        #\HALFWIDTH_LEFT_CORNER_BRACKET
                                        :end-character
                                        #\HALFWIDTH_RIGHT_CORNER_BRACKET
                                        :transformer #'identity)
  (values))