j14i/cl-macros huggingface dataset:
Write a Common Lisp macro to handle this code pattern:
(bind ((#2a((a b c) (d e f)) #2a((1 2 3) (4 5 6)))) (list a b c d e f))

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-167| #2A((1 2 3) (4 5 6))) (a (row-major-aref #:|values-167| 0)) (b (row-major-aref #:|values-167| 1)) (c (row-major-aref #:|values-167| 2)) (d (row-major-aref #:|values-167| 3)) (e (row-major-aref #:|values-167| 4)) (f (row-major-aref #:|values-167| 5))) (declare (ignorable #:|values-167|)) (progn (list a b c d e f)))
Create a Common Lisp macro for the following transformation. Before code:
(ps-once-only nil
  :key
  nil)

What needs to change: Macro call that should be transformed by PS-ONCE-ONLY

Macro definition:
(defmacro PS-ONCE-ONLY ...)

Macroexpansion:
(let* ()
  `(let* ()
     ,(let* ()
        :key
        nil)))
You are a Common Lisp macro expert. Given this code pattern:
(match maybe m ((just x) x) (nothing else))

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

Macro definition:
(defmacro match (adt obj &body clauses)
  "Perform pattern matching on OBJ with (adt-type) ADT.

Each clause must have the following syntax:

<var> := <symbol> | '_'
<lhs> := '_'
       | (<symbol> <var>*)
<clause> := (<lhs> <lisp code>)

The symbol '_' denotes a wildcard, as well as a fallthough.

Note that pattern matching is only shallow (patterns are one-level
deep).
"
  (assert (symbolp adt)
          (adt)
          "MATCH requires a symbol for the first argument. Given ~S."
          adt)

  (let ((ctors (mapcar #'car (get-constructors adt)))
        (types (mapcar (lambda (clause)
                         (ensure-car (car clause)))
                       clauses))
        (once (gensym "OBJ-")))

    ;; Check for duplicate matches.
    (let ((dupes (duplicates types)))
      (when dupes
        (warn "Duplicate matching clauses exist. Duplicate pattern ~
               constructors:~{ ~S~}"
              dupes)))

    ;; Check for match exhaustiveness.
    (unless (some #'wild? types)
      (let ((diff (set-difference ctors types)))
        (when diff
          (warn "Non-exhaustive match on ~A data ~
                 type. Missing cases:~{ ~S~}" adt diff))))

    ;; Generate the matching code.
    `(let ((,once ,obj))
       (check-type ,once ,adt)
       (etypecase ,once
         ,@(loop :for (bindings . body) :in clauses
                 :collect (let ((type (ensure-car bindings)))
                            (if (wild? type)
                                `(t ,@body)
                                `(,type
                                  (with-data ,(ensure-list bindings)
                                             ,once
                                    ,@body)))))))))

Macroexpansion:
(let ((#:obj-147 m)) (check-type #:obj-147 maybe) (etypecase #:obj-147 (just (with-data (just x) #:obj-147 x)) (nothing (with-data (nothing) #:obj-147 else))))
You are a Common Lisp macro expert. Given this code pattern:
(dig 'some-name)

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

Macro definition:
(defmacro DIG ...)

Macroexpansion:
(dig 1 'some-name)
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:
(as-> nil nil)
You are a Common Lisp macro expert. Given this code pattern:
(when (slot-boundp item slot) (when (eq (slot-value item slot) nil) (setf subnodes (remove slot subnodes))) (let ((position (position slot subnodes))) (setf (slot-value node-copy slot) (if position (nth position subnode-copies) (slot-value item slot)))))

Write a macro that addresses: 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 (slot-boundp item slot) (progn (when (eq (slot-value item slot) nil) (setf subnodes (remove slot subnodes))) (let ((position (position slot subnodes))) (setf (slot-value node-copy slot) (if position (nth position subnode-copies) (slot-value item slot))))))
Create a Common Lisp macro for the following transformation. Before code:
(with-env [str 0])

What needs to change: 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 (#:g123) (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 #:g123 (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)) [str 0])) (setf (find-class (quote foo) nil) nil) (setf (find-class (quote bar) nil) nil) #:g123)
You are a Common Lisp macro expert. Given this code pattern:
(without-symbol-access
  nil
  nil)

Write a macro that addresses: Macro call that should be transformed by WITHOUT-SYMBOL-ACCESS

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

Macroexpansion:
(let ((*symbol-access* nil))
  nil
  nil)
Generate a defmacro form that transforms code like this:
(matrix-typecase nil)

Pattern to recognize: Macro call that should be transformed by MATRIX-TYPECASE

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

Macroexpansion:
nil
Generate a defmacro form that transforms code like this:
(define-simple-definition-resolver symbol-macro designator-symbol-macro-p)

Pattern to recognize: 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 symbol-macro (symbol-macro #:package141) (when (ignore-errors (designator-symbol-macro-p symbol-macro)) (list (make-instance (quote symbol-macro) :designator symbol-macro :package #:package141))))
Define a macro that eliminates this repetitive pattern:
($/ "[_]*.mr." "i")

Issue: Macro call that should be transformed by $/

Macro definition:
(defmacro $/ (regex options)
  `(make-bson-regex (empty-str ,regex) ,options))

Macroexpansion:
(make-bson-regex (empty-str "[_]*.mr.") "i")
Define a macro that eliminates this repetitive pattern:
(cond->)

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

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

Macroexpansion:
nil
Write a Common Lisp macro to handle this code pattern:
(enable-sharp-boolean-syntax)

Problem: Macro call that should be transformed by ENABLE-SHARP-BOOLEAN-SYNTAX

Macro definition:
(defmacro ENABLE-SHARP-BOOLEAN-SYNTAX ...)

Macroexpansion:
(eval-when (:compile-toplevel :execute)
  (setf *readtable* (copy-readtable *readtable*))
  (set-sharp-boolean-syntax-in-readtable)
  (values))
Generate a defmacro form that transforms code like this:
(collect-file nil nil)

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

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

Macroexpansion:
(common-lisp:let* ((#:generator-542 (generator nil)) #:items-536 (#:out-538 t))
  (declare (type generator #:generator-542)
           (type boolean #:out-538))
  (with-open-file (#:outfile-535 nil :direction :output)
    (tagbody
     #:ll-543
      (setq #:items-536 (next-in #:generator-542 (go end)))
      (common-lisp:funcall #'print #:items-536 #:outfile-535)
      (go #:ll-543)
     end))
  #:out-538)
Write a Common Lisp macro to handle this code pattern:
(enable-readtime-wrapper-syntax 'some-name)

Problem: Macro call that should be transformed by ENABLE-READTIME-WRAPPER-SYNTAX

Macro definition:
(defmacro ENABLE-READTIME-WRAPPER-SYNTAX ...)

Macroexpansion:
(eval-when (:compile-toplevel :execute)
  (setf *readtable* (copy-readtable *readtable*))
  (set-readtime-wrapper-syntax-in-readtable 'some-name #\RIGHT_CURLY_BRACKET)
  (values))
Define a macro that eliminates this repetitive pattern:
(true "Happy")

Issue: 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 "Happy")) :value-form (quote "Happy") :body (lambda nil "Happy") :expected (quote t) :comparison (quote geq)))
Define a macro that eliminates this repetitive pattern:
(defhandler labels (labels bindings &rest body) `(with-imposed-bindings (,labels ,(clean-fbindings bindings) ,(declare-fbindings-ignorable bindings) (list* ',labels ,(dump-fbindings bindings) (m-list ,@body)))))

Issue: 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-labels (labels bindings &rest body) (sb-int:quasiquote (with-imposed-bindings (#S(sb-impl::comma :expr labels :kind 0) #S(sb-impl::comma :expr (clean-fbindings bindings) :kind 0) #S(sb-impl::comma :expr (declare-fbindings-ignorable bindings) :kind 0) (list* (quote #S(sb-impl::comma :expr labels :kind 0)) #S(sb-impl::comma :expr (dump-fbindings bindings) :kind 0) (m-list #S(sb-impl::comma :expr body :kind 2))))))) (setf (gethash (quote labels) *form-handler*) (quote hander-labels)))
Create a Common Lisp macro for the following transformation. Before code:
(some->> nil)

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

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

Macroexpansion:
(let* ((#:|some120| nil))
  #:|some120|)
You are a Common Lisp macro expert. Given this code pattern:
(define-binary-op-mapping-definer define-comparison-ops `(progn (defmethod ,op ((x memptr) (y memptr)) (if (and (eq (memptr-mem x) (memptr-mem y)) (,cl (memptr-ptr x) (memptr-ptr y))) 1 0)) (defmethod ,op ((x number) (y number)) (if (,cl x y) 1 0))))

Write a macro that addresses: Macro call that should be transformed by define-binary-op-mapping-definer

Macro definition:
(defmacro define-binary-op-mapping-definer (name &body body)
  `(defmacro ,name (&rest map)
     `(progn ,@(loop for (vacietis cl) on map by #'cddr collect
                    (let ((op (find-symbol (symbol-name vacietis) '#:vacietis.c)))
                      ,@body)))))

Macroexpansion:
(defmacro define-comparison-ops (&rest map) (sb-int:quasiquote (progn #S(sb-impl::comma :expr (loop for (vacietis cl) on map by (function cddr) collect (let ((op (find-symbol (symbol-name vacietis) (quote #:vacietis.c)))) (sb-int:quasiquote (progn (defmethod #S(sb-impl::comma :expr op :kind 0) ((x memptr) (y memptr)) (if (and (eq (memptr-mem x) (memptr-mem y)) (#S(sb-impl::comma :expr cl :kind 0) (memptr-ptr x) (memptr-ptr y))) 1 0)) (defmethod #S(sb-impl::comma :expr op :kind 0) ((x number) (y number)) (if (#S(sb-impl::comma :expr cl :kind 0) x y) 1 0)))))) :kind 2))))
You are a Common Lisp macro expert. Given this code pattern:
(false (sleep 1))

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

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

Macroexpansion:
(eval-in-context *context* (make-instance (quote comparison-result) :expression (quote (false (sleep 1))) :value-form (quote (sleep 1)) :body (lambda nil (sleep 1)) :expected (quote nil) :comparison (quote geq)))
Create a Common Lisp macro for the following transformation. Before code:
(destructure-specialized-lambda-list descriptive-lambda-list vanilla-lambda-list type-list specialized-lambda-list (with-effective-qualifier generic-function qualifier `(%lay-method-base-for-dispatch ,generic-function ,qualifier ,type-list ,descriptive-lambda-list (dispatch ,generic-function ,qualifier ,specialized-lambda-list) ,@body)))

What needs to change: Macro call that should be transformed by destructure-specialized-lambda-list

Macro definition:
(defmacro destructure-specialized-lambda-list (descriptive-lambda-list-sym vanilla-lambda-list-sym type-list-sym specialized-lambda-list &body body)
  "if specialized-lambda-list is ((a integer) b):
descriptive-lambda-list will be ((x integer) (x t))
type-list will be (integer t) and vanilla-lambda-list is (a b)"
  (let ((item (gensym)))
    `(let* ((,descriptive-lambda-list-sym
             (loop :for ,item :in ,specialized-lambda-list
                :if (listp ,item)
                :collect ,item
                :else :collect (list ,item t)))
            (,vanilla-lambda-list-sym (mapcar #'first ,descriptive-lambda-list-sym))
            (,type-list-sym (mapcar #'second ,descriptive-lambda-list-sym)))
       (declare (ignorable ,descriptive-lambda-list-sym ,vanilla-lambda-list-sym ,type-list-sym))
       ,@body)))

Macroexpansion:
(let* ((descriptive-lambda-list (loop :for #:g125 :in specialized-lambda-list :if (listp #:g125) :collect #:g125 :else :collect (list #:g125 t))) (vanilla-lambda-list (mapcar (function first) descriptive-lambda-list)) (type-list (mapcar (function second) descriptive-lambda-list))) (declare (ignorable descriptive-lambda-list vanilla-lambda-list type-list)) (with-effective-qualifier generic-function qualifier (sb-int:quasiquote (%lay-method-base-for-dispatch #S(sb-impl::comma :expr generic-function :kind 0) #S(sb-impl::comma :expr qualifier :kind 0) #S(sb-impl::comma :expr type-list :kind 0) #S(sb-impl::comma :expr descriptive-lambda-list :kind 0) (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)) #S(sb-impl::comma :expr body :kind 2)))))
You are a Common Lisp macro expert. Given this code pattern:
(defmethod* nil
    nil)

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

Macro definition:
(defmacro DEFMETHOD* ...)

Macroexpansion:
(defmethod nil (the t ()))
Generate a defmacro form that transforms code like this:
(mvlet* ((x)) x)

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

Macro definition:
(defmacro mvlet* ((&rest bindings) &body body &environment env)
  "Expand a series of nested `multiple-value-bind' forms.

`mvlet*' is similar in intent to Scheme’s `let-values', but with a
different and less parenthesis-intensive syntax. Each binding is a
list of

    (var var*... expr)

A simple example should suffice to show both the implementation and
the motivation:

    (defun uptime (seconds)
      (mvlet* ((minutes seconds (truncate seconds 60))
               (hours minutes (truncate minutes 60))
               (days hours (truncate hours 24)))
        (declare ((integer 0 *) days hours minutes seconds))
        (fmt \"~d day~:p, ~d hour~:p, ~d minute~:p, ~d second~:p\"
             days hours minutes seconds)))

Note that declarations work just like `let*'."
  (cond ((null bindings)
         `(locally ,@body))
        ((every #'simple-binding-p bindings)
         `(let* ,bindings ,@body))
        (t (multiple-value-bind (body decls)
               (parse-body body)
             (let* ((bindings (canonicalize-bindings bindings))
                    (mvbinds (member-if-not #'simple-binding-p bindings))
                    (simple-binds (ldiff bindings mvbinds)))
               (if simple-binds
                   (multiple-value-bind (local other)
                       (partition-declarations (mapcar #'car simple-binds) decls env)
                     `(let* ,simple-binds
                        ,@local
                        (mvlet* ,mvbinds
                          ,@other
                          ,@body)))
                   (let* ((vars (butlast (car bindings)))
                          (expr (lastcar (car bindings))))
                     (multiple-value-bind (local other)
                         (partition-declarations vars decls env)
                       `(multiple-value-bind ,vars
                            ,expr
                          ,@local
                          (mvlet* ,(cdr bindings)
                            ,@other
                            ,@body))))))))))

Macroexpansion:
(let* ((x)) x)
Define a macro that eliminates this repetitive pattern:
(form-fiddle:lambda-forms `(lambda () ,@body))

Issue: Macro call that should be transformed by for

Macro definition:
(defmacro for (&environment env bindings &body body)
  (let ((*environment* env))
    (multiple-value-bind (bind-init bind-forms bind-exit bind-post) (convert-bindings bindings)
      (multiple-value-bind (clause-init body-forms clause-exit) (convert-clauses body)
        `(with-interleaving
           ,@bind-init
           ,@clause-init
           (with-for-block ()
             (with-for-tagbody
                 (progn ,@bind-forms
                        ,@body-forms
                        ,@bind-post)
               (return-for
                ,@clause-exit
                ,@bind-exit))))))))

Macroexpansion:
(form-fiddle:lambda-forms (sb-int:quasiquote (lambda nil #S(sb-impl::comma :expr body :kind 2))))
Define a macro that eliminates this repetitive pattern:
(signal-syntax-error* error-pos "No character for hex-code ~X." number)

Issue: Macro call that should be transformed by signal-syntax-error*

Macro definition:
(defmacro signal-syntax-error* (pos format-control &rest format-arguments)
  `(error 'ppcre-syntax-error
          :pos ,pos
          :format-control ,format-control
          :format-arguments (list ,@format-arguments)))

Macroexpansion:
(error (quote ppcre-syntax-error) :pos error-pos :format-control "No character for hex-code ~X." :format-arguments (list number))
Create a Common Lisp macro for the following transformation. Before code:
(nth-value-or 1 (values 1 nil 1) (values 2 2 2))

What needs to change: Macro call that should be transformed by nth-value-or

Macro definition:
(defmacro nth-value-or (nth-value &body forms)
  "Evaluates FORM arguments one at a time, until the NTH-VALUE returned by one
of the forms is true. It then returns all the values returned by evaluating
that form. If none of the forms return a true nth value, this form returns
NIL."
  (once-only (nth-value)
    (with-gensyms (values)
      `(let ((,values (multiple-value-list ,(first forms))))
         (if (nth ,nth-value ,values)
             (values-list ,values)
             ,(if (rest forms)
                  `(nth-value-or ,nth-value ,@(rest forms))
                  nil))))))

Macroexpansion:
(let ((#:nth-value149 1)) (let ((#:values150 (multiple-value-list (values 1 nil 1)))) (if (nth #:nth-value149 #:values150) (values-list #:values150) (nth-value-or #:nth-value149 (values 2 2 2)))))
Generate a defmacro form that transforms code like this:
(defvar* nil nil)

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

Macro definition:
(defmacro DEFVAR* ...)

Macroexpansion:
(defvar/param defvar nil nil nil)