[User]
Generate a defmacro form that transforms code like this:
(defun-compile-time walk-function-call (map-function reduce-function screamer? partial? nested? form environment) (unless (null (rest (last form))) (error "Improper function call form: ~S" form)) (cond ((lambda-expression? (first form)) (if reduce-function (funcall reduce-function (funcall map-function form 'lambda-call) (funcall reduce-function (reduce reduce-function (mapcar #'(lambda (subform) (walk map-function reduce-function screamer? partial? nested? subform environment)) (rest form))) (funcall reduce-function (walk-lambda-list map-function reduce-function screamer? partial? nested? (second (first form)) environment) (reduce reduce-function (mapcar #'(lambda (subform) (walk map-function reduce-function screamer? partial? nested? subform environment)) (peal-off-documentation-string-and-declarations (rest (rest (first form))) t)))))) (funcall map-function form 'lambda-call))) ((valid-function-name? (first form)) (if (symbolp (first form)) (if reduce-function (funcall reduce-function (funcall map-function form 'symbol-call) (reduce reduce-function (mapcar #'(lambda (subform) (walk map-function reduce-function screamer? partial? nested? subform environment)) (rest form)))) (funcall map-function form 'symbol-call)) (if reduce-function (funcall reduce-function (funcall map-function form 'setf-call) (reduce reduce-function (mapcar #'(lambda (subform) (walk map-function reduce-function screamer? partial? nested? subform environment)) (rest form)))) (funcall map-function form 'setf-call)))) (t (error "CAR of form ~S is not a valid function" form))))

Pattern to recognize: Macro call that should be transformed by defun-compile-time

(defun-compile-time walk-function-call (map-function reduce-function screamer? partial? nested? form environment) (unless (null (rest (last form))) (error "Improper function call form: ~S" form)) (cond ((lambda-expression? (first form)) (if reduce-function (funcall reduce-function (funcall map-function form 'lambda-call) (funcall reduce-function (reduce reduce-function (mapcar #'(lambda (subform) (walk map-function reduce-function screamer? partial? nested? subform environment)) (rest form))) (funcall reduce-function (walk-lambda-list map-function reduce-function screamer? partial? nested? (second (first form)) environment) (reduce reduce-function (mapcar #'(lambda (subform) (walk map-function reduce-function screamer? partial? nested? subform environment)) (peal-off-documentation-string-and-declarations (rest (rest (first form))) t)))))) (funcall map-function form 'lambda-call))) ((valid-function-name? (first form)) (if (symbolp (first form)) (if reduce-function (funcall reduce-function (funcall map-function form 'symbol-call) (reduce reduce-function (mapcar #'(lambda (subform) (walk map-function reduce-function screamer? partial? nested? subform environment)) (rest form)))) (funcall map-function form 'symbol-call)) (if reduce-function (funcall reduce-function (funcall map-function form 'setf-call) (reduce reduce-function (mapcar #'(lambda (subform) (walk map-function reduce-function screamer? partial? nested? subform environment)) (rest form)))) (funcall map-function form 'setf-call)))) (t (error "CAR of form ~S is not a valid function" form))))

[Assistant]
(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))))

;; macroexpand:
(eval-when (:compile-toplevel :load-toplevel :execute) (common-lisp:defun walk-function-call (map-function reduce-function screamer? partial? nested? form environment) (unless (null (rest (last form))) (error "Improper function call form: ~S" form)) (cond ((lambda-expression? (first form)) (if reduce-function (funcall reduce-function (funcall map-function form (quote lambda-call)) (funcall reduce-function (reduce reduce-function (mapcar (function (lambda (subform) (walk map-function reduce-function screamer? partial? nested? subform environment))) (rest form))) (funcall reduce-function (walk-lambda-list map-function reduce-function screamer? partial? nested? (second (first form)) environment) (reduce reduce-function (mapcar (function (lambda (subform) (walk map-function reduce-function screamer? partial? nested? subform environment))) (peal-off-documentation-string-and-declarations (rest (rest (first form))) t)))))) (funcall map-function form (quote lambda-call)))) ((valid-function-name? (first form)) (if (symbolp (first form)) (if reduce-function (funcall reduce-function (funcall map-function form (quote symbol-call)) (reduce reduce-function (mapcar (function (lambda (subform) (walk map-function reduce-function screamer? partial? nested? subform environment))) (rest form)))) (funcall map-function form (quote symbol-call))) (if reduce-function (funcall reduce-function (funcall map-function form (quote setf-call)) (reduce reduce-function (mapcar (function (lambda (subform) (walk map-function reduce-function screamer? partial? nested? subform environment))) (rest form)))) (funcall map-function form (quote setf-call))))) (t (error "CAR of form ~S is not a valid function" form)))) (eval-when (:compile-toplevel) (compile (quote walk-function-call))))


[User]
You are a Common Lisp macro expert. Given this code pattern:
(lret* ((shape (ensure-shape shape)) (array (make-array shape))) (loop for i from 0 below (array-total-size array) do (setf (row-major-aref array i) (array-index-row-major array i))))

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

(lret* ((shape (ensure-shape shape)) (array (make-array shape))) (loop for i from 0 below (array-total-size array) do (setf (row-major-aref array i) (array-index-row-major array i))))

[Assistant]
(defmacro lret ((&rest bindings) &body body)
  "Return the initial value of the last binding in BINDINGS. The idea
is to create something, initialize it, and then return it.

    (lret ((x 1)
           (y (make-array 1)))
      (setf (aref y 0) x))
    => #(1)

Note that the value returned is the value initially bound. Subsequent
assignments are ignored.

    (lret ((x 1))
      (setf x 2))
    => 1

Furthermore, on Lisps that support it, the variable may be made
read-only, making assignment a compiler-time error.

`lret' may seem trivial, but it fufills the highest purpose a macro
can: it eliminates a whole class of bugs (initializing an object, but
forgetting to return it).

Cf. `aprog1' in Anaphora."
  `(lret-aux let ,bindings
     ,@body))

;; macroexpand:
(lret-aux let* ((shape (ensure-shape shape)) (array (make-array shape))) (loop for i from 0 below (array-total-size array) do (setf (row-major-aref array i) (array-index-row-major array i))))


[User]
Write a Common Lisp macro to handle this code pattern:
(do-immutable-map (_ value object) (declare (ignore _)) (scan value))

Problem: Macro call that should be transformed by do-immutable-map

(do-immutable-map (_ value object) (declare (ignore _)) (scan value))

[Assistant]
(defmacro do-immutable-map ((key value map &optional result) &body body)
  "Iterate over MAP in ascending key order, binding KEY and VALUE."
  `(avl:do-avl (,key ,value (immutable-map-data ,map) ,result)
     ,@body))

;; macroexpand:
(avl:do-avl (_ value (immutable-map-data object) nil) (declare (ignore _)) (scan value))


[User]
Define a macro that eliminates this repetitive pattern:
(with-lock (lru-pool-lock pool) (add-to-lru-pool pool host-port stream eviction-callback))

Issue: Macro call that should be transformed by with-lock

(with-lock (lru-pool-lock pool) (add-to-lru-pool pool host-port stream eviction-callback))

[Assistant]
(defmacro with-lock (lock &body body)
  (declare (ignorable lock))
  #+thread-support `(bt2:with-lock-held (,lock)
                      ,@body)
  #-thread-support `(progn ,@body))

;; macroexpand:
(bt2:with-lock-held ((lru-pool-lock pool)) (add-to-lru-pool pool host-port stream eviction-callback))


[User]
You are a Common Lisp macro expert. Given this code pattern:
(with-yield-binds (format nil (if (sql-statement-p (statement-clause-statement clause)) "~:[~A ~;~*~](~A)" "~:[~A ~;~*~]~A") (string= (sql-clause-name clause) "") (sql-clause-name clause) (yield (statement-clause-statement clause))))

Write a macro that addresses: Macro call that should be transformed by with-yield-binds

(with-yield-binds (format nil (if (sql-statement-p (statement-clause-statement clause)) "~:[~A ~;~*~](~A)" "~:[~A ~;~*~]~A") (string= (sql-clause-name clause) "") (sql-clause-name clause) (yield (statement-clause-statement clause))))

[Assistant]
(defmacro with-yield-binds (&body body)
  `(let ((*bind-values* nil)
         (*use-global-bind-values* t))
     (values
      (progn ,@body)
      (loop for bind in (reverse *bind-values*)
            append bind))))

;; macroexpand:
(let ((*bind-values* nil) (*use-global-bind-values* t)) (values (progn (format nil (if (sql-statement-p (statement-clause-statement clause)) "~:[~A ~;~*~](~A)" "~:[~A ~;~*~]~A") (string= (sql-clause-name clause) "") (sql-clause-name clause) (yield (statement-clause-statement clause)))) (loop for bind in (reverse *bind-values*) append bind)))


[User]
Define a macro that eliminates this repetitive pattern:
(with-decoder-simple-list-semantics (let (result) (setf result (json-rpc:invoke-rpc (format nil "{~@[~*\"jsonrpc\":\"2.0\",~]\"method\":\"~a\",\"params\":[1,2],\"id\":999}" (json-rpc-2-p) method-name))) (is (string= result (format nil "{~@[~*\"jsonrpc\":\"2.0\",~]\"result\":{\"digits\":3,\"letters\":\"three\"},~@[~*\"error\":null,~]\"id\":999}" (json-rpc-2-p) (not (json-rpc-2-p)))))))

Issue: Macro call that should be transformed by with-decoder-simple-list-semantics

(with-decoder-simple-list-semantics (let (result) (setf result (json-rpc:invoke-rpc (format nil "{~@[~*\"jsonrpc\":\"2.0\",~]\"method\":\"~a\",\"params\":[1,2],\"id\":999}" (json-rpc-2-p) method-name))) (is (string= result (format nil "{~@[~*\"jsonrpc\":\"2.0\",~]\"result\":{\"digits\":3,\"letters\":\"three\"},~@[~*\"error\":null,~]\"id\":999}" (json-rpc-2-p) (not (json-rpc-2-p)))))))

[Assistant]
(defmacro with-decoder-simple-list-semantics (&body body)
  "Execute BODY in a dynamic environement where the decoder semantics
is such as set by SET-DECODER-SIMPLE-LIST-SEMANTICS."
  `(with-shadowed-custom-vars
     (set-decoder-simple-list-semantics)
     ,@body))

;; macroexpand:
(with-shadowed-custom-vars (set-decoder-simple-list-semantics) (let (result) (setf result (json-rpc:invoke-rpc (format nil "{~@[~*\"jsonrpc\":\"2.0\",~]\"method\":\"~a\",\"params\":[1,2],\"id\":999}" (json-rpc-2-p) method-name))) (is (string= result (format nil "{~@[~*\"jsonrpc\":\"2.0\",~]\"result\":{\"digits\":3,\"letters\":\"three\"},~@[~*\"error\":null,~]\"id\":999}" (json-rpc-2-p) (not (json-rpc-2-p)))))))


[User]
Define a macro that eliminates this repetitive pattern:
(make-avl-map ('foo val1) ('bar val2))

Issue: Macro call that should be transformed by make-avl-map

(make-avl-map ('foo val1) ('bar val2))

[Assistant]
(defmacro make-avl-map (&rest pairs)
  "Construct an AVL tree from literal (key-expr value-expr) pairs.
Usage: (make-avl-map ('foo val1) ('bar val2))"
  (let ((tree (gensym "TREE")))
    `(let ((,tree (empty-avl-tree)))
       ,@(loop :for (k v) :in pairs
               :collect `(setf ,tree (avl-set ,tree ,k ,v)))
       ,tree)))

;; macroexpand:
(let ((#:tree162 (empty-avl-tree))) (setf #:tree162 (avl-set #:tree162 (quote foo) val1)) (setf #:tree162 (avl-set #:tree162 (quote bar) val2)) #:tree162)


[User]
Generate a defmacro form that transforms code like this:
(defalias path:root-p (pathname) cl-fad:pathname-root-p)

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

(defalias path:root-p (pathname) cl-fad:pathname-root-p)

[Assistant]
(defmacro defalias (name args realname)
  `(progn
     (defun ,name ,args
       ,(if (eql '&rest (first args))
            `(apply #',realname ,(second args))
            `(,realname ,@args)))
     (define-compiler-macro ,name (&rest args)
       (list* ',realname args))))

;; macroexpand:
(progn (defun path:root-p (pathname) (pathname-root-p pathname)) (define-compiler-macro path:root-p (&rest args) (list* (quote pathname-root-p) args)))


[User]
Write a Common Lisp macro to handle this code pattern:
(define-modf-rewrite rest (expr) `(cdr ,(second expr)))

Problem: Macro call that should be transformed by define-modf-rewrite

(define-modf-rewrite rest (expr) `(cdr ,(second expr)))

[Assistant]
(defmacro define-modf-rewrite (name (expr) &body body)
  "Define a new rewrite rule.  If a form starting with NAME is encountered, call
the defined function to return a form that we can deal with (i.e. one defined
via DEFINE-MODF-EXPANDER, DEFINE-MODF-FUNCTION, and DEFINE-MODF-METHOD)."
  `(eval-when (:compile-toplevel :load-toplevel :execute)
     (setf (gethash ',name *modf-rewrites*)
           (lambda (,expr)
             ,@body))))

;; macroexpand:
(eval-when (:compile-toplevel :load-toplevel :execute) (setf (gethash (quote rest) *modf-rewrites*) (lambda (expr) (sb-int:quasiquote (cdr #S(sb-impl::comma :expr (second expr) :kind 0))))))


[User]
Generate a defmacro form that transforms code like this:
(as->* nil :key nil)

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

(as->* nil :key nil)

[Assistant]
(defmacro AS->* ...)

;; macroexpand:
(as-> nil nil :key)


[User]
Create a Common Lisp macro for the following transformation. Before code:
(define-error for-loop-simple-expression () () "Only simple expressions are allowed in the condition and update slots of a for loop")

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

(define-error for-loop-simple-expression () () "Only simple expressions are allowed in the condition and update slots of a for loop")

[Assistant]
(defmacro define-error (name (&key (error-type 'varjo-error) (prefix "Varjo"))
                            (&rest args) error-string &body body)
  `(defcondition ,name (:error-type ,error-type :prefix ,prefix) ,args
       ,error-string ,@body))

;; macroexpand:
(defcondition for-loop-simple-expression (:error-type varjo-error :prefix "Varjo") nil "Only simple expressions are allowed in the condition and update slots of a for loop")


[User]
Write a Common Lisp macro to handle this code pattern:
(define HUGE_VAL most-positive-double-float)

Problem: Macro call that should be transformed by define

(define HUGE_VAL most-positive-double-float)

[Assistant]
(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)))

;; macroexpand:
(progn (eval-when (:compile-toplevel :load-toplevel :execute) (defvar *preprocessor-defines* (make-hash-table)) (setf (gethash (quote huge_val) *preprocessor-defines*) #A((26) base-char . "MOST-POSITIVE-DOUBLE-FLOAT"))) (defparameter huge_val most-positive-double-float))


[User]
Generate a defmacro form that transforms code like this:
(define-direct-binding being (var &rest sub-bindings) (let ((bindings (loop for bind in sub-bindings collect (list* var bind))) (being-counter (gensym (string 'being-counter))) (being-tag (gensym (string 'being-tag))) (vars (loop for var in (lambda-fiddle:extract-lambda-vars (enlist var)) collect `(,var NIL)))) (multiple-value-bind (bind-init bind-forms) (convert-bindings bindings) (values `(with-interleaving (let ((,being-counter 0) ,@vars)) ,@(loop for bind in bind-init collect (remove-bindings vars bind))) `(tagbody ,being-tag (case ,being-counter ,@(loop for form in (butlast bind-forms) for i from 0 collect `(,i (macrolet ((end-for () `(progn (incf ,',being-counter) (go ,',being-tag)))) ,form))) (T ,@(last bind-forms))))))))

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

(define-direct-binding being (var &rest sub-bindings) (let ((bindings (loop for bind in sub-bindings collect (list* var bind))) (being-counter (gensym (string 'being-counter))) (being-tag (gensym (string 'being-tag))) (vars (loop for var in (lambda-fiddle:extract-lambda-vars (enlist var)) collect `(,var NIL)))) (multiple-value-bind (bind-init bind-forms) (convert-bindings bindings) (values `(with-interleaving (let ((,being-counter 0) ,@vars)) ,@(loop for bind in bind-init collect (remove-bindings vars bind))) `(tagbody ,being-tag (case ,being-counter ,@(loop for form in (butlast bind-forms) for i from 0 collect `(,i (macrolet ((end-for () `(progn (incf ,',being-counter) (go ,',being-tag)))) ,form))) (T ,@(last bind-forms))))))))

[Assistant]
(defmacro define-direct-binding (name args &body body)
  (let ((env (or (lambda-fiddle:environment-lambda-var args) (gensym "ENVIRONMENT"))))
    `(progn (setf (binding ',name)
                  (lambda ,(lambda-fiddle:remove-environment-part args)
                    (let ((,env *environment*))
                      (declare (ignorable ,env))
                      ,@body)))
            ',name)))

;; macroexpand:
(progn (setf (binding (quote being)) (lambda (var &rest sub-bindings) (let ((#:environment124 *environment*)) (declare (ignorable #:environment124)) (let ((bindings (loop for bind in sub-bindings collect (list* var bind))) (being-counter (gensym (string (quote being-counter)))) (being-tag (gensym (string (quote being-tag)))) (vars (loop for var in (lambda-fiddle:extract-lambda-vars (enlist var)) collect (sb-int:quasiquote (#S(sb-impl::comma :expr var :kind 0) nil))))) (multiple-value-bind (bind-init bind-forms) (convert-bindings bindings) (values (sb-int:quasiquote (with-interleaving (let ((#S(sb-impl::comma :expr being-counter :kind 0) 0) #S(sb-impl::comma :expr vars :kind 2))) #S(sb-impl::comma :expr (loop for bind in bind-init collect (remove-bindings vars bind)) :kind 2))) (sb-int:quasiquote (tagbody #S(sb-impl::comma :expr being-tag :kind 0) (case #S(sb-impl::comma :expr being-counter :kind 0) #S(sb-impl::comma :expr (loop for form in (butlast bind-forms) for i from 0 collect (sb-int:quasiquote (#S(sb-impl::comma :expr i :kind 0) (macrolet ((end-for nil (sb-int:quasiquote (progn (incf #S(sb-impl::comma :expr (quote #S(sb-impl::comma :expr being-counter :kind 0)) :kind 0)) (go #S(sb-impl::comma :expr (quote #S(sb-impl::comma :expr being-tag :kind 0)) :kind 0)))))) #S(sb-impl::comma :expr form :kind 0))))) :kind 2) (t #S(sb-impl::comma :expr (last bind-forms) :kind 2))))))))))) (quote being))


[User]
Write a Common Lisp macro to handle this code pattern:
(gatherer nil)

Problem: Macro call that should be transformed by GATHERER

(gatherer nil)

[Assistant]
(defmacro GATHERER ...)

;; macroexpand:
(common-lisp:let ((#:lastcons-445 (list nil)) #:lst-446)
  (declare (type cons #:lastcons-445)
           (type list #:lst-446))
  (setq #:lst-446 #:lastcons-445)
  (common-lisp:let (#:out-448)
    #'(lambda (#:items-444 result-p)
        (cond
         ((null result-p)
          (tagbody
            (setq #:lastcons-445
                    (setf (cdr #:lastcons-445) (cons #:items-444 nil)))))
         (t
          (progn
           (setq #:lst-446 (cdr #:lst-446))
           (setq #:out-448
                   (common-lisp:funcall nil
                                        (common-lisp:funcall #'scan
                                                             #:lst-446))))
          #:out-448)))))


[User]
Create a Common Lisp macro for the following transformation. Before code:
(def-dynenv-fun nil
    nil)

What needs to change: Macro call that should be transformed by DEF-DYNENV-FUN

(def-dynenv-fun nil
    nil)

[Assistant]
(defmacro DEF-DYNENV-FUN ...)

;; macroexpand:
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defun nil (&rest #:args) (apply (dynenv-function nil) #:args))
  (defvar #:nil143 (lambda ()))
  (setf (get 'nil 'dynenv-fun) '#:nil143))


[User]
Define a macro that eliminates this repetitive pattern:
(with-additional-indent (reporter stream "× ") (when (slot-value report 'description) (format/indent reporter stream "~A~%" (slot-value report 'description))) (format/indent reporter stream "Raised an error ~A (expected: ~S)" (slot-value report 'got) (slot-value report 'expected)))

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

(with-additional-indent (reporter stream "× ") (when (slot-value report 'description) (format/indent reporter stream "~A~%" (slot-value report 'description))) (format/indent reporter stream "Raised an error ~A (expected: ~S)" (slot-value report 'got) (slot-value report 'expected)))

[Assistant]
(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))))

;; macroexpand:
(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) (when (slot-value report (quote description)) (format/indent reporter stream "~A~%" (slot-value report (quote description)))) (format/indent reporter stream "Raised an error ~A (expected: ~S)" (slot-value report (quote got)) (slot-value report (quote expected)))))


[User]
You are a Common Lisp macro expert. Given this code pattern:
(node 'some-name)

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

(node 'some-name)

[Assistant]
(defmacro NODE ...)

;; macroexpand:
(make+finish-node+relations quote some-name 'nil 'nil)


[User]
Generate a defmacro form that transforms code like this:
(-<> nil nil)

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

(-<> nil nil)

[Assistant]
(defmacro -<> ...)

;; macroexpand:
(-> nil nil)


[User]
Write a Common Lisp macro to handle this code pattern:
(slet it it)

Problem: Macro call that should be transformed by slet

(slet it it)

[Assistant]
(defmacro slet (form &body body)
  "Binds the FORM to IT (via SYMBOL-MACROLET) in the scope of the BODY. IT can
be set with SETF."
  `(symbolic ignore-first ,form (progn ,@body)))

;; macroexpand:
(symbolic ignore-first it (progn it))


[User]
Write a Common Lisp macro to handle this code pattern:
(def-neo4j-fun traverse (node-id (return-type :node) (max-depth 1) (order :depth-first) uniqueness relationships prune-evaluator return-filter) :post (:uri-spec (format nil "node/~A/traverse/~A" node-id (string-downcase (symbol-name return-type)))) (:encode (list (cons "order" (case order (:depth-first "depth_first") (:breadth-first "breadth_first"))) (cons "uniqueness" uniqueness) (cons "relationships" relationships) (cons "prune_evaluator" prune-evaluator) (cons "return_filter" return-filter) (cons "max_depth" max-depth)) :string) (: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

(def-neo4j-fun traverse (node-id (return-type :node) (max-depth 1) (order :depth-first) uniqueness relationships prune-evaluator return-filter) :post (:uri-spec (format nil "node/~A/traverse/~A" node-id (string-downcase (symbol-name return-type)))) (:encode (list (cons "order" (case order (:depth-first "depth_first") (:breadth-first "breadth_first"))) (cons "uniqueness" uniqueness) (cons "relationships" relationships) (cons "prune_evaluator" prune-evaluator) (cons "return_filter" return-filter) (cons "max_depth" max-depth)) :string) (:status-handlers (200 (decode-neo4j-json-output body)) (404 (error 'node-not-found-error :uri uri))))

[Assistant]
(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)))))))))

;; macroexpand:
(progn (defun traverse (&key node-id (return-type :node) (max-depth 1) (order :depth-first) uniqueness relationships prune-evaluator return-filter) (let ((uri (format nil "node/~A/traverse/~A" node-id (string-downcase (symbol-name return-type)))) (json (encode-neo4j-json-payload (list (cons "order" (case order (:depth-first "depth_first") (:breadth-first "breadth_first"))) (cons "uniqueness" uniqueness) (cons "relationships" relationships) (cons "prune_evaluator" prune-evaluator) (cons "return_filter" return-filter) (cons "max_depth" max-depth)) :string))) (make-neo4j-request :post 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))))))))


[User]
Create a Common Lisp macro for the following transformation. Before code:
(matrix-etypecase nil)

What needs to change: Macro call that should be transformed by MATRIX-ETYPECASE

(matrix-etypecase nil)

[Assistant]
(defmacro MATRIX-ETYPECASE ...)

;; macroexpand:
nil


[User]
Create a Common Lisp macro for the following transformation. Before code:
(defsynonym next-iteration :next-iteration)

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

(defsynonym next-iteration :next-iteration)

[Assistant]
(defmacro defsynonym (symbol synonym)
  "Set SYNONYM for a SYMBOL. "
  `(eval-always
     (setf (get ',symbol 'synonym) ',synonym)))

;; macroexpand:
(eval-always (setf (get (quote next-iteration) (quote synonym)) (quote :next-iteration)))


[User]
Generate a defmacro form that transforms code like this:
(defsynonym first-iteration-p :first-iteration-p)

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

(defsynonym first-iteration-p :first-iteration-p)

[Assistant]
(defmacro defsynonym (symbol synonym)
  "Set SYNONYM for a SYMBOL. "
  `(eval-always
     (setf (get ',symbol 'synonym) ',synonym)))

;; macroexpand:
(eval-always (setf (get (quote first-iteration-p) (quote synonym)) (quote :first-iteration-p)))


[User]
Create a Common Lisp macro for the following transformation. Before code:
(with-env [plist :c])

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

(with-env [plist :c])

[Assistant]
(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))

;; macroexpand:
(let (#:g129) (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 #:g129 (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)) [plist :c])) (setf (find-class (quote foo) nil) nil) (setf (find-class (quote bar) nil) nil) #:g129)


[User]
You are a Common Lisp macro expert. Given this code pattern:
(keep-bops nil nil)

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

(keep-bops nil nil)

[Assistant]
(defmacro KEEP-BOPS ...)

;; macroexpand:
(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) '(nil nil))
                                     (remprop (car b) 'properties)
                                     t))
                                 bs)))
                      *binfix*)))
     (assign-properties))))


[User]
Generate a defmacro form that transforms code like this:
(f_%
  nil
  (progn))

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

(f_%
  nil
  (progn))

[Assistant]
(defmacro F_% ...)

;; macroexpand:
(lambda (&rest #:|ignore128|) (declare (ignore #:|ignore128|)) nil (progn))


[User]
Define a macro that eliminates this repetitive pattern:
(defsyntax nil
  :key
  nil)

Issue: Macro call that should be transformed by DEFSYNTAX

(defsyntax nil
  :key
  nil)

[Assistant]
(defmacro defsyntax (name &body options)
  `(progn
     (setf (get ',name :options) ',options)
     (defvar ,name (defreadtable ,name ,@options))))

;; macroexpand:
(progn
 (setf (get 'nil :options) '(:key nil))
 (defvar nil
   (defreadtable nil
     :key
     nil)))


[User]
You are a Common Lisp macro expert. Given this code pattern:
(as-> nil (progn))

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

(as-> nil (progn))

[Assistant]
(defmacro AS-> ...)

;; macroexpand:
(let* (((progn) nil))
  (progn))


[User]
Generate a defmacro form that transforms code like this:
(when (cdr clauses) `(cond ,@(cdr clauses)))

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

(when (cdr clauses) `(cond ,@(cdr clauses)))

[Assistant]
(defmacro when (test &body forms)
  `(if ,test
	   ,(cl:if (cadr forms)
			   `(progn ,@forms)
			   (car forms))))

;; macroexpand:
(if (cdr clauses) (sb-int:quasiquote (cond #S(sb-impl::comma :expr (cdr clauses) :kind 2))))


[User]
Generate a defmacro form that transforms code like this:
(gathering nil
  (progn))

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

(gathering nil
  (progn))

[Assistant]
(defmacro GATHERING ...)

;; macroexpand:
(common-lisp:let ()
  (progn)
  (values))


[User]
Generate a defmacro form that transforms code like this:
(defun-compile-time is-magic-declaration? (form) (and (consp form) (eq (first form) 'declare) (consp (rest form)) (consp (second form)) (eq (first (second form)) 'magic)))

Pattern to recognize: Macro call that should be transformed by defun-compile-time

(defun-compile-time is-magic-declaration? (form) (and (consp form) (eq (first form) 'declare) (consp (rest form)) (consp (second form)) (eq (first (second form)) 'magic)))

[Assistant]
(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))))

;; macroexpand:
(eval-when (:compile-toplevel :load-toplevel :execute) (common-lisp:defun is-magic-declaration? (form) (and (consp form) (eq (first form) (quote declare)) (consp (rest form)) (consp (second form)) (eq (first (second form)) (quote magic)))) (eval-when (:compile-toplevel) (compile (quote is-magic-declaration?))))


[User]
Write a Common Lisp macro to handle this code pattern:
(lret* () 1)

Problem: Macro call that should be transformed by lret

(lret* () 1)

[Assistant]
(defmacro lret ((&rest bindings) &body body)
  "Return the initial value of the last binding in BINDINGS. The idea
is to create something, initialize it, and then return it.

    (lret ((x 1)
           (y (make-array 1)))
      (setf (aref y 0) x))
    => #(1)

Note that the value returned is the value initially bound. Subsequent
assignments are ignored.

    (lret ((x 1))
      (setf x 2))
    => 1

Furthermore, on Lisps that support it, the variable may be made
read-only, making assignment a compiler-time error.

`lret' may seem trivial, but it fufills the highest purpose a macro
can: it eliminates a whole class of bugs (initializing an object, but
forgetting to return it).

Cf. `aprog1' in Anaphora."
  `(lret-aux let ,bindings
     ,@body))

;; macroexpand:
(lret-aux let* nil 1)


[User]
Generate a defmacro form that transforms code like this:
(define-declaration nil
    (progn))

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

(define-declaration nil
    (progn))

[Assistant]
(defmacro DEFINE-DECLARATION ...)

;; macroexpand:
(eval-when (:compile-toplevel :load-toplevel :execute)
  (proclaim '(declaration nil))
  (flet ((sb-cltl2::func (progn)
           ))
    (setf (sb-int:info :declaration :known 'nil)
            (lambda
                (sb-kernel:lexenv sb-cltl2::spec sb-cltl2::pd-vars
                 sb-cltl2::pd-fvars)
              (multiple-value-bind (sb-cltl2::kind sb-cltl2::data)
                  (sb-cltl2::func sb-cltl2::spec sb-kernel:lexenv)
                (sb-cltl2::update-lexenv-user-data sb-kernel:lexenv
                                                   sb-cltl2::kind
                                                   sb-cltl2::data
                                                   sb-cltl2::pd-vars
                                                   sb-cltl2::pd-fvars))))))


[User]
Write a Common Lisp macro to handle this code pattern:
(ps-html nil (progn))

Problem: Macro call that should be transformed by PS-HTML

(ps-html nil (progn))

[Assistant]
(defmacro PS-HTML ...)

;; macroexpand:
(stringify nil (progn))


[User]
Generate a defmacro form that transforms code like this:
(defclass/a dbd-postgres-query (dbi-query) ((name :initarg :name) (freedp :initform nil :accessor query-freed-p)) (:default-initargs :fields nil))

Pattern to recognize: Macro call that should be transformed by defclass/a

(defclass/a dbd-postgres-query (dbi-query) ((name :initarg :name) (freedp :initform nil :accessor query-freed-p)) (:default-initargs :fields nil))

[Assistant]
(defmacro defclass/a (name superclasses slots &rest class-options)
  `(progn
     (defclass ,name ,superclasses ,slots ,@class-options)
     (deftype ,(intern (format nil "<~A>" (symbol-name name))) () ',name)
     (setf (find-class ',(intern (format nil "<~A>" (symbol-name name))))
           (find-class ',name))))

;; macroexpand:
(progn (defclass dbd-postgres-query (dbi-query) ((name :initarg :name) (freedp :initform nil :accessor query-freed-p)) (:default-initargs :fields nil)) (deftype <dbd-postgres-query> nil (quote dbd-postgres-query)) (setf (find-class (quote <dbd-postgres-query>)) (find-class (quote dbd-postgres-query))))


[User]
You are a Common Lisp macro expert. Given this code pattern:
(c?-with-stored (v :bar store 'nothing) (bwhen (val (value v)) (1- val)))

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

(c?-with-stored (v :bar store 'nothing) (bwhen (val (value v)) (1- val)))

[Assistant]
(defmacro c? (&body body)
  `(make-c-dependent
    :code ',body
    :value-state :unevaluated
    :rule (c-lambda ,@body)))

;; macroexpand:
(c? (bwhen-c-stored (v :bar store (quote nothing)) (bwhen (val (value v)) (1- val))))


[User]
Write a Common Lisp macro to handle this code pattern:
(make-window-or-instance nil)

Problem: Macro call that should be transformed by MAKE-WINDOW-OR-INSTANCE

(make-window-or-instance nil)

[Assistant]
(defmacro MAKE-WINDOW-OR-INSTANCE ...)

;; macroexpand:
(make-$instance nil)


[User]
You are a Common Lisp macro expert. Given this code pattern:
(with-iter-value (value it) value)

Write a macro that addresses: Macro call that should be transformed by with-iter-value

(with-iter-value (value it) value)

[Assistant]
(defmacro with-iter-value ((pattern iter) &body body)
  "Bind the current element of a sequence, pointed to by a static iterator, to a variable.

   This macro may only be used within the body of a WITH-ITERATORS
   macro.

   The current value of the sequence, with iterator ITER, is bound to
   the variable(s) specified by PATTERN, with the bindings visible to
   FORMS.

   If the iterator is already at the end of the sequence a non-local
   jump, to the end of the enclosing WITH-ITERATORS form, is
   performed.

   After binding, the iterator is advanced to the next element of the
   sequence.

   PATTERN:

     A binding pattern specifying the variable(s) to which the current
     element of the sequence is bound.

     This may either be a symbol, naming a variable, or a list which
     is interpreted as a pattern to `destructuring-bind`.

   ITER:

     Symbol identifying the iterator, as established by the
     WITH-ITERATORS form.

     This must name an iterator introduced in a parent WITH-ITERATORS
     form.

   BODY:

     The body of the WITH-ITER-VALUE form:

       (DECLARATION* FORM*)

     The body consists of a list of forms evaluated in an implicit
     PROGN, with the value of the last form returned from the
     WITH-ITER-VALUE form. The binding(s) introduced by PATTERN are
     visible to forms.

     The forms may be preceded by declaration expressions, which may
     apply to the variables introduced in PATTERN.

     NOTE: If there are no more elements in the sequence, the forms
     are not evaluated and a non-local jump to the end of the
     enclosing WITH-ITERATORS form is performed."

  `(with-iter-values ((,pattern ,iter)) ,@body))

;; macroexpand:
(with-iter-values ((value it)) value)


[User]
Create a Common Lisp macro for the following transformation. Before code:
(%escape-string-form form)

What needs to change: Macro call that should be transformed by %escape-string-form

(%escape-string-form form)

[Assistant]
(defmacro %escape-string-form (val)
  (let ((val2 (gensym)))
    `(let ((,val2 ,val))
       (if (should-escape-p ,val2)
           `(escape-string ,,val2)
           ,val2))))

;; macroexpand:
(let ((#:g122 form)) (if (should-escape-p #:g122) (sb-int:quasiquote (escape-string #S(sb-impl::comma :expr #:g122 :kind 0))) #:g122))


[User]
Write a Common Lisp macro to handle this code pattern:
(undefreply nil :key nil)

Problem: Macro call that should be transformed by UNDEFREPLY

(undefreply nil :key nil)

[Assistant]
(defmacro UNDEFREPLY ...)

;; macroexpand:
(undefine-reply 'nil :qualifiers '(:key) :participants `nil)


[User]
Write a Common Lisp macro to handle this code pattern:
(action (:after node-lisp node bound-variables) (let ((new-vars (loop :for (lisp-var . coalton-var) :in (node-lisp-vars node) :for target := (and (not (member coalton-var bound-variables :test #'eq)) (alias-substitution-target coalton-var aliases)) :collect (cons lisp-var (if target (node-variable-value target) coalton-var))))) (unless (equal new-vars (node-lisp-vars node)) (make-node-lisp :type (node-type node) :vars new-vars :form (node-lisp-form node)))))

Problem: Macro call that should be transformed by action

(action (:after node-lisp node bound-variables) (let ((new-vars (loop :for (lisp-var . coalton-var) :in (node-lisp-vars node) :for target := (and (not (member coalton-var bound-variables :test #'eq)) (alias-substitution-target coalton-var aliases)) :collect (cons lisp-var (if target (node-variable-value target) coalton-var))))) (unless (equal new-vars (node-lisp-vars node)) (make-node-lisp :type (node-type node) :vars new-vars :form (node-lisp-form node)))))

[Assistant]
(defmacro action ((when type &rest args) &body body)
  "Construct an action block, turning `body` into a lambda function
accepting `args` if `args` are provided. If there are no `args`, then
`body` is assumed to be a function object and is used directly with
`when` and `type` to create an `action` instance. Otherwise, the first
argument in `args` is declared to be a node of type `type`, and the
`args` and `body` are used to generate a lambda function."
  (check-type when keyword)
  (check-type type symbol)
  (assert (subtypep type 'node))
  (assert (or (not (endp args)) (= 1 (length body))))
  (if (endp args)
      `(make-action ',when ',type ,@body)
      `(make-action ',when ',type
                    (lambda (,@args)
                      (declare (type ,type ,(first args)))
                      ,@body))))

;; macroexpand:
(make-action (quote :after) (quote node-lisp) (lambda (node bound-variables) (declare (type node-lisp node)) (let ((new-vars (loop :for (lisp-var . coalton-var) :in (node-lisp-vars node) :for target := (and (not (member coalton-var bound-variables :test (function eq))) (alias-substitution-target coalton-var aliases)) :collect (cons lisp-var (if target (node-variable-value target) coalton-var))))) (unless (equal new-vars (node-lisp-vars node)) (make-node-lisp :type (node-type node) :vars new-vars :form (node-lisp-form node))))))


[User]
Define a macro that eliminates this repetitive pattern:
(define-class some-class (some super classes) ((slot1)) (:accessor-name-package (find-package :nclasses/test.dummy)))

Issue: Macro call that should be transformed by define-class

(define-class some-class (some super classes) ((slot1)) (:accessor-name-package (find-package :nclasses/test.dummy)))

[Assistant]
(defmacro define-class (name supers slots &rest options)
  "Convenience wrapper of `defclass'.

It automates a lot of boilerplate (like exporting all the accessors of a class)
plus adds some new features.

Slot options:

- The initform can be specified as the second value.

- `:accessor', `:reader' and `:writer' can be set to either a name, NIL or T.
  If NIL, the method is not generated.
  If T, the method is generated using the `:accessor-name-transformer' class option value.

- The `:export' option allows to control the slot-name export on a per-slot basis.

New class options (defaults are NIL unless specified):

- `:slot-definition-transformer' (default: `default-slot-definition-transformer').
  A function that takes a SLOT-DEFINITION and returns a new one.

- `:accessor-name-package': The package of the generated accessors.  See
  `:accessor-name-transformer'.  Some special values are accepted:
  - `:slot-name': The package of the slot-name.
  - `:default': The current package.

- `:accessor-name-transformer' (default `default-accessor-name-transformer').

  A function of (SLOT-NAME SLOT-DEFINITION) arguments that returns the accessor
  name (a symbol).  Other transformer: `dwim-accessor-name-transformer'.

- `:automatic-accessors-p': Whether to generate accessor names automatically for
  all slots.

  As a special case, the accessor is not generated if all following conditions are met:
  - `:accessor-name-package' is `:slot-name',
  - slot name package is different from current package,
  - if the `:accessor' slot option is not provided,

- `:initarg-name-transformer' (default: `default-initarg-name-transformer'.)

  A function of (SLOT-NAME SLOT-DEFINITION) arguments that returns the accessor
  name (a symbol.

- `:automatic-initargs-p' (default: T): Whether to generate accessor names
  automatically for all slots.

- `:predicate-name-transformer' (default: `default-predicate-name-transformer').

  A function of (SLOT-NAME SLOT-DEFINITION) arguments that returns the predicate
  name (a symbol).

- `:automatic-predicates-p' (default: T): Whether to generate a predicate
  for the class.

- `:type-inference' (default: `default-type-inference').

  Function that returns the type of a slot definition (with an initform).  It
  takes 3 arguments:

  - The initform.
  - The slot name.
  - The rest of the slot definition.

- `:automatic-types-p': Whether to generate the type automatically for all
  slots.  The type can still be specified manually with the `:type' slot option.

- Self-explanatory export options (all NIL by default):
  - `:export-class-name-p'
  - `:export-accessor-names-p'
  - `:export-slot-names-p'
  - `:export-predicate-name'"
  (build-defclass-like-expansion
   name supers slots options
   (lambda (processed-slots clean-options)
     `(defclass ,name ,supers
        ,processed-slots
        ,@clean-options))))

;; macroexpand:
(progn (defclass some-class (some super classes) ((slot1 :initform nil :accessor slot1 :initarg :slot1))) (unless (fboundp (quote some-class-p)) (define-generic some-class-p (object) #A((75) base-char . "Auto-generated predicate for whether OBJECT is an instance of `some-class'.") (declare (sb-ext:muffle-conditions style-warning)) (typep object (quote some-class)))) (setf (documentation (quote slot1) (quote function)) #A((48) base-char . "Auto-generated accessor function for slot SLOT1.")) (ignore-errors (setf (documentation (fdefinition (quote slot1)) (quote function)) #A((48) base-char . "Auto-generated accessor function for slot SLOT1."))) (ignore-errors (setf (documentation (fdefinition (quote (setf slot1))) (quote function)) #A((48) base-char . "Auto-generated accessor function for slot SLOT1."))) (find-class (quote some-class) nil))


[User]
Write a Common Lisp macro to handle this code pattern:
(defclass/std test () ((a b)))

Problem: Macro call that should be transformed by defclass/std

(defclass/std test () ((a b)))

[Assistant]
(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))

;; macroexpand:
(defclass test nil ((a :accessor a :initarg :a :initform nil) (b :accessor b :initarg :b :initform nil)))


[User]
You are a Common Lisp macro expert. Given this code pattern:
(ƒ→ nil (progn))

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

(ƒ→ nil (progn))

[Assistant]
(defmacro Ƒ→ ...)

;; macroexpand:
(defn nil (progn) (&optional α)
      (let ((α (or α t)))
        (cond)))


[User]
Define a macro that eliminates this repetitive pattern:
(make-window-or-instance nil (progn))

Issue: Macro call that should be transformed by MAKE-WINDOW-OR-INSTANCE

(make-window-or-instance nil (progn))

[Assistant]
(defmacro MAKE-WINDOW-OR-INSTANCE ...)

;; macroexpand:
(make-$instance nil (progn))


[User]
Generate a defmacro form that transforms code like this:
(assoc-cdr "oauth_verifier" parameters #'equal)

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

(assoc-cdr "oauth_verifier" parameters #'equal)

[Assistant]
(defmacro assoc-cdr (key alist &optional (test '#'eql))
  `(cdr (assoc ,key ,alist :test ,test)))

;; macroexpand:
(cdr (assoc "oauth_verifier" parameters :test (function equal)))


[User]
Write a Common Lisp macro to handle this code pattern:
(some-<> nil)

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

(some-<> nil)

[Assistant]
(defmacro SOME-<> ...)

;; macroexpand:
(let* ((#:g120 nil))
  #:g120)


[User]
Generate a defmacro form that transforms code like this:
(is (= 2 (length s)))

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

(is (= 2 (length s)))

[Assistant]
(defmacro is (test &rest reason-args)
  "The DWIM checking operator.

If TEST returns a true value a test-passed result is generated,
otherwise a test-failure result is generated. The reason, unless
REASON-ARGS is provided, is generated based on the form of TEST:

 (predicate expected actual) - Means that we want to check
 whether, according to PREDICATE, the ACTUAL value is
 in fact what we EXPECTED.

 (predicate value) - Means that we want to ensure that VALUE
 satisfies PREDICATE.

 Wrapping the TEST form in a NOT simply produces a negated reason
 string."
  (assert (listp test)
          (test)
          "Argument to IS must be a list, not ~S" test)
  (let (bindings effective-test default-reason-args)
    (with-gensyms (e a v)
      (flet ((process-entry (predicate expected actual &optional negatedp)
               ;; make sure EXPECTED is holding the entry that starts with 'values
               (when (and (consp actual)
                          (eq (car actual) 'values))
                 (assert (not (and (consp expected)
                                   (eq (car expected) 'values))) ()
                                   "Both the expected and actual part is a values expression.")
                 (rotatef expected actual))
               (let ((setf-forms))
                 (if (and (consp expected)
                          (eq (car expected) 'values))
                     (progn
                       (setf expected (copy-list expected))
                       (setf setf-forms (loop for cell = (rest expected) then (cdr cell)
                                              for i from 0
                                              while cell
                                              when (eq (car cell) '*)
                                              collect `(setf (elt ,a ,i) nil)
                                              and do (setf (car cell) nil)))
                       (setf bindings (list (list e `(list ,@(rest expected)))
                                            (list a `(multiple-value-list ,actual)))))
                     (setf bindings (list (list e expected)
                                          (list a actual))))
                 (setf effective-test `(progn
                                         ,@setf-forms
                                         ,(if negatedp
                                              `(not (,predicate ,e ,a))
                                              `(,predicate ,e ,a)))))))
        (list-match-case test
          ((not (?predicate ?expected ?actual))
           (process-entry ?predicate ?expected ?actual t)
           (setf default-reason-args
                 (list "~2&~S~2% evaluated to ~2&~S~2% which is ~2&~S~2%to ~2&~S~2% (it should not be)"
                       `',?actual a `',?predicate e)))
          ((not (?satisfies ?value))
           (setf bindings (list (list v ?value))
                 effective-test `(not (,?satisfies ,v))
                 default-reason-args
                 (list "~2&~S~2% evaluated to ~2&~S~2% which satisfies ~2&~S~2% (it should not)"
                       `',?value v `',?satisfies)))
          ((?predicate ?expected ?actual)
           (process-entry ?predicate ?expected ?actual)
           (setf default-reason-args
                 (list "~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%"
                       `',?actual a `',?predicate e)))
          ((?satisfies ?value)
           (setf bindings (list (list v ?value))
                 effective-test `(,?satisfies ,v)
                 default-reason-args
                 (list "~2&~S~2% evaluated to ~2&~S~2% which does not satisfy ~2&~S~2%"
                       `',?value v `',?satisfies)))
          (?_
           (setf bindings '()
                 effective-test test
                 default-reason-args (list "~2&~S~2% was NIL." `',test)))))
      `(let ,bindings
         (if ,effective-test
             (add-result 'test-passed :test-expr ',test)
             (process-failure ',test
                              ,@(or reason-args default-reason-args)))))))

;; macroexpand:
(let ((#:e259 2) (#:a260 (length s))) (if (progn (= #:e259 #:a260)) (add-result (quote test-passed) :test-expr (quote (= 2 (length s)))) (process-failure (quote (= 2 (length s))) "~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%" (quote (length s)) #:a260 (quote =) #:e259)))


[User]
Create a Common Lisp macro for the following transformation. Before code:
(some-> nil :key nil)

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

(some-> nil :key nil)

[Assistant]
(defmacro SOME-> ...)

;; macroexpand:
(let* ((#:|some128| nil)
       (#:|some128| (when #:|some128| (:key #:|some128|)))
       (#:|some128| (when #:|some128| (nil #:|some128|))))
  #:|some128|)


[User]
Generate a defmacro form that transforms code like this:
(define-cfun c-realloc)

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

(define-cfun c-realloc)

[Assistant]
(defmacro define-cfun (name-or-function &optional (package *package*))
  (when-let ((fun (find-function name-or-function)))
    (with-wrap-attempt ("function ~S" name-or-function) name-or-function
      (with-slots (name type c-symbol fields) fun
        (let* ((fun-name (intern (symbol-name name) package))
               (param-names (mapcar #'foreign-type-name fields))
               (param-syms (mapcar (lambda (x) (gensym (symbol-name x))) param-names))
               (make-function-p (not (foreign-function-variadic-p fun)))
               (maybe-cbv-return
                 (when (cbv-return-p fun)
                   (list 'return-value))))
          (with-gensyms (!fun !fields rest)
            (let ((form
                    (if make-function-p
                        `(defun ,fun-name (,@maybe-cbv-return
                                           ,@param-names ,@(when (foreign-function-variadic-p fun) `(&rest ,rest)))
                           ,@(when maybe-cbv-return `((declare (ignorable ,@maybe-cbv-return))))
                           ,(let ((!fun (find-function name-or-function)))
                              (with-slots ((!fields fields)) !fun
                                (foreign-to-ffi
                                 (and (car !fields) (foreign-type (car !fields)))
                                 param-syms
                                 param-names
                                 !fields
                                 (make-foreign-funcall !fun (and maybe-cbv-return 'return-value)
                                                       param-syms (when (foreign-function-variadic-p fun) rest))))))
                        `(defmacro ,fun-name (,@maybe-cbv-return
                                              ,@param-names ,@(when (foreign-function-variadic-p fun) `(&rest ,rest)))
                           ,@(when maybe-cbv-return `((declare (ignorable ,@maybe-cbv-return))))
                           (let ((,!fun (find-function ',name-or-function)))
                             (with-slots ((,!fields fields)) ,!fun
                               (foreign-to-ffi
                                (and (car ,!fields) (foreign-type (car ,!fields)))
                                ',param-syms
                                (list ,@param-names)
                                ,!fields
                                (make-foreign-funcall ,!fun ,(and maybe-cbv-return 'return-value)
                                                      ',param-syms ,(when (foreign-function-variadic-p fun) rest)))))))))
              `(progn
                 ,@(when (foreign-function-cbv-p fun)
                     (list (funcall *build-libffi-definition* fun)))
                 ,form))))))))

;; macroexpand:
(progn (defun c-realloc (ptr size) (let ((#:ptr213 ptr)) (declare (ignorable #:ptr213)) (let ((#:size214 size)) (declare (ignorable #:size214)) (cffi-sys:%foreign-funcall "realloc" (:pointer #:ptr213 :unsigned-long-long #:size214 :pointer) :convention :cdecl)))))


[User]
Write a Common Lisp macro to handle this code pattern:
(validate-superclass*)

Problem: Macro call that should be transformed by VALIDATE-SUPERCLASS*

(validate-superclass*)

[Assistant]
(defmacro VALIDATE-SUPERCLASS* ...)

;; macroexpand:
(progn)


[User]
Generate a defmacro form that transforms code like this:
(define-custom-var (:integer *integer-handler*) (constantly 0) "Designator for a function of 1 string argument (integer token).")

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

(define-custom-var (:integer *integer-handler*) (constantly 0) "Designator for a function of 1 string argument (integer token).")

[Assistant]
(defmacro define-custom-var ((key name) &rest other-args)
  `(eval-when (:compile-toplevel :load-toplevel :execute)
     (progn (pushnew '(,name . ,key) *custom-vars* :test #'equal)
            (defvar ,name ,@other-args))))

;; macroexpand:
(eval-when (:compile-toplevel :load-toplevel :execute) (progn (pushnew (quote (*integer-handler* . :integer)) *custom-vars* :test (function equal)) (defvar *integer-handler* (constantly 0) "Designator for a function of 1 string argument (integer token).")))


[User]
Write a Common Lisp macro to handle this code pattern:
(define-inference-rule nil
    (progn))

Problem: Macro call that should be transformed by DEFINE-INFERENCE-RULE

(define-inference-rule nil
    (progn))

[Assistant]
(defmacro DEFINE-INFERENCE-RULE ...)

;; macroexpand:
(setf (symbol-inference-rules 'nil)
        (sb-int:named-lambda 'nil
            (progn)))


[User]
Write a Common Lisp macro to handle this code pattern:
(aif (incf x) it :never)

Problem: Macro call that should be transformed by aif

(aif (incf x) it :never)

[Assistant]
(defmacro aif (test then &optional else)
  "Like IF, except binds the result of the test to IT (via LET) for
the scope of the then and else expressions."
  `(anaphoric if ,test ,then ,else))

;; macroexpand:
(anaphoric if (incf x) it :never)


[User]
Define a macro that eliminates this repetitive pattern:
(defmethod nil nil)

Issue: Macro call that should be transformed by DEFMETHOD

(defmethod nil nil)

[Assistant]
(defmacro DEFMETHOD ...)

;; macroexpand:
(common-lisp:defmethod nil nil)


[User]
You are a Common Lisp macro expert. Given this code pattern:
(define-condition/a dbi-notsupported-error (dbi-database-error) ((method-name :initarg :method-name :type (or symbol string))) (:documentation "Exception raised if e.g. commit() is called for a database which do not support transactions.") (:report (lambda (condition stream) (format stream "`~A' isn't supported on the current driver." (slot-value condition 'method-name)))))

Write a macro that addresses: Macro call that should be transformed by define-condition/a

(define-condition/a dbi-notsupported-error (dbi-database-error) ((method-name :initarg :method-name :type (or symbol string))) (:documentation "Exception raised if e.g. commit() is called for a database which do not support transactions.") (:report (lambda (condition stream) (format stream "`~A' isn't supported on the current driver." (slot-value condition 'method-name)))))

[Assistant]
(defmacro define-condition/a (name parent-types slots &body options)
  `(progn
     (define-condition ,name ,parent-types ,slots ,@options)
     (deftype ,(intern (format nil "<~A>" (symbol-name name))) () ',name)
     (setf (find-class ',(intern (format nil "<~A>" (symbol-name name))))
           (find-class ',name))))

;; macroexpand:
(progn (define-condition dbi-notsupported-error (dbi-database-error) ((method-name :initarg :method-name :type (or symbol string))) (:documentation "Exception raised if e.g. commit() is called for a database which do not support transactions.") (:report (lambda (condition stream) (format stream "`~A' isn't supported on the current driver." (slot-value condition (quote method-name)))))) (deftype <dbi-notsupported-error> nil (quote dbi-notsupported-error)) (setf (find-class (quote <dbi-notsupported-error>)) (find-class (quote dbi-notsupported-error))))


[User]
Generate a defmacro form that transforms code like this:
(@ nil (progn))

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

(@ nil (progn))

[Assistant]
(defmacro @ ...)

;; macroexpand:
(message-oo.mangle::|PROGN:| nil nil)


[User]
Generate a defmacro form that transforms code like this:
(with-prepared-query query (conn (format nil "SELECT 1 FROM sqlite_master WHERE tbl_name = '~A' AND sql LIKE '%AUTOINCREMENT%'" table-name)) (and (first (dbi:fetch (dbi:execute query) :format :values)) t))

Pattern to recognize: Macro call that should be transformed by with-prepared-query

(with-prepared-query query (conn (format nil "SELECT 1 FROM sqlite_master WHERE tbl_name = '~A' AND sql LIKE '%AUTOINCREMENT%'" table-name)) (and (first (dbi:fetch (dbi:execute query) :format :values)) t))

[Assistant]
(defmacro with-prepared-query (query (conn sql &key use-prepare-cached) &body body)
  `(call-with-prepared-query ,conn ,sql (lambda (,query) ,@body) :use-prepare-cached ,use-prepare-cached))

;; macroexpand:
(call-with-prepared-query conn (format nil "SELECT 1 FROM sqlite_master WHERE tbl_name = '~A' AND sql LIKE '%AUTOINCREMENT%'" table-name) (lambda (query) (and (first (dbi.driver:fetch (dbi.driver:execute query) :format :values)) t)) :use-prepare-cached nil)


[User]
You are a Common Lisp macro expert. Given this code pattern:
(c-assert (eq :nascent (c-state c)))

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

(c-assert (eq :nascent (c-state c)))

[Assistant]
(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)))))

;; macroexpand:
(unless *stop* (unless (eq :nascent (c-state c)) (c-break "failed assertion: ~a" (quote (eq :nascent (c-state c))))))


[User]
Generate a defmacro form that transforms code like this:
(with-disable-handler-restart (handler) (with-hook-restart (setf result (multiple-value-list (apply handler result)))))

Pattern to recognize: Macro call that should be transformed by with-disable-handler-restart

(with-disable-handler-restart (handler) (with-hook-restart (setf result (multiple-value-list (apply handler result)))))

[Assistant]
(defmacro with-disable-handler-restart ((handler) &body body)
  "This is intended to wrap all handler executions."
  `(restart-case
       (progn ,@body)
     (disable-handler ()
       :report
       (lambda (stream)
         (format stream "Disable handler ~a which causes the error." ,handler))
       (disable-hook *hook* ,handler))))

;; macroexpand:
(restart-case (progn (with-hook-restart (setf result (multiple-value-list (apply handler result))))) (disable-handler nil :report (lambda (stream) (format stream "Disable handler ~a which causes the error." handler)) (disable-hook *hook* handler)))


[User]
Define a macro that eliminates this repetitive pattern:
(caching-types
  nil
  :key
  nil)

Issue: Macro call that should be transformed by CACHING-TYPES

(caching-types
  nil
  :key
  nil)

[Assistant]
(defmacro CACHING-TYPES ...)

;; macroexpand:
(call-with-disjoint-hash
 (lambda ()
   (call-with-subtype-hash
    (lambda ()
      (call-with-equiv-hash
       (lambda () (call-with-subtypep-cache (lambda () nil :key nil))))))))


[User]
Create a Common Lisp macro for the following transformation. Before code:
(answer (foo 1) 2)

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

(answer (foo 1) 2)

[Assistant]
(defmacro answer (call &body forms)
  (let ((name (if (listp call) (car call) call))
        (sym (gensym)))
    `(if-called
      ',name
      (let ((,sym (fdefinition ',name)))
        (declare (ignorable ,sym))
        (let ((times 0))
          (lambda (&rest args)
            (declare (ignorable args))
            ,(let ((cases
                     `(case (prog1 times (incf times))
                        ,.(loop
                            for i from 0
                            for (form . rest) on forms
                            collect `(,(if rest i T) ,form)))))
               (if (listp call)
                   `(trivia:match args
                     ((list . ,(cdr call)) ,cases)
                     (_ (unhandled)))
                   cases))))))))

;; macroexpand:
(if-called (quote foo) (let ((#:g160 (fdefinition (quote foo)))) (declare (ignorable #:g160)) (let ((times 0)) (lambda (&rest args) (declare (ignorable args)) (trivia.level2:match args ((list 1) (case (prog1 times (incf times)) (t 2))) (_ (unhandled)))))))


[User]
You are a Common Lisp macro expert. Given this code pattern:
(define-element-maker :text "text" '(:x :y))

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

(define-element-maker :text "text" '(:x :y))

[Assistant]
(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))))

;; macroexpand:
(progn (defmethod assert-required-attributes ((element (eql :text)) attributes) (declare (ignore element)) (unless (evenp (length attributes)) (warn "attribute list may be missing data: ~A" attributes)) (let ((missing (set-difference (quote (:x :y)) attributes))) (when missing (error (quote missing-attributes) :message (format nil "~A missing attributes: ~{~A~^ ~}" :text missing))))) (defmethod make-svg-element ((element (eql :text)) attributes) (when *check-required-attributes* (assert-required-attributes element attributes)) (make-instance (quote svg-element) :name "text" :attributes attributes)))


[User]
You are a Common Lisp macro expert. Given this code pattern:
($/ "[_]*.mr." "i")

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

($/ "[_]*.mr." "i")

[Assistant]
(defmacro $ (&rest args)
  `(kv ,@args))

;; macroexpand:
(make-bson-regex (empty-str "[_]*.mr.") "i")


[User]
Create a Common Lisp macro for the following transformation. Before code:
(define-value-binding symbols (var package &rest status &aux (iterator (package-iterator package (or status '(:internal :external :inherited)))) next symbol) (declare (type function iterator)) `(multiple-value-bind (,next ,symbol) (funcall ,iterator) (if ,next (setf ,var ,symbol) (end-for))))

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

(define-value-binding symbols (var package &rest status &aux (iterator (package-iterator package (or status '(:internal :external :inherited)))) next symbol) (declare (type function iterator)) `(multiple-value-bind (,next ,symbol) (funcall ,iterator) (if ,next (setf ,var ,symbol) (end-for))))

[Assistant]
(defmacro define-value-binding (name (var &rest args) &body body)
  (let ((vars (lambda-fiddle:extract-lambda-vars (lambda-fiddle:remove-aux-part args))))
    (emit-binding-definition name var args body :extra-vars vars)))

;; macroexpand:
(define-direct-binding symbols (var package &rest status) (let ((#:iterator164 (gensym #A((8) base-char . "ITERATOR"))) (#:next165 (gensym #A((4) base-char . "NEXT"))) (#:symbol166 (gensym #A((6) base-char . "SYMBOL"))) (#:package162 (gensym #A((7) base-char . "PACKAGE"))) (#:status163 (gensym #A((6) base-char . "STATUS")))) (values* (sb-int:quasiquote (with-interleaving (let* #S(sb-impl::comma :expr (list* (list #:package162 package) (list #:status163 (list* (quote list) status)) (list #:iterator164 (list (quote package-iterator) #:package162 (list (quote or) #:status163 (quote (:internal :external :inherited))))) (list #:next165 nil) (list #:symbol166 nil) (loop for #:var161 in (lambda-fiddle:extract-lambda-vars (enlist var)) collect (list #:var161 nil))) :kind 0) (declare (ignorable #S(sb-impl::comma :expr #:iterator164 :kind 0) #S(sb-impl::comma :expr #:next165 :kind 0) #S(sb-impl::comma :expr #:symbol166 :kind 0) #S(sb-impl::comma :expr #:package162 :kind 0) #S(sb-impl::comma :expr #:status163 :kind 0))) #S(sb-impl::comma :expr (sb-int:quasiquote (declare (type #S(sb-impl::comma :expr (quote function) :kind 0) #S(sb-impl::comma :expr #:iterator164 :kind 0)))) :kind 0)) #S(sb-impl::comma :expr nil :kind 0))) (let ((iterator #:iterator164) (next #:next165) (symbol #:symbol166) (package #:package162) (status #:status163)) (declare (ignorable iterator next symbol package status)) (sb-int:quasiquote (multiple-value-bind (#S(sb-impl::comma :expr next :kind 0) #S(sb-impl::comma :expr symbol :kind 0)) (funcall #S(sb-impl::comma :expr iterator :kind 0)) (if #S(sb-impl::comma :expr next :kind 0) (setf #S(sb-impl::comma :expr var :kind 0) #S(sb-impl::comma :expr symbol :kind 0)) (end-for))))))))


[User]
You are a Common Lisp macro expert. Given this code pattern:
(lambda-ematch0 ((list* pattern body) (list* (list pattern) body)))

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

(lambda-ematch0 ((list* pattern body) (list* (list pattern) body)))

[Assistant]
(defmacro lambda-ematch0 (&body clauses)
  (alexandria:with-gensyms (arg)
    `(lambda (,arg)
       (ematch0 ,arg
         ,@clauses))))

;; macroexpand:
(lambda (#:arg168) (ematch0 #:arg168 ((list* pattern body) (list* (list pattern) body))))


[User]
Write a Common Lisp macro to handle this code pattern:
(with-hamt set (:test test :hash hash :table table) (flet ((%insert (table x) (%set-insert table x (funcall hash x) 0 test))) (make-instance 'hash-set :test test :hash hash :table (reduce #'%insert xs :initial-value table))))

Problem: Macro call that should be transformed by with-hamt

(with-hamt set (:test test :hash hash :table table) (flet ((%insert (table x) (%set-insert table x (funcall hash x) 0 test))) (make-instance 'hash-set :test test :hash hash :table (reduce #'%insert xs :initial-value table))))

[Assistant]
(defmacro with-hamt (hamt (&key test hash table) &body body)
  "Accessing HAMT slots"
  `(with-accessors ((,test hamt-test)
                    (,hash hamt-hash)
                    (,table hamt-table))
       ,hamt
     ,@body))

;; macroexpand:
(with-accessors ((test hamt-test) (hash hamt-hash) (table hamt-table)) set (flet ((%insert (table x) (%set-insert table x (funcall hash x) 0 test))) (make-instance (quote hash-set) :test test :hash hash :table (reduce (function %insert) xs :initial-value table))))


[User]
Create a Common Lisp macro for the following transformation. Before code:
(defclause in (&whole form seq &rest args &key &allow-other-keys &environment env) "Iterates over a sequence. IN must be used in combination with FOR, GENERATING and similar macros (those that bind *ITERATION-VARIABLE*). In implementations with extensible sequences (currently ABCL and SBCL), native sequence iterators are used, and all sequence types are supported, not just lists and vectors. In other implementations, an iterator specialized for lists or vectors is used depending on the type of sequence. All `args` are passed down to make-sequence-iterator (see the extensible sequences API paper for details [Rhodes2007]). IN can perform destructuring." (if (symbolp *iteration-variable*) (let ((state (gensym "STATE")) (limit (gensym "LIMIT")) (from-end (gensym "FROM-END")) (step (gensym "STEP")) (endp (gensym "ENDP")) (elt (gensym "ELT")) (sequence (gensym "SEQUENCE"))) `((with (,sequence ,seq) ,state ,limit ,from-end ,step ,endp ,elt) (initially (multiple-value-setq (,state ,limit ,from-end ,step ,endp ,elt) (make-sequence-iterator ,sequence ,@args))) ,(make-step :form `(setf ,state (funcall ,step ,sequence ,state ,from-end))) ,(make-simple-iteration :precondition `(not (funcall ,endp ,sequence ,state ,limit ,from-end)) :init `(funcall ,elt ,sequence ,state) :step `(funcall ,elt ,sequence ,state)))) (expand-with-simple-destructuring form env)))

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

(defclause in (&whole form seq &rest args &key &allow-other-keys &environment env) "Iterates over a sequence. IN must be used in combination with FOR, GENERATING and similar macros (those that bind *ITERATION-VARIABLE*). In implementations with extensible sequences (currently ABCL and SBCL), native sequence iterators are used, and all sequence types are supported, not just lists and vectors. In other implementations, an iterator specialized for lists or vectors is used depending on the type of sequence. All `args` are passed down to make-sequence-iterator (see the extensible sequences API paper for details [Rhodes2007]). IN can perform destructuring." (if (symbolp *iteration-variable*) (let ((state (gensym "STATE")) (limit (gensym "LIMIT")) (from-end (gensym "FROM-END")) (step (gensym "STEP")) (endp (gensym "ENDP")) (elt (gensym "ELT")) (sequence (gensym "SEQUENCE"))) `((with (,sequence ,seq) ,state ,limit ,from-end ,step ,endp ,elt) (initially (multiple-value-setq (,state ,limit ,from-end ,step ,endp ,elt) (make-sequence-iterator ,sequence ,@args))) ,(make-step :form `(setf ,state (funcall ,step ,sequence ,state ,from-end))) ,(make-simple-iteration :precondition `(not (funcall ,endp ,sequence ,state ,limit ,from-end)) :init `(funcall ,elt ,sequence ,state) :step `(funcall ,elt ,sequence ,state)))) (expand-with-simple-destructuring form env)))

[Assistant]
(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*)))

;; macroexpand:
(progn (defmacro in (&whole form seq &rest args &key &allow-other-keys &environment env) "Iterates over a sequence. IN must be used in combination with FOR, GENERATING and similar macros (those that bind *ITERATION-VARIABLE*). In implementations with extensible sequences (currently ABCL and SBCL), native sequence iterators are used, and all sequence types are supported, not just lists and vectors. In other implementations, an iterator specialized for lists or vectors is used depending on the type of sequence. All `args` are passed down to make-sequence-iterator (see the extensible sequences API paper for details [Rhodes2007]). IN can perform destructuring." (if (symbolp *iteration-variable*) (let ((state (gensym "STATE")) (limit (gensym "LIMIT")) (from-end (gensym "FROM-END")) (step (gensym "STEP")) (endp (gensym "ENDP")) (elt (gensym "ELT")) (sequence (gensym "SEQUENCE"))) (sb-int:quasiquote ((with (#S(sb-impl::comma :expr sequence :kind 0) #S(sb-impl::comma :expr seq :kind 0)) #S(sb-impl::comma :expr state :kind 0) #S(sb-impl::comma :expr limit :kind 0) #S(sb-impl::comma :expr from-end :kind 0) #S(sb-impl::comma :expr step :kind 0) #S(sb-impl::comma :expr endp :kind 0) #S(sb-impl::comma :expr elt :kind 0)) (initially (multiple-value-setq (#S(sb-impl::comma :expr state :kind 0) #S(sb-impl::comma :expr limit :kind 0) #S(sb-impl::comma :expr from-end :kind 0) #S(sb-impl::comma :expr step :kind 0) #S(sb-impl::comma :expr endp :kind 0) #S(sb-impl::comma :expr elt :kind 0)) (make-sequence-iterator #S(sb-impl::comma :expr sequence :kind 0) #S(sb-impl::comma :expr args :kind 2)))) #S(sb-impl::comma :expr (make-step :form (sb-int:quasiquote (setf #S(sb-impl::comma :expr state :kind 0) (funcall #S(sb-impl::comma :expr step :kind 0) #S(sb-impl::comma :expr sequence :kind 0) #S(sb-impl::comma :expr state :kind 0) #S(sb-impl::comma :expr from-end :kind 0))))) :kind 0) #S(sb-impl::comma :expr (make-simple-iteration :precondition (sb-int:quasiquote (not (funcall #S(sb-impl::comma :expr endp :kind 0) #S(sb-impl::comma :expr sequence :kind 0) #S(sb-impl::comma :expr state :kind 0) #S(sb-impl::comma :expr limit :kind 0) #S(sb-impl::comma :expr from-end :kind 0)))) :init (sb-int:quasiquote (funcall #S(sb-impl::comma :expr elt :kind 0) #S(sb-impl::comma :expr sequence :kind 0) #S(sb-impl::comma :expr state :kind 0))) :step (sb-int:quasiquote (funcall #S(sb-impl::comma :expr elt :kind 0) #S(sb-impl::comma :expr sequence :kind 0) #S(sb-impl::comma :expr state :kind 0)))) :kind 0)))) (expand-with-simple-destructuring form env))) (pushnew (quote in) *clauses*))


[User]
Write a Common Lisp macro to handle this code pattern:
(collect-min nil nil)

Problem: Macro call that should be transformed by COLLECT-MIN

(collect-min nil nil)

[Assistant]
(defmacro COLLECT-MIN ...)

;; macroexpand:
(common-lisp:let* ((#:generator-286 (generator nil))
                   #:items-276
                   (#:generator-284 (generator nil))
                   #:numbers-275
                   (#:number-278 nil)
                   #:result-279)
  (declare (type generator #:generator-286)
           (type generator #:generator-284)
           (type (null-or t) #:result-279))
  (tagbody
   #:ll-287
    (setq #:items-276 (next-in #:generator-286 (go end)))
    (setq #:numbers-275 (next-in #:generator-284 (go end)))
    (if (or (null #:number-278) (> #:number-278 #:numbers-275))
        (setq #:number-278 #:numbers-275
              #:result-279 #:items-276))
    (go #:ll-287)
   end)
  (if (null #:number-278)
      (setq #:result-279 nil))
  #:result-279)


[User]
Generate a defmacro form that transforms code like this:
(define-simple-definition-resolver generic-function designator-generic-function-p)

Pattern to recognize: Macro call that should be transformed by define-simple-definition-resolver

(define-simple-definition-resolver generic-function designator-generic-function-p)

[Assistant]
(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))))))

;; macroexpand:
(define-definition-resolver generic-function (generic-function #:package136) (when (ignore-errors (designator-generic-function-p generic-function)) (list (make-instance (quote generic-function) :designator generic-function :package #:package136))))


[User]
Write a Common Lisp macro to handle this code pattern:
(dynamic-relet nil)

Problem: Macro call that should be transformed by DYNAMIC-RELET

(dynamic-relet nil)

[Assistant]
(defmacro DYNAMIC-RELET ...)

;; macroexpand:
(dynamic-wind
  :proceed
  #:proceed188
  (let ()
    (declare (special))
    (#:proceed188)))


[User]
Write a Common Lisp macro to handle this code pattern:
(between (char #\!) (string "Salvē") (char #\!))

Problem: Macro call that should be transformed by between

(between (char #\!) (string "Salvē") (char #\!))

[Assistant]
(defmacro between (a parser b &key (id nil))
  "A main parser flanked by two other ones. Only the value of the main parser is
kept. Good for parsing backets, parentheses, etc."
  (declare (ignore id))
  `(*> ,a (<* ,parser ,b)))

;; macroexpand:
(*> (char #\EXCLAMATION_MARK) (<* (string "Salvē") (char #\EXCLAMATION_MARK)))


[User]
Define a macro that eliminates this repetitive pattern:
(with-decoder-simple-clos-semantics (setf x (decode-json-from-string "{\"x\":1}")) (is (equal (symbol-package (first-bound-slot-name x)) (find-package :keyword))))

Issue: Macro call that should be transformed by with-decoder-simple-clos-semantics

(with-decoder-simple-clos-semantics (setf x (decode-json-from-string "{\"x\":1}")) (is (equal (symbol-package (first-bound-slot-name x)) (find-package :keyword))))

[Assistant]
(defmacro with-decoder-simple-clos-semantics (&body body)
  "Execute BODY in a dynamic environement where the decoder semantics
is such as set by SET-DECODER-SIMPLE-CLOS-SEMANTICS."
  `(with-shadowed-custom-vars
     (set-decoder-simple-clos-semantics)
     ,@body))

;; macroexpand:
(with-shadowed-custom-vars (set-decoder-simple-clos-semantics) (setf x (decode-json-from-string "{\"x\":1}")) (is (equal (symbol-package (first-bound-slot-name x)) (find-package :keyword))))


[User]
Generate a defmacro form that transforms code like this:
(dynamic-let nil
  :key
  nil)

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

(dynamic-let nil
  :key
  nil)

[Assistant]
(defmacro DYNAMIC-LET ...)

;; macroexpand:
(let ()
  (dynamic-wind
    :proceed
    #:g195
    (let ()
      (declare (special))
      (#:g195 :key nil))))


[User]
Define a macro that eliminates this repetitive pattern:
(max-of nil)

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

(max-of nil)

[Assistant]
(defmacro MAX-OF ...)

;; macroexpand:
(lc (nil) maximize)


[User]
Generate a defmacro form that transforms code like this:
(defhandler let (let bindings &rest body) (let ((names (loop for binding in bindings collect (force-first binding)))) `(list* ',let (list ,@(loop for binding in bindings collect (if (symbolp binding) `',binding `(list ',(first binding) ,@(e-list (rest binding)))))) (with-imposed-bindings (,let ,names (declare (ignorable ,@names)) (m-list ,@body))))))

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

(defhandler let (let bindings &rest body) (let ((names (loop for binding in bindings collect (force-first binding)))) `(list* ',let (list ,@(loop for binding in bindings collect (if (symbolp binding) `',binding `(list ',(first binding) ,@(e-list (rest binding)))))) (with-imposed-bindings (,let ,names (declare (ignorable ,@names)) (m-list ,@body))))))

[Assistant]
(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))))))

;; macroexpand:
(progn (defun hander-let (let bindings &rest body) (let ((names (loop for binding in bindings collect (force-first binding)))) (sb-int:quasiquote (list* (quote #S(sb-impl::comma :expr let :kind 0)) (list #S(sb-impl::comma :expr (loop for binding in bindings collect (if (symbolp binding) (sb-int:quasiquote (quote #S(sb-impl::comma :expr binding :kind 0))) (sb-int:quasiquote (list (quote #S(sb-impl::comma :expr (first binding) :kind 0)) #S(sb-impl::comma :expr (e-list (rest binding)) :kind 2))))) :kind 2)) (with-imposed-bindings (#S(sb-impl::comma :expr let :kind 0) #S(sb-impl::comma :expr names :kind 0) (declare (ignorable #S(sb-impl::comma :expr names :kind 2))) (m-list #S(sb-impl::comma :expr body :kind 2)))))))) (setf (gethash (quote let) *form-handler*) (quote hander-let)))


[User]
Write a Common Lisp macro to handle this code pattern:
(asynchronously (val) (put 2) (flet ((%continue () (continue-flow (+ 1 val)))) (run-it (-> :heh () (funcall #'%continue)))))

Problem: Macro call that should be transformed by asynchronously

(asynchronously (val) (put 2) (flet ((%continue () (continue-flow (+ 1 val)))) (run-it (-> :heh () (funcall #'%continue)))))

[Assistant]
(defmacro asynchronously (lambda-list &body body)
  "Splits current flow allowing manually managing its execution via #'continue-flow and
#'interrupt-flow functions. Consing: ~32 bytes per invocation"
  (with-gensyms (continue-arg condi)
    (flow-lambda-macro (flow-context)
      (let ((fu-body `((flet ((continue-flow (&optional ,continue-arg)
                                (capture-flow-value ,flow-context ,continue-arg)
                                (dispatch-rest ,flow-context))
                              (interrupt-flow (&optional ,condi)
                                (error ,condi)))
                         (declare (ignorable (function continue-flow)
                                             (function interrupt-flow)))
                         ,@body))))
        (with-flow-function-macro (body-fu lambda-list fu-body)
          `(dispatch-asynchronously ,flow-context #',body-fu))))))

;; macroexpand:
(%flow-lambda (#:flow-context151) (%with-flow-function (#:body-fu152 (val) (flet ((continue-flow (&optional #:continue-arg149) (capture-flow-value #:flow-context151 #:continue-arg149) (dispatch-rest #:flow-context151)) (interrupt-flow (&optional #:condi150) (error #:condi150))) (declare (ignorable (function continue-flow) (function interrupt-flow))) (put 2) (flet ((%continue nil (continue-flow (+ 1 val)))) (run-it (-> :heh nil (funcall (function %continue))))))) (dispatch-asynchronously #:flow-context151 (function #:body-fu152))))


[User]
You are a Common Lisp macro expert. Given this code pattern:
(defun-compile-time indirect-callees-internal (function-names callees) (if (null function-names) callees (let ((function-name (first function-names))) (if (member function-name callees :test #'equal) (indirect-callees-internal (rest function-names) callees) (indirect-callees-internal (rest function-names) (indirect-callees-internal (callees function-name) (cons function-name callees)))))))

Write a macro that addresses: Macro call that should be transformed by defun-compile-time

(defun-compile-time indirect-callees-internal (function-names callees) (if (null function-names) callees (let ((function-name (first function-names))) (if (member function-name callees :test #'equal) (indirect-callees-internal (rest function-names) callees) (indirect-callees-internal (rest function-names) (indirect-callees-internal (callees function-name) (cons function-name callees)))))))

[Assistant]
(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))))

;; macroexpand:
(eval-when (:compile-toplevel :load-toplevel :execute) (common-lisp:defun indirect-callees-internal (function-names callees) (if (null function-names) callees (let ((function-name (first function-names))) (if (member function-name callees :test (function equal)) (indirect-callees-internal (rest function-names) callees) (indirect-callees-internal (rest function-names) (indirect-callees-internal (callees function-name) (cons function-name callees))))))) (eval-when (:compile-toplevel) (compile (quote indirect-callees-internal))))


[User]
You are a Common Lisp macro expert. Given this code pattern:
(define-compile-struct sql-statement)

Write a macro that addresses: Macro call that should be transformed by define-compile-struct

(define-compile-struct sql-statement)

[Assistant]
(defmacro define-compile-struct (structure-name &rest defstruct-options)
  (flet ((symbolcat (&rest symbols)
           (intern (format nil "~{~A~^-~}" symbols) #.*package*)))
    (let ((compiled-name (symbolcat structure-name :compiled)))
      `(progn
         (defstruct (,compiled-name (:include ,structure-name ,@defstruct-options))
           (sql nil :type string)
           (bind nil :type list))

         (defmethod find-compile-function ((object ,structure-name))
           (function ,(symbolcat :make compiled-name)))

         (defmethod print-object ((object ,compiled-name) stream)
           (format stream "#<SXQL-COMPILED: ~A [~{~A~^, ~}]>"
                   (,(symbolcat compiled-name :sql) object)
                   (,(symbolcat compiled-name :bind) object)))

         (defmethod yield ((object ,compiled-name))
           (values
            (,(symbolcat compiled-name :sql) object)
            (,(symbolcat compiled-name :bind) object)))))))

;; macroexpand:
(progn (defstruct (sql-statement-compiled (:include sql-statement)) (sql nil :type string) (bind nil :type list)) (defmethod find-compile-function ((object sql-statement)) (function make-sql-statement-compiled)) (defmethod print-object ((object sql-statement-compiled) stream) (format stream "#<SXQL-COMPILED: ~A [~{~A~^, ~}]>" (sql-statement-compiled-sql object) (sql-statement-compiled-bind object))) (defmethod yield ((object sql-statement-compiled)) (values (sql-statement-compiled-sql object) (sql-statement-compiled-bind object))))


[User]
You are a Common Lisp macro expert. Given this code pattern:
(defalias path:-d (directory) cl-fad:directory-exists-p)

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

(defalias path:-d (directory) cl-fad:directory-exists-p)

[Assistant]
(defmacro defalias (name args realname)
  `(progn
     (defun ,name ,args
       ,(if (eql '&rest (first args))
            `(apply #',realname ,(second args))
            `(,realname ,@args)))
     (define-compiler-macro ,name (&rest args)
       (list* ',realname args))))

;; macroexpand:
(progn (defun path:-d (directory) (directory-exists-p directory)) (define-compiler-macro path:-d (&rest args) (list* (quote directory-exists-p) args)))


[User]
Define a macro that eliminates this repetitive pattern:
(builder :session (:csrf :form-token "test_input_name") #'(lambda (env) (let ((req (make-request env))) `(200 (:content-type "text/html") (,(if (and (eq :post (request-method req)) (assoc "name" (request-body-parameters req) :test #'string=)) (cdr (assoc "name" (request-body-parameters req) :test #'string=)) (html-form env)))))))

Issue: Macro call that should be transformed by builder

(builder :session (:csrf :form-token "test_input_name") #'(lambda (env) (let ((req (make-request env))) `(200 (:content-type "text/html") (,(if (and (eq :post (request-method req)) (assoc "name" (request-body-parameters req) :test #'string=)) (cdr (assoc "name" (request-body-parameters req) :test #'string=)) (html-form env)))))))

[Assistant]
(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)))

;; macroexpand:
(reduce (function funcall) (remove-if (function null) (list (find-middleware :session) (lambda (#:app210) (funcall (find-middleware :csrf) #:app210 :form-token "test_input_name")))) :initial-value (to-app (function (lambda (env) (let ((req (make-request env))) (sb-int:quasiquote (200 (:content-type "text/html") (#S(sb-impl::comma :expr (if (and (eq :post (request-method req)) (assoc "name" (request-body-parameters req) :test (function string=))) (cdr (assoc "name" (request-body-parameters req) :test (function string=))) (html-form env)) :kind 0)))))))) :from-end t)


[User]
Create a Common Lisp macro for the following transformation. Before code:
(defstore add (&rest args))

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

(defstore add (&rest args))

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

;; macroexpand:
(eval-when (:compile-toplevel :load-toplevel :execute) (progn (ensure-store (quote add) (quote (&rest args)))))


[User]
Define a macro that eliminates this repetitive pattern:
(define-test capture (fail-compile (defun foo () (frob)) style-warning))

Issue: Macro call that should be transformed by define-test

(define-test capture (fail-compile (defun foo () (frob)) style-warning))

[Assistant]
(defmacro define-test (name &body arguments-and-body)
  (destructuring-bind (nparent name) (if (listp name) name (list NIL name))
    (form-fiddle:with-body-options (body options parent home (test-class 'test) (compile-at :compile-time) defun) arguments-and-body
      (let ((body (remove 'define-test body :key (lambda (a) (when (listp a) (car a))) :test #'eql))
            (defs (remove 'define-test body :key (lambda (a) (when (listp a) (car a))) :test-not #'eql))
            (home-form (or home `(find-package ,(package-name *package*)))))
        (when (and parent nparent)
          (error "Cannot specify parent through name and through a keyword argument at the same time!"))
        `(let ((*package* (find-package ,(package-name *package*)))) ; Make sure package stays consistent throughout initialisation.
           (setf (find-test ',name ,home-form)
                 (ensure-test ',test-class
                              :name ',name
                              :home ,home-form
                              :tests (list ,@(loop for form in body
                                                   collect (ecase compile-at
                                                             (:compile-time `(lambda () ,form))
                                                             (:execute `(lambda () (call-compile ',form))))))
                              :parent ',(or parent nparent)
                              ,@(loop for option in options
                                      collect `',option)))
           ,@(loop for (def subname . body) in defs
                   collect `(,def (,name ,subname)
                              :home ,home
                              ,@body))
           ,@(when defun
               `((defun ,(if (stringp name) (read-symbol name) name) (&rest test-args)
                   (apply #'test (find-test ',name ,home-form) test-args))))
           ',name)))))

;; macroexpand:
(let ((*package* (find-package #A((9) base-char . "PARACHUTE")))) (setf (find-test (quote capture) (find-package #A((9) base-char . "PARACHUTE"))) (ensure-test (quote test) :name (quote capture) :home (find-package #A((9) base-char . "PARACHUTE")) :tests (list (lambda nil (fail-compile (defun foo nil (frob)) style-warning))) :parent (quote nil))) (quote capture))