j14i/cl-macros huggingface dataset:
You are a Common Lisp macro expert. Given this code pattern:
(defun-compile-time indirect-callees-internal (function-names callees) (if (null function-names) callees (let ((function-name (first function-names))) (if (member function-name callees :test #'equal) (indirect-callees-internal (rest function-names) callees) (indirect-callees-internal (rest function-names) (indirect-callees-internal (callees function-name) (cons function-name callees)))))))

Write a macro that addresses: 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-callees-internal (function-names callees) (if (null function-names) callees (let ((function-name (first function-names))) (if (member function-name callees :test (function equal)) (indirect-callees-internal (rest function-names) callees) (indirect-callees-internal (rest function-names) (indirect-callees-internal (callees function-name) (cons function-name callees))))))) (eval-when (:compile-toplevel) (compile (quote indirect-callees-internal))))
You are a Common Lisp macro expert. Given this code pattern:
(define-compile-struct sql-statement)

Write a macro that addresses: Macro call that should be transformed by define-compile-struct

Macro definition:
(defmacro define-compile-struct (structure-name &rest defstruct-options)
  (flet ((symbolcat (&rest symbols)
           (intern (format nil "~{~A~^-~}" symbols) #.*package*)))
    (let ((compiled-name (symbolcat structure-name :compiled)))
      `(progn
         (defstruct (,compiled-name (:include ,structure-name ,@defstruct-options))
           (sql nil :type string)
           (bind nil :type list))

         (defmethod find-compile-function ((object ,structure-name))
           (function ,(symbolcat :make compiled-name)))

         (defmethod print-object ((object ,compiled-name) stream)
           (format stream "#<SXQL-COMPILED: ~A [~{~A~^, ~}]>"
                   (,(symbolcat compiled-name :sql) object)
                   (,(symbolcat compiled-name :bind) object)))

         (defmethod yield ((object ,compiled-name))
           (values
            (,(symbolcat compiled-name :sql) object)
            (,(symbolcat compiled-name :bind) object)))))))

Macroexpansion:
(progn (defstruct (sql-statement-compiled (:include sql-statement)) (sql nil :type string) (bind nil :type list)) (defmethod find-compile-function ((object sql-statement)) (function make-sql-statement-compiled)) (defmethod print-object ((object sql-statement-compiled) stream) (format stream "#<SXQL-COMPILED: ~A [~{~A~^, ~}]>" (sql-statement-compiled-sql object) (sql-statement-compiled-bind object))) (defmethod yield ((object sql-statement-compiled)) (values (sql-statement-compiled-sql object) (sql-statement-compiled-bind object))))
You are a Common Lisp macro expert. Given this code pattern:
(defalias path:-d (directory) cl-fad:directory-exists-p)

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

Macro definition:
(defmacro defalias (name args realname)
  `(progn
     (defun ,name ,args
       ,(if (eql '&rest (first args))
            `(apply #',realname ,(second args))
            `(,realname ,@args)))
     (define-compiler-macro ,name (&rest args)
       (list* ',realname args))))

Macroexpansion:
(progn (defun path:-d (directory) (directory-exists-p directory)) (define-compiler-macro path:-d (&rest args) (list* (quote directory-exists-p) args)))
Define a macro that eliminates this repetitive pattern:
(builder :session (:csrf :form-token "test_input_name") #'(lambda (env) (let ((req (make-request env))) `(200 (:content-type "text/html") (,(if (and (eq :post (request-method req)) (assoc "name" (request-body-parameters req) :test #'string=)) (cdr (assoc "name" (request-body-parameters req) :test #'string=)) (html-form env)))))))

Issue: Macro call that should be transformed by builder

Macro definition:
(defmacro builder (&rest app-or-middlewares)
  (let ((middlewares (butlast app-or-middlewares)))
    `(reduce #'funcall
             (remove-if
              #'null
              (list
               ,@(loop for mw in middlewares
                       when mw
                         collect (convert-to-middleware-form mw))))
             :initial-value (to-app ,(car (last app-or-middlewares)))
             :from-end t)))

Macroexpansion:
(reduce (function funcall) (remove-if (function null) (list (find-middleware :session) (lambda (#:app210) (funcall (find-middleware :csrf) #:app210 :form-token "test_input_name")))) :initial-value (to-app (function (lambda (env) (let ((req (make-request env))) (sb-int:quasiquote (200 (:content-type "text/html") (#S(sb-impl::comma :expr (if (and (eq :post (request-method req)) (assoc "name" (request-body-parameters req) :test (function string=))) (cdr (assoc "name" (request-body-parameters req) :test (function string=))) (html-form env)) :kind 0)))))))) :from-end t)
Create a Common Lisp macro for the following transformation. Before code:
(defstore add (&rest args))

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 (ensure-store (quote add) (quote (&rest args)))))
Define a macro that eliminates this repetitive pattern:
(define-test capture (fail-compile (defun foo () (frob)) style-warning))

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

Macro definition:
(defmacro define-test (name &body arguments-and-body)
  (destructuring-bind (nparent name) (if (listp name) name (list NIL name))
    (form-fiddle:with-body-options (body options parent home (test-class 'test) (compile-at :compile-time) defun) arguments-and-body
      (let ((body (remove 'define-test body :key (lambda (a) (when (listp a) (car a))) :test #'eql))
            (defs (remove 'define-test body :key (lambda (a) (when (listp a) (car a))) :test-not #'eql))
            (home-form (or home `(find-package ,(package-name *package*)))))
        (when (and parent nparent)
          (error "Cannot specify parent through name and through a keyword argument at the same time!"))
        `(let ((*package* (find-package ,(package-name *package*)))) ; Make sure package stays consistent throughout initialisation.
           (setf (find-test ',name ,home-form)
                 (ensure-test ',test-class
                              :name ',name
                              :home ,home-form
                              :tests (list ,@(loop for form in body
                                                   collect (ecase compile-at
                                                             (:compile-time `(lambda () ,form))
                                                             (:execute `(lambda () (call-compile ',form))))))
                              :parent ',(or parent nparent)
                              ,@(loop for option in options
                                      collect `',option)))
           ,@(loop for (def subname . body) in defs
                   collect `(,def (,name ,subname)
                              :home ,home
                              ,@body))
           ,@(when defun
               `((defun ,(if (stringp name) (read-symbol name) name) (&rest test-args)
                   (apply #'test (find-test ',name ,home-form) test-args))))
           ',name)))))

Macroexpansion:
(let ((*package* (find-package #A((9) base-char . "PARACHUTE")))) (setf (find-test (quote capture) (find-package #A((9) base-char . "PARACHUTE"))) (ensure-test (quote test) :name (quote capture) :home (find-package #A((9) base-char . "PARACHUTE")) :tests (list (lambda nil (fail-compile (defun foo nil (frob)) style-warning))) :parent (quote nil))) (quote capture))
Define a macro that eliminates this repetitive pattern:
(defun-compile-time cps-convert-if (antecedent consequent alternate continuation types value? environment) (let ((c (gensym "CONTINUATION-")) (dummy-argument (gensym "DUMMY-")) (other-arguments (gensym "OTHER-"))) (possibly-beta-reduce-funcall `#'(lambda (,c) (declare (magic)) ,(cps-convert antecedent `#'(lambda (&optional ,dummy-argument &rest ,other-arguments) (declare (magic) (ignore ,other-arguments)) (if ,dummy-argument ,(cps-convert consequent c types value? environment) ,(cps-convert alternate c types value? environment))) '() t environment)) '() continuation t)))

Issue: 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 cps-convert-if (antecedent consequent alternate continuation types value? environment) (let ((c (gensym "CONTINUATION-")) (dummy-argument (gensym "DUMMY-")) (other-arguments (gensym "OTHER-"))) (possibly-beta-reduce-funcall (sb-int:quasiquote (function (lambda (#S(sb-impl::comma :expr c :kind 0)) (declare (magic)) #S(sb-impl::comma :expr (cps-convert antecedent (sb-int:quasiquote (function (lambda (&optional #S(sb-impl::comma :expr dummy-argument :kind 0) &rest #S(sb-impl::comma :expr other-arguments :kind 0)) (declare (magic) (ignore #S(sb-impl::comma :expr other-arguments :kind 0))) (if #S(sb-impl::comma :expr dummy-argument :kind 0) #S(sb-impl::comma :expr (cps-convert consequent c types value? environment) :kind 0) #S(sb-impl::comma :expr (cps-convert alternate c types value? environment) :kind 0))))) (quote nil) t environment) :kind 0)))) (quote nil) continuation t))) (eval-when (:compile-toplevel) (compile (quote cps-convert-if))))
Create a Common Lisp macro for the following transformation. Before code:
(defclause collecting-into (vars &rest args &key initially by finally) "Synonym for accumulating-to." (declare (ignore initially by finally)) `(accumulating-to ,vars ,@args))

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 collecting-into (vars &rest args &key initially by finally) "Synonym for accumulating-to." (declare (ignore initially by finally)) (sb-int:quasiquote (accumulating-to #S(sb-impl::comma :expr vars :kind 0) #S(sb-impl::comma :expr args :kind 2)))) (pushnew (quote collecting-into) *clauses*))
Generate a defmacro form that transforms code like this:
(define-language-macro nil)

Pattern to recognize: Macro call that should be transformed by DEFINE-LANGUAGE-MACRO

Macro definition:
(defmacro DEFINE-LANGUAGE-MACRO ...)

Macroexpansion:
(defmacro nil (&whole whole &body body)
  (declare (ignore body))
  `(macrolet ((,(car whole) (&body body)
                (let* ((lang (make-instance ',(car whole)))
                       (env (top-level-environment lang)))
                  (codegen-text (sexp->ops lang body env) ,*pretty*))))
     ,@(if *pretty*
           `((let ((*text-pretty-printer* (get-pretty-printer)))
               ,whole))
           `(,whole))))
You are a Common Lisp macro expert. Given this code pattern:
(builder (:static :path nil :root (asdf:system-relative-pathname :lack #P"data/")) (lambda (env) (declare (ignore env)) `(200 (:content-type "text/plain") ("ok"))))

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

Macro definition:
(defmacro builder (&rest app-or-middlewares)
  (let ((middlewares (butlast app-or-middlewares)))
    `(reduce #'funcall
             (remove-if
              #'null
              (list
               ,@(loop for mw in middlewares
                       when mw
                         collect (convert-to-middleware-form mw))))
             :initial-value (to-app ,(car (last app-or-middlewares)))
             :from-end t)))

Macroexpansion:
(reduce (function funcall) (remove-if (function null) (list (lambda (#:app228) (funcall (find-middleware :static) #:app228 :path nil :root (asdf/system:system-relative-pathname :lack #P"data/"))))) :initial-value (to-app (lambda (env) (declare (ignore env)) (sb-int:quasiquote (200 (:content-type "text/plain") ("ok"))))) :from-end t)
Generate a defmacro form that transforms code like this:
(and nil :key nil)

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

Macro definition:
(defmacro AND ...)

Macroexpansion:
(if (if nil
        :key)
    nil)
Create a Common Lisp macro for the following transformation. Before code:
(fnn nil (progn))

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

Macro definition:
(defmacro FNN ...)

Macroexpansion:
(lambda () (progn))
Write a Common Lisp macro to handle this code pattern:
(->* 'some-name)

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

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

Macroexpansion:
(-> 'some-name)
Define a macro that eliminates this repetitive pattern:
(with nil)

Issue: Macro call that should be transformed by WITH

Macro definition:
(defmacro WITH ...)

Macroexpansion:
nil
You are a Common Lisp macro expert. Given this code pattern:
(with-decoder-simple-list-semantics (let ((*json-symbols-package* (find-package :keyword))) (is (equalp '((:hello-key . "hej") (:*hi-starts-with-upper-case . "tjena") (:+json+-all-capitals . "totae majusculae") (:+two-words+ . "duo verba") (:camel-case--*mixed--+4-parts+ . "partes miscella quatuor")) (decode-json-from-string " { \"helloKey\" : \"hej\" , \"HiStartsWithUpperCase\" : \"tjena\", \"JSONAllCapitals\": \"totae majusculae\", \"TWO_WORDS\": \"duo verba\", \"camelCase_Mixed_4_PARTS\": \"partes miscella quatuor\" }")))))

Write a macro that addresses: Macro call that should be transformed by with-decoder-simple-list-semantics

Macro definition:
(defmacro with-decoder-simple-list-semantics (&body body)
  "Execute BODY in a dynamic environement where the decoder semantics
is such as set by SET-DECODER-SIMPLE-LIST-SEMANTICS."
  `(with-shadowed-custom-vars
     (set-decoder-simple-list-semantics)
     ,@body))

Macroexpansion:
(with-shadowed-custom-vars (set-decoder-simple-list-semantics) (let ((*json-symbols-package* (find-package :keyword))) (is (equalp (quote ((:hello-key . "hej") (:*hi-starts-with-upper-case . "tjena") (:+json+-all-capitals . "totae majusculae") (:+two-words+ . "duo verba") (:camel-case--*mixed--+4-parts+ . "partes miscella quatuor"))) (decode-json-from-string " { \"helloKey\" : \"hej\" , \"HiStartsWithUpperCase\" : \"tjena\", \"JSONAllCapitals\": \"totae majusculae\", \"TWO_WORDS\": \"duo verba\", \"camelCase_Mixed_4_PARTS\": \"partes miscella quatuor\" }")))))
Generate a defmacro form that transforms code like this:
(define-alist-cache content-encoding-cache)

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

Macro definition:
(defmacro define-alist-cache (cache-name)
  (let ((var (intern (format nil "*~A*" cache-name))))
  `(progn
     (defvar ,var)
     (defun ,(intern (format nil "LOOKUP-IN-~A" cache-name)) (elt)
       (when (boundp ',var)
         (alexandria:assoc-value ,var elt)))
     (defun (setf ,(intern (format nil "LOOKUP-IN-~A" cache-name))) (val elt)
       (when (boundp ',var)
         (setf (alexandria:assoc-value ,var elt) val))
       val))))

Macroexpansion:
(progn (defvar *content-encoding-cache*) (defun lookup-in-content-encoding-cache (elt) (when (boundp (quote *content-encoding-cache*)) (assoc-value *content-encoding-cache* elt))) (defun (setf lookup-in-content-encoding-cache) (val elt) (when (boundp (quote *content-encoding-cache*)) (setf (assoc-value *content-encoding-cache* elt) val)) val))
Generate a defmacro form that transforms code like this:
(with-unique-names (value) (values `((,name (,value) (when ,value (incf ,var)))) `((inline ,name))))

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

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

Macroexpansion:
(let ((value (gensym #A((5) base-char . "VALUE")))) (values (quasiquote ((#S(sb-impl::comma :expr name :kind 0) (#S(sb-impl::comma :expr value :kind 0)) (when #S(sb-impl::comma :expr value :kind 0) (incf #S(sb-impl::comma :expr var :kind 0)))))) (quasiquote ((inline #S(sb-impl::comma :expr name :kind 0))))))
You are a Common Lisp macro expert. Given this code pattern:
(js-inline)

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

Macro definition:
(defmacro JS-INLINE ...)

Macroexpansion:
(js-inline* '(progn))
Define a macro that eliminates this repetitive pattern:
(->>)

Issue: Macro call that should be transformed by ->>

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

Macroexpansion:
nil
Write a Common Lisp macro to handle this code pattern:
(in-package nil)

Problem: Macro call that should be transformed by IN-PACKAGE

Macro definition:
(defmacro IN-PACKAGE ...)

Macroexpansion:
(common-lisp:in-package #A((3) base-char . "NIL"))
Generate a defmacro form that transforms code like this:
(signals circular-dependency (run 'circular-0))

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

Macro definition:
(defmacro signals (condition-spec
                   &body body)
  "Generates a pass if BODY signals a condition of type
CONDITION. BODY is evaluated in a block named NIL, CONDITION is
not evaluated."
  (let ((block-name (gensym)))
    (destructuring-bind (condition &optional reason-control &rest reason-args)
        (ensure-list condition-spec)
      `(block ,block-name
         (handler-bind ((,condition (lambda (c)
                                      (declare (ignore c))
                                      ;; ok, body threw condition
                                      (add-result 'test-passed
                                                  :test-expr ',condition)
                                      (return-from ,block-name t))))
           (block nil
             ,@body))
         (process-failure
           ',condition
           ,@(if reason-control
                 `(,reason-control ,@reason-args)
                 `("Failed to signal a ~S" ',condition)))
         (return-from ,block-name nil)))))

Macroexpansion:
(block #:g287 (handler-bind ((circular-dependency (lambda (c) (declare (ignore c)) (add-result (quote test-passed) :test-expr (quote circular-dependency)) (return-from #:g287 t)))) (block nil (run (quote circular-0)))) (process-failure (quote circular-dependency) "Failed to signal a ~S" (quote circular-dependency)) (return-from #:g287 nil))
Generate a defmacro form that transforms code like this:
(define-modf-rewrite cddddr (expr) `(cdr (cdddr ,(second expr))))

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

Macro definition:
(defmacro define-modf-rewrite (name (expr) &body body)
  "Define a new rewrite rule.  If a form starting with NAME is encountered, call
the defined function to return a form that we can deal with (i.e. one defined
via DEFINE-MODF-EXPANDER, DEFINE-MODF-FUNCTION, and DEFINE-MODF-METHOD)."
  `(eval-when (:compile-toplevel :load-toplevel :execute)
     (setf (gethash ',name *modf-rewrites*)
           (lambda (,expr)
             ,@body))))

Macroexpansion:
(eval-when (:compile-toplevel :load-toplevel :execute) (setf (gethash (quote cddddr) *modf-rewrites*) (lambda (expr) (sb-int:quasiquote (cdr (cdddr #S(sb-impl::comma :expr (second expr) :kind 0)))))))
Define a macro that eliminates this repetitive pattern:
($map-reduce "foo" m r :out "testit" :query ($> "l" -900) :limit 2)

Issue: Macro call that should be transformed by $map-reduce

Macro definition:
(defmacro $map-reduce (collection map reduce &key (query nil) (limit 0) (out nil) 
		       (keeptemp nil) (finalize nil) (verbose t))
  "Run map reduce on the mongo server. map and reduce are either the names of the 
javascript functions, created with defjs or defsrvjs or are function definitions in javascript.
The keywords refer to option available for map reduce in mongo. This returns a result summary document.
When using :keeptemp t without specificing :out the collection is mr.<collection> "
    `(db.find "$cmd" (kv (kv "mapreduce" ,collection) 
			 (kv "map"    (or (jsdef ,map) ',map))
			 (kv "reduce" (or (jsdef ,reduce) ',reduce))
			 (when ,finalize (kv "finalize" (jsdef ,finalize)))
			 (kv "out"      (if ,out ,out (concatenate 'string "mr." ,collection))) 
			 (kv "verbose"  ,verbose)
			 (kv "limit"    ,limit)
			 (kv "keeptemp" ,keeptemp)
			 (kv "query"    ,query))))

Macroexpansion:
(db.find "$cmd" (kv (kv "mapreduce" "foo") (kv "map" (or (jsdef m) (quote m))) (kv "reduce" (or (jsdef r) (quote r))) (when nil (kv "finalize" (jsdef nil))) (kv "out" (if "testit" "testit" (concatenate (quote string) "mr." "foo"))) (kv "verbose" t) (kv "limit" 2) (kv "keeptemp" nil) (kv "query" ($> "l" -900))))
Define a macro that eliminates this repetitive pattern:
(ct-let* nil)

Issue: Macro call that should be transformed by CT-LET*

Macro definition:
(defmacro CT-LET* ...)

Macroexpansion:
(cond (*within-captured-dynenv* (progn))
      (t
       (error
        "No macrodynamic environment has been captured to establish CT-LET* bindings.")))
Write a Common Lisp macro to handle this code pattern:
(defmacro* nil
    nil)

Problem: Macro call that should be transformed by DEFMACRO*

Macro definition:
(defmacro DEFMACRO* ...)

Macroexpansion:
(defmacro nil () `(with-yield))
You are a Common Lisp macro expert. Given this code pattern:
(defvar-unbound *saw-backslash* "Whether we have to re-process an \L or \U because it closes several scopes.")

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 *saw-backslash*) (setf (documentation (quote *saw-backslash*) (quote variable)) "Whether we have to re-process an L or U because it closes several scopes."))