j14i/cl-macros huggingface dataset:
Generate a defmacro form that transforms code like this:
(make-name-transformer "FOO-" name "-BAR")

Pattern to recognize: Macro call that should be transformed by make-name-transformer

Macro definition:
(defmacro make-name-transformer (&rest elements)
  "Return an accessor name transformer.
The unquoted `name' symbol argument is substituted for the slot name.
Class option examples:

  :accessor-name-transformer (make-name-transformer \"FOO-\" name \"-BAR\")

Use the slot name directly:

  :accessor-name-transformer (make-name-transformer name)"
  `(lambda (name definition)
    (declare (ignorable definition))
    (concatenate-symbol ,@(mapcar (lambda (el)
                                    (if (and (symbolp el)
                                             (string= (symbol-name el) "NAME"))
                                        'name
                                        el))
                                  elements))))

Macroexpansion:
(lambda (name definition) (declare (ignorable definition)) (concatenate-symbol "FOO-" name "-BAR"))
You are a Common Lisp macro expert. Given this code pattern:
(defstore example (&rest args &key (a 0) (b (the integer (init-b args))) (c 0)))

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

Macro definition:
(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)))

Macroexpansion:
(eval-when (:compile-toplevel :load-toplevel :execute) (progn (defun a-init-function152 (args a #:a?166) (declare (ignorable args a #:a?166)) (the integer (init-b args))) (ensure-store (quote example) (quote (&rest args &key (a 0 #:a?166) (b (the integer (a-init-function152 args a #:a?166)) #:b?167) (c 0 #:c?168))))))
Define a macro that eliminates this repetitive pattern:
(with-table-name table-name-b (yield-only-contents clause-b))

Issue: Macro call that should be transformed by with-table-name

Macro definition:
(defmacro with-table-name (table-name &body body)
  `(let ((*table-name-scope* ,table-name))
     ,@body))

Macroexpansion:
(let ((*table-name-scope* table-name-b)) (yield-only-contents clause-b))
Write a Common Lisp macro to handle this code pattern:
(defjs reduce8(k vals) (let ((arr (make-array)) (index 0)) (dolist (c vals) (setf (aref arr index) c) (incf index 1)) (return (ps:create :retval (aref arr 5)))))

Problem: Macro call that should be transformed by defjs

Macro definition:
(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)))))))

Macroexpansion:
(let* ((js-body (parenscript:ps (lambda (k vals) (let ((arr (make-array)) (index 0)) (dolist (c vals) (setf (aref arr index) c) (incf index 1)) (return (parenscript:create :retval (aref arr 5)))))))) (setf (gethash (quote reduce8) *js-definitions*) js-body) (defun reduce8 (k vals) (get-element "retval" (car (docs (db.eval js-body k vals))))))
Write a Common Lisp macro to handle this code pattern:
(with-hamt set (:test test :hash hash :table table) (%hamt-lookup table x (funcall hash x) 0 test))

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

Macro definition:
(defmacro with-hamt (hamt (&key test hash table) &body body)
  "Accessing HAMT slots"
  `(with-accessors ((,test hamt-test)
                    (,hash hamt-hash)
                    (,table hamt-table))
       ,hamt
     ,@body))

Macroexpansion:
(with-accessors ((test hamt-test) (hash hamt-hash) (table hamt-table)) set (%hamt-lookup table x (funcall hash x) 0 test))
You are a Common Lisp macro expert. Given this code pattern:
(<*> (string "hi") (string "bye"))

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

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

Macroexpansion:
(lambda (#:<*>-offset268) (multiple-value-bind (#:<*>-res269 #:<*>-next270) (funcall (string "hi") #:<*>-offset268) (if (failure? #:<*>-res269) (fail #:<*>-next270) (fmap (lambda (xs) (cons #:<*>-res269 xs)) (multiple-value-bind (#:<*>-res271 #:<*>-next272) (funcall (string "bye") #:<*>-next270) (if (failure? #:<*>-res271) (fail #:<*>-next272) (fmap (lambda (xs) (cons #:<*>-res271 xs)) (ok #:<*>-next272 nil))))))))
Generate a defmacro form that transforms code like this:
(with-yield (loop for line = (read-line file nil 'eof) until (eq line 'eof) do (yield line)) (close file))

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

Macro definition:
(defmacro with-yield (&body body)
  (let ((point (gensym))
        (current (gensym)))
    `(let (,point ,current)
       (with-call/cc
	 (labels ((yield (&rest values)
		    (setf ,current values)
		    (let/cc k
		      (setf ,point k))))
	   ,@body
	   (setf ,point nil)))
       (gen-lambda ()
	 (cond ((null ,point)
		'generator-stop)
	       (t
		(let ((current ,current))
		  (funcall ,point nil)
		  ;values-handler: see gen-lambda
		  (apply #'values (funcall values-handler current)))))))))

Macroexpansion:
(let (#:g137 #:g138) (with-call/cc (labels ((yield (&rest values) (setf #:g138 values) (let/cc k (setf #:g137 k)))) (loop for line = (read-line file nil (quote eof)) until (eq line (quote eof)) do (yield line)) (close file) (setf #:g137 nil))) (gen-lambda nil (cond ((null #:g137) (quote generator-stop)) (t (let ((current #:g138)) (funcall #:g137 nil) (apply (function values) (funcall values-handler current)))))))
Generate a defmacro form that transforms code like this:
(defclause (nconcing expr &optional into var at (place 'end)) "Nconc into a list" (return-collection-code :variable var :expression expr :start-operation 'nconc :place place :one-element nil))

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

Macro definition:
(defmacro defclause (clause-template &body body)
  (define-clause 'defun clause-template body nil))

Macroexpansion:
(eval-when (:compile-toplevel :load-toplevel :execute) (defun clause-nconcing-19 (&key ((:nconcing expr)) ((:into var)) ((:at place) (quote end))) "Nconc into a list" (return-collection-code :variable var :expression expr :start-operation (quote nconc) :place place :one-element nil)) (install-clause-info (quote (nconcing)) (quote (nconcing &optional :into :at)) (quote clause-nconcing-19) "Nconc into a list" nil) (quote (nconcing expr &optional into var at (place (quote end)))))
Define a macro that eliminates this repetitive pattern:
(define-element-maker :mask "mask" '(:id))

Issue: Macro call that should be transformed by define-element-maker

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

Macroexpansion:
(progn (defmethod assert-required-attributes ((element (eql :mask)) attributes) (declare (ignore element)) (unless (evenp (length attributes)) (warn "attribute list may be missing data: ~A" attributes)) (let ((missing (set-difference (quote (:id)) attributes))) (when missing (error (quote missing-attributes) :message (format nil "~A missing attributes: ~{~A~^ ~}" :mask missing))))) (defmethod make-svg-element ((element (eql :mask)) attributes) (when *check-required-attributes* (assert-required-attributes element attributes)) (make-instance (quote svg-element) :name "mask" :attributes attributes)))
Create a Common Lisp macro for the following transformation. Before code:
(signal-syntax-error "Unknown token ~A in parse tree." parse-tree)

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

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

Macroexpansion:
(signal-syntax-error* nil "Unknown token ~A in parse tree." parse-tree)
Generate a defmacro form that transforms code like this:
(cond-> nil)

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

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

Macroexpansion:
(let* ((#:|cond130| nil))
  #:|cond130|)
Generate a defmacro form that transforms code like this:
(defgenerator takewhile (predicate generator) "Emits items from generator until predicate fails. Eg: (takewhile (lambda (x) (< x 5)) (list->generator '(1 4 6 4 1))) -> 1 4" (do-generator (item generator) (unless (funcall predicate item) (return)) (yield item)))

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

Macro definition:
(defmacro defgenerator (name arguments &body body)
  (multiple-value-bind (remaining-forms declarations doc-string)
      (alexandria:parse-body body :documentation t)
    `(defun ,name ,arguments
       ,doc-string
       ,@declarations
       (with-yield
	 ,@remaining-forms))))

Macroexpansion:
(defun takewhile (predicate generator) "Emits items from generator until predicate fails. Eg: (takewhile (lambda (x) (< x 5)) (list->generator '(1 4 6 4 1))) -> 1 4" (with-yield (do-generator (item generator) (unless (funcall predicate item) (return)) (yield item))))
You are a Common Lisp macro expert. Given this code pattern:
(with-unique-names (value repeat) `((,name (,value) (tagbody ,repeat (cond ((consp ,value) (rplacd ,tail (setq ,tail (cons (car ,value) nil))) (setq ,value (cdr ,value)) (go ,repeat)) (t (rplacd ,tail ,value)))))))

Write a macro that addresses: Macro call that should be transformed by with-unique-names

Macro definition:
(defmacro with-unique-names (names &body body)
  `(let ,(mapcar (lambda (sym)
                   `(,sym (gensym ,(symbol-name sym))))
                  names)
     ,@body))

Macroexpansion:
(let ((value (gensym #A((5) base-char . "VALUE"))) (repeat (gensym #A((6) base-char . "REPEAT")))) (quasiquote ((#S(sb-impl::comma :expr name :kind 0) (#S(sb-impl::comma :expr value :kind 0)) (tagbody #S(sb-impl::comma :expr repeat :kind 0) (cond ((consp #S(sb-impl::comma :expr value :kind 0)) (rplacd #S(sb-impl::comma :expr tail :kind 0) (setq #S(sb-impl::comma :expr tail :kind 0) (cons (car #S(sb-impl::comma :expr value :kind 0)) nil))) (setq #S(sb-impl::comma :expr value :kind 0) (cdr #S(sb-impl::comma :expr value :kind 0))) (go #S(sb-impl::comma :expr repeat :kind 0))) (t (rplacd #S(sb-impl::comma :expr tail :kind 0) #S(sb-impl::comma :expr value :kind 0)))))))))
Define a macro that eliminates this repetitive pattern:
(define-hook (:build clear-asdf most-negative-fixnum) () (asdf:clear-configuration) (setf (fdefinition 'asdf:upgrade-asdf) (lambda ())) #+quicklisp (setf ql:*local-project-directories* ()) (dolist (system (asdf:already-loaded-systems)) (asdf:register-immutable-system system) (asdf:clear-system system)))

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

Macro definition:
(defmacro define-hook ((type name &optional (priority 0)) args &body body)
  (ecase type (:pre-load) (:load) (:build) (:deploy) (:boot) (:quit))
  (check-type name symbol)
  `(let ((,name (or (hook ,type ',name)
                    (make-instance 'hook :name ',name :type ,type))))
     (setf (hook-priority ,name) ,priority)
     (setf (hook-function ,name) (flet ((,name (&key ,@args &allow-other-keys)
                                          ,@body))
                                   #',name))
     (setf (hook ,type ',name) ,name)
     (setf (docstring ,name) ,(if (stringp (car body)) (car body)))
     ',name))

Macroexpansion:
(let ((clear-asdf (or (hook :build (quote clear-asdf)) (make-instance (quote hook) :name (quote clear-asdf) :type :build)))) (setf (hook-priority clear-asdf) most-negative-fixnum) (setf (hook-function clear-asdf) (flet ((clear-asdf (&key &allow-other-keys) (uiop/configuration:clear-configuration) (setf (fdefinition (quote asdf/upgrade:upgrade-asdf)) (lambda nil)) (setf quicklisp-client:*local-project-directories* nil) (dolist (system (asdf/operate:already-loaded-systems)) (asdf/system-registry:register-immutable-system system) (asdf/system-registry:clear-system system)))) (function clear-asdf))) (setf (hook :build (quote clear-asdf)) clear-asdf) (setf (docstring clear-asdf) nil) (quote clear-asdf))
You are a Common Lisp macro expert. Given this code pattern:
(lambda-coro
  nil
  nil)

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

Macro definition:
(defmacro LAMBDA-CORO ...)

Macroexpansion:
(progn
 (defcoroutine #:name127
     (#:arg128)
   (macrolet ((yield (form)
                (let ((g!-it (gensym "IT")))
                  `(progn
                    (let ((,g!-it ,form))
                      (cl-coroutine:yield ,g!-it))
                    ,'#:arg128)))
              (last-yield-value ()
                '#:arg128))
     nil
     nil
     (coexit!)))
 (make-coroutine '#:name127))
Create a Common Lisp macro for the following transformation. Before code:
(collect-file nil :key nil)

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

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

Macroexpansion:
(common-lisp:let* ((#:generator-560 (generator :key)) #:items-554 (#:out-556 t))
  (declare (type generator #:generator-560)
           (type boolean #:out-556))
  (with-open-file (#:outfile-553 nil :direction :output)
    (tagbody
     #:ll-561
      (setq #:items-554 (next-in #:generator-560 (go end)))
      (common-lisp:funcall nil #:items-554 #:outfile-553)
      (go #:ll-561)
     end))
  #:out-556)
Generate a defmacro form that transforms code like this:
(advisable-lambda nil)

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

Macro definition:
(defmacro ADVISABLE-LAMBDA ...)

Macroexpansion:
(make-instance 'advisable-function :main #'(lambda ()) :arguments 'nil
               :dispatcher-generator
               #'(lambda (#:fobj122)
                   #'(lambda ()
                       #A((29) base-char . "Advisable function dispatcher")
                       (let ((#:fixed123 (append)))
                         (apply-before #:fobj122 #:fixed123)
                         (multiple-value-prog1
                             (apply-around #:fobj122 #:fixed123)
                           (apply-after #:fobj122 #:fixed123))))))
You are a Common Lisp macro expert. Given this code pattern:
(with-mocks () (answer (foo 1) 2) (answer (foo 2) 3) (answer foo 42) (is (eql 2 (foo 1))) (is (eql 2 (foo 1))) (is (eql 3 (foo 2))) (is (eql 3 (foo 2))) (is (eql 42 (foo))) (is (eql 42 (foo 'foo))))

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

Macro definition:
(defmacro with-mocks ((&key (recordp T)) &body body)
  "Execute BODY in a new mocking context.  Invocations will be recorded
if RECORDP is set (default true)."
  `(call-with-mocks
    (lambda () ,@body)
    :recordp ,recordp))

Macroexpansion:
(call-with-mocks (lambda nil (answer (foo 1) 2) (answer (foo 2) 3) (answer foo 42) (is (eql 2 (foo 1))) (is (eql 2 (foo 1))) (is (eql 3 (foo 2))) (is (eql 3 (foo 2))) (is (eql 42 (foo))) (is (eql 42 (foo (quote foo))))) :recordp t)
Define a macro that eliminates this repetitive pattern:
(->
  nil
  nil)

Issue: Macro call that should be transformed by ->

Macro definition:
(defmacro -> ...)

Macroexpansion:
(let* ((#:var148 nil) (#:var149 (nil #:var148)))
  #:var149)
Create a Common Lisp macro for the following transformation. Before code:
(iter
  nil
  nil)

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

Macro definition:
(defmacro ITER ...)

Macroexpansion:
(let* ()
  (block nil
    (block nil
      (tagbody
        (progn)
       loop-top-nil
        (progn nil)
        (progn)
        (go loop-top-nil)
        (progn))
      nil)))
Create a Common Lisp macro for the following transformation. Before code:
(*> +many-comments+ +opt-fws+)

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

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

Macroexpansion:
(lambda (#:*>-offset140) (multiple-value-bind (#:*>-res141 #:*>-next142) (funcall +many-comments+ #:*>-offset140) (if (ok? #:*>-res141) (funcall +opt-fws+ #:*>-next142) (fail #:*>-next142))))
Create a Common Lisp macro for the following transformation. Before code:
(defvariant nil
  (progn))

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

Macro definition:
(defmacro DEFVARIANT ...)

Macroexpansion:
(progn
 (defstruct (nil (:constructor nil)))
 (defstruct (nil-progn (:include nil)))
 (defmacro match-nil (expr &body match-cases)
   #A((34) base-char . "Match values of variant type: NIL.")
   (let ((expr-var (gensym "-val")))
     `(let ((,expr-var ,expr))
        ,(build-dispatch `,'nil `,'((progn)) match-cases expr-var)))))
Write a Common Lisp macro to handle this code pattern:
(disable-dot-syntax)

Problem: Macro call that should be transformed by DISABLE-DOT-SYNTAX

Macro definition:
(defmacro disable-dot-syntax ()
  "Restore readtable which was active before last call to If there was no such call, the standard
readtable is used."
  `(eval-when (:compile-toplevel :load-toplevel :execute)
    (%disable-dot-syntax)))

Macroexpansion:
(eval-when (:compile-toplevel :load-toplevel :execute) (%disable-dot-syntax))
Create a Common Lisp macro for the following transformation. Before code:
(aif (list 1 2 3) (sif (car it) (setf it 'a) :foo))

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

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

Macroexpansion:
(anaphoric if (list 1 2 3) (sif (car it) (setf it (quote a)) :foo) nil)
Define a macro that eliminates this repetitive pattern:
(defrequirement add (&rest addends) "all args < 10" (every (lambda (n) (< n 10)) addends))

Issue: Macro call that should be transformed by defrequirement

Macro definition:
(defmacro defrequirement (name (&rest lambda-list) &body body)
  "Adds a precondition to the NAMEd function. It can be either a generic or
   non-generic function. If it's the former, then use a specialized lambda list,
   otherwise use an ordinary lambda list. The docstring, if any, will be used in
   failure reports."
  #+qpq-precondition-checks-disabled
  (declare (ignore name lambda-list body))
  #+qpq-precondition-checks-disabled
  (values)
  #-qpq-precondition-checks-disabled
  (multiple-value-bind (remaining-forms declarations doc-string)
      (parse-body body :documentation t)
    (declare (ignore declarations))
    (let* ((stripped-ll (strip-lambda-list lambda-list))
           (lambda-vars (remove-if (rcurry #'member
                                           '(&optional &rest
                                             &key &allow-other-keys &aux))
                                   stripped-ll))
           (method `(progn
                      (ensure-contracted-function ',name',stripped-ll)
                      (defmethod ,name
                          :require
                          ,(format nil "~A"
                            (or doc-string
                             (description<-remaining-forms
                              remaining-forms)))
                        ,lambda-list
                        (declare (ignorable ,@lambda-vars))
                        ,@body))))
      (if (every #'symbolp lambda-list)
          `(if (and (fboundp ',name)
                    (not (typep (fdefinition ',name) 'generic-function)))
               (defcontract ,name :require ,lambda-list
                 (declare (ignorable ,@lambda-vars))
                 ,@body)
               ,method)
          method))))

Macroexpansion:
(if (and (fboundp (quote add)) (not (typep (fdefinition (quote add)) (quote generic-function)))) (defcontract add :require (&rest addends) (declare (ignorable addends)) "all args < 10" (every (lambda (n) (< n 10)) addends)) (progn (ensure-contracted-function (quote add) (quote (&rest addends))) (defmethod add :require #A((13) base-char . "all args < 10") (&rest addends) (declare (ignorable addends)) "all args < 10" (every (lambda (n) (< n 10)) addends))))
Define a macro that eliminates this repetitive pattern:
(make-$instance nil nil)

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

Macro definition:
(defmacro MAKE-$INSTANCE ...)

Macroexpansion:
(let ((class (symbol-value nil)))
  (funcall (mcs-slot-value class (index-of-basicnew-fn)) class nil))