j14i/cl-macros huggingface dataset:
Create a Common Lisp macro for the following transformation. Before code:
(mvlet* ((x 2) (y x)) x y)

What needs to change: 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 2) (y x)) x y)
Create a Common Lisp macro for the following transformation. Before code:
(augment *initial* init)

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

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

Macroexpansion:
(setf *initial* (nconc *initial* init))
Write a Common Lisp macro to handle this code pattern:
(*> +open-brace+ +consume-space+)

Problem: Macro call that should be transformed by *>

Macro definition:
(defmacro *> (parser &rest parsers)
  "Combination of parsers yielding the result of the rightmost one."
  (let ((offset (gensym "*>-OFFSET")))
    `(lambda (,offset)
       ,(reduce (lambda (i p)
                  (let ((res  (gensym "*>-RES"))
                        (next (gensym "*>-NEXT")))
                    `(multiple-value-bind (,res ,next) ,i
                       (if (ok? ,res)
                           (funcall ,p ,next)
                           (fail ,next)))))
                parsers
                :initial-value `(funcall ,parser ,offset)))))

Macroexpansion:
(lambda (#:*>-offset178) (multiple-value-bind (#:*>-res179 #:*>-next180) (funcall +open-brace+ #:*>-offset178) (if (ok? #:*>-res179) (funcall +consume-space+ #:*>-next180) (fail #:*>-next180))))
Write a Common Lisp macro to handle this code pattern:
(check-cursor-attached cluffer:backward-item (cursor))

Problem: Macro call that should be transformed by check-cursor-attached

Macro definition:
(defmacro check-cursor-attached (name arguments)
  (let ((args (substitute '(cursor cluffer:cursor) 'cursor arguments)))
    `(defmethod ,name :before ,args
       (declare (ignore ,@(set-difference (remove 'cursor arguments)
                                          lambda-list-keywords)))
       (unless (cluffer:cursor-attached-p cursor)
         (error 'cluffer:cursor-detached)))))

Macroexpansion:
(defmethod cluffer:backward-item :before ((cursor cluffer:cursor)) (declare (ignore)) (unless (cluffer:cursor-attached-p cursor) (error (quote cluffer:cursor-detached))))
Define a macro that eliminates this repetitive pattern:
(when 'some-name)

Issue: Macro call that should be transformed by WHEN

Macro definition:
(defmacro WHEN ...)

Macroexpansion:
(if 'some-name
    nil)
Create a Common Lisp macro for the following transformation. Before code:
(resolving
  nil)

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

Macro definition:
(defmacro RESOLVING ...)

Macroexpansion:
(resolve
  nil)
Define a macro that eliminates this repetitive pattern:
(cond->> nil)

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

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

Macroexpansion:
(let* ((#:g135 nil))
  #:g135)
You are a Common Lisp macro expert. Given this code pattern:
(builder (:session :keep-empty nil) (lambda (env) (when (string= (getf env :path-info) "/session") (setf (gethash "user" (getf env :lack.session)) "Eitaro")) '(200 () ("hi"))))

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 (lambda (#:app224) (funcall (find-middleware :session) #:app224 :keep-empty nil)))) :initial-value (to-app (lambda (env) (when (string= (getf env :path-info) "/session") (setf (gethash "user" (getf env :lack.session)) "Eitaro")) (quote (200 nil ("hi"))))) :from-end t)
Create a Common Lisp macro for the following transformation. Before code:
(with-quote-char (format out "~{~{~A;~%~}~^~%~}" (mapcar (lambda (class) (mapcar #'sxql:yield (table-definition class))) (all-dao-classes))) (format out "~2&~A;~%" (sxql:yield (schema-migrations-table-definition))))

What needs to change: Macro call that should be transformed by with-quote-char

Macro definition:
(defmacro with-quote-char (&body body)
  `(let ((sxql:*quote-character* (or sxql:*quote-character*
                                     (connection-quote-character *connection*))))
     ,@body))

Macroexpansion:
(let ((sxql/sql-type:*quote-character* (or sxql/sql-type:*quote-character* (connection-quote-character *connection*)))) (format out "~{~{~A;~%~}~^~%~}" (mapcar (lambda (class) (mapcar (function sxql/sql-type:yield) (table-definition class))) (all-dao-classes))) (format out "~2&~A;~%" (sxql/sql-type:yield (schema-migrations-table-definition))))
Define a macro that eliminates this repetitive pattern:
(when (node-slot linebreak) (format stream "~&~a" indent))

Issue: 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 (node-slot linebreak) (format stream "~&~a" indent))
Define a macro that eliminates this repetitive pattern:
(match either m ((right x) (funcall f x)) ((left b) (left b)))

Issue: 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-149 m)) (check-type #:obj-149 either) (etypecase #:obj-149 (right (with-data (right x) #:obj-149 (funcall f x))) (left (with-data (left b) #:obj-149 (left b)))))
Create a Common Lisp macro for the following transformation. Before code:
(with-rules nil
  nil)

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

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

Macroexpansion:
(dolist (nil (alexandria:hash-table-keys cl-rules.core::*rules*)) nil)
You are a Common Lisp macro expert. Given this code pattern:
(augment prev-code prev)

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

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

Macroexpansion:
(setf prev-code (nconc prev-code prev))
Write a Common Lisp macro to handle this code pattern:
(ƒƒ 'some-name)

Problem: Macro call that should be transformed by ƑƑ

Macro definition:
(defmacro ƑƑ ...)

Macroexpansion:
(defun 'some-name (&optional α) (cond))
Write a Common Lisp macro to handle this code pattern:
(c-assert (or (null before) (eql (fm-parent kid) (fm-parent before))))

Problem: Macro call that should be transformed by c-assert

Macro definition:
(defmacro c-assert (assertion &optional places fmt$ &rest fmt-args)
  (declare (ignorable assertion places fmt$ fmt-args))
   #+(or)`(progn) 
  `(unless *stop*
     (unless ,assertion
       ,(if fmt$
            `(c-break ,fmt$ ,@fmt-args)
          `(c-break "failed assertion: ~a" ',assertion)))))

Macroexpansion:
(unless *stop* (unless (or (null before) (eql (fm-parent kid) (fm-parent before))) (c-break "failed assertion: ~a" (quote (or (null before) (eql (fm-parent kid) (fm-parent before)))))))
Generate a defmacro form that transforms code like this:
($map-reduce "foo" m r :out "testit" :query ($> "l" -900))

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

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

Macroexpansion:
(db.find "$cmd" (kv (kv "mapreduce" "foo") (kv "map" (or (jsdef m) (quote m))) (kv "reduce" (or (jsdef r) (quote r))) (when nil (kv "finalize" (jsdef nil))) (kv "out" (if "testit" "testit" (concatenate (quote string) "mr." "foo"))) (kv "verbose" t) (kv "limit" 0) (kv "keeptemp" nil) (kv "query" ($> "l" -900))))
Create a Common Lisp macro for the following transformation. Before code:
(without-package-lock (:common-lisp #+lispworks :implementation) (defmethod print-object :around ((rt readtable) stream) (let ((name (readtable-name rt))) (if name (print-unreadable-object (rt stream :type nil :identity t) (format stream "~A ~S" :named-readtable name)) (call-next-method)))))

What needs to change: Macro call that should be transformed by without-package-lock

Macro definition:
(defmacro without-package-lock ((&rest package-names) &body body)
  (declare (ignorable package-names))
  #+clisp
  (return-from without-package-lock
    `(ext:without-package-lock (,@package-names) ,@body))
  #+lispworks
  (return-from without-package-lock
    `(let ((hcl:*packages-for-warn-on-redefinition*
             (set-difference hcl:*packages-for-warn-on-redefinition*
                             '(,@package-names)
                             :key (lambda (package-designator)
                                    (if (packagep package-designator)
                                        (package-name package-designator)
                                        package-designator))
                             :test #'string=)))
       ,@body))
  `(progn ,@body))

Macroexpansion:
(progn (defmethod print-object :around ((rt readtable) stream) (let ((name (readtable-name rt))) (if name (print-unreadable-object (rt stream :type nil :identity t) (format stream "~A ~S" :named-readtable name)) (call-next-method)))))
You are a Common Lisp macro expert. Given this code pattern:
(defrte nil nil)

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

Macro definition:
(defmacro DEFRTE ...)

Macroexpansion:
(eval-when (:compile-toplevel :load-toplevel :execute)
  (setf (getf (symbol-plist '-nil) :rte-pattern) 'nil
        (gethash 'nil *rte-hash*) 'nil)
  (defun -nil (seq)
    (declare (optimize (speed 3) (debug 0) (safety 0)))
    (block check
      (typecase seq
        (list
         (tagbody
           (go 1)
          1
           (if (null seq)
               (return-from check nil)
               (case (pop seq) (t (return-from check nil))))))
        (simple-vector
         (let ((i 0) (len (length seq)))
           (declare (type (and unsigned-byte fixnum) i len)
                    (ignorable len))
           (tagbody
             (go 1)
            1
             (if (>= i len)
                 (return-from check nil)
                 (case (prog1 (svref seq i) (incf i))
                   (t (return-from check nil)))))))
        (vector
         (let ((i 0) (len (length seq)))
           (declare (type (and fixnum unsigned-byte) i len)
                    (ignorable len))
           (tagbody
             (go 1)
            1
             (if (>= i len)
                 (return-from check nil)
                 (case (prog1 (aref seq i) (incf i))
                   (t (return-from check nil)))))))
        (sequence
         (let ((i 0) (len (sb-sequence:length seq)))
           (declare (type (and fixnum unsigned-byte) i len)
                    (ignorable len))
           (tagbody
             (go 1)
            1
             (if (or (sb-sequence:emptyp seq) (>= i len))
                 (return-from check nil)
                 (case (prog1 (sb-sequence:elt seq i) (incf i))
                   (t (return-from check nil)))))))
        (t nil)))))
Generate a defmacro form that transforms code like this:
(signal-syntax-error "Unknown symbol ~A in character class." item)

Pattern to recognize: Macro call that should be transformed by signal-syntax-error

Macro definition:
(defmacro signal-syntax-error (format-control &rest format-arguments)
  `(signal-syntax-error* nil ,format-control ,@format-arguments))

Macroexpansion:
(signal-syntax-error* nil "Unknown symbol ~A in character class." item)
Create a Common Lisp macro for the following transformation. Before code:
(with-data (rect x y) pt (set-data pt (rect y x)))

What needs to change: Macro call that should be transformed by with-data

Macro definition:
(defmacro with-data ((name &rest vars) obj &body body)
  "Destructure the ADT value OBJ, whose constructor is NAME. VARS must
be symbol which will be bound, or they must be the symbol '_', which
means the value will not be bound."
  (let* ((once (gensym "ONCE-"))
         (bindings (loop :for i :from 0
                         :for v :in vars
                         :when (not (wild? v))
                           :collect `(,v (,(field name i)
                                          ,once)))))
    `(let ((,once ,obj))
       (declare (ignorable ,once))
       (let (,@bindings)
         ,@body))))

Macroexpansion:
(let ((#:once-146 pt)) (declare (ignorable #:once-146)) (let ((x (rect%0 #:once-146)) (y (rect%1 #:once-146))) (set-data pt (rect y x))))
Generate a defmacro form that transforms code like this:
(define EXIT_FAILURE 1)

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

Macro definition:
(defmacro define (name value &rest docstring)
  "Like a #define but also visible to Lisp code."
  `(progn
     (eval-when (:compile-toplevel :load-toplevel :execute)
       (defvar ,(pp-defines *package*) (make-hash-table))
       (setf (gethash ',name ,(pp-defines *package*)) ,(prin1-to-string value)))
     (defparameter ,name ,value ,@docstring)))

Macroexpansion:
(progn (eval-when (:compile-toplevel :load-toplevel :execute) (defvar *preprocessor-defines* (make-hash-table)) (setf (gethash (quote exit_failure) *preprocessor-defines*) #A((1) base-char . "1"))) (defparameter exit_failure 1))
Write a Common Lisp macro to handle this code pattern:
(def-neo4j-fun get-node (node-id) :get (:uri-spec (if node-id (format nil "node/~A" node-id) "")) (:status-handlers (200 (decode-neo4j-json-output body)) (404 (error 'node-not-found-error :uri uri))))

Problem: Macro call that should be transformed by def-neo4j-fun

Macro definition:
(defmacro def-neo4j-fun (name lambda-list method &rest args)
  `(progn
     (defun ,name (&key ,@lambda-list)
       (let ((uri ,(cadr (assoc :uri-spec args)))
             (json (encode-neo4j-json-payload ,@(aif (assoc :encode args)
                                                     (cdr it)
                                                     (list '() :string)))))
         (make-neo4j-request ,method uri json
                             (list ,@(mapcar (lambda (handler)
                                               `(list ,(car handler) (lambda (body uri json)
                                                                  ,(cadr handler))))
                                             (cdr (assoc :status-handlers args)))))))))

Macroexpansion:
(progn (defun get-node (&key node-id) (let ((uri (if node-id (format nil "node/~A" node-id) "")) (json (encode-neo4j-json-payload nil :string))) (make-neo4j-request :get uri json (list (list 200 (lambda (body uri json) (decode-neo4j-json-output body))) (list 404 (lambda (body uri json) (error (quote node-not-found-error) :uri uri))))))))
Generate a defmacro form that transforms code like this:
(alist-bind (type) form (alist-bind ((type-tag :tag)) type (cond ((or (string= ":char" type-tag) (string= ":unsigned-char" type-tag)) '((:string))) (t `((:pointer ,@(parse-type type type-tag)))))))

Pattern to recognize: Macro call that should be transformed by alist-bind

Macro definition:
(defmacro alist-bind ((&rest vars) alist &body body)
  "Inefficient but doesn't really matter here"
  (once-only (alist)
    `(let (,@(mapcar (lambda (x)
                       (if (consp x)
                           `(,(car x) (aval ,(cadr x) ,alist))
                           `(,x (aval ,(make-keyword x) ,alist))))
                     vars))
       ,@body)))

Macroexpansion:
(let ((#:alist234 form)) (let ((type (aval :type #:alist234))) (alist-bind ((type-tag :tag)) type (cond ((or (string= ":char" type-tag) (string= ":unsigned-char" type-tag)) (quote ((:string)))) (t (sb-int:quasiquote ((:pointer #S(sb-impl::comma :expr (parse-type type type-tag) :kind 2)))))))))
Create a Common Lisp macro for the following transformation. Before code:
(letrec nil
  nil)

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

Macro definition:
(defmacro LETREC ...)

Macroexpansion:
(let ()
  (flet ()
    nil
    (setf)
    nil))
Create a Common Lisp macro for the following transformation. Before code:
(with-additional-indent (reporter stream "× ") (let ((description (possible-report-description report)) (duration (slot-value report 'duration))) (when description (format/indent reporter stream description)) (when duration (format stream " ") (print-duration stream duration (slot-value report 'slow-threshold)))) (when (slot-value report 'description) (format/indent reporter stream (concatenate 'string "~&" (report-expected-line report)))))

What needs to change: 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* (+ *additional-indent* 2))) (declare (ignorable first-line-indent)) (write-string "× " stream) (let ((description (possible-report-description report)) (duration (slot-value report (quote duration)))) (when description (format/indent reporter stream description)) (when duration (format stream " ") (print-duration stream duration (slot-value report (quote slow-threshold))))) (when (slot-value report (quote description)) (format/indent reporter stream (concatenate (quote string) "~&" (report-expected-line report))))))
Generate a defmacro form that transforms code like this:
(-> :two () (increment))

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

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

Macroexpansion:
(atomically :two nil (increment))
Create a Common Lisp macro for the following transformation. Before code:
(defproto 'some-name)

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

Macro definition:
(defmacro DEFPROTO ...)

Macroexpansion:
(progn
 (declaim (special (quote some-name)))
 (eval-when (:compile-toplevel))
 (setf (symbol-value ''some-name)
         (ensure-object (when (boundp ''some-name) (symbol-value ''some-name))
                        (list) :properties (list) :nickname ''some-name)))
Write a Common Lisp macro to handle this code pattern:
(drelet* 'some-name)

Problem: Macro call that should be transformed by DRELET*

Macro definition:
(defmacro DRELET* ...)

Macroexpansion:
(dynamic-relet* 'some-name)