j14i/cl-macros huggingface dataset:
Define a macro that eliminates this repetitive pattern:
(set-custom-vars :integer #'parse-number :real #'parse-number :boolean #'json-boolean-to-lisp :beginning-of-array #'make-accumulator :array-element #'accumulator-add :end-of-array #'accumulator-get-sequence :beginning-of-object #'make-accumulator :object-key #'accumulator-add-key :object-value #'accumulator-add-value :end-of-object #'accumulator-get :beginning-of-string #'make-vector-accumulator :string-char #'vector-accumulator-add :end-of-string #'vector-accumulator-get-string)

Issue: Macro call that should be transformed by set-custom-vars

Macro definition:
(defmacro set-custom-vars (&rest key-args)
  `(setq
    ,@(loop for (supplied-key value) on key-args by #'cddr
         append (loop for (var . var-key) in *custom-vars*
                   thereis (if (eql var-key supplied-key)
                               (list var value))))))

Macroexpansion:
(setq *integer-handler* (function parse-number) *real-handler* (function parse-number) *boolean-handler* (function json-boolean-to-lisp) *beginning-of-array-handler* (function make-accumulator) *end-of-array-handler* (function accumulator-get-sequence) *beginning-of-object-handler* (function make-accumulator) *object-key-handler* (function accumulator-add-key) *object-value-handler* (function accumulator-add-value) *end-of-object-handler* (function accumulator-get) *beginning-of-string-handler* (function make-vector-accumulator) *string-char-handler* (function vector-accumulator-add) *end-of-string-handler* (function vector-accumulator-get-string))
Create a Common Lisp macro for the following transformation. Before code:
(defstore example (&key (a 0) (b 0) (c (the integer (init-c a b)))))

What needs to change: 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 (a #:a?163 b #:b?164) (declare (ignorable a #:a?163 b #:b?164)) (the integer (init-c a b))) (ensure-store (quote example) (quote (&key (a 0 #:a?163) (b 0 #:b?164) (c (the integer (a-init-function152 a #:a?163 b #:b?164)) #:c?165))))))
Define a macro that eliminates this repetitive pattern:
(with-prepared-query query (conn (format nil "SHOW CREATE VIEW `~A`" table-name)) (let ((results (dbi:execute query))) (getf (first (dbi:fetch-all results :format :plist)) :|Create View|)))

Issue: 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 "SHOW CREATE VIEW `~A`" table-name) (lambda (query) (let ((results (dbi.driver:execute query))) (getf (first (dbi.driver:fetch-all results :format :plist)) :|Create View|))) :use-prepare-cached nil)
Define a macro that eliminates this repetitive pattern:
(when else-body `(make-simple-block ,else-body))

Issue: 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 else-body (sb-int:quasiquote (make-simple-block #S(sb-impl::comma :expr else-body :kind 0))))
Generate a defmacro form that transforms code like this:
(define-case-aware-find-symbol find-pragma-name #:with-c-syntax.pragma-name)

Pattern to recognize: Macro call that should be transformed by define-case-aware-find-symbol

Macro definition:
(defmacro define-case-aware-find-symbol
    (finder-function-name package-name
     &key (upcased-package-name (format nil "~A.~A" (string package-name) '#:UPCASED))
       (docstring
        (format nil "Find a symbol in `~A' package having a same NAME. If not found, returns `nil'."
                package-name)))
  `(eval-when (:compile-toplevel :load-toplevel :execute)
     (defpackage ,upcased-package-name
       (:use)
       (:intern
        ,@(loop for sym being the external-symbol of package-name
                collect (string-upcase (symbol-name sym)))))
     ,@(loop for sym being the external-symbol of package-name
             for upcased = (string-upcase (symbol-name sym))
             collect `(setf (symbol-value (find-symbol ,upcased ',upcased-package-name))
                            ',sym))
     (defun ,finder-function-name (string &optional (readtable-case (readtable-case *readtable*)))
       ,@(if docstring `(,docstring))
       (ecase readtable-case
         ((:upcase :invert)
          (if-let ((up-sym (find-symbol string ',upcased-package-name)))
            (symbol-value up-sym)))
         ((:downcase :preserve)
          (find-symbol string ',package-name))))))

Macroexpansion:
(eval-when (:compile-toplevel :load-toplevel :execute) (defpackage #A((33) base-char . "WITH-C-SYNTAX.PRAGMA-NAME.UPCASED") (:use) (:intern #A((4) base-char . "STDC") #A((4) base-char . "ONCE") #A((13) base-char . "WITH_C_SYNTAX"))) (setf (symbol-value (find-symbol #A((4) base-char . "STDC") (quote #A((33) base-char . "WITH-C-SYNTAX.PRAGMA-NAME.UPCASED")))) (quote with-c-syntax.pragma-name:stdc)) (setf (symbol-value (find-symbol #A((4) base-char . "ONCE") (quote #A((33) base-char . "WITH-C-SYNTAX.PRAGMA-NAME.UPCASED")))) (quote with-c-syntax.pragma-name:|once|)) (setf (symbol-value (find-symbol #A((13) base-char . "WITH_C_SYNTAX") (quote #A((33) base-char . "WITH-C-SYNTAX.PRAGMA-NAME.UPCASED")))) (quote with-c-syntax.pragma-name:with_c_syntax)) (defun find-pragma-name (string &optional (readtable-case (readtable-case *readtable*))) #A((101) base-char . "Find a symbol in `WITH-C-SYNTAX.PRAGMA-NAME' package having a same NAME. If not found, returns `nil'.") (ecase readtable-case ((:upcase :invert) (if-let ((up-sym (find-symbol string (quote #A((33) base-char . "WITH-C-SYNTAX.PRAGMA-NAME.UPCASED"))))) (symbol-value up-sym))) ((:downcase :preserve) (find-symbol string (quote #:with-c-syntax.pragma-name))))))
Create a Common Lisp macro for the following transformation. Before code:
(do-files (file (app-path "themes/") "tmpl") (compile-template :common-lisp-backend file))

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

Macro definition:
(defmacro do-files ((var path &optional extension) &body body)
  "For each file under PATH, run BODY. If EXTENSION is provided, only run
BODY on files that match the given extension."
  (alexandria:with-gensyms (extension-p)
    `(flet ((,extension-p (file)
              (string= (pathname-type file) ,extension)))
       (cl-fad:walk-directory ,path (lambda (,var) ,@body)
                              :follow-symlinks nil
                              :test (if ,extension
                                        #',extension-p
                                        (constantly t))))))

Macroexpansion:
(flet ((#:extension-p289 (file) (string= (pathname-type file) "tmpl"))) (cl-fad:walk-directory (app-path "themes/") (lambda (file) (compile-template :common-lisp-backend file)) :follow-symlinks nil :test (if "tmpl" (function #:extension-p289) (constantly t))))
You are a Common Lisp macro expert. Given this code pattern:
(true 5)

Write a macro that addresses: 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 5)) :value-form (quote 5) :body (lambda nil 5) :expected (quote t) :comparison (quote geq)))
Create a Common Lisp macro for the following transformation. Before code:
(defclause (multiply expr &optional into var result-type (type 'number)) "Multiply into a variable" (return-reduction-code :identity 1 :operation '* :expression expr :test nil :variable var :type type :accum-kind :increment))

What needs to change: 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-multiply-11 (&key ((:multiply expr)) ((:into var)) ((:result-type type) (quote number))) "Multiply into a variable" (return-reduction-code :identity 1 :operation (quote *) :expression expr :test nil :variable var :type type :accum-kind :increment)) (install-clause-info (quote (multiply)) (quote (multiply &optional :into :result-type)) (quote clause-multiply-11) "Multiply into a variable" nil) (quote (multiply expr &optional into var result-type (type (quote number)))))
Write a Common Lisp macro to handle this code pattern:
(with-wcs-math-error-handling (ret (atanh x)) (check-wcs-math-result))

Problem: Macro call that should be transformed by with-wcs-math-error-handling

Macro definition:
(defmacro with-wcs-math-error-handling
    ((var-or-var-list
      (function x &optional (y nil y-supplied-p))
      &rest keyargs
      &key underflow-value)
     &body body)
  (declare (ignorable underflow-value))
  (let ((x_ (gensym)) (y_ (gensym)) (args_ (gensym))
        (var-list (ensure-list var-or-var-list)))
    `(let* ((,x_ ,x)
            (,y_ ,y)
            (,args_ (list ,x_ ,@(if y-supplied-p `(,y_)))))
       (declare (ignorable ,y_)
                (type list ,args_)
                (dynamic-extent ,args_))
       (catch 'return-from-with-wcs-math-error-handling
         (multiple-value-bind ,var-list
             (call-with-wcs-math-error-handler ',function ,args_
                                               ,@keyargs)
           (flet ((check-wcs-math-result
                      (&optional (ret ,(first var-list))
                                 (arg-list ,args_))
                    (check-wcs-math-result ret arg-list)))
             ,@body))))))

Macroexpansion:
(let* ((#:g218 x) (#:g219 nil) (#:g220 (list #:g218))) (declare (ignorable #:g219) (type list #:g220) (dynamic-extent #:g220)) (catch (quote return-from-with-wcs-math-error-handling) (multiple-value-bind (ret) (call-with-wcs-math-error-handler (quote atanh) #:g220) (flet ((check-wcs-math-result (&optional (ret ret) (arg-list #:g220)) (check-wcs-math-result ret arg-list))) (check-wcs-math-result)))))
Create a Common Lisp macro for the following transformation. Before code:
(->*
  nil
  :key
  nil)

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

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

Macroexpansion:
(let* ((#:var194 nil) (#:var195 (nil #:var194)) (#:var196 (:key #:var195)))
  #:var196)
Write a Common Lisp macro to handle this code pattern:
(let+ nil)

Problem: Macro call that should be transformed by LET+

Macro definition:
(defmacro LET+ ...)

Macroexpansion:
(locally)
You are a Common Lisp macro expert. Given this code pattern:
(fmap #'nreverse (recurse (list res) next))

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

Macro definition:
(defmacro fmap (f thing)
  "Apply a pure function to the inner contents of some parsing operation, if the
parsing itself was successful."
  `(multiple-value-bind (res next) ,thing
     (if (failure? res)
         (fail next)
         (values (funcall ,f res) next))))

Macroexpansion:
(multiple-value-bind (res next) (recurse (list res) next) (if (failure? res) (fail next) (values (funcall (function nreverse) res) next)))
Write a Common Lisp macro to handle this code pattern:
(some-> nil (progn))

Problem: Macro call that should be transformed by SOME->

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

Macroexpansion:
(let* ((#:|some127| nil) (#:|some127| (when #:|some127| (progn #:|some127|))))
  #:|some127|)
Generate a defmacro form that transforms code like this:
(setypecase (car x) (symbol (setf it :no)) (string (setf it "OK")) (integer (setf it :noon)))

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

Macro definition:
(defmacro setypecase (keyform &body cases)
  "Like ETYPECASE, except binds the keyform to IT (via SYMBOL-MACROLET) for
the scope of the cases. IT can be set with SETF."
  `(symbolic etypecase ,keyform ,@cases))

Macroexpansion:
(symbolic etypecase (car x) (symbol (setf it :no)) (string (setf it "OK")) (integer (setf it :noon)))
Create a Common Lisp macro for the following transformation. Before code:
(iterate
  nil
  (progn))

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

Macro definition:
(defmacro ITERATE ...)

Macroexpansion:
(iter
  nil
  (progn))
Define a macro that eliminates this repetitive pattern:
(sif 1 (aif it it))

Issue: Macro call that should be transformed by sif

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

Macroexpansion:
(symbolic if 1 (aif it it) nil)
Write a Common Lisp macro to handle this code pattern:
(lambda-match0 ((list* 'guard1 _) t))

Problem: Macro call that should be transformed by lambda-match0

Macro definition:
(defmacro lambda-match0 (&body clauses)
  (alexandria:with-gensyms (arg)
    `(lambda (,arg)
       (match0 ,arg
         ,@clauses))))

Macroexpansion:
(lambda (#:arg164) (match0 #:arg164 ((list* (quote guard1) _) t)))
Write a Common Lisp macro to handle this code pattern:
(with-transaction *db* (commit *db*) (setf value :foo))

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

Macro definition:
(defmacro with-transaction (conn &body body)
  "Start a transaction and commit at the end of this block. If the evaluation `body` is interrupted, the transaction is rolled back automatically."
  (let ((conn-var (gensym "CONN-VAR")))
    `(let ((,conn-var ,conn))
       (if (in-transaction ,conn-var)
           (with-savepoint ,conn-var ,@body)
           (%with-transaction ,conn-var ,@body)))))

Macroexpansion:
(let ((#:conn-var161 *db*)) (if (in-transaction #:conn-var161) (with-savepoint #:conn-var161 (commit *db*) (setf value :foo)) (%with-transaction #:conn-var161 (commit *db*) (setf value :foo))))
You are a Common Lisp macro expert. Given this code pattern:
(maybe-once-only nil
  :key
  nil)

Write a macro that addresses: Macro call that should be transformed by MAYBE-ONCE-ONLY

Macro definition:
(defmacro MAYBE-ONCE-ONLY ...)

Macroexpansion:
(let* ((#:g184 nil))
  `(let* ,(nreverse #:g184)
     ,:key
     ,nil))
Create a Common Lisp macro for the following transformation. Before code:
(defclause finally (&rest forms) "Evaluates <form> after the last iteration, before returning a value." (mapcar (lambda (form) (make-finalization :form form)) forms))

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 finally (&rest forms) "Evaluates <form> after the last iteration, before returning a value." (mapcar (lambda (form) (make-finalization :form form)) forms)) (pushnew (quote finally) *clauses*))
Write a Common Lisp macro to handle this code pattern:
(sum-of nil
  :key
  nil)

Problem: Macro call that should be transformed by SUM-OF

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

Macroexpansion:
(lc (nil :key nil) sum)
You are a Common Lisp macro expert. Given this code pattern:
(deferror "42701" duplicate-column syntax-error-or-access-violation)

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

Macro definition:
(defmacro deferror (code typename &optional (superclass 'database-error))
  `(progn (define-condition ,typename (,superclass) ())
          (setf (gethash ,code *error-table*) ',typename)))

Macroexpansion:
(progn (define-condition duplicate-column (syntax-error-or-access-violation) nil) (setf (gethash "42701" *error-table*) (quote duplicate-column)))
Create a Common Lisp macro for the following transformation. Before code:
(cond-> nil (progn))

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

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

Macroexpansion:
(let* ((#:|cond132| nil)
       (#:|cond132|
        (if progn
            #:|cond132|
            #:|cond132|)))
  #:|cond132|)
Write a Common Lisp macro to handle this code pattern:
(in-compile-time nil)

Problem: Macro call that should be transformed by IN-COMPILE-TIME

Macro definition:
(defmacro IN-COMPILE-TIME ...)

Macroexpansion:
(macrolet ((#:macro141 (&environment ())
             ))
  (#:macro141))
Write a Common Lisp macro to handle this code pattern:
(when (not (or (eql (top-info) 'typedef) (eql (top-info) 'decl))) (format stream ";"))

Problem: 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 (not (or (eql (top-info) (quote typedef)) (eql (top-info) (quote decl)))) (format stream ";"))
Create a Common Lisp macro for the following transformation. Before code:
(def-neo4j-fun get-node-properties (node-id) :get (:uri-spec (format nil "node/~A/properties" node-id)) (:status-handlers (200 (decode-neo4j-json-output body)) (204 nil) (404 (error 'node-not-found-error :uri uri))))

What needs to change: 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 get-node-properties (&key node-id) (let ((uri (format nil "node/~A/properties" node-id)) (json (encode-neo4j-json-payload nil :string))) (make-neo4j-request :get uri json (list (list 200 (lambda (body uri json) (decode-neo4j-json-output body))) (list 204 (lambda (body uri json) nil)) (list 404 (lambda (body uri json) (error (quote node-not-found-error) :uri uri))))))))
Generate a defmacro form that transforms code like this:
(lambda ())

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

Macro definition:
(defmacro LAMBDA ...)

Macroexpansion:
#'(lambda ())
Create a Common Lisp macro for the following transformation. Before code:
(gen-lambda-with-sticky-stop () (loop for g in generators for v in valfuncs do (let ((data (multiple-value-list (funcall v g)))) (if (car data) (progn (push (car data) sigs) (push (cdr data) stor)) (sticky-stop)))) (when (= 0 (length (remove-if (lambda (x) (eq x :filled)) sigs))) (sticky-stop)) (let ((tmp stor)) (setf stor nil) (setf sigs nil) (apply #'values (nreverse tmp))))

What needs to change: Macro call that should be transformed by gen-lambda-with-sticky-stop

Macro definition:
(defmacro gen-lambda-with-sticky-stop (&rest rest)
  `(make-instance 
    'basic-generator 
    :function (sticky-stop-lambda ,@rest)))

Macroexpansion:
(make-instance (quote basic-generator) :function (sticky-stop-lambda nil (loop for g in generators for v in valfuncs do (let ((data (multiple-value-list (funcall v g)))) (if (car data) (progn (push (car data) sigs) (push (cdr data) stor)) (sticky-stop)))) (when (= 0 (length (remove-if (lambda (x) (eq x :filled)) sigs))) (sticky-stop)) (let ((tmp stor)) (setf stor nil) (setf sigs nil) (apply (function values) (nreverse tmp)))))
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 (slot-value nil ':key) nil)
Define a macro that eliminates this repetitive pattern:
(with-wcs-math-error-handling (ret (ftruncate x)) (check-wcs-math-result))

Issue: Macro call that should be transformed by with-wcs-math-error-handling

Macro definition:
(defmacro with-wcs-math-error-handling
    ((var-or-var-list
      (function x &optional (y nil y-supplied-p))
      &rest keyargs
      &key underflow-value)
     &body body)
  (declare (ignorable underflow-value))
  (let ((x_ (gensym)) (y_ (gensym)) (args_ (gensym))
        (var-list (ensure-list var-or-var-list)))
    `(let* ((,x_ ,x)
            (,y_ ,y)
            (,args_ (list ,x_ ,@(if y-supplied-p `(,y_)))))
       (declare (ignorable ,y_)
                (type list ,args_)
                (dynamic-extent ,args_))
       (catch 'return-from-with-wcs-math-error-handling
         (multiple-value-bind ,var-list
             (call-with-wcs-math-error-handler ',function ,args_
                                               ,@keyargs)
           (flet ((check-wcs-math-result
                      (&optional (ret ,(first var-list))
                                 (arg-list ,args_))
                    (check-wcs-math-result ret arg-list)))
             ,@body))))))

Macroexpansion:
(let* ((#:g251 x) (#:g252 nil) (#:g253 (list #:g251))) (declare (ignorable #:g252) (type list #:g253) (dynamic-extent #:g253)) (catch (quote return-from-with-wcs-math-error-handling) (multiple-value-bind (ret) (call-with-wcs-math-error-handler (quote ftruncate) #:g253) (flet ((check-wcs-math-result (&optional (ret ret) (arg-list #:g253)) (check-wcs-math-result ret arg-list))) (check-wcs-math-result)))))
Define a macro that eliminates this repetitive pattern:
(signal-syntax-error* (car this-last-pos) "Quantifier '~A' not allowed." (subseq (lexer-str lexer) (car this-last-pos) (lexer-pos lexer)))

Issue: Macro call that should be transformed by signal-syntax-error*

Macro definition:
(defmacro signal-syntax-error* (pos format-control &rest format-arguments)
  `(error 'ppcre-syntax-error
          :pos ,pos
          :format-control ,format-control
          :format-arguments (list ,@format-arguments)))

Macroexpansion:
(error (quote ppcre-syntax-error) :pos (car this-last-pos) :format-control "Quantifier '~A' not allowed." :format-arguments (list (subseq (lexer-str lexer) (car this-last-pos) (lexer-pos lexer))))