j14i/cl-macros huggingface dataset:
Generate a defmacro form that transforms code like this:
(declare-unary-operator nil)

Pattern to recognize: Macro call that should be transformed by DECLARE-UNARY-OPERATOR

Macro definition:
(defmacro DECLARE-UNARY-OPERATOR ...)

Macroexpansion:
(eval-when (:compile-toplevel :load-toplevel :execute)
  (infix-math/data::save-unary-operator 'nil))
Create a Common Lisp macro for the following transformation. Before code:
($send nil :key nil)

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

Macro definition:
(defmacro $SEND ...)

Macroexpansion:
(send-message nil :key nil)
Create a Common Lisp macro for the following transformation. Before code:
(ensure-getf options :binder binder)

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

Macro definition:
(defmacro ensure-getf (place key &optional default)
  (once-only (key default)
    `(setf (getf ,place ,key) (getf ,place ,key ,default))))

Macroexpansion:
(let ((#:key171 :binder) (#:default172 binder)) (setf (getf options #:key171) (getf options #:key171 #:default172)))
Generate a defmacro form that transforms code like this:
(define-op (:is-not-distinct-from infix-op))

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

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

Macroexpansion:
(defstruct (is-not-distinct-from-op (:include infix-op (name "IS NOT DISTINCT FROM")) (:constructor make-is-not-distinct-from-op (left right))))
Define a macro that eliminates this repetitive pattern:
(mapcar 'e list)

Issue: Macro call that should be transformed by m

Macro definition:
(defmacro m (form &environment *env*)
  (e form))

Macroexpansion:
(mapcar (quote e) list)
You are a Common Lisp macro expert. Given this code pattern:
(lret ((out (make-array len :element-type (array-element-type array)))) (replace* out (%flatten array)))

Write a macro that addresses: 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 ((out (make-array len :element-type (array-element-type array)))) (replace* out (%flatten array)))
Generate a defmacro form that transforms code like this:
(defclause (maximize expr &optional into var) "Maximize value of an expression" (return-extremum-code expr var 'max))

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-maximize-12 (&key ((:maximize expr)) ((:into var))) "Maximize value of an expression" (return-extremum-code expr var (quote max))) (install-clause-info (quote (maximize)) (quote (maximize &optional :into)) (quote clause-maximize-12) "Maximize value of an expression" nil) (quote (maximize expr &optional into var)))
You are a Common Lisp macro expert. Given this code pattern:
(defvar-unbound *term-char* "Bound to the closing outer delimiter while parsing a string.")

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

Macro definition:
(defmacro defvar-unbound (variable-name documentation)
  "Like DEFVAR, but the variable will be unbound rather than getting
an initial value.  This is useful for variables which should have no
global value but might have a dynamically bound value."
  ;; stolen from comp.lang.lisp article <k7727i3s.fsf@comcast.net> by
  ;; "prunesquallor@comcast.net"
  `(eval-when (:load-toplevel :compile-toplevel :execute)
    (defvar ,variable-name)
    (setf (documentation ',variable-name 'variable)
            ,documentation)))

Macroexpansion:
(eval-when (:load-toplevel :compile-toplevel :execute) (defvar *term-char*) (setf (documentation (quote *term-char*) (quote variable)) "Bound to the closing outer delimiter while parsing a string."))
Generate a defmacro form that transforms code like this:
(define-cfun __errno_location)

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

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

Macroexpansion:
nil
You are a Common Lisp macro expert. Given this code pattern:
(action (:after node-variable node) (setf node-vars (adjoin (node-variable-value node) node-vars)) (values))

Write a macro that addresses: 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-variable) (lambda (node) (declare (type node-variable node)) (setf node-vars (adjoin (node-variable-value node) node-vars)) (values)))
Create a Common Lisp macro for the following transformation. Before code:
(adding-smart-slot-methods obj slot (slot-value obj slot))

What needs to change: Macro call that should be transformed by adding-smart-slot-methods

Macro definition:
(defmacro adding-smart-slot-methods (obj slot expr)
  (with-gensyms (err class name alt args val)
    `(handler-case ,expr
       (simple-error (,err)
         (let ((,class (class-of ,obj))
               (,name (symbol-name ,slot)))
           (dolist (,alt (c2mop:class-slots ,class)
                         (error ,err))
             (let ((,alt (c2mop:slot-definition-name ,alt)))
               (when (string= ,name (symbol-name ,alt))
                 (add-method (ensure-generic-function 'smart-slot-value)
                             (make-instance
                              'standard-method
                              :specializers
                              (list ,class
                                    (c2mop:intern-eql-specializer ,slot))
                              :lambda-list '(,obj ,slot)
                              :function
                              (lambda (,args _)
                                (declare (ignorable _))
                                (slot-value (first ,args) ,alt))))
                 (add-method (ensure-generic-function 'smart-set-slot-value)
                             (make-instance
                              'standard-method
                              :specializers
                              (list ,class
                                    (c2mop:intern-eql-specializer ,slot)
                                    (find-class 't))
                              :lambda-list '(,obj ,slot ,val)
                              :function
                              (lambda (,args _)
                                (declare (ignorable _))
                                (:= (slot-value (first ,args) ,alt)
                                    (third ,args)))))
                 (let ((,slot ,alt))
                   (return ,expr))))))))))

Macroexpansion:
(handler-case (slot-value obj slot) (simple-error (#:g149) (let ((#:g150 (class-of obj)) (#:g151 (symbol-name slot))) (dolist (#:g152 (sb-mop:class-slots #:g150) (error #:g149)) (let ((#:g152 (sb-mop:slot-definition-name #:g152))) (when (string= #:g151 (symbol-name #:g152)) (add-method (ensure-generic-function (quote smart-slot-value)) (make-instance (quote standard-method) :specializers (list #:g150 (sb-mop:intern-eql-specializer slot)) :lambda-list (quote (obj slot)) :function (lambda (#:g153 _) (declare (ignorable _)) (slot-value (first #:g153) #:g152)))) (add-method (ensure-generic-function (quote smart-set-slot-value)) (make-instance (quote standard-method) :specializers (list #:g150 (sb-mop:intern-eql-specializer slot) (find-class (quote t))) :lambda-list (quote (obj slot #:g154)) :function (lambda (#:g153 _) (declare (ignorable _)) (:= (slot-value (first #:g153) #:g152) (third #:g153))))) (let ((slot #:g152)) (return (slot-value obj slot)))))))))
Generate a defmacro form that transforms code like this:
(define-condition/a dbi-unimplemented-error (dbi-interface-error) ((method-name :initarg :method-name :type (or symbol string))) (:documentation "Exception raised if the DBD driver has not specified a mandatory method.") (:report (lambda (condition stream) (format stream "`~A' must be implemented." (slot-value condition 'method-name)))))

Pattern to recognize: Macro call that should be transformed by define-condition/a

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

Macroexpansion:
(progn (define-condition dbi-unimplemented-error (dbi-interface-error) ((method-name :initarg :method-name :type (or symbol string))) (:documentation "Exception raised if the DBD driver has not specified a mandatory method.") (:report (lambda (condition stream) (format stream "`~A' must be implemented." (slot-value condition (quote method-name)))))) (deftype <dbi-unimplemented-error> nil (quote dbi-unimplemented-error)) (setf (find-class (quote <dbi-unimplemented-error>)) (find-class (quote dbi-unimplemented-error))))
You are a Common Lisp macro expert. Given this code pattern:
(max-of nil
  nil)

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

Macro definition:
(defmacro MAX-OF ...)

Macroexpansion:
(lc (nil nil) maximize)
Write a Common Lisp macro to handle this code pattern:
(defun-compile-time check-function-name (function-name) (unless (valid-function-name? function-name) (error "Invalid function name: ~S" function-name)))

Problem: 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 check-function-name (function-name) (unless (valid-function-name? function-name) (error "Invalid function name: ~S" function-name))) (eval-when (:compile-toplevel) (compile (quote check-function-name))))
You are a Common Lisp macro expert. Given this code pattern:
(js nil)

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

Macro definition:
(defmacro JS ...)

Macroexpansion:
(ps
  nil)
Generate a defmacro form that transforms code like this:
(true (< 8 5))

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

Macro definition:
(defmacro true (form &optional description &rest format-args)
  `(eval-in-context
    *context*
    (make-instance 'comparison-result
                   :expression '(true ,form)
                   :value-form ',form
                   :body (lambda () ,form)
                   :expected 'T
                   :comparison 'geq
                   ,@(when description
                       `(:description (format NIL ,description ,@format-args))))))

Macroexpansion:
(eval-in-context *context* (make-instance (quote comparison-result) :expression (quote (true (< 8 5))) :value-form (quote (< 8 5)) :body (lambda nil (< 8 5)) :expected (quote t) :comparison (quote geq)))
You are a Common Lisp macro expert. Given this code pattern:
(subtest "Inner testcase with multiline description." (is 'foo 'foo "Foo with multiline description!"))

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

Macro definition:
(defmacro subtest (desc &body body)
  `(%subtest ,desc (lambda () ,@body)))

Macroexpansion:
(%subtest "Inner testcase with multiline description." (lambda nil (is (quote foo) (quote foo) "Foo with multiline description!")))
Generate a defmacro form that transforms code like this:
(augment decls decs)

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

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

Macroexpansion:
(setf decls (nconc decls decs))
Generate a defmacro form that transforms code like this:
(with-html-string (let ((*print-pretty*)) (:div (:textarea "123"))))

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

Macro definition:
(defmacro with-html (&body body &environment env)
  "Interpret BODY as HTML. Consult README.txt for the syntax."
  `(let ((*html* (ensure-html-stream *html*)))
     ,(if (and (null (cdr body)) (atom (car body)))
          (car body)
          `(progn ,@(parse-html body env)))))

Macroexpansion:
(with-output-to-string (*html*) (with-html (let ((*print-pretty*)) (:div (:textarea "123")))))
Generate a defmacro form that transforms code like this:
(do-generator (x (list->generator data)) (yield x))

Pattern to recognize: 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 ((#:g170 (list->generator data))) (loop do (if-generator ((x) #:g170) (progn (yield x)) (return))))
Define a macro that eliminates this repetitive pattern:
(define-op (:as infix-splicing-op))

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

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

Macroexpansion:
(defstruct (as-op (:include infix-splicing-op (name "AS")) (:constructor make-as-op (left right))))
You are a Common Lisp macro expert. Given this code pattern:
(define-option-expander size (package n) (declare (ignore n)) (error "SIZE option not applicable."))

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

Macro definition:
(defmacro define-option-expander (name (package &rest arguments) &body body)
  (let ((args (gensym "ARGS")))
    `(defmethod expand-option ((,(gensym "TYPE") (eql ,(intern (string name) "KEYWORD"))) ,package ,args)
       (destructuring-bind ,arguments ,args
         ,@body))))

Macroexpansion:
(defmethod expand-option ((#:type138 (eql :size)) package #:args137) (destructuring-bind (n) #:args137 (declare (ignore n)) (error "SIZE option not applicable.")))
Generate a defmacro form that transforms code like this:
(cond-<>>
  'some-name)

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

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

Macroexpansion:
'some-name
Create a Common Lisp macro for the following transformation. Before code:
(compile-$flavor-$methods nil nil)

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

Macro definition:
(defmacro COMPILE-$FLAVOR-$METHODS ...)

Macroexpansion:
(eval-when (:load-toplevel) (combine-class-methods nil nil))
Create a Common Lisp macro for the following transformation. Before code:
(with-header-output (buffer) (let ((cookies (cookie-jar-host-cookies cookie-jar (uri-host uri) (or (uri-path uri) "/") :securep (string= (uri-scheme uri) "https")))) (when cookies (fast-write-sequence (ascii-string-to-octets "Cookie: ") buffer) (fast-write-sequence (ascii-string-to-octets (write-cookie-header cookies)) buffer) (fast-write-sequence +crlf+ buffer))))

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

Macro definition:
(defmacro with-header-output ((buffer &optional output) &body body)
  `(with-fast-output (,buffer ,output)
     (declare (ignorable ,buffer))
     (let ((*header-buffer* ,buffer))
       ,@body)))

Macroexpansion:
(with-fast-output (buffer nil) (declare (ignorable buffer)) (let ((*header-buffer* buffer)) (let ((cookies (cookie-jar-host-cookies cookie-jar (uri-host uri) (or (uri-path uri) "/") :securep (string= (uri-scheme uri) "https")))) (when cookies (fast-write-sequence (ascii-string-to-octets "Cookie: ") buffer) (fast-write-sequence (ascii-string-to-octets (write-cookie-header cookies)) buffer) (fast-write-sequence +crlf+ buffer)))))