j14i/cl-macros huggingface dataset:
Generate a defmacro form that transforms code like this:
(def-neo4j-fun create-node (properties) :post (:uri-spec (format nil "node")) (:encode properties :string) (:status-handlers (201 (decode-neo4j-json-output body)) (400 (error 'invalid-data-sent-error :uri uri :json json))))

Pattern to recognize: Macro call that should be transformed by def-neo4j-fun

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

Macroexpansion:
(progn (defun create-node (&key properties) (let ((uri (format nil "node")) (json (encode-neo4j-json-payload properties :string))) (make-neo4j-request :post uri json (list (list 201 (lambda (body uri json) (decode-neo4j-json-output body))) (list 400 (lambda (body uri json) (error (quote invalid-data-sent-error) :uri uri :json json))))))))
Generate a defmacro form that transforms code like this:
(match0 (find v1 seq2 :key #'car) ((list* _ o2) (cons (list v1 :type `(or ,(getf o1 :type) ,(getf o2 :type)) :place (or (getf o1 :place) (getf o2 :place)) :ignorable (or (getf o1 :ignorable) (getf o2 :ignorable))) (merge-variables rest seq2))))

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

Macro definition:
(defmacro match0 (*what* &body clauses &environment *env*)
  (once-only (*what*)
    (parse-patterns clauses)))

Macroexpansion:
(let ((#:*what*146 (find v1 seq2 :key (function car)))) (declare (ignorable #:*what*146)) (if (and (consp #:*what*146) (let ((#:*what*147 (car #:*what*146))) (declare (ignorable #:*what*147)) t) (let ((#:*what*148 (cdr #:*what*146))) (declare (ignorable #:*what*148)) t)) (let* ((#:*what*147 (car #:*what*146)) (#:*what*148 (cdr #:*what*146)) (o2 #:*what*148)) (declare (ignorable o2 #:*what*148 #:*what*147)) (cons (list v1 :type (sb-int:quasiquote (or #S(sb-impl::comma :expr (getf o1 :type) :kind 0) #S(sb-impl::comma :expr (getf o2 :type) :kind 0))) :place (or (getf o1 :place) (getf o2 :place)) :ignorable (or (getf o1 :ignorable) (getf o2 :ignorable))) (merge-variables rest seq2))) nil))
Create a Common Lisp macro for the following transformation. Before code:
(lret ((start 0) (result (make-array len :element-type 'character))) (declare (array-index start) ((simple-array character (*)) result)) (do-strings (s more?) (nlet rec (s) (etypecase s (string (with-string-dispatch () s (replace result s :start1 start) (incf start (length s)))) (character (setf (schar result start) s) (incf start)) (symbol (rec (symbol-name s))))) (boolean-when separator? (when more? (replace result separator :start1 start) (incf start sep-len)))) (boolean-when separator? (when end (replace result separator :start1 start))))

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

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

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

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

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

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

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

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

Macroexpansion:
(lret-aux let ((start 0) (result (make-array len :element-type (quote character)))) (declare (array-index start) ((simple-array character (*)) result)) (do-strings (s more?) (nlet rec (s) (etypecase s (string (with-string-dispatch nil s (replace result s :start1 start) (incf start (length s)))) (character (setf (schar result start) s) (incf start)) (symbol (rec (symbol-name s))))) (boolean-when separator? (when more? (replace result separator :start1 start) (incf start sep-len)))) (boolean-when separator? (when end (replace result separator :start1 start))))
You are a Common Lisp macro expert. Given this code pattern:
(do-generators ((a (repeat 2)) (:list b '(4 5 6)) (c (list->generator '(8 9)) :fill-value 30)) (print (* a (+ b c))))

Write a macro that addresses: Macro call that should be transformed by do-generator

Macro definition:
(defmacro do-generator ((var &rest vars-and-generator) &body body)
  "Steps through the specified generator, binding the value it returns to var, then executing the body for each step. If multiple variables are specified and the generator returns multiple values, the extra values will be bound to the extra variables."
  (let ((g (gensym)))
    `(let ((,g ,(car (last vars-and-generator))))
       (loop 
	  do (if-generator ((,var ,@(butlast vars-and-generator)) ,g)
			   (progn
			     ,@body)
			   (return))))))

Macroexpansion:
(let ((#:g153 (multi-gen (repeat 2) (list->generator (quote (4 5 6))) (list (list->generator (quote (8 9))) :fill-value 30)))) (loop do (destructuring-bind (#:g155 . #:g154) (multiple-value-list (next-generator-value #:g153)) (unless #:g155 (return)) (let ((a (elt (elt #:g154 0) 0)) (b (elt (elt #:g154 1) 0)) (c (elt (elt #:g154 2) 0))) (print (* a (+ b c)))))))
Write a Common Lisp macro to handle this code pattern:
(yield-all (flatten (cdr list)))

Problem: Macro call that should be transformed by yield-all

Macro definition:
(defmacro yield-all (generator)
  "Walks through generator, re-yielding all of the items in it. Only meant for use inside of a defgenerator or with-yield block."
  (let ((x (gensym)))
    `(do-generator (,x ,generator)
       (yield ,x))))

Macroexpansion:
(do-generator (#:g185 (flatten (cdr list))) (yield #:g185))
Create a Common Lisp macro for the following transformation. Before code:
(with-component-testers (a b #'pathname-name) (components-are-member '(nil :wild :unspecific)) (components-are-string=))

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

Macro definition:
(defmacro with-component-testers ((a b key) &body body)
  (let ((k (gensym)))
    `(let* ((,k ,key)
            (,a (funcall ,k ,a))
            (,b (funcall ,k ,b)))
       (labels ((components-are (test)
                  (and (funcall test ,a) (funcall test ,b)))
                (components-are-member (values)
                  (and (member ,a values :test #'eql)
                       (member ,b values :test #'eql)
                       (eql ,a ,b)))
                (components-are-string= ()
                  (and (stringp ,a) (stringp ,b) (string= ,a ,b)))
                (components-are-every (test)
                  (and (consp ,a)
                       (consp ,b)
                       (every test ,a ,b))))
         (declare (ignorable #'components-are #'components-are-member
                             #'components-are-string= #'components-are-every))
         (if (or ,@body)
             (values t ,a ,b)
             nil)))))

Macroexpansion:
(let* ((#:g146 (function pathname-name)) (a (funcall #:g146 a)) (b (funcall #:g146 b))) (labels ((components-are (test) (and (funcall test a) (funcall test b))) (components-are-member (values) (and (member a values :test (function eql)) (member b values :test (function eql)) (eql a b))) (components-are-string= nil (and (stringp a) (stringp b) (string= a b))) (components-are-every (test) (and (consp a) (consp b) (every test a b)))) (declare (ignorable (function components-are) (function components-are-member) (function components-are-string=) (function components-are-every))) (if (or (components-are-member (quote (nil :wild :unspecific))) (components-are-string=)) (values t a b) nil)))
Generate a defmacro form that transforms code like this:
(and nil)

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

Macro definition:
(defmacro AND ...)

Macroexpansion:
(the t nil)
Write a Common Lisp macro to handle this code pattern:
(with-xml-group-element (s (element-name e) (element-attributes e)) (loop for sub-element across (element-contents e) do (stream-out s sub-element)))

Problem: Macro call that should be transformed by with-xml-group-element

Macro definition:
(defmacro with-xml-group-element ((stream element properties) &body body)
  (let ((s (gensym "stream"))
        (e (gensym "element")))
    `(let ((,s ,stream)
           (,e ,element))
       (begin-group->xml ,s ,e ,properties)
       (with-indentation 
         ,@body)
       (end-group->xml ,s ,e))))

Macroexpansion:
(let ((#:|stream132| s) (#:|element133| (element-name e))) (begin-group->xml #:|stream132| #:|element133| (element-attributes e)) (with-indentation (loop for sub-element across (element-contents e) do (stream-out s sub-element))) (end-group->xml #:|stream132| #:|element133|))
Generate a defmacro form that transforms code like this:
(when val (cond ((stringp val) (format stream "\"~a\"" val)) ((characterp val) (cond ((eql val #\tab) (format stream "'\\t'")) ((or (eql val #\nul) (eql val #\null)) (format stream "'\\0'")) ((eql val #\return) (format stream "'\\r'")) ((eql val #\newline) (format stream "'\\n'")) ((eql val #\') (format stream "'\\''")) (t (format stream "'~a'" val)))) ((floatp val) (format stream "~a" (substitute #\e #\d (format nil "~,8e" val)))) (t (format stream "~a" val))) )

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

Macro definition:
(defmacro when (test &body forms)
  `(if ,test
	   ,(cl:if (cadr forms)
			   `(progn ,@forms)
			   (car forms))))

Macroexpansion:
(if val (cond ((stringp val) (format stream "\"~a\"" val)) ((characterp val) (cond ((eql val #\Tab) (format stream "'\\t'")) ((or (eql val #\Nul) (eql val #\Nul)) (format stream "'\\0'")) ((eql val #\Return) (format stream "'\\r'")) ((eql val #\Newline) (format stream "'\\n'")) ((eql val #\APOSTROPHE) (format stream "'\\''")) (t (format stream "'~a'" val)))) ((floatp val) (format stream "~a" (substitute #\LATIN_SMALL_LETTER_E #\LATIN_SMALL_LETTER_D (format nil "~,8e" val)))) (t (format stream "~a" val))))
Create a Common Lisp macro for the following transformation. Before code:
(drelet* nil
  :key
  nil)

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

Macro definition:
(defmacro DRELET* ...)

Macroexpansion:
(dynamic-relet* nil
  :key
  nil)
Write a Common Lisp macro to handle this code pattern:
(defhandler go (go tag) `(list ',go ',tag))

Problem: Macro call that should be transformed by defhandler

Macro definition:
(defmacro defhandler (symbol lambda-list &body body)
  (let ((syms (force-list symbol)))
    (let ((func (intern (format nil "~A~A" 'hander- (first syms)))))
      `(progn
         (defun ,func ,lambda-list
           ,@body)
         (setf
          ,@(loop for sym in syms
               collect `(gethash ',sym *form-handler*)
               collect `',func))))))

Macroexpansion:
(progn (defun hander-go (go tag) (sb-int:quasiquote (list (quote #S(sb-impl::comma :expr go :kind 0)) (quote #S(sb-impl::comma :expr tag :kind 0))))) (setf (gethash (quote go) *form-handler*) (quote hander-go)))
Generate a defmacro form that transforms code like this:
(defun-compile-time indirect-callers (function-name) (indirect-callers-internal (callers function-name) '()))

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

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

Macroexpansion:
(eval-when (:compile-toplevel :load-toplevel :execute) (common-lisp:defun indirect-callers (function-name) (indirect-callers-internal (callers function-name) (quote nil))) (eval-when (:compile-toplevel) (compile (quote indirect-callers))))
You are a Common Lisp macro expert. Given this code pattern:
(is 1 1)

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

Macro definition:
(defmacro is (got expected &rest args)
  (with-gensyms (duration result new-args desc)
    (once-only (expected)
      `(let* ((,new-args (list ,@args))
              (,desc (parse-description-and-test ,new-args)))
         (with-catching-errors (:description ,desc :expected ,expected)
           (with-duration ((,duration ,result) ,got)
             (test ,result ,expected ,new-args
                   :duration ,duration)))))))

Macroexpansion:
(let ((#:expected156 1)) (let* ((#:new-args154 (list)) (#:desc155 (parse-description-and-test #:new-args154))) (with-catching-errors (:description #:desc155 :expected #:expected156) (with-duration ((#:duration152 #:result153) 1) (test #:result153 #:expected156 #:new-args154 :duration #:duration152)))))
You are a Common Lisp macro expert. Given this code pattern:
(do-instance-combinations 'some-name)

Write a macro that addresses: Macro call that should be transformed by DO-INSTANCE-COMBINATIONS

Macro definition:
(defmacro DO-INSTANCE-COMBINATIONS ...)

Macroexpansion:
(do-combinations 'some-name)
Create a Common Lisp macro for the following transformation. Before code:
(with-mocks () (if-called 'foo (constantly 42)) (is (eql 42 (foo))))

What needs to change: 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 (if-called (quote foo) (constantly 42)) (is (eql 42 (foo)))) :recordp t)
Write a Common Lisp macro to handle this code pattern:
(with-c-compilation-unit (:return-last-statement (eql (first body) '{)) (parse-with-lexer (list-lexer body) *c-parser*))

Problem: Macro call that should be transformed by with-c-compilation-unit

Macro definition:
(defmacro with-c-compilation-unit ((&key return-last-statement)
				   &body body)
  "Establishes variable bindings for a new compilation."
  `(let ((*struct-specs* (copy-hash-table *struct-specs*))
         (*typedef-names* (copy-hash-table *typedef-names*))
	 (*return-last-statement* ,return-last-statement)
         (*function-pointer-ids* nil))
     ,@body))

Macroexpansion:
(let ((*struct-specs* (copy-hash-table *struct-specs*)) (*typedef-names* (copy-hash-table *typedef-names*)) (*return-last-statement* (eql (first body) (quote {))) (*function-pointer-ids* nil)) (parse-with-lexer (list-lexer body) *c-parser*))
Generate a defmacro form that transforms code like this:
(multiple-value-match (values 1 2) ((2) 1) ((1 y) y))

Pattern to recognize: Macro call that should be transformed by multiple-value-match

Macro definition:
(defmacro multiple-value-match (values-form &body clauses)
  "Matches the multiple values of VALUES-FORM with CLAUSES. Unlike
MATCH, CLAUSES have to have the form of (PATTERNS . BODY), where
PATTERNS is a list of patterns. The number of values that will be used
to match is determined by the maximum arity of PATTERNS among CLAUSES.

Examples:

    (multiple-value-match (values 1 2)
     ((2) 1)
     ((1 y) y))
    => 2"
  (compile-multiple-value-match values-form clauses nil))

Macroexpansion:
(multiple-value-bind (#:var156 #:var157) (values 1 2) (declare (ignorable #:var156 #:var157)) (%or (%if (%equals #:var156 2) (%or 1 (fail)) (fail)) (%or (%if (%equals #:var156 1) (%or (let ((y #:var157)) y) (fail)) (fail)) nil)))
Generate a defmacro form that transforms code like this:
(action (:after node-direct-application) #'direct-application-better-infer-types)

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

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

Macroexpansion:
(make-action (quote :after) (quote node-direct-application) (function direct-application-better-infer-types))
You are a Common Lisp macro expert. Given this code pattern:
(*> +colon+ #'2-digits)

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 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 (#:*>-offset125) (multiple-value-bind (#:*>-res126 #:*>-next127) (funcall +colon+ #:*>-offset125) (if (ok? #:*>-res126) (funcall (function 2-digits) #:*>-next127) (fail #:*>-next127))))
Create a Common Lisp macro for the following transformation. Before code:
(with-store-entry (key store :quiet quiet) (setf (item key store) nil))

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

Macro definition:
(defmacro with-store-entry ((key store &key quiet) &body body)
  `(prog1
       (progn
	 ,@body)
     (unless ,quiet
       (kick-c-link ,key ,store))))

Macroexpansion:
(prog1 (progn (setf (item key store) nil)) (unless quiet (kick-c-link key store)))
Write a Common Lisp macro to handle this code pattern:
(with-table-name nil (yield (when-op-right op)))

Problem: 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* nil)) (yield (when-op-right op)))
You are a Common Lisp macro expert. Given this code pattern:
(with-package (package) (loop for (option . args) in definition-options do (ecase option (:nicknames (loop for nick in args do (add-package-nickname package nick))) (:documentation (setf (documentation package T) (format NIL "~a -- ~a" (documentation package T) (car args)))) (:use (use-package args package)) (:shadow (shadow args package)) (:shadowing-import-from (shadowing-import (collect-symbols-from (car args) (cdr args)) package)) (:import-from (import (collect-symbols-from (car args) (cdr args)) package)) (:export (export args package)) (:intern (loop for symbol in args do (intern (symbol-name symbol) package))) (:local-nicknames (loop for (nickname name) in args do (trivial-package-local-nicknames:add-package-local-nickname nickname name package))) (:size (error "SIZE option not applicable to EXTEND-PACKAGE.")))))

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

Macro definition:
(defmacro with-package ((var &optional (package var)) &body body)
  `(let ((,var (ensure-package ,package)))
     ,@body))

Macroexpansion:
(let ((package (ensure-package package))) (loop for (option . args) in definition-options do (ecase option (:nicknames (loop for nick in args do (add-package-nickname package nick))) (:documentation (setf (documentation package t) (format nil "~a -- ~a" (documentation package t) (car args)))) (:use (use-package args package)) (:shadow (shadow args package)) (:shadowing-import-from (shadowing-import (collect-symbols-from (car args) (cdr args)) package)) (:import-from (import (collect-symbols-from (car args) (cdr args)) package)) (:export (export args package)) (:intern (loop for symbol in args do (intern (symbol-name symbol) package))) (:local-nicknames (loop for (nickname name) in args do (sb-ext:add-package-local-nickname nickname name package))) (:size (error "SIZE option not applicable to EXTEND-PACKAGE.")))))
You are a Common Lisp macro expert. Given this code pattern:
(match 1 (x (if (eql x 1) (fail) x)) (_ 'ok))

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

Macro definition:
(defmacro match (arg &body clauses)
  "Matches ARG with CLAUSES. CLAUSES is a list of the form of (PATTERN
. BODY) where PATTERN is a pattern specifier and BODY is an implicit
progn. If ARG matches some PATTERN, `match` then evaluates
the corresponding BODY and returns the evaluated value.  If no pattern matches,
then returns NIL.

Evaluating a form (FAIL) in the clause body causes the latest pattern
matching to fail. For example,

    (match 1
      (x (if (eql x 1)
             (fail)
             x))
      (_ 'ok))

returns OK, because the form (FAIL) in the first clause is
evaluated.

If BODY starts with the symbols WHEN or UNLESS, then the next form
will be used to introduce (FAIL). That is,

    (match list ((list x) when (oddp x) x))
    (match list ((list x) unless (evenp x) x))

will be translated to

    (match list ((list x) (if (oddp x) x (fail))))
    (match list ((list x) (if (evenp x) (fail) x)))

Examples:

    (match 1 (1 1))
    => 1
    (match 1 (2 2))
    => 2
    (match 1 (x x))
    => 1
    (match (list 1 2 3)
      (list x y z) (+ x y z))
    => 6"
  (compile-match-1 arg clauses nil))

Macroexpansion:
(let ((#:var139 1)) (declare (ignorable #:var139)) (%or (%or (let ((x #:var139)) (if (eql x 1) (fail) x)) (quote ok) (fail)) nil))
Define a macro that eliminates this repetitive pattern:
(defsynonym :maximize :max)

Issue: Macro call that should be transformed by defsynonym

Macro definition:
(defmacro defsynonym (symbol synonym)
  "Set SYNONYM for a SYMBOL. "
  `(eval-always
     (setf (get ',symbol 'synonym) ',synonym)))

Macroexpansion:
(eval-always (setf (get (quote :maximize) (quote synonym)) (quote :max)))
You are a Common Lisp macro expert. Given this code pattern:
(-> nil nil)

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

Macro definition:
(defmacro -> ...)

Macroexpansion:
(nil nil)