j14i/cl-macros huggingface dataset:
Define a macro that eliminates this repetitive pattern:
(define-method-combination% standard () ((around (:around)) (before (:before)) (primary () :required t) (after (:after) :order :most-specific-last)) (labels ((call-methods (methods) (mapcar (curry #'list 'call-method) methods)) (call-primary (primary) `(call-method ,(first primary) ,(rest primary))) (call-before (before form) (if before `(progn ,@(call-methods before) ,form) form)) (call-after (after form) (if after `(multiple-value-prog1 ,form ,@(call-methods after)) form)) (call-around (around form) (if around `(call-method ,(first around) (,@(rest around) (make-method ,form))) form))) (->> (call-primary primary) (call-before before) (call-after after) (call-around around))))

Issue: Macro call that should be transformed by define-method-combination

Macro definition:
(defmacro define-method-combination (name &rest args)
  `(progn
     (define-method-combination% ,name ,@args)
     (c2mop:define-method-combination ,name ,@args)))

Macroexpansion:
(define-method-combination% standard nil ((around (:around)) (before (:before)) (primary nil :required t) (after (:after) :order :most-specific-last)) (labels ((call-methods (methods) (mapcar (curry (function list) (quote call-method)) methods)) (call-primary (primary) (sb-int:quasiquote (call-method #S(sb-impl::comma :expr (first primary) :kind 0) #S(sb-impl::comma :expr (rest primary) :kind 0)))) (call-before (before form) (if before (sb-int:quasiquote (progn #S(sb-impl::comma :expr (call-methods before) :kind 2) #S(sb-impl::comma :expr form :kind 0))) form)) (call-after (after form) (if after (sb-int:quasiquote (multiple-value-prog1 #S(sb-impl::comma :expr form :kind 0) #S(sb-impl::comma :expr (call-methods after) :kind 2))) form)) (call-around (around form) (if around (sb-int:quasiquote (call-method #S(sb-impl::comma :expr (first around) :kind 0) (#S(sb-impl::comma :expr (rest around) :kind 2) (make-method #S(sb-impl::comma :expr form :kind 0))))) form))) (->> (call-primary primary) (call-before before) (call-after after) (call-around around))))
Create a Common Lisp macro for the following transformation. Before code:
(define-component dot :input-type "dot" :output-type "png" :compile-function (lambda (input-pathname output-pathname) (inferior-shell:run `("dot" "-Tpng" ,input-pathname "-o" ,output-pathname) :show t)))

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

Macro definition:
(defmacro define-component (name &key input-type output-type compile-function)
  "Define an ASDF component."
  `(progn
     (defclass ,name (source-file)
       ((type :initform ,input-type)
        (output :reader output :initarg :output)))

     (defmethod perform ((o load-op) (component ,name)) t)

     (defmethod output-files ((operation compile-op) (component ,name))
       (list
        (output-pathname component ,output-type)))

     (defmethod perform ((o compile-op) (component ,name))
       (funcall ,compile-function
                (component-pathname component)
                (output-pathname component ,output-type)))

     (import ',name :asdf)))

Macroexpansion:
(progn (defclass dot (source-file) ((type :initform "dot") (output :reader output :initarg :output))) (defmethod perform ((o load-op) (component dot)) t) (defmethod output-files ((operation compile-op) (component dot)) (list (output-pathname component "png"))) (defmethod perform ((o compile-op) (component dot)) (funcall (lambda (input-pathname output-pathname) (inferior-shell:run (sb-int:quasiquote ("dot" "-Tpng" #S(sb-impl::comma :expr input-pathname :kind 0) "-o" #S(sb-impl::comma :expr output-pathname :kind 0))) :show t)) (component-pathname component) (output-pathname component "png"))) (import (quote dot) :asdf))
You are a Common Lisp macro expert. Given this code pattern:
(collect-max nil (progn))

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

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

Macroexpansion:
(common-lisp:let* ((#:generator-366 (generator (progn)))
                   #:items-356
                   (#:generator-364 (generator nil))
                   #:numbers-355
                   (#:number-358 nil)
                   #:result-359)
  (declare (type generator #:generator-366)
           (type generator #:generator-364)
           (type (null-or t) #:result-359))
  (tagbody
   #:ll-367
    (setq #:items-356 (next-in #:generator-366 (go end)))
    (setq #:numbers-355 (next-in #:generator-364 (go end)))
    (if (or (null #:number-358) (< #:number-358 #:numbers-355))
        (setq #:number-358 #:numbers-355
              #:result-359 #:items-356))
    (go #:ll-367)
   end)
  (if (null #:number-358)
      (setq #:result-359 nil))
  #:result-359)
Create a Common Lisp macro for the following transformation. Before code:
(unwind-protect nil
    :key
  nil)

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

Macro definition:
(defmacro UNWIND-PROTECT ...)

Macroexpansion:
(common-lisp:unwind-protect :key nil)
Define a macro that eliminates this repetitive pattern:
(define-comparison-ops == = < < > > <= <= >= >=)

Issue: Macro call that should be transformed by define

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

Macroexpansion:
(progn (progn (defmethod vacietis.c:== ((x memptr) (y memptr)) (if (and (eq (memptr-mem x) (memptr-mem y)) (= (memptr-ptr x) (memptr-ptr y))) 1 0)) (defmethod vacietis.c:== ((x number) (y number)) (if (= x y) 1 0))) (progn (defmethod vacietis.c:< ((x memptr) (y memptr)) (if (and (eq (memptr-mem x) (memptr-mem y)) (< (memptr-ptr x) (memptr-ptr y))) 1 0)) (defmethod vacietis.c:< ((x number) (y number)) (if (< x y) 1 0))) (progn (defmethod vacietis.c:> ((x memptr) (y memptr)) (if (and (eq (memptr-mem x) (memptr-mem y)) (> (memptr-ptr x) (memptr-ptr y))) 1 0)) (defmethod vacietis.c:> ((x number) (y number)) (if (> x y) 1 0))) (progn (defmethod vacietis.c:<= ((x memptr) (y memptr)) (if (and (eq (memptr-mem x) (memptr-mem y)) (<= (memptr-ptr x) (memptr-ptr y))) 1 0)) (defmethod vacietis.c:<= ((x number) (y number)) (if (<= x y) 1 0))) (progn (defmethod vacietis.c:>= ((x memptr) (y memptr)) (if (and (eq (memptr-mem x) (memptr-mem y)) (>= (memptr-ptr x) (memptr-ptr y))) 1 0)) (defmethod vacietis.c:>= ((x number) (y number)) (if (>= x y) 1 0))))
Create a Common Lisp macro for the following transformation. Before code:
(defclause for (var-or-vars iteration &environment env) "General iteration clause. Its actual behaviour is controlled by ITERATION, a macro form that FOR expands with *ITERATION-VARIABLE* bound to VAR. Example: in (for x (in '(1 2 3))), IN is a macro that expands into clauses that make use of *ITERATION-VARIABLE*, which is bound to the symbol X in the example. For certain iteration macros, VAR can be a lambda-list as well, in which case destructuring is applied. Example: (for (x &optional y) (in-list '((1 2) (3))))." (let ((*iteration-variable* var-or-vars)) (macroexpand iteration env)))

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

Macro definition:
(defmacro defclause (name arglist &body body)
  "Same as cl:defmacro, but additionally records <name> in *clauses* as a known clause macro."
  `(progn
     (defmacro ,name ,arglist ,@body)
     (pushnew ',name *clauses*)))

Macroexpansion:
(progn (defmacro for (var-or-vars iteration &environment env) "General iteration clause. Its actual behaviour is controlled by ITERATION, a macro form that FOR expands with *ITERATION-VARIABLE* bound to VAR. Example: in (for x (in '(1 2 3))), IN is a macro that expands into clauses that make use of *ITERATION-VARIABLE*, which is bound to the symbol X in the example. For certain iteration macros, VAR can be a lambda-list as well, in which case destructuring is applied. Example: (for (x &optional y) (in-list '((1 2) (3))))." (let ((*iteration-variable* var-or-vars)) (macroexpand iteration env))) (pushnew (quote for) *clauses*))
Write a Common Lisp macro to handle this code pattern:
(defsynonym reducing :reduce)

Problem: 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 reducing) (quote synonym)) (quote :reduce)))
Generate a defmacro form that transforms code like this:
(define-custom-var (:object-scope *object-scope-variables*) '(*internal-decoder*) "A list of symbols naming dynamic variables which should be re-bound in the scope of every JSON Object.")

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

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

Macroexpansion:
(eval-when (:compile-toplevel :load-toplevel :execute) (progn (pushnew (quote (*object-scope-variables* . :object-scope)) *custom-vars* :test (function equal)) (defvar *object-scope-variables* (quote (*internal-decoder*)) "A list of symbols naming dynamic variables which should be re-bound in the scope of every JSON Object.")))
You are a Common Lisp macro expert. Given this code pattern:
(lambda-match)

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

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

Macroexpansion:
(lambda (#:arg145) (match #:arg145))
Define a macro that eliminates this repetitive pattern:
(define _IOLBF 2)

Issue: Macro call that should be transformed by define

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

Macroexpansion:
(progn (eval-when (:compile-toplevel :load-toplevel :execute) (defvar *preprocessor-defines* (make-hash-table)) (setf (gethash (quote _iolbf) *preprocessor-defines*) #A((1) base-char . "2"))) (defparameter _iolbf 2))
Write a Common Lisp macro to handle this code pattern:
(with-autoload-on-missing (let ((*standard-output* (make-broadcast-stream)) (*error-output* (make-broadcast-stream))) (asdf:load-system driver-system :verbose nil)))

Problem: Macro call that should be transformed by with-autoload-on-missing

Macro definition:
(defmacro with-autoload-on-missing (&body body)
  (let ((retrying (gensym))
        (e (gensym)))
    `(let ((,retrying (make-hash-table :test 'equal)))
       (handler-bind ((asdf:missing-component
                        (lambda (,e)
                          (unless (gethash (asdf::missing-requires ,e) ,retrying)
                            (setf (gethash (asdf::missing-requires ,e) ,retrying) t)
                            (when (find :quicklisp *features*)
                              (uiop:symbol-call '#:ql-dist '#:ensure-installed
                                                (uiop:symbol-call '#:ql-dist '#:find-system
                                                                  (asdf::missing-requires ,e)))
                              (invoke-restart (find-restart 'asdf:retry ,e)))))))
         ,@body))))

Macroexpansion:
(let ((#:g158 (make-hash-table :test (quote equal)))) (handler-bind ((asdf/find-component:missing-component (lambda (#:g159) (unless (gethash (asdf/find-component:missing-requires #:g159) #:g158) (setf (gethash (asdf/find-component:missing-requires #:g159) #:g158) t) (when (find :quicklisp *features*) (uiop/package:symbol-call (quote #:ql-dist) (quote #:ensure-installed) (uiop/package:symbol-call (quote #:ql-dist) (quote #:find-system) (asdf/find-component:missing-requires #:g159))) (invoke-restart (find-restart (quote asdf/session:retry) #:g159))))))) (let ((*standard-output* (make-broadcast-stream)) (*error-output* (make-broadcast-stream))) (asdf/operate:load-system driver-system :verbose nil))))
Generate a defmacro form that transforms code like this:
(with-prepared-query query (conn (format nil "SELECT pg_get_viewdef('~A'::regclass) AS def" table-name)) (let ((results (dbi:execute query))) (string-right-trim '(#\Space #\;) (string-left-trim '(#\Space) (first (first (dbi:fetch-all results :format :values)))))))

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

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

Macroexpansion:
(call-with-prepared-query conn (format nil "SELECT pg_get_viewdef('~A'::regclass) AS def" table-name) (lambda (query) (let ((results (dbi.driver:execute query))) (string-right-trim (quote (#\Space #\SEMICOLON)) (string-left-trim (quote (#\Space)) (first (first (dbi.driver:fetch-all results :format :values))))))) :use-prepare-cached nil)
Write a Common Lisp macro to handle this code pattern:
(coexit!)

Problem: Macro call that should be transformed by COEXIT!

Macro definition:
(defmacro COEXIT! ...)

Macroexpansion:
(coexit (values))
Create a Common Lisp macro for the following transformation. Before code:
(-> :g (a) (values (+ a 5) -1))

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

Macro definition:
(defmacro -> (invariant &body args)
  "See flow:atomically"
  `(atomically ,invariant ,@args))

Macroexpansion:
(atomically :g (a) (values (+ a 5) -1))
Define a macro that eliminates this repetitive pattern:
(define-hook (:build uiop) () (unless uiop/image:*image-dumped-p* (setf uiop/image:*image-dumped-p* T) (setf uiop/image::*image-restored-p* :in-regress) (uiop/image:call-image-dump-hook) (setf uiop/image::*image-restored-p* NIL)))

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 ((uiop (or (hook :build (quote uiop)) (make-instance (quote hook) :name (quote uiop) :type :build)))) (setf (hook-priority uiop) 0) (setf (hook-function uiop) (flet ((uiop (&key &allow-other-keys) (unless uiop/image:*image-dumped-p* (setf uiop/image:*image-dumped-p* t) (setf uiop/image::*image-restored-p* :in-regress) (uiop/image:call-image-dump-hook) (setf uiop/image::*image-restored-p* nil)))) (function uiop))) (setf (hook :build (quote uiop)) uiop) (setf (docstring uiop) nil) (quote uiop))
Generate a defmacro form that transforms code like this:
;; Exporting closure variables requires building pandoric protocol manually
(let ((a 0))
  (let ((b 1))
    (let (this self)
      (setq
        this (lambda (n) (incf a n) (setq b (* b n)))
        self (dlambda
               (:pandoric-get (sym)
                 (case sym
                   ((a) a)
                   ((b) b)
                   (t (error "Unknown: ~a" sym))))
               (:pandoric-set (sym val)
                 (case sym
                   ((a) (setq a val))
                   ((b) (setq b val))))
               (t (&rest args) (apply this args)))))))

;; Manual self construction for every closure is painful

Pattern to recognize: Need to export closure variables through pandoric protocol, but manually building the self dlambda for each set of variables is repetitive

Macro definition:
(defmacro plambda (largs pargs &rest body)
  (let ((pargs (mapcar #'list pargs)))
    `(let (this self)
       (setq
         this (lambda ,largs ,@body)
         self (dlambda
                (:pandoric-get (sym)
                  ,(pandoriclet-get pargs))
                (:pandoric-set (sym val)
                  ,(pandoriclet-set pargs))
                (t (&rest args)
                  (apply this args)))))))

Macroexpansion:
;; (let ((a 0))
;;   (let ((b 1))
;;     (plambda (n) (a b)
;;       (incf a n)
;;       (setq b (* b n)))))
;;
;; Now:
;; (with-pandoric (a b) closure
;;   (format t "a=~a b=~a~%" a b))
;; a and b are accessible through the pandoric protocol
Define a macro that eliminates this repetitive pattern:
(*> +comment+ +skip-all-space+)

Issue: 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 (#:*>-offset248) (multiple-value-bind (#:*>-res249 #:*>-next250) (funcall +comment+ #:*>-offset248) (if (ok? #:*>-res249) (funcall +skip-all-space+ #:*>-next250) (fail #:*>-next250))))
Define a macro that eliminates this repetitive pattern:
(if-generator (vals gen) (loop for val in vals for j from 0 do (push val (elt stor j))) (if fail-if-short (error 'insufficient-items :format-control "Insufficient items in generator") (return (apply #'values (mapcar #'reverse stor)))))

Issue: Macro call that should be transformed by if-generator

Macro definition:
(defmacro if-generator ((var gen) true-clause &optional false-clause)
  "Pulls a single iteration out of gen. If a single var is specified, it places all the values from the iteration in a list under var. If var is a list, destructures values into the vars in the list. If the generator has stopped, evaluates false-clause, otherwise evaluates true-clause."
  `(,@(if (listp var)
	 `(multiple-value-bind ,var
	      (funcall ,gen))
	 `(let ((,var (multiple-value-list (funcall ,gen))))))
      (if (eq 'generator-stop
	      ,(if (listp var)
		   (car var)
		   `(car ,var)))
	  ,false-clause
	  ,true-clause)))

Macroexpansion:
(let ((vals (multiple-value-list (funcall gen)))) (if (eq (quote generator-stop) (car vals)) (if fail-if-short (error (quote insufficient-items) :format-control "Insufficient items in generator") (return (apply (function values) (mapcar (function reverse) stor)))) (loop for val in vals for j from 0 do (push val (elt stor j)))))
You are a Common Lisp macro expert. Given this code pattern:
(enable-case-preserving-syntax)

Write a macro that addresses: Macro call that should be transformed by ENABLE-CASE-PRESERVING-SYNTAX

Macro definition:
(defmacro ENABLE-CASE-PRESERVING-SYNTAX ...)

Macroexpansion:
(eval-when (:compile-toplevel :execute)
  (setf *readtable* (copy-readtable *readtable*))
  (set-case-preserving-syntax-in-readtable :start-character #\COMMA
                                           :dispatch-character #\NUMBER_SIGN
                                           :readtable-case :preserve :packages
                                           nil)
  (values))
You are a Common Lisp macro expert. Given this code pattern:
(if-it (mismatch suffix string :from-end t :test test :end2 (when -end (- (length string) -end))) (zerop it) t)

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

Macro definition:
(defmacro if-it (test then &optional else)
  "Like IF. IT is bound to TEST."
  `(let ((it ,test))
     (if it ,then ,else)))

Macroexpansion:
(let ((it (mismatch suffix string :from-end t :test test :end2 (when -end (- (length string) -end))))) (if it (zerop it) t))
Write a Common Lisp macro to handle this code pattern:
(enable-feature-cond-syntax)

Problem: Macro call that should be transformed by ENABLE-FEATURE-COND-SYNTAX

Macro definition:
(defmacro ENABLE-FEATURE-COND-SYNTAX ...)

Macroexpansion:
(eval-when (:compile-toplevel :execute)
  (setf *readtable* (copy-readtable *readtable*))
  (set-feature-cond-syntax-in-readtable :start-character #\ASTERISK
                                        :dispatch-character #\NUMBER_SIGN
                                        :end-character nil :readtable-case nil)
  (values))
You are a Common Lisp macro expert. Given this code pattern:
(macroexpand-convention (form) (if (consp form) (expand-export-structure-using-head (first form) form) form))

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

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

Macroexpansion:
(multiple-value-bind (result expanded-p) (progn (if (consp form) (expand-export-structure-using-head (first form) form) form)) (values result (or expanded-p (not (eq result form)))))
Create a Common Lisp macro for the following transformation. Before code:
(do-notation bind-either ((sum (left 1)) (str (either->string sum))) (print str))

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

Macro definition:
(defmacro do-notation (bind-function expressions &body body)
  "Given a BIND-FUNCTION and all the bind expressions, evaluate BODY."
  `(progn
     ,@(reduce (lambda (acc do-binding)
		 (append `((,bind-function (lambda (,(car do-binding)) ,@acc)
					   ,@(cdr do-binding)))))
	       (reverse expressions)
	       :initial-value body)))

Macroexpansion:
(progn (bind-either (lambda (sum) (bind-either (lambda (str) (print str)) (either->string sum))) (left 1)))
Write a Common Lisp macro to handle this code pattern:
(defjs map1() (if (< this.k 90) (emit this.name 1) (emit this.k 99)))

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 nil (if (< this.k 90) (emit this.name 1) (emit this.k 99)))))) (setf (gethash (quote map1) *js-definitions*) js-body) (defun map1 nil (get-element "retval" (car (docs (db.eval js-body))))))
Write a Common Lisp macro to handle this code pattern:
(destructuring-bind () :key nil)

Problem: Macro call that should be transformed by DESTRUCTURING-BIND

Macro definition:
(defmacro DESTRUCTURING-BIND ...)

Macroexpansion:
(sb-int:binding* ((nil (sb-c::check-ds-list :key 0 0 'nil)))
  nil)