[User]
Write a Common Lisp macro to handle this code pattern:
(bind (((:plist a (b _) (c _ 2) (dd d)) '(:b #\b :a #\a :d #\d))) (list a b c dd))

Problem: Macro call that should be transformed by bind

(bind (((:plist a (b _) (c _ 2) (dd d)) '(:b #\b :a #\a :d #\d))) (list a b c dd))

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

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

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

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

;; macroexpand:
(let* ((#:|values-187| (quote (:b #\LATIN_SMALL_LETTER_B :a #\LATIN_SMALL_LETTER_A :d #\LATIN_SMALL_LETTER_D))) (a (getf #:|values-187| :a)) (b (getf #:|values-187| :b)) (c (getf #:|values-187| :c 2)) (dd (getf #:|values-187| :d))) (declare (ignorable #:|values-187|)) (progn (list a b c dd)))


[User]
Define a macro that eliminates this repetitive pattern:
(defstore example (a))

Issue: Macro call that should be transformed by defstore

(defstore example (a))

[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 example) (quote (a)))))


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

Issue: Macro call that should be transformed by DYNENV-MACROLET

(dynenv-macrolet nil
  :key
  nil)

[Assistant]
(defmacro DYNENV-MACROLET ...)

;; macroexpand:
(macrolet ()
  :key
  nil)


[User]
Create a Common Lisp macro for the following transformation. Before code:
(defun-compile-time check-lambda-list (lambda-list) (unless (null (rest (last lambda-list))) (error "Improper lambda-list: ~S" lambda-list)) (let ((rest (member '&rest lambda-list :test #'eq))) (if rest (let ((rest (rest rest))) (unless (not (member '&rest rest :test #'eq)) (error "&REST cannot appear more than once: ~S" lambda-list)) (unless (and (not (null rest)) (not (member (first rest) lambda-list-keywords :test #'eq)) (or (null (rest rest)) (member (first (rest rest)) lambda-list-keywords :test #'eq))) (error "&REST must be followed by exactly one variable: ~S" lambda-list))))) (let ((allow-other-keys (member '&allow-other-keys lambda-list :test #'eq))) (if allow-other-keys (unless (or (null (rest allow-other-keys)) (member (first (rest allow-other-keys)) lambda-list-keywords :test #'eq)) (error "&ALLOW-OTHER-KEYS must not be followed by a parameter: ~S" lambda-list)))) (let ((keywords (remove-if-not #'(lambda (argument) (member argument lambda-list-keywords :test #'eq)) lambda-list))) (unless (every #'(lambda (keyword) (member keyword *ordered-lambda-list-keywords* :test #'eq)) keywords) (error "Invalid lambda list keyword: ~S" lambda-list)) (unless (every #'(lambda (x y) (member y (member x *ordered-lambda-list-keywords* :test #'eq) :test #'eq)) keywords (rest keywords)) (error "Invalid order for lambda list keywords: ~S" lambda-list))) (check-lambda-list-internal lambda-list))

What needs to change: Macro call that should be transformed by defun-compile-time

(defun-compile-time check-lambda-list (lambda-list) (unless (null (rest (last lambda-list))) (error "Improper lambda-list: ~S" lambda-list)) (let ((rest (member '&rest lambda-list :test #'eq))) (if rest (let ((rest (rest rest))) (unless (not (member '&rest rest :test #'eq)) (error "&REST cannot appear more than once: ~S" lambda-list)) (unless (and (not (null rest)) (not (member (first rest) lambda-list-keywords :test #'eq)) (or (null (rest rest)) (member (first (rest rest)) lambda-list-keywords :test #'eq))) (error "&REST must be followed by exactly one variable: ~S" lambda-list))))) (let ((allow-other-keys (member '&allow-other-keys lambda-list :test #'eq))) (if allow-other-keys (unless (or (null (rest allow-other-keys)) (member (first (rest allow-other-keys)) lambda-list-keywords :test #'eq)) (error "&ALLOW-OTHER-KEYS must not be followed by a parameter: ~S" lambda-list)))) (let ((keywords (remove-if-not #'(lambda (argument) (member argument lambda-list-keywords :test #'eq)) lambda-list))) (unless (every #'(lambda (keyword) (member keyword *ordered-lambda-list-keywords* :test #'eq)) keywords) (error "Invalid lambda list keyword: ~S" lambda-list)) (unless (every #'(lambda (x y) (member y (member x *ordered-lambda-list-keywords* :test #'eq) :test #'eq)) keywords (rest keywords)) (error "Invalid order for lambda list keywords: ~S" lambda-list))) (check-lambda-list-internal lambda-list))

[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 check-lambda-list (lambda-list) (unless (null (rest (last lambda-list))) (error "Improper lambda-list: ~S" lambda-list)) (let ((rest (member (quote &rest) lambda-list :test (function eq)))) (if rest (let ((rest (rest rest))) (unless (not (member (quote &rest) rest :test (function eq))) (error "&REST cannot appear more than once: ~S" lambda-list)) (unless (and (not (null rest)) (not (member (first rest) lambda-list-keywords :test (function eq))) (or (null (rest rest)) (member (first (rest rest)) lambda-list-keywords :test (function eq)))) (error "&REST must be followed by exactly one variable: ~S" lambda-list))))) (let ((allow-other-keys (member (quote &allow-other-keys) lambda-list :test (function eq)))) (if allow-other-keys (unless (or (null (rest allow-other-keys)) (member (first (rest allow-other-keys)) lambda-list-keywords :test (function eq))) (error "&ALLOW-OTHER-KEYS must not be followed by a parameter: ~S" lambda-list)))) (let ((keywords (remove-if-not (function (lambda (argument) (member argument lambda-list-keywords :test (function eq)))) lambda-list))) (unless (every (function (lambda (keyword) (member keyword *ordered-lambda-list-keywords* :test (function eq)))) keywords) (error "Invalid lambda list keyword: ~S" lambda-list)) (unless (every (function (lambda (x y) (member y (member x *ordered-lambda-list-keywords* :test (function eq)) :test (function eq)))) keywords (rest keywords)) (error "Invalid order for lambda list keywords: ~S" lambda-list))) (check-lambda-list-internal lambda-list)) (eval-when (:compile-toplevel) (compile (quote check-lambda-list))))


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

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

(when nil)

[Assistant]
(defmacro WHEN ...)

;; macroexpand:
(if nil
    nil)


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

Write a macro that addresses: Macro call that should be transformed by DEFINE-PACKAGE-SYNTAX

(define-package-syntax
  'some-name)

[Assistant]
(defmacro define-package-syntax (&body (package . options))
  (unless (typep package 'package-designator)
    (push package options)
    (setq package *package*))
  `(defsyntax ,(package-syntax-name package)
     ,@options))

;; macroexpand:
(defsyntax syntax
  'some-name)


[User]
Generate a defmacro form that transforms code like this:
($+ result)

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

($+ result)

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

;; macroexpand:
(construct-$+- 1 result)


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

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

(cond->>
  nil
  :key
  nil)

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

;; macroexpand:
(let* ((#:var166 nil)
       (#:var167
        (if :key
            (->>
              #:var166)
            #:var166))
       (#:var168
        (if nil
            (->>
              #:var167)
            #:var167)))
  #:var168)


[User]
Generate a defmacro form that transforms code like this:
(min-of 'some-name)

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

(min-of 'some-name)

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

;; macroexpand:
(lc ('some-name) minimize)


[User]
Write a Common Lisp macro to handle this code pattern:
(define-error if-test-type-mismatch (:error-type varjo-critical-error) (test-obj) "The result of the test must be a bool.~%~s" (primary-type test-obj))

Problem: Macro call that should be transformed by define-error

(define-error if-test-type-mismatch (:error-type varjo-critical-error) (test-obj) "The result of the test must be a bool.~%~s" (primary-type test-obj))

[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 if-test-type-mismatch (:error-type varjo-critical-error :prefix "Varjo") (test-obj) "The result of the test must be a bool.~%~s" (primary-type test-obj))


[User]
Generate a defmacro form that transforms code like this:
(sif it it)

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

(sif it it)

[Assistant]
(defmacro sif (test then &optional else)
  "Like IF, except binds the test form to IT (via SYMBOL-MACROLET) for
the scope of the then and else expressions. IT can be set with SETF"
  `(symbolic if ,test ,then ,else))

;; macroexpand:
(symbolic if it it nil)


[User]
Generate a defmacro form that transforms code like this:
(macroexpand-convention (form) (if (consp form) (expand-add-declaration-using-head (first form) decl-specifier form) form))

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

(macroexpand-convention (form) (if (consp form) (expand-add-declaration-using-head (first form) decl-specifier form) form))

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

;; macroexpand:
(multiple-value-bind (result expanded-p) (progn (if (consp form) (expand-add-declaration-using-head (first form) decl-specifier form) form)) (values result (or expanded-p (not (eq result form)))))


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

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

(defgeneric nil
    (progn))

[Assistant]
(defmacro DEFGENERIC ...)

;; macroexpand:
(progn
 (eval-when (:compile-toplevel)
   (common-lisp:defgeneric nil
       (progn)))
 (eval-when (:load-toplevel :execute)
   (common-lisp:defgeneric nil
       (progn))))


[User]
Define a macro that eliminates this repetitive pattern:
(alist-bind (name fields) form (let ((sym (foreign-type-symbol name :cstruct *package*))) (let ((cstruct-fields (parse-fields fields))) (when (symbol-package sym) (pushnew `(:struct (,sym)) *foreign-record-list* :test #'equal)) `(define-foreign-record ',sym :struct ,(aval :bit-size form) ,(aval :bit-alignment form) ',cstruct-fields))))

Issue: Macro call that should be transformed by alist-bind

(alist-bind (name fields) form (let ((sym (foreign-type-symbol name :cstruct *package*))) (let ((cstruct-fields (parse-fields fields))) (when (symbol-package sym) (pushnew `(:struct (,sym)) *foreign-record-list* :test #'equal)) `(define-foreign-record ',sym :struct ,(aval :bit-size form) ,(aval :bit-alignment form) ',cstruct-fields))))

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

;; macroexpand:
(let ((#:alist241 form)) (let ((name (aval :name #:alist241)) (fields (aval :fields #:alist241))) (let ((sym (foreign-type-symbol name :cstruct *package*))) (let ((cstruct-fields (parse-fields fields))) (when (symbol-package sym) (pushnew (sb-int:quasiquote (:struct (#S(sb-impl::comma :expr sym :kind 0)))) *foreign-record-list* :test (function equal))) (sb-int:quasiquote (define-foreign-record (quote #S(sb-impl::comma :expr sym :kind 0)) :struct #S(sb-impl::comma :expr (aval :bit-size form) :kind 0) #S(sb-impl::comma :expr (aval :bit-alignment form) :kind 0) (quote #S(sb-impl::comma :expr cstruct-fields :kind 0))))))))


[User]
Create a Common Lisp macro for the following transformation. Before code:
(-> :g ((a (b))) (put a) (put b) (mt:open-latch latch))

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

(-> :g ((a (b))) (put a) (put b) (mt:open-latch latch))

[Assistant]
(defmacro -> (invariant &body args)
  "See flow:atomically"
  `(atomically ,invariant ,@args))

;; macroexpand:
(atomically :g ((a (b))) (put a) (put b) (cl-muth:open-latch latch))


[User]
Define a macro that eliminates this repetitive pattern:
(asif (car x) (setf x :oops) (setf it :yes!))

Issue: Macro call that should be transformed by asif

(asif (car x) (setf x :oops) (setf it :yes!))

[Assistant]
(defmacro asif (test then &optional else)
  "Like IF, except binds the result of the test to IT (via LET) for
the the scope of the then-expression, and the test form to IT (via
SYMBOL-MACROLET) for the scope of the else-expression. Within scope of
the else-expression, IT can be set with SETF."
    `(let ((it ,test))
       (if it
	   ,then
	   (symbolic ignore-first ,test ,else))))

;; macroexpand:
(let ((it (car x))) (if it (setf x :oops) (symbolic ignore-first (car x) (setf it :yes!))))


[User]
Create a Common Lisp macro for the following transformation. Before code:
(define-simple-documentation-lookup variable cl:variable)

What needs to change: Macro call that should be transformed by define-simple-documentation-lookup

(define-simple-documentation-lookup variable cl:variable)

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

;; macroexpand:
(defmethod documentation ((variable variable)) (common-lisp:documentation (designator variable) (quote common-lisp:variable)))


[User]
Create a Common Lisp macro for the following transformation. Before code:
(define-test dependency (false (sleep 1)))

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

(define-test dependency (false (sleep 1)))

[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 dependency) (find-package #A((9) base-char . "PARACHUTE"))) (ensure-test (quote test) :name (quote dependency) :home (find-package #A((9) base-char . "PARACHUTE")) :tests (list (lambda nil (false (sleep 1)))) :parent (quote nil))) (quote dependency))


[User]
You are a Common Lisp macro expert. Given this code pattern:
(bind (((:labels my-oddp (x)) (cond ((<= x 0) nil) ((= x 1) t) (t (my-oddp (- x 2)))))) (ensure (my-oddp 1)) (ensure (my-oddp 7)) (ensure-null (my-oddp 2)))

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

(bind (((:labels my-oddp (x)) (cond ((<= x 0) nil) ((= x 1) t) (t (my-oddp (- x 2)))))) (ensure (my-oddp 1)) (ensure (my-oddp 7)) (ensure-null (my-oddp 2)))

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

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

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

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

;; macroexpand:
(labels ((my-oddp (x) (progn (cond ((<= x 0) nil) ((= x 1) t) (t (my-oddp (- x 2))))))) (progn (ensure (my-oddp 1)) (ensure (my-oddp 7)) (ensure-null (my-oddp 2))))


[User]
Write a Common Lisp macro to handle this code pattern:
;; Closure variables are opaque - can't inspect or modify them
(let ((acc 0) (mul 1))
  (lambda (n)
    (incf acc n)
    (setf mul (* mul n))))

;; To access acc/mul: must add specific getter/setter methods
;; This doesn't scale - every variable needs its own accessor

Problem: Closure internals are opaque — want a general protocol for reading/writing any closed-over variable

;; Closure variables are opaque - can't inspect or modify them
(let ((acc 0) (mul 1))
  (lambda (n)
    (incf acc n)
    (setf mul (* mul n))))

;; To access acc/mul: must add specific getter/setter methods
;; This doesn't scale - every variable needs its own accessor

[Assistant]
(defun pandoriclet-get (letargs)
  `(case sym
     ,@(mapcar #`((,(car a1)) ,(car a1))
               letargs)
     (t (error
          "Unknown pandoric get: ~a"
          sym))))

(defun pandoriclet-set (letargs)
  `(case sym
     ,@(mapcar #`((,(car a1))
                   (setq ,(car a1) val))
               letargs)
     (t (error
          "Unknown pandoric set: ~a"
          sym val))))

(defmacro pandoriclet (letargs &rest body)
  (let ((letargs (cons
                   '(this)
                   (let-binding-transform
                     letargs))))
    `(let (,@letargs)
       (setq this ,@(last body))
       ,@(butlast body)
       (dlambda
         (:pandoric-get (sym)
           ,(pandoriclet-get letargs))
         (:pandoric-set (sym val)
           ,(pandoriclet-set letargs))
         (t (&rest args)
           (apply this args))))))

;; macroexpand:
;; (pandoriclet ((acc 0) (mul 1))
;;   (lambda (n) (incf acc n) (setf mul (* mul n))))
;;
;; Now:
;; (closure :pandoric-get 'acc)    => value of acc
;; (closure :pandoric-set 'acc 100) => sets acc to 100
;; (closure 5)                      => normal call
;;
;; with-pandoric makes them look like regular variables:
;; (with-pandoric (acc mul) closure
;;   (setf acc (+ acc 10)))


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

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

(defmethod nil
  (progn))

[Assistant]
(defmacro DEFMETHOD ...)

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


[User]
Write a Common Lisp macro to handle this code pattern:
(whichever (1+ x))

Problem: Macro call that should be transformed by whichever

(whichever (1+ x))

[Assistant]
(defmacro whichever (&rest possibilities &environment env)
  "Evaluates exactly one of POSSIBILITIES, chosen at random."
  (setf possibilities (mapcar (lambda (p) (macroexpand p env)) possibilities))
  (let ((length (length possibilities)))
    (cond
      ((= 1 length)
       (first possibilities))
      ((every #'constantp possibilities)
       `(svref (load-time-value (vector ,@possibilities))
               (random ,length)))
      (T
       (labels ((expand (possibilities position random-number)
                  (if (null (cdr possibilities))
                      (car possibilities)
                      (let* ((length (length possibilities))
                             (half (truncate length 2))
                             (second-half (nthcdr half possibilities))
                             (first-half (butlast possibilities (- length half))))
                        `(if (< ,random-number ,(+ position half))
                             ,(expand first-half position random-number)
                             ,(expand second-half (+ position half) random-number))))))
         (with-gensyms (random-number)
           `(let ((,random-number (random ,length)))
              ,(expand possibilities 0 random-number))))))))

;; macroexpand:
(1+ x)


[User]
You are a Common Lisp macro expert. Given this code pattern:
(with-special-initargs* nil)

Write a macro that addresses: Macro call that should be transformed by WITH-SPECIAL-INITARGS*

(with-special-initargs* nil)

[Assistant]
(defmacro WITH-SPECIAL-INITARGS* ...)

;; macroexpand:
(progn)


[User]
You are a Common Lisp macro expert. Given this code pattern:
(define-class some-class (some super classes) () (1 2) (3 4))

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

(define-class some-class (some super classes) () (1 2) (3 4))

[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) nil (1 2) (3 4)) (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)))) (find-class (quote some-class) nil))


[User]
Define a macro that eliminates this repetitive pattern:
(with-special-initargs* nil
  :key
  nil)

Issue: Macro call that should be transformed by WITH-SPECIAL-INITARGS*

(with-special-initargs* nil
  :key
  nil)

[Assistant]
(defmacro WITH-SPECIAL-INITARGS* ...)

;; macroexpand:
(progn :key nil)


[User]
Define a macro that eliminates this repetitive pattern:
(def-dynenv-var nil nil)

Issue: Macro call that should be transformed by DEF-DYNENV-VAR

(def-dynenv-var nil nil)

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

;; macroexpand:
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defvar #:nil172 (load-time-value nil))
  (setf (get 'nil 'dynenv-var) '#:nil172)
  (define-symbol-macro nil (get-dynenv-var 'nil)))


[User]
Write a Common Lisp macro to handle this code pattern:
(with-table node hash depth (bitmap array bits index hit) (flet ((%insert (table) (%set-insert table key hash (1+ depth) test))) (let ((new-node (cond (hit (%insert (aref array index))) ((= depth 6) (make-instance 'set-leaf :key key)) (t (%insert (make-instance 'set-table)))))) (make-instance 'set-table :bitmap (logior bitmap (ash 1 bits)) :table (funcall (if hit #'vec-update #'vec-insert) array index new-node)))))

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

(with-table node hash depth (bitmap array bits index hit) (flet ((%insert (table) (%set-insert table key hash (1+ depth) test))) (let ((new-node (cond (hit (%insert (aref array index))) ((= depth 6) (make-instance 'set-leaf :key key)) (t (%insert (make-instance 'set-table)))))) (make-instance 'set-table :bitmap (logior bitmap (ash 1 bits)) :table (funcall (if hit #'vec-update #'vec-insert) array index new-node)))))

[Assistant]
(defmacro with-table (node hash depth
                      (bitmap array bits index hit)
                      &body body)
  "Bitshifting in HAMT tables"
  `(let* ((,bitmap (table-bitmap ,node))
          (,array (table-array ,node))
          (,bits (get-bits ,hash ,depth))
          (,index (get-index ,bits ,bitmap))
          (,hit (logbitp ,bits ,bitmap)))
     ,@body))

;; macroexpand:
(let* ((bitmap (table-bitmap node)) (array (table-array node)) (bits (get-bits hash depth)) (index (get-index bits bitmap)) (hit (logbitp bits bitmap))) (flet ((%insert (table) (%set-insert table key hash (1+ depth) test))) (let ((new-node (cond (hit (%insert (aref array index))) ((= depth 6) (make-instance (quote set-leaf) :key key)) (t (%insert (make-instance (quote set-table))))))) (make-instance (quote set-table) :bitmap (logior bitmap (ash 1 bits)) :table (funcall (if hit (function vec-update) (function vec-insert)) array index new-node)))))


[User]
Generate a defmacro form that transforms code like this:
(dletf* 'some-name)

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

(dletf* 'some-name)

[Assistant]
(defmacro DLETF* ...)

;; macroexpand:
(dlet ('nil)
  (dlet ((some-name nil))
    (progn)))


[User]
Define a macro that eliminates this repetitive pattern:
(bind (((:labels constant (x)) (declare (ignore x)) 42)) (ensure-same (constant 1) 42))

Issue: Macro call that should be transformed by bind

(bind (((:labels constant (x)) (declare (ignore x)) 42)) (ensure-same (constant 1) 42))

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

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

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

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

;; macroexpand:
(labels ((constant (x) (declare (ignore x)) (progn 42))) (progn (ensure-same (constant 1) 42)))


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

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

(fgathering nil)

[Assistant]
(defmacro FGATHERING ...)

;; macroexpand:
(flet ()
  (values))


[User]
Generate a defmacro form that transforms code like this:
(with-wrap-attempt () name (let ((extern (make-instance 'foreign-extern :name name :c-symbol c-symbol :type (ensure-type type "extern ~S of type ~S" name type)))) (setf (gethash name *foreign-externs*) extern)))

Pattern to recognize: Macro call that should be transformed by with-wrap-attempt

(with-wrap-attempt () name (let ((extern (make-instance 'foreign-extern :name name :c-symbol c-symbol :type (ensure-type type "extern ~S of type ~S" name type)))) (setf (gethash name *foreign-externs*) extern)))

[Assistant]
(defmacro with-wrap-attempt ((&optional format-control &rest format-args) wrappable-name &body body)
  `(call-with-wrap-attempt ,wrappable-name (lambda () ,@body) ,format-control (list ,@format-args)))

;; macroexpand:
(call-with-wrap-attempt name (lambda nil (let ((extern (make-instance (quote foreign-extern) :name name :c-symbol c-symbol :type (ensure-type type "extern ~S of type ~S" name type)))) (setf (gethash name *foreign-externs*) extern))) nil (list))


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

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

(defmethod* nil
    :key
  nil)

[Assistant]
(defmacro DEFMETHOD* ...)

;; macroexpand:
(defmethod nil :key (with-yield ()))


[User]
Write a Common Lisp macro to handle this code pattern:
(def-unbound-dynenv-fun nil)

Problem: Macro call that should be transformed by DEF-UNBOUND-DYNENV-FUN

(def-unbound-dynenv-fun nil)

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

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


[User]
Define a macro that eliminates this repetitive pattern:
(with-yield-binds (let ((when-else (loop for obj in (conjunctive-op-expressions op) collect (with-table-name nil (yield obj))))) (format nil "CASE ~{~A~^ ~} END" when-else)))

Issue: Macro call that should be transformed by with-yield-binds

(with-yield-binds (let ((when-else (loop for obj in (conjunctive-op-expressions op) collect (with-table-name nil (yield obj))))) (format nil "CASE ~{~A~^ ~} END" when-else)))

[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 (let ((when-else (loop for obj in (conjunctive-op-expressions op) collect (with-table-name nil (yield obj))))) (format nil "CASE ~{~A~^ ~} END" when-else))) (loop for bind in (reverse *bind-values*) append bind)))


[User]
Write a Common Lisp macro to handle this code pattern:
(when (find (subseq arg 2) *clon-shuffle-opts-long* :test #'string-equal) (setf expecting-arg t))

Problem: Macro call that should be transformed by when

(when (find (subseq arg 2) *clon-shuffle-opts-long* :test #'string-equal) (setf expecting-arg t))

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

;; macroexpand:
(if (find (subseq arg 2) *clon-shuffle-opts-long* :test (function string-equal)) (setf expecting-arg t))


[User]
Generate a defmacro form that transforms code like this:
(make-name-transformer nil (progn))

Pattern to recognize: Macro call that should be transformed by MAKE-NAME-TRANSFORMER

(make-name-transformer nil (progn))

[Assistant]
(defmacro MAKE-NAME-TRANSFORMER ...)

;; macroexpand:
(lambda (name definition)
  (declare (ignorable definition))
  (concatenate-symbol nil (progn)))


[User]
You are a Common Lisp macro expert. Given this code pattern:
(define-custom-var (:object-key *object-key-handler*))

Write a macro that addresses: Macro call that should be transformed by define-custom-var

(define-custom-var (:object-key *object-key-handler*))

[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 (*object-key-handler* . :object-key)) *custom-vars* :test (function equal)) (defvar *object-key-handler*)))


[User]
You are a Common Lisp macro expert. Given this code pattern:
(builder :session :csrf #'(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)))))))

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

(builder :session :csrf #'(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) (find-middleware :csrf))) :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]
Define a macro that eliminates this repetitive pattern:
(define-mustache-character #\# (make-instance 'section-start-tag :text arg-text :end end :open-delimiter *open-delimiter* :close-delimiter *close-delimiter*))

Issue: Macro call that should be transformed by define

(define-mustache-character #\# (make-instance 'section-start-tag :text arg-text :end end :open-delimiter *open-delimiter* :close-delimiter *close-delimiter*))

[Assistant]
(defmacro define (name template)
  "Define a named renderer of string TEMPLATE."
  `(setf (symbol-function ',name)
         (compile-template ,template)))

;; macroexpand:
(set-mustache-character #\NUMBER_SIGN (lambda (raw-text arg-text escapep start end) (declare (ignorable raw-text arg-text escapep start end) (type simple-string raw-text arg-text) (boolean escapep) (offset start end)) (make-instance (quote section-start-tag) :text arg-text :end end :open-delimiter *open-delimiter* :close-delimiter *close-delimiter*)))


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

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

(with-decoder-simple-list-semantics (setf x (decode-json-from-string "{\"x\":1}")) (is (equal (symbol-package (caar x)) (find-package :keyword))))

[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) (setf x (decode-json-from-string "{\"x\":1}")) (is (equal (symbol-package (caar x)) (find-package :keyword))))


[User]
Write a Common Lisp macro to handle this code pattern:
(define-op (:is-distinct-from infix-op))

Problem: Macro call that should be transformed by define-op

(define-op (:is-distinct-from infix-op))

[Assistant]
(defmacro define-op ((op-name struct-type &key sql-op-name include-slots (package (find-package '#:sxql/operator))) &body body)
  (check-type op-name symbol)
  (let ((struct-name (intern (concatenate 'string (symbol-name op-name) #.(string :-op)) package)))
    `(defstruct (,struct-name (:include ,struct-type
                               (name ,(or sql-op-name
                                          (with-output-to-string (s)
                                            (loop for c across (symbol-name op-name)
                                                  if (char= c #\-)
                                                    do (write-char #\Space s)
                                                  else
                                                    do (write-char c s)))))
                               ,@include-slots)
                              (:constructor ,(intern (concatenate 'string
                                                                  #.(string :make-)
                                                                  (symbol-name op-name)
                                                                  #.(string :-op))
                                                     package)
                                  ,(ecase struct-type
                                     ((unary-op
                                       unary-splicing-op
                                       unary-postfix-op) '(var))
                                     ((infix-op
                                       infix-splicing-op
                                       infix-list-op) '(left right))
                                     (conjunctive-op '(&rest expressions)))))
       ,@body)))

;; macroexpand:
(defstruct (is-distinct-from-op (:include infix-op (name "IS DISTINCT FROM")) (:constructor make-is-distinct-from-op (left right))))


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

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

(defrule nil
  (progn))

[Assistant]
(defmacro DEFRULE ...)

;; macroexpand:
(setf (gethash #A((3) base-char . "NIL") cl-rules.core::*rules*)
        '#S(cl-rules.core::rule
            :name #A((3) base-char . "NIL")
            :conditions (#S(cl-rules.core::condn
                            :name #A((5) base-char . "PROGN")
                            :args nil))
            :actions nil))


[User]
You are a Common Lisp macro expert. Given this code pattern:
(defun* nil
    nil)

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

(defun* nil
    nil)

[Assistant]
(defmacro DEFUN* ...)

;; macroexpand:
(defun nil () (with-yield))


[User]
Define a macro that eliminates this repetitive pattern:
(define-modf-rewrite caadr (expr) `(car (cadr ,(second expr))))

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

(define-modf-rewrite caadr (expr) `(car (cadr ,(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 caadr) *modf-rewrites*) (lambda (expr) (sb-int:quasiquote (car (cadr #S(sb-impl::comma :expr (second expr) :kind 0)))))))


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

Write a macro that addresses: Macro call that should be transformed by LAMBDA-CORO

(lambda-coro
  'some-name)

[Assistant]
(defmacro LAMBDA-CORO ...)

;; macroexpand:
(progn
 (defcoroutine #:name133
     (#:arg134)
   (macrolet ((yield (form)
                (let ((g!-it (gensym "IT")))
                  `(progn
                    (let ((,g!-it ,form))
                      (cl-coroutine:yield ,g!-it))
                    ,'#:arg134)))
              (last-yield-value ()
                '#:arg134))
     'some-name
     (coexit!)))
 (make-coroutine '#:name133))


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

Issue: Macro call that should be transformed by UNLESS

(unless nil)

[Assistant]
(defmacro UNLESS ...)

;; macroexpand:
(if nil
    nil
    nil)


[User]
You are a Common Lisp macro expert. Given this code pattern:
(with-prepared-query query (*connection* sql :use-prepare-cached *use-prepare-cached*) (let* ((query (with-trace-sql (execute-with-retry query binds))) (format (or format :plist)) (*plist-row-lispify* (if lispify-specified lispify (case format (:plist t) (otherwise nil))))) (retrieve-from-query query format)))

Write a macro that addresses: Macro call that should be transformed by with-prepared-query

(with-prepared-query query (*connection* sql :use-prepare-cached *use-prepare-cached*) (let* ((query (with-trace-sql (execute-with-retry query binds))) (format (or format :plist)) (*plist-row-lispify* (if lispify-specified lispify (case format (:plist t) (otherwise nil))))) (retrieve-from-query query format)))

[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 *connection* sql (lambda (query) (let* ((query (with-trace-sql (execute-with-retry query binds))) (format (or format :plist)) (*plist-row-lispify* (if lispify-specified lispify (case format (:plist t) (otherwise nil))))) (retrieve-from-query query format))) :use-prepare-cached *use-prepare-cached*)


[User]
You are a Common Lisp macro expert. Given this code pattern:
(letv*)

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

(letv*)

[Assistant]
(defmacro LETV* ...)

;; macroexpand:
(block nil)


[User]
Define a macro that eliminates this repetitive pattern:
(do+ (for x (to 5)) (generating y (in #(0 1))) (collect (list x y)) (when (oddp x) (is (eql (try-update y) y))))

Issue: Macro call that should be transformed by do+

(do+ (for x (to 5)) (generating y (in #(0 1))) (collect (list x y)) (when (oddp x) (is (eql (try-update y) y))))

[Assistant]
(defmacro do+ (&body body)
  "High-level, extensible iteration construct. Refer to the manual for syntax and semantics."
  `(do+/internal nil ,@body))

;; macroexpand:
(do+/internal nil (for x (to 5)) (generating y (in #(0 1))) (collect (list x y)) (when (oddp x) (is (eql (try-update y) y))))


[User]
Create a Common Lisp macro for the following transformation. Before code:
(terminate-producing)

What needs to change: Macro call that should be transformed by TERMINATE-PRODUCING

(terminate-producing)

[Assistant]
(defmacro TERMINATE-PRODUCING ...)

;; macroexpand:
(go end)


[User]
Generate a defmacro form that transforms code like this:
(defstore example (a b c))

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

(defstore example (a b c))

[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 example) (quote (a b c)))))


[User]
Generate a defmacro form that transforms code like this:
(doseq (item seq) (when (cl:zerop n) (return)) (accumulate c item) (cl:decf n))

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

(doseq (item seq) (when (cl:zerop n) (return)) (accumulate c item) (cl:decf n))

[Assistant]
(defmacro doseq (name/seq &body body)
  "Iterate over the elements of a single sequence SEQUENCE.

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

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

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

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

   NAME is the block name, NIL if not given.

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

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

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

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

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

;; macroexpand:
(do-sequences nil ((item seq)) (when (zerop n) (return)) (accumulate c item) (decf n))


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

Problem: Macro call that should be transformed by MATCH

(match nil)

[Assistant]
(defmacro MATCH ...)

;; macroexpand:
(match* (nil))


[User]
Generate a defmacro form that transforms code like this:
(macroexpand-convention (form) (if (consp form) (expand-metaclass-using-head (first form) metaclass form) form))

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

(macroexpand-convention (form) (if (consp form) (expand-metaclass-using-head (first form) metaclass form) form))

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

;; macroexpand:
(multiple-value-bind (result expanded-p) (progn (if (consp form) (expand-metaclass-using-head (first form) metaclass form) form)) (values result (or expanded-p (not (eq result form)))))


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

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

(-<>> nil :key nil)

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

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


[User]
Generate a defmacro form that transforms code like this:
(defstore naxpy (a x y))

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

(defstore naxpy (a x y))

[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 naxpy) (quote (a x y)))))


[User]
Define a macro that eliminates this repetitive pattern:
(switch (13) ((+ 12 2) :oops) ((- 13 1) :oops2) (t :yay))

Issue: Macro call that should be transformed by switch

(switch (13) ((+ 12 2) :oops) ((- 13 1) :oops2) (t :yay))

[Assistant]
(defmacro switch (&whole whole (object &key (test 'eql) (key 'identity))
                         &body clauses)
  "Evaluates first matching clause, returning its values, or evaluates and
returns the values of T or OTHERWISE if no keys match."
  (generate-switch-body whole object clauses test key))

;; macroexpand:
(let ((#:value130 (identity 13))) (cond ((eql #:value130 (+ 12 2)) :oops) ((eql #:value130 (- 13 1)) :oops2) (nil) (t (progn :yay))))


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

Problem: Macro call that should be transformed by WHILE

(while nil
  nil)

[Assistant]
(defmacro WHILE ...)

;; macroexpand:
(loop while nil
      do (progn nil))


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

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

(with-slots nil
    nil)

[Assistant]
(defmacro WITH-SLOTS ...)

;; macroexpand:
(let ((#:g178 nil))
  (declare (ignorable #:g178))
  (declare (sb-pcl::%variable-rebinding #:g178 nil))
  (symbol-macrolet ()))


[User]
You are a Common Lisp macro expert. Given this code pattern:
(defstore foo (a b))

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

(defstore foo (a b))

[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 foo) (quote (a b)))))


[User]
Define a macro that eliminates this repetitive pattern:
(define L_tmpnam 16)

Issue: Macro call that should be transformed by define

(define L_tmpnam 16)

[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 l_tmpnam) *preprocessor-defines*) #A((2) base-char . "16"))) (defparameter l_tmpnam 16))


[User]
Define a macro that eliminates this repetitive pattern:
(define-fixture-restore variable (symbol value) (setf (symbol-value symbol) value))

Issue: Macro call that should be transformed by define-fixture-restore

(define-fixture-restore variable (symbol value) (setf (symbol-value symbol) value))

[Assistant]
(defmacro define-fixture-restore (name args &body body)
  `(progn (setf (gethash ',name *fixture-restores*)
                (lambda ,args ,@body))
          ',name))

;; macroexpand:
(progn (setf (gethash (quote variable) *fixture-restores*) (lambda (symbol value) (setf (symbol-value symbol) value))) (quote variable))


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

What needs to change: Macro call that should be transformed by SUM-OF

(sum-of nil
  (progn))

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

;; macroexpand:
(lc (nil (progn)) sum)


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

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

(defgeneric nil
    nil)

[Assistant]
(defmacro DEFGENERIC ...)

;; macroexpand:
(progn
 (eval-when (:compile-toplevel)
   (common-lisp:defgeneric nil
       nil))
 (eval-when (:load-toplevel :execute)
   (common-lisp:defgeneric nil
       nil)))


[User]
Generate a defmacro form that transforms code like this:
(defstore example (x &rest args))

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

(defstore example (x &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 example) (quote (x &rest args)))))


[User]
Create a Common Lisp macro for the following transformation. Before code:
(compile-$flavor-$methods nil :key nil)

What needs to change: Macro call that should be transformed by COMPILE-$FLAVOR-$METHODS

(compile-$flavor-$methods nil :key nil)

[Assistant]
(defmacro COMPILE-$FLAVOR-$METHODS ...)

;; macroexpand:
(eval-when (:load-toplevel) (combine-class-methods nil :key nil))


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

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

(defstore example (object &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 example) (quote (object &rest args)))))


[User]
Define a macro that eliminates this repetitive pattern:
(keep-bops)

Issue: Macro call that should be transformed by KEEP-BOPS

(keep-bops)

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

;; macroexpand:
(eval-when (:load-toplevel :compile-toplevel :execute)
  (progn
   (init-binfix)
   (unless t
     (setq *binfix*
             (delete nil
                     (mapcar
                      (lambda (bs)
                        (setq bs
                                (delete-if
                                 (lambda (b)
                                   (unless (member (car b) 'nil)
                                     (remprop (car b) 'properties)
                                     t))
                                 bs)))
                      *binfix*)))
     (assign-properties))))


[User]
Write a Common Lisp macro to handle this code pattern:
(define-global-var* nil :key nil)

Problem: Macro call that should be transformed by DEFINE-GLOBAL-VAR*

(define-global-var* nil :key nil)

[Assistant]
(defmacro DEFINE-GLOBAL-VAR* ...)

;; macroexpand:
(sb-ext:define-load-time-global nil :key nil)


[User]
Generate a defmacro form that transforms code like this:
(next-in 'some-name)

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

(next-in 'some-name)

[Assistant]
(defmacro NEXT-IN ...)

;; macroexpand:
(do-next-in 'some-name #'(lambda ()))


[User]
Generate a defmacro form that transforms code like this:
(enable-quasi-quoted-string-to-string-emitting-form-syntax nil)

Pattern to recognize: Macro call that should be transformed by ENABLE-QUASI-QUOTED-STRING-TO-STRING-EMITTING-FORM-SYNTAX

(enable-quasi-quoted-string-to-string-emitting-form-syntax nil)

[Assistant]
(defmacro ENABLE-QUASI-QUOTED-STRING-TO-STRING-EMITTING-FORM-SYNTAX ...)

;; macroexpand:
(eval-when (:compile-toplevel :execute)
  (setf *readtable* (copy-readtable *readtable*))
  (set-quasi-quoted-string-to-string-emitting-form-syntax-in-readtable nil
                                                                       :with-inline-emitting
                                                                       nil
                                                                       :declarations
                                                                       'nil
                                                                       :start-character
                                                                       nil
                                                                       :end-character
                                                                       nil
                                                                       :unquote-character
                                                                       #\COMMA
                                                                       :splice-character
                                                                       #\COMMERCIAL_AT
                                                                       :destructive-splice-character
                                                                       #\FULL_STOP
                                                                       :dispatched-quasi-quote-name
                                                                       "str")
  (values))


[User]
Write a Common Lisp macro to handle this code pattern:
(define-mustache-character #\/ (make-instance 'section-end-tag :text arg-text :start start))

Problem: Macro call that should be transformed by define-mustache-character

(define-mustache-character #\/ (make-instance 'section-end-tag :text arg-text :start start))

[Assistant]
(defmacro define-mustache-character (char &body body)
  `(set-mustache-character
    ,char (lambda (raw-text arg-text escapep start end)
            (declare (ignorable raw-text arg-text escapep start end)
                     (type simple-string raw-text arg-text)
                     (boolean escapep)
                     (offset start end))
            ,@body)))

;; macroexpand:
(set-mustache-character #\SOLIDUS (lambda (raw-text arg-text escapep start end) (declare (ignorable raw-text arg-text escapep start end) (type simple-string raw-text arg-text) (boolean escapep) (offset start end)) (make-instance (quote section-end-tag) :text arg-text :start start)))


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

Issue: Macro call that should be transformed by ALTER

(alter nil nil)

[Assistant]
(defmacro ALTER ...)

;; macroexpand:
(compiler-let ((*optimize-series-expressions* nil)) (alter nil nil))


[User]
Generate a defmacro form that transforms code like this:
($> "l" -9)

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

($> "l" -9)

[Assistant]
(defmacro $> (&rest args)
  `($op "$gt" ,@args))

;; macroexpand:
($op "$gt" "l" -9)


[User]
Create a Common Lisp macro for the following transformation. Before code:
(make-name-transformer)

What needs to change: Macro call that should be transformed by MAKE-NAME-TRANSFORMER

(make-name-transformer)

[Assistant]
(defmacro MAKE-NAME-TRANSFORMER ...)

;; macroexpand:
(lambda (name definition) (declare (ignorable definition)) (concatenate-symbol))


[User]
Write a Common Lisp macro to handle this code pattern:
(pop-preprocessor-directive-token token-list "")

Problem: Macro call that should be transformed by pop-preprocessor-directive-token

(pop-preprocessor-directive-token token-list "")

[Assistant]
(defmacro pop-preprocessor-directive-token (token-list directive-name &key (errorp t))
  "Pops the next token in TOKEN-LIST ignoring `+whitespace-marker+'"
  (with-gensyms (head_)
    `(let ((,head_
             (check-and-pop-pp-directive-token-1 ,token-list ,directive-name ,errorp)))
       (if (eq +whitespace-marker+ ,head_)
           (check-and-pop-pp-directive-token-1 ,token-list ,directive-name ,errorp)
           ,head_))))

;; macroexpand:
(let ((#:head_267 (check-and-pop-pp-directive-token-1 token-list "" t))) (if (eq +whitespace-marker+ #:head_267) (check-and-pop-pp-directive-token-1 token-list "" t) #:head_267))


[User]
Generate a defmacro form that transforms code like this:
(action (:after node-variable node) (when (eq name (node-variable-value node)) (incf count)) (values))

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

(action (:after node-variable node) (when (eq name (node-variable-value node)) (incf count)) (values))

[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-variable) (lambda (node) (declare (type node-variable node)) (when (eq name (node-variable-value node)) (incf count)) (values)))


[User]
Create a Common Lisp macro for the following transformation. Before code:
(defjs reduce6(k vals) (let ((sum 0) (index 0)) (dolist (c vals) (if (= index 3) (return c) (progn (incf index 1) (incf sum c)))) (return sum)))

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

(defjs reduce6(k vals) (let ((sum 0) (index 0)) (dolist (c vals) (if (= index 3) (return c) (progn (incf index 1) (incf sum c)))) (return sum)))

[Assistant]
(defmacro defjs (name args &body body)
  "Define client side javascript. Works like defun; body is in lisp, with parenscript
   additions, like return. So (defjs hello (x y) (return (+ x y))) defines an adder.
   macro creates a lisp function which sends the javascript function over to the mongo
   server to be evaluated. Result is processed and returned to the reader.
   This will execute 10 times on the server :
   (mapcar (lambda (x) (hello 10 x)) (list 1 2 3 4 5 6 7 8 9 10))"
  `(let* ((js-body (parenscript:ps (lambda ,args ,@body))))
     (setf (gethash ',name *js-definitions*) js-body)
     (defun ,name ,args
       (get-element "retval" (car (docs (db.eval js-body ,@args)))))))

;; macroexpand:
(let* ((js-body (parenscript:ps (lambda (k vals) (let ((sum 0) (index 0)) (dolist (c vals) (if (= index 3) (return c) (progn (incf index 1) (incf sum c)))) (return sum)))))) (setf (gethash (quote reduce6) *js-definitions*) js-body) (defun reduce6 (k vals) (get-element "retval" (car (docs (db.eval js-body k vals))))))


[User]
Generate a defmacro form that transforms code like this:
(enable-sharp-comment-syntax)

Pattern to recognize: Macro call that should be transformed by ENABLE-SHARP-COMMENT-SYNTAX

(enable-sharp-comment-syntax)

[Assistant]
(defmacro ENABLE-SHARP-COMMENT-SYNTAX ...)

;; macroexpand:
(eval-when (:compile-toplevel :execute)
  (setf *readtable* (copy-readtable *readtable*))
  (set-sharp-comment-syntax-in-readtable)
  (values))


[User]
Create a Common Lisp macro for the following transformation. Before code:
(decf 'some-name)

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

(decf 'some-name)

[Assistant]
(defmacro DECF ...)

;; macroexpand:
(let* ((#:some-name177 some-name)
       (#:new176 (sb-impl::xsubtract 1 '#:some-name177)))
  (funcall #'(setf quote) #:new176 #:some-name177))


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

Problem: Macro call that should be transformed by DEFUN*

(defun* nil
    (progn))

[Assistant]
(defmacro DEFUN* ...)

;; macroexpand:
(progn (declaim (ftype (function (t) t) nil)) (defun (progn) (the t ())))


[User]
Generate a defmacro form that transforms code like this:
(defsynonym :counting :count)

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

(defsynonym :counting :count)

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

;; macroexpand:
(eval-always (setf (get (quote :counting) (quote synonym)) (quote :count)))


[User]
Generate a defmacro form that transforms code like this:
(dynamic-relet* nil
  (progn))

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

(dynamic-relet* nil
  (progn))

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

;; macroexpand:
(progn (progn))


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

Issue: Macro call that should be transformed by COLLECT-LAST

(collect-last nil nil)

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

;; macroexpand:
(common-lisp:let* ((#:generator-517 (generator nil))
                   #:items-511
                   (#:item-513 nil))
  (declare (type generator #:generator-517)
           (type (null-or t) #:item-513))
  (tagbody
   #:ll-518
    (setq #:items-511 (next-in #:generator-517 (go end)))
    (setq #:item-513 #:items-511)
    (go #:ll-518)
   end)
  #:item-513)


[User]
Write a Common Lisp macro to handle this code pattern:
(with-assert-observers ("changing bar to 2" bar bar-1) (setf (value (store-lookup :bar store)) 2))

Problem: Macro call that should be transformed by with-assert-observers

(with-assert-observers ("changing bar to 2" bar bar-1) (setf (value (store-lookup :bar store)) 2))

[Assistant]
(defmacro with-assert-observers ((desc &rest asserted-observers) &body body)
  `(let ((*observers* nil))
     (trc ,desc " -- checking observers")
     ,@body
     (let ((superfluous-observers (loop for run in *observers* if (not (member run (list ,@asserted-observers))) collect run))
	   (failed-observers (loop for asserted in (list ,@asserted-observers) if (not (member asserted *observers*)) collect asserted)))
       (trc "called observers on" *observers* :superflous superfluous-observers :failed failed-observers)
       (assert (not superfluous-observers))
       (assert (not failed-observers)))))

;; macroexpand:
(let ((*observers* nil)) (trc "changing bar to 2" " -- checking observers") (setf (value (store-lookup :bar store)) 2) (let ((superfluous-observers (loop for run in *observers* if (not (member run (list bar bar-1))) collect run)) (failed-observers (loop for asserted in (list bar bar-1) if (not (member asserted *observers*)) collect asserted))) (trc "called observers on" *observers* :superflous superfluous-observers :failed failed-observers) (assert (not superfluous-observers)) (assert (not failed-observers))))


[User]
Write a Common Lisp macro to handle this code pattern:
(define-condition/a dbi-internal-error (dbi-database-error) () (:documentation "Exception raised when the database encounters an internal error, e.g. the cursor is not valid anymore, the transaction is out of sync."))

Problem: Macro call that should be transformed by define-condition/a

(define-condition/a dbi-internal-error (dbi-database-error) () (:documentation "Exception raised when the database encounters an internal error, e.g. the cursor is not valid anymore, the transaction is out of sync."))

[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-internal-error (dbi-database-error) nil (:documentation "Exception raised when the database encounters an internal error, e.g. the cursor is not valid anymore, the transaction is out of sync.")) (deftype <dbi-internal-error> nil (quote dbi-internal-error)) (setf (find-class (quote <dbi-internal-error>)) (find-class (quote dbi-internal-error))))


[User]
Create a Common Lisp macro for the following transformation. Before code:
(with-decoder-simple-list-semantics (let ((*json-symbols-package* (find-package :keyword)) (*json-identifier-name-to-lisp* #'simplified-camel-case-to-lisp)) (is (equalp '((:hello-key . "hej") (:hi-starts-with-upper-case . "tjena") (:jsonall-capitals . "totae majusculae") (:two_words . "duo verba") (:camel-case_mixed_4_parts . "partes miscella quatuor")) (decode-json-from-string " { \"helloKey\" : \"hej\" , \"HiStartsWithUpperCase\" : \"tjena\", \"JSONAllCapitals\": \"totae majusculae\", \"TWO_WORDS\": \"duo verba\", \"camelCase_Mixed_4_PARTS\": \"partes miscella quatuor\" }")))))

What needs to change: Macro call that should be transformed by with-decoder-simple-list-semantics

(with-decoder-simple-list-semantics (let ((*json-symbols-package* (find-package :keyword)) (*json-identifier-name-to-lisp* #'simplified-camel-case-to-lisp)) (is (equalp '((:hello-key . "hej") (:hi-starts-with-upper-case . "tjena") (:jsonall-capitals . "totae majusculae") (:two_words . "duo verba") (:camel-case_mixed_4_parts . "partes miscella quatuor")) (decode-json-from-string " { \"helloKey\" : \"hej\" , \"HiStartsWithUpperCase\" : \"tjena\", \"JSONAllCapitals\": \"totae majusculae\", \"TWO_WORDS\": \"duo verba\", \"camelCase_Mixed_4_PARTS\": \"partes miscella quatuor\" }")))))

[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 ((*json-symbols-package* (find-package :keyword)) (*json-identifier-name-to-lisp* (function simplified-camel-case-to-lisp))) (is (equalp (quote ((:hello-key . "hej") (:hi-starts-with-upper-case . "tjena") (:jsonall-capitals . "totae majusculae") (:two_words . "duo verba") (:camel-case_mixed_4_parts . "partes miscella quatuor"))) (decode-json-from-string " { \"helloKey\" : \"hej\" , \"HiStartsWithUpperCase\" : \"tjena\", \"JSONAllCapitals\": \"totae majusculae\", \"TWO_WORDS\": \"duo verba\", \"camelCase_Mixed_4_PARTS\": \"partes miscella quatuor\" }")))))


[User]
Define a macro that eliminates this repetitive pattern:
(check-cursor-attached cluffer:delete-item (cursor))

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

(check-cursor-attached cluffer:delete-item (cursor))

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

;; macroexpand:
(defmethod cluffer:delete-item :before ((cursor cluffer:cursor)) (declare (ignore)) (unless (cluffer:cursor-attached-p cursor) (error (quote cluffer:cursor-detached))))


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

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

(with-standard-readtable
  nil)

[Assistant]
(defmacro WITH-STANDARD-READTABLE ...)

;; macroexpand:
(bind ((*readtable* (with-standard-io-syntax (copy-readtable *readtable*))))
  nil)


[User]
Create a Common Lisp macro for the following transformation. Before code:
(decf nil (progn))

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

(decf nil (progn))

[Assistant]
(defmacro DECF ...)

;; macroexpand:
(setq nil (sb-impl::xsubtract (progn) nil))


[User]
Write a Common Lisp macro to handle this code pattern:
(draw scene (:circle :cx (random 500) :cy (random 500) :r (+ 10 (random 45))) :stroke "rgb(232, 229, 148)" :fill (one-of *groovy-test-colors*))

Problem: Macro call that should be transformed by draw

(draw scene (:circle :cx (random 500) :cy (random 500) :r (+ 10 (random 45))) :stroke "rgb(232, 229, 148)" :fill (one-of *groovy-test-colors*))

[Assistant]
(defmacro draw (scene (shape &rest params) &rest opts)
  (let ((element (gensym)))
    `(let ((,element (funcall #'make-svg-element ,shape (append (list ,@params) (list ,@opts)))))
       (add-element ,scene ,element)
       ,element)))

;; macroexpand:
(let ((#:g145 (funcall (function make-svg-element) :circle (append (list :cx (random 500) :cy (random 500) :r (+ 10 (random 45))) (list :stroke "rgb(232, 229, 148)" :fill (one-of *groovy-test-colors*)))))) (add-element scene #:g145) #:g145)


[User]
Define a macro that eliminates this repetitive pattern:
(define-cruft dispatch-macro-char-p (char rt) "Is CHAR a dispatch macro character in RT?" #+ :common-lisp (handler-case (locally #+clisp (declare (notinline get-dispatch-macro-character)) (get-dispatch-macro-character char #\x rt) t) (error () nil)))

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

(define-cruft dispatch-macro-char-p (char rt) "Is CHAR a dispatch macro character in RT?" #+ :common-lisp (handler-case (locally #+clisp (declare (notinline get-dispatch-macro-character)) (get-dispatch-macro-character char #\x rt) t) (error () nil)))

[Assistant]
(defmacro define-cruft (name lambda-list &body (docstring . alternatives))
  (assert (typep docstring 'string) (docstring) "Docstring missing!")
  (assert (not (null alternatives)))
  `(progn
     (declaim (inline ,name))
     (defun ,name ,lambda-list ,docstring ,(first alternatives))))

;; macroexpand:
(progn (declaim (inline dispatch-macro-char-p)) (defun dispatch-macro-char-p (char rt) "Is CHAR a dispatch macro character in RT?" (handler-case (locally (get-dispatch-macro-character char #\LATIN_SMALL_LETTER_X rt) t) (error nil nil))))


[User]
Create a Common Lisp macro for the following transformation. Before code:
(define-simple-documentation-lookup structure cl:structure)

What needs to change: Macro call that should be transformed by define-simple-documentation-lookup

(define-simple-documentation-lookup structure cl:structure)

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

;; macroexpand:
(defmethod documentation ((structure structure)) (common-lisp:documentation (designator structure) (quote common-lisp:structure)))


[User]
Generate a defmacro form that transforms code like this:
(collect-length 'some-name)

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

(collect-length 'some-name)

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

;; macroexpand:
(common-lisp:let* ((#:generator-468 (generator 'some-name)) (#:number-465 0))
  (declare (type generator #:generator-468)
           (type fixnum #:number-465))
  (tagbody
   #:ll-469
    (next-in #:generator-468 (go end))
    (incf #:number-465)
    (go #:ll-469)
   end)
  #:number-465)


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

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

(with-symbol-access)

[Assistant]
(defmacro WITH-SYMBOL-ACCESS ...)

;; macroexpand:
(let ((*symbol-access* t)))


[User]
Define a macro that eliminates this repetitive pattern:
(make-window-or-instance 'some-name)

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

(make-window-or-instance 'some-name)

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

;; macroexpand:
(make-$instance 'some-name)


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

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

(dreletf nil)

[Assistant]
(defmacro DRELETF ...)

;; macroexpand:
(let ((#:symbol-store231
       (with-symbol-access
         (list))))
  (special-symbol-reprogv #:symbol-store231
      (list)
    (locally (declare (special)))))


[User]
Create a Common Lisp macro for the following transformation. Before code:
(do-readtable (char readtable readtable) (set-syntax-from-char char #\A readtable))

What needs to change: Macro call that should be transformed by do-readtable

(do-readtable (char readtable readtable) (set-syntax-from-char char #\A readtable))

[Assistant]
(defmacro do-readtable ((entry-designator readtable &optional result)
                        &body body)
  "Iterate through a readtable's macro characters, and dispatch macro characters."
  (destructuring-bind (char &optional reader-fn non-terminating-p disp? table)
      (if (symbolp entry-designator)
          (list entry-designator)
          entry-designator)
    (let ((iter (gensym "ITER+"))
          (more? (gensym "MORE?+"))
          (rt (gensym "READTABLE+")))
      `(let ((,rt ,readtable))
         (with-readtable-iterator (,iter ,rt)
           (loop
             (multiple-value-bind (,more?
                                   ,char
                                   ,@(when reader-fn (list reader-fn))
                                   ,@(when disp? (list disp?))
                                   ,@(when table (list table)))
                 (,iter)
               (unless ,more? (return ,result))
               (let ,(when non-terminating-p
                       ;; FIXME: N-T-P should be incorporated in iterators.
                       `((,non-terminating-p
                          (nth-value 1 (get-macro-character ,char ,rt)))))
                 ,@body))))))))

;; macroexpand:
(let ((#:readtable+146 readtable)) (with-readtable-iterator (#:iter+144 #:readtable+146) (loop (multiple-value-bind (#:more?+145 char) (#:iter+144) (unless #:more?+145 (return readtable)) (let nil (set-syntax-from-char char #\LATIN_CAPITAL_LETTER_A readtable))))))


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

Problem: Macro call that should be transformed by DEFOBJECT

(defobject nil (progn))

[Assistant]
(defmacro DEFOBJECT ...)

;; macroexpand:
(object :parents (list) :properties (list (list 'progn nil)))


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

Problem: Macro call that should be transformed by DYNENV-FUNCTION

(dynenv-function nil)

[Assistant]
(defmacro DYNENV-FUNCTION ...)

;; macroexpand:
(dynenv-function% 'nil)


[User]
Create a Common Lisp macro for the following transformation. Before code:
(define-path-instruction-pair line-to "L" (x y))

What needs to change: Macro call that should be transformed by define-path-instruction-pair

(define-path-instruction-pair line-to "L" (x y))

[Assistant]
(defmacro define-path-instruction-pair (name instruction (&rest args))
  (let ((draw-relative (intern (concatenate 'string (string name) "-R"))))
    `(progn
       (defun ,name (,@args)
         (format-instruction ,instruction ,@args))
       (defun ,draw-relative (,@args)
         (format-instruction ,(string-downcase instruction) ,@args)))))

;; macroexpand:
(progn (defun line-to (x y) (format-instruction "L" x y)) (defun line-to-r (x y) (format-instruction "l" x y)))


[User]
Generate a defmacro form that transforms code like this:
(with-unique-js-names nil)

Pattern to recognize: Macro call that should be transformed by WITH-UNIQUE-JS-NAMES

(with-unique-js-names nil)

[Assistant]
(defmacro WITH-UNIQUE-JS-NAMES ...)

;; macroexpand:
(with-ps-gensyms nil)


[User]
Create a Common Lisp macro for the following transformation. Before code:
(is-true t)

What needs to change: Macro call that should be transformed by is-true

(is-true t)

[Assistant]
(defmacro is-true (condition &rest reason-args)
  "Like IS this check generates a pass if CONDITION returns true
  and a failure if CONDITION returns false. Unlike IS this check
  does not inspect CONDITION to determine how to report the
  failure."
  `(if ,condition
       (add-result 'test-passed :test-expr ',condition)
       (process-failure ',condition
                        ,@(or reason-args
                              `("~S did not return a true value" ',condition)))))

;; macroexpand:
(if t (add-result (quote test-passed) :test-expr (quote t)) (process-failure (quote t) "~S did not return a true value" (quote t)))


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

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

(or nil)

[Assistant]
(defmacro OR ...)

;; macroexpand:
(the t nil)


[User]
Create a Common Lisp macro for the following transformation. Before code:
(is (= 0 (dummy-add a (- a))))

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

(is (= 0 (dummy-add a (- a))))

[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 ((#:e158 0) (#:a159 (dummy-add a (- a)))) (if (progn (= #:e158 #:a159)) (add-result (quote test-passed) :test-expr (quote (= 0 (dummy-add a (- a))))) (process-failure (quote (= 0 (dummy-add a (- a)))) "~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%" (quote (dummy-add a (- a))) #:a159 (quote =) #:e158)))