j14i/cl-macros huggingface dataset:
Create a Common Lisp macro for the following transformation. Before code:
(with-temp (input-file :tmpdir d :template "XXXXXX.prolog" :debug (<= 1 *debug-prolog*)) (with-open-file (s input-file :direction :output :if-does-not-exist :error) (dolist (r rules) (print-rule s r))) (run-command-with-debug-print `("swipl" "--quiet" "-l" ,input-file ,@args) :input input :output output :error error))

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

Macro definition:
(defmacro with-temp ((var &key directory template (tmpdir "/tmp/") debug) &body body)
  "Create a temporary file, then remove the file by unwind-protect.
Most arguments are analogous to mktemp.
When DIRECTORY is non-nil, creates a directory instead.
DEBUG is a form.
When evaluated to non-nil, it does not remove the directory so that you can investigate what happened inside the directory.
It may be evaluated multiple times."
  (with-gensyms (command)
    `(let ((,var (uiop:run-program
                  (let ((,command (format nil "mktemp --tmpdir='~a' ~@[-d~*~] ~@[~a~]"
                                          ,tmpdir ,directory ,template)))
                    (when ,debug
                      (format *error-output* "~&; ~a~%" ,command))
                    ,command)
                  :output '(:string :stripped t))))
       (unwind-protect
            (progn ,@body)
         (if ,debug
             (format *error-output* "~&; not removing ~a for debugging~%" ,var)
             (uiop:run-program (format nil "rm -rf ~a" (namestring ,var)) :ignore-error-status t))))))

Macroexpansion:
(let ((input-file (uiop/run-program:run-program (let ((#:command176 (format nil "mktemp --tmpdir='~a' ~@[-d~*~] ~@[~a~]" d nil "XXXXXX.prolog"))) (when (<= 1 *debug-prolog*) (format *error-output* "~&; ~a~%" #:command176)) #:command176) :output (quote (:string :stripped t))))) (unwind-protect (progn (with-open-file (s input-file :direction :output :if-does-not-exist :error) (dolist (r rules) (print-rule s r))) (run-command-with-debug-print (sb-int:quasiquote ("swipl" "--quiet" "-l" #S(sb-impl::comma :expr input-file :kind 0) #S(sb-impl::comma :expr args :kind 2))) :input input :output output :error error)) (if (<= 1 *debug-prolog*) (format *error-output* "~&; not removing ~a for debugging~%" input-file) (uiop/run-program:run-program (format nil "rm -rf ~a" (namestring input-file)) :ignore-error-status t))))
Define a macro that eliminates this repetitive pattern:
(define-test timeout :time-limit 0.5 (sleep 0.75))

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 timeout) (find-package #A((9) base-char . "PARACHUTE"))) (ensure-test (quote test) :name (quote timeout) :home (find-package #A((9) base-char . "PARACHUTE")) :tests (list (lambda nil (sleep 0.75))) :parent (quote nil) (quote :time-limit) (quote 0.5))) (quote timeout))
Write a Common Lisp macro to handle this code pattern:
(enable-reader-syntax nil)

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

Macro definition:
(defmacro ENABLE-READER-SYNTAX ...)

Macroexpansion:
(eval-when (:compile-toplevel :load-toplevel :execute)
  (push *readtable* *previous-readtables*)
  (setq *readtable* (copy-readtable))
  (%enable-reader-syntax *readtable* nil))
Generate a defmacro form that transforms code like this:
(when (node-slot type) (del-proxy type))

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

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

Macroexpansion:
(if (node-slot type) (del-proxy type))
Create a Common Lisp macro for the following transformation. Before code:
(do+ (for x (across #(3 2 1) :start 2 :end 0)) (collect x))

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

Macro definition:
(defmacro do+ (&body body)
  "High-level, extensible iteration construct. Refer to the manual for syntax and semantics."
  `(do+/internal nil ,@body))

Macroexpansion:
(do+/internal nil (for x (across #(3 2 1) :start 2 :end 0)) (collect x))
Write a Common Lisp macro to handle this code pattern:
(defhandler load-time-value (load-time-value form &optional (read-only-p nil rop-p)) `(list ',load-time-value ,(e form) ,@(when rop-p `(',read-only-p))))

Problem: Macro call that should be transformed by defhandler

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

Macroexpansion:
(progn (defun hander-load-time-value (load-time-value form &optional (read-only-p nil rop-p)) (sb-int:quasiquote (list (quote #S(sb-impl::comma :expr load-time-value :kind 0)) #S(sb-impl::comma :expr (e form) :kind 0) #S(sb-impl::comma :expr (when rop-p (sb-int:quasiquote ((quote #S(sb-impl::comma :expr read-only-p :kind 0))))) :kind 2)))) (setf (gethash (quote load-time-value) *form-handler*) (quote hander-load-time-value)))
You are a Common Lisp macro expert. Given this code pattern:
(when (or body initializer) `(make-block ,body))

Write a macro that addresses: 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 (or body initializer) (sb-int:quasiquote (make-block #S(sb-impl::comma :expr body :kind 0))))
You are a Common Lisp macro expert. Given this code pattern:
(deferror "42P07" duplicate-table 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-table (syntax-error-or-access-violation) nil) (setf (gethash "42P07" *error-table*) (quote duplicate-table)))
Generate a defmacro form that transforms code like this:
(auto-permute-typecase 'some-name)

Pattern to recognize: Macro call that should be transformed by AUTO-PERMUTE-TYPECASE

Macro definition:
(defmacro AUTO-PERMUTE-TYPECASE ...)

Macroexpansion:
(typecase 'some-name)
Define a macro that eliminates this repetitive pattern:
(dynamic-relet nil
  :key
  nil)

Issue: Macro call that should be transformed by DYNAMIC-RELET

Macro definition:
(defmacro DYNAMIC-RELET ...)

Macroexpansion:
(dynamic-wind
  :proceed
  #:proceed191
  (let ()
    (declare (special))
    (#:proceed191 :key nil)))
Define a macro that eliminates this repetitive pattern:
(rem-bops)

Issue: Macro call that should be transformed by REM-BOPS

Macro definition:
(defmacro REM-BOPS ...)

Macroexpansion:
(eval-when (:load-toplevel :compile-toplevel :execute)
  (progn (save-binfix) (mapc 'rmbop 'nil) (assign-properties)))
Generate a defmacro form that transforms code like this:
(mvlet* 'some-name)

Pattern to recognize: Macro call that should be transformed by MVLET*

Macro definition:
(defmacro MVLET* ...)

Macroexpansion:
(progn (let* ((quote) (some-name))))
Generate a defmacro form that transforms code like this:
(define-bug user-func-invalid-x () (kind name args) "Invalid types found in internal user-function construction. Our apologies for this mistake. If you have the time please raise an issue at https://github.com/cbaggers/varjo/issues including the code that triggered this issue. Problematic Definition: NAME: ~s ~a: ~s" name kind args)

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

Macro definition:
(defmacro define-bug (name (&key (error-type 'varjo-error) (prefix "Varjo Bug"))
                            (&rest args) error-string &body body)
  `(defcondition ,name (:error-type ,error-type :prefix ,prefix) ,args
       ,error-string ,@body))

Macroexpansion:
(defcondition user-func-invalid-x (:error-type varjo-error :prefix "Varjo Bug") (kind name args) "Invalid types found in internal user-function construction. Our apologies for this mistake. If you have the time please raise an issue at https://github.com/cbaggers/varjo/issues including the code that triggered this issue. Problematic Definition: NAME: ~s ~a: ~s" name kind args)
Create a Common Lisp macro for the following transformation. Before code:
(define-op (:not unary-op))

What needs to change: 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 (not-op (:include unary-op (name "NOT")) (:constructor make-not-op (var))))
You are a Common Lisp macro expert. Given this code pattern:
(collect-or nil)

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

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

Macroexpansion:
(common-lisp:let* ((#:generator-326 (generator nil))
                   #:bools-322
                   (#:bool-323 nil))
  (declare (type generator #:generator-326))
  (tagbody
   #:ll-327
    (setq #:bools-322 (next-in #:generator-326 (go end)))
    (if (setq #:bool-323 #:bools-322)
        (go end))
    (go #:ll-327)
   end)
  #:bool-323)
You are a Common Lisp macro expert. Given this code pattern:
(action (:after node-field) #'handle-static-superclass)

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-field) (function handle-static-superclass))
Create a Common Lisp macro for the following transformation. Before code:
(inext-noexit 'some-name)

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

Macro definition:
(defmacro INEXT-NOEXIT ...)

Macroexpansion:
(let ((vals (multiple-value-list (funcall (i-coro 'some-name) nil))))
  (if (not vals)
      (values nil nil)
      (values (car vals) t)))
Generate a defmacro form that transforms code like this:
(bind (((:flet doit (x)) "whatever" (declare (type fixnum x)) (setf x (* 2 x)) (setf x (+ x 3)) x)) (ensure-same (doit 1) 5) (ensure-same (doit 2) 7))

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

Macro definition:
(defmacro bind ((&rest bindings) &body body)
  "Bind is a replacement for let*, destructuring-bind, multiple-value-bind and more. 

An example is probably the best way to describe its syntax:

    \(bind \(\(a 2\)
           \(\(b &rest args &key \(c 2\) &allow-other-keys\) '\(:a :c 5 :d 10 :e 54\)\)
           \(\(:values d e\) \(truncate 4.5\)\)
           \(\(:structure xxx- slot1 slot2\) \(make-xxx\)\)
           \(\(:flet name \(arg1 arg2\)\) \(+ arg1 arg2\)\)\)
         \(list a b c d e args\)\)

Simple bindings are as in let*. Destructuring is done if the first item
in a binding is a list. Multiple value binding is done if the first item
in a binding is a list and the first item in the list is ':values'. Other
forms have their own syntax. For example, :structure first has the conc
name and then slot names whereas :flet has the function name and a list
of arguments and then the function body (in an implicit progn)."
  (let (declarations)
    (loop while (and (consp (car body)) (eq (caar body) 'declare)) do
          (push (first body) declarations)
          (setf body (rest body)))
    (if bindings
	(let ((*all-declarations* (bind-expand-declarations (nreverse declarations))))
	  (prog1
	      (bind-macro-helper bindings body)
	    (check-for-unused-variable-declarations *all-declarations*)))
        `(locally
             ,@declarations
           ,@body))))

Macroexpansion:
(flet ((doit (x) "whatever" (declare (type fixnum x)) (progn (setf x (* 2 x)) (setf x (+ x 3)) x))) (progn (ensure-same (doit 1) 5) (ensure-same (doit 2) 7)))
Generate a defmacro form that transforms code like this:
(without-dependency-capture
  nil
  (progn))

Pattern to recognize: Macro call that should be transformed by WITHOUT-DEPENDENCY-CAPTURE

Macro definition:
(defmacro WITHOUT-DEPENDENCY-CAPTURE ...)

Macroexpansion:
(let ((%dependent% nil))
  nil
  (progn))
You are a Common Lisp macro expert. Given this code pattern:
(define-condition missing-partial (serious-condition) ())

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

Macro definition:
(defmacro define (name template)
  "Define a named renderer of string TEMPLATE."
  `(setf (symbol-function ',name)
         (compile-template ,template)))

Macroexpansion:
(progn (sb-kernel::%define-condition (quote missing-partial) (quote (serious-condition)) (sb-kernel::find-condition-layout (quote missing-partial) (quote (serious-condition))) (list) (list) (quote nil) (quote nil) (sb-c:source-location)) (sb-kernel::%set-condition-report (quote missing-partial) nil) (quote missing-partial))
Define a macro that eliminates this repetitive pattern:
(do+ (terminate outer-loop 3))

Issue: Macro call that should be transformed by do+

Macro definition:
(defmacro do+ (&body body)
  "High-level, extensible iteration construct. Refer to the manual for syntax and semantics."
  `(do+/internal nil ,@body))

Macroexpansion:
(do+/internal nil (terminate outer-loop 3))
Generate a defmacro form that transforms code like this:
(->>
  nil
  :key
  nil)

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

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

Macroexpansion:
(let* ((#:var187 nil) (#:var188 (:key #:var187)) (#:var189 (nil #:var188)))
  #:var189)
Write a Common Lisp macro to handle this code pattern:
(receive (new-k new-v) (funcall fn k v) (dict* new new-k new-v))

Problem: Macro call that should be transformed by receive

Macro definition:
(defmacro receive (formals expr &body body)
  "Stricter version of `multiple-value-bind'.

Use `receive' when you want to enforce that EXPR should return a
certain number of values, or a minimum number of values.

If FORMALS is a proper list, then EXPR must return exactly as many
values -- no more and no less -- as there are variables in FORMALS.

If FORMALS is an improper list (VARS . REST), then EXPR must return at
least as many values as there are VARS, and any further values are
bound, as a list, to REST.

Lastly, if FORMALS is a symbol, bind that symbol to all the values
returned by EXPR, as if by `multiple-value-list'.

From Scheme (SRFI-8)."
  ;; It's probably not worth stack-allocating the thunk.
  (cond ((null formals)
         `(multiple-value-call
              (lambda ()
                ,@body)
            ,expr))
        ((atom formals)
         ;; This could also be written:
         #+(or) `(let ((,formals (multiple-value-list ,expr)))
                   ,@body)
         ;; But I want it to be possible to declare FORMALS to have
         ;; dynamic extent, and most Lisps support that for &rest
         ;; lists.
         `(multiple-value-call
              (lambda (&rest ,formals)
                ,@body)
            ,expr))
        ((proper-list-p formals)
         (when (intersection formals lambda-list-keywords)
           (error "Lambda list keywords in formals: ~a" formals))
         `(multiple-value-call
              (lambda ,formals
                ,@body)
            ,expr))
        (t (let* ((last (last formals))
                  (vars (append (butlast formals)
                                (list (car last))))
                  (rest (cdr last)))
             (when (intersection (cons rest vars) lambda-list-keywords)
               (error "Lambda list keywords in formals: ~a" formals))
             `(multiple-value-call
                  (lambda (,@vars &rest ,rest)
                    ,@body)
                ,expr)))))

Macroexpansion:
(multiple-value-call (lambda (new-k new-v) (dict* new new-k new-v)) (funcall fn k v))
Define a macro that eliminates this repetitive pattern:
(gatherlet nil
  (progn))

Issue: Macro call that should be transformed by GATHERLET

Macro definition:
(defmacro GATHERLET ...)

Macroexpansion:
(common-lisp:let ()
  (progn))
Write a Common Lisp macro to handle this code pattern:
(with-cache ("foo" :store storage) 1)

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

Macro definition:
(defmacro with-cache ((key &key store expire) &body body)
  "If a cache indicated by KEY exists, this just returns the cache
value without evaluating BODY. Otherwise, this evaluates BODY and
stores the evaluated value into STORE with KEY and EXPIRE. KEY is a
form that an evaluated value indicates the cache key.

Example:

    (defun f (x)
      (with-cache (x *store*)
        (very-complex-computation x)))"
  (once-only (key store expire)
    (with-gensyms (value exists-p)
      `(multiple-value-bind (,value ,exists-p)
           (getcache ,key ,store)
         (if ,exists-p
             ,value
             (let ((,value (progn ,@body)))
               (setcache ,key ,value ,store :expire ,expire)
               ,value))))))

Macroexpansion:
(let ((#:key232 "foo") (#:store233 storage) (#:expire234 nil)) (multiple-value-bind (#:value235 #:exists-p236) (getcache #:key232 #:store233) (if #:exists-p236 #:value235 (let ((#:value235 (progn 1))) (setcache #:key232 #:value235 #:store233 :expire #:expire234) #:value235))))
Write a Common Lisp macro to handle this code pattern:
(deferror "58" system-error)

Problem: 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 system-error (database-error) nil) (setf (gethash "58" *error-table*) (quote system-error)))
Generate a defmacro form that transforms code like this:
(some-<>>
  'some-name)

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

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

Macroexpansion:
'some-name
Write a Common Lisp macro to handle this code pattern:
(f_%
  nil)

Problem: Macro call that should be transformed by F_%

Macro definition:
(defmacro F_% ...)

Macroexpansion:
(lambda (&rest #:|ignore126|) (declare (ignore #:|ignore126|)) nil)
Generate a defmacro form that transforms code like this:
(finish T)

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

Macro definition:
(defmacro finish (form &optional description &rest format-args)
  `(eval-in-context
    *context*
    (make-instance 'finishing-result
                   :expression '(finish ,form)
                   :body (lambda () ,form)
                   ,@(when description
                       `(:description (format NIL ,description ,@format-args))))))

Macroexpansion:
(eval-in-context *context* (make-instance (quote finishing-result) :expression (quote (finish t)) :body (lambda nil t)))
Write a Common Lisp macro to handle this code pattern:
(aprog1 :yes (unless (eql it :yes) (error "Broken.")) :no)

Problem: Macro call that should be transformed by aprog1

Macro definition:
(defmacro aprog1 (first &body rest)
  "Binds IT to the first form so that it can be used in the rest of the
forms. The whole thing returns IT."
  `(anaphoric prog1 ,first ,@rest))

Macroexpansion:
(anaphoric prog1 :yes (unless (eql it :yes) (error "Broken.")) :no)