j14i/cl-macros huggingface dataset:
Write a Common Lisp macro to handle this code pattern:
(if-let (x (opaque nil)) :bad (and (not x) :ok))

Problem: Macro call that should be transformed by if-let

Macro definition:
(defmacro if-let (bindings &body (then-form &optional else-form))
    "Creates new variable bindings, and conditionally executes either
THEN-FORM or ELSE-FORM. ELSE-FORM defaults to NIL.

BINDINGS must be either single binding of the form:

 (variable initial-form)

or a list of bindings of the form:

 ((variable-1 initial-form-1)
  (variable-2 initial-form-2)
  ...
  (variable-n initial-form-n))

All initial-forms are executed sequentially in the specified order. Then all
the variables are bound to the corresponding values.

If all variables were bound to true values, the THEN-FORM is executed with the
bindings in effect, otherwise the ELSE-FORM is executed with the bindings in
effect."
    (let* ((binding-list (if (and (consp bindings) (symbolp (car bindings)))
                             (list bindings)
                             bindings))
         (variables (mapcar #'car binding-list)))
    `(let ,binding-list
       (if (and ,@variables)
           ,then-form
           ,else-form))))

Macroexpansion:
(let ((x (opaque nil))) (if (and x) :bad (and (not x) :ok)))
Create a Common Lisp macro for the following transformation. Before code:
(ƒ nil)

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

Macro definition:
(defmacro Ƒ ...)

Macroexpansion:
(defun nil (&optional α)
  (let ((α (or α t)))
    (cond)))
Write a Common Lisp macro to handle this code pattern:
(collect-fn nil :key nil)

Problem: Macro call that should be transformed by COLLECT-FN

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

Macroexpansion:
(common-lisp:let* ((#:c-176 (common-lisp:funcall :key)))
  (tagbody
   #:ll-181
    (setq #:c-176 (common-lisp:funcall nil #:c-176))
    (go #:ll-181))
  #:c-176)
Create a Common Lisp macro for the following transformation. Before code:
(with-reader-case 'some-name)

What needs to change: Macro call that should be transformed by WITH-READER-CASE

Macro definition:
(defmacro WITH-READER-CASE ...)

Macroexpansion:
(let ()
  (let ((#:previous-case182 (readtable-case *readtable*)))
    (setf (readtable-case *readtable*) 'some-name)
    (unwind-protect (progn)
      (setf (readtable-case *readtable*) #:previous-case182))))
Generate a defmacro form that transforms code like this:
(c-assert self)

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

Macro definition:
(defmacro c-assert (assertion &optional places fmt$ &rest fmt-args)
  (declare (ignorable assertion places fmt$ fmt-args))
   #+(or)`(progn) 
  `(unless *stop*
     (unless ,assertion
       ,(if fmt$
            `(c-break ,fmt$ ,@fmt-args)
          `(c-break "failed assertion: ~a" ',assertion)))))

Macroexpansion:
(unless *stop* (unless self (c-break "failed assertion: ~a" (quote self))))
You are a Common Lisp macro expert. Given this code pattern:
(deftag h* (body attrs &key) `(dynamic-tag :name (heading-depth-heading) ,@attrs ,@body))

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

Macro definition:
(defmacro deftag (name (body attrs-var &rest ll) &body tag)
  "Define NAME as a tag.
If NAME is not a keyword, it will also be defined as a macro with an
implicit `with-html'."
  (let ((definer
          (if (keywordp name)
              'deftag/keyword
              'deftag/macro)))
    `(,definer ,name (,body ,attrs-var ,@ll) ,@tag)))

Macroexpansion:
(deftag/macro h* (body attrs &key) (sb-int:quasiquote (dynamic-tag :name (heading-depth-heading) #S(sb-impl::comma :expr attrs :kind 2) #S(sb-impl::comma :expr body :kind 2))))
Define a macro that eliminates this repetitive pattern:
(bind (((:flet constant (x)) (declare (ignore x)) 42)) (ensure-same (constant 1) 42))

Issue: 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 ((constant (x) (declare (ignore x)) (progn 42))) (progn (ensure-same (constant 1) 42)))
Create a Common Lisp macro for the following transformation. Before code:
(with-yield-binds (format nil "~A ~{~A~^, ~}" (sql-clause-name clause) (mapcar #'yield (expression-list-clause-expressions clause))))

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

Macro definition:
(defmacro with-yield-binds (&body body)
  `(let ((*bind-values* nil)
         (*use-global-bind-values* t))
     (values
      (progn ,@body)
      (loop for bind in (reverse *bind-values*)
            append bind))))

Macroexpansion:
(let ((*bind-values* nil) (*use-global-bind-values* t)) (values (progn (format nil "~A ~{~A~^, ~}" (sql-clause-name clause) (mapcar (function yield) (expression-list-clause-expressions clause)))) (loop for bind in (reverse *bind-values*) append bind)))
Define a macro that eliminates this repetitive pattern:
(with-decoder-simple-list-semantics (setf x (decode-json-from-string "{\"x\":1}")) (is (equal (symbol-package (caar x)) (find-package :json-test))))

Issue: 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) (setf x (decode-json-from-string "{\"x\":1}")) (is (equal (symbol-package (caar x)) (find-package :json-test))))
Write a Common Lisp macro to handle this code pattern:
(with-flow-let-macro (flow-list flow) (flow-lambda-macro (flow-context) `(dispatch-concurrently ,flow-context ,flow-list)))

Problem: Macro call that should be transformed by with-flow-let-macro

Macro definition:
(defmacro with-flow-let-macro ((var flow) &body body)
  `(with-gensyms (,var)
     `(let ((,,var (list ,@,flow)))
        ,,@body)))

Macroexpansion:
(with-gensyms (flow-list) (sb-int:quasiquote (let ((#S(sb-impl::comma :expr flow-list :kind 0) (list #S(sb-impl::comma :expr flow :kind 2)))) #S(sb-impl::comma :expr (flow-lambda-macro (flow-context) (sb-int:quasiquote (dispatch-concurrently #S(sb-impl::comma :expr flow-context :kind 0) #S(sb-impl::comma :expr flow-list :kind 0)))) :kind 0))))
You are a Common Lisp macro expert. Given this code pattern:
(collect-min nil (progn))

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

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

Macroexpansion:
(common-lisp:let* ((#:generator-299 (generator (progn)))
                   #:items-289
                   (#:generator-297 (generator nil))
                   #:numbers-288
                   (#:number-291 nil)
                   #:result-292)
  (declare (type generator #:generator-299)
           (type generator #:generator-297)
           (type (null-or t) #:result-292))
  (tagbody
   #:ll-300
    (setq #:items-289 (next-in #:generator-299 (go end)))
    (setq #:numbers-288 (next-in #:generator-297 (go end)))
    (if (or (null #:number-291) (> #:number-291 #:numbers-288))
        (setq #:number-291 #:numbers-288
              #:result-292 #:items-289))
    (go #:ll-300)
   end)
  (if (null #:number-291)
      (setq #:result-292 nil))
  #:result-292)
Define a macro that eliminates this repetitive pattern:
(dlet* 'some-name)

Issue: Macro call that should be transformed by DLET*

Macro definition:
(defmacro DLET* ...)

Macroexpansion:
(dynamic-let* 'some-name)
Generate a defmacro form that transforms code like this:
(defgeneric* nil
    nil)

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

Macro definition:
(defmacro DEFGENERIC* ...)

Macroexpansion:
(defgeneric nil)
Define a macro that eliminates this repetitive pattern:
(match '(:name \"John\" :age 23) ((plist :name \"John\" :age age) age)) => 23"))

Issue: Macro call that should be transformed by match

Macro definition:
(defmacro match (arg &body clauses)
  "Matches ARG with CLAUSES. CLAUSES is a list of the form of (PATTERN
. BODY) where PATTERN is a pattern specifier and BODY is an implicit
progn. If ARG matches some PATTERN, `match` then evaluates
the corresponding BODY and returns the evaluated value.  If no pattern matches,
then returns NIL.

Evaluating a form (FAIL) in the clause body causes the latest pattern
matching to fail. For example,

    (match 1
      (x (if (eql x 1)
             (fail)
             x))
      (_ 'ok))

returns OK, because the form (FAIL) in the first clause is
evaluated.

If BODY starts with the symbols WHEN or UNLESS, then the next form
will be used to introduce (FAIL). That is,

    (match list ((list x) when (oddp x) x))
    (match list ((list x) unless (evenp x) x))

will be translated to

    (match list ((list x) (if (oddp x) x (fail))))
    (match list ((list x) (if (evenp x) (fail) x)))

Examples:

    (match 1 (1 1))
    => 1
    (match 1 (2 2))
    => 2
    (match 1 (x x))
    => 1
    (match (list 1 2 3)
      (list x y z) (+ x y z))
    => 6"
  (compile-match-1 arg clauses nil))

Macroexpansion:
(let ((#:var153 (quote (:name |"JOHN"| :age 23)))) (declare (ignorable #:var153)) (%or (%if (plistp #:var153) (let ((#:g154 (plistname #:var153)) (#:g155 (plistage #:var153))) (declare (ignorable #:g154 #:g155)) (%or (let ((age #:g155)) (let ((|"JOHN"| #:g154)) age)) (fail))) (fail)) nil))
Generate a defmacro form that transforms code like this:
(incf 'some-name)

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

Macro definition:
(defmacro INCF ...)

Macroexpansion:
(let* ((#:some-name199 some-name) (#:new198 (+ 1 '#:some-name199)))
  (funcall #'(setf quote) #:new198 #:some-name199))
Write a Common Lisp macro to handle this code pattern:
(when (node-slot shared) (del-proxy shared))

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 (node-slot shared) (del-proxy shared))
Define a macro that eliminates this repetitive pattern:
(defhandler return-from (return-from name &optional (value nil value-p)) `(list ',return-from ',name ,@(when value-p `(,(e value)))))

Issue: 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-return-from (return-from name &optional (value nil value-p)) (sb-int:quasiquote (list (quote #S(sb-impl::comma :expr return-from :kind 0)) (quote #S(sb-impl::comma :expr name :kind 0)) #S(sb-impl::comma :expr (when value-p (sb-int:quasiquote (#S(sb-impl::comma :expr (e value) :kind 0)))) :kind 2)))) (setf (gethash (quote return-from) *form-handler*) (quote hander-return-from)))
Create a Common Lisp macro for the following transformation. Before code:
(ct-let* nil
  (progn))

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

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

Macroexpansion:
(cond (*within-captured-dynenv* (progn (progn)))
      (t
       (error
        "No macrodynamic environment has been captured to establish CT-LET* bindings.")))
Define a macro that eliminates this repetitive pattern:
(product-of nil
  nil)

Issue: Macro call that should be transformed by PRODUCT-OF

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

Macroexpansion:
(lc (nil nil) multiply)
Write a Common Lisp macro to handle this code pattern:
(with-csv-output-stream (csv-stream stream) (iter (for row in rows-of-items) (write-csv-row row :stream csv-stream)) (unless stream (get-output-stream-string csv-stream)))

Problem: Macro call that should be transformed by with-csv-output-stream

Macro definition:
(defmacro with-csv-output-stream ((name inp) &body body)
  (alexandria:with-unique-names (opened?)
    `(multiple-value-bind (,name ,opened?) (%out-stream ,inp)
      (flet ((body () ,@body))
        (unwind-protect (body)
          (when (and ,name ,opened?)
            (close ,name)))))))

Macroexpansion:
(multiple-value-bind (csv-stream #:opened?198) (%out-stream stream) (flet ((body nil (iter (for row in rows-of-items) (write-csv-row row :stream csv-stream)) (unless stream (get-output-stream-string csv-stream)))) (unwind-protect (body) (when (and csv-stream #:opened?198) (close csv-stream)))))
Define a macro that eliminates this repetitive pattern:
(dflet ((bar/mock (string) (cond ((equalp string "Hello, World!") 42)))) (is (eql 43 (foo/mock))) (is (eql 43 (foo/mock "HELLO, WORLD!"))))

Issue: Macro call that should be transformed by dflet

Macro definition:
(defmacro dflet ((&rest definitions) &body body)
  "Like FLET, but dynamically sets the FDEFINITIONS during the duration of
the BODY."
  `(progf
       ',(mapcar #'car definitions)
       (list
        ,.(mapcar (lambda (definition)
                    `(lambda ,(cadr definition)
                       ,@(cddr definition)))
                  definitions))
     ,@body))

Macroexpansion:
(progf (quote (bar/mock)) (list (lambda (string) (cond ((equalp string "Hello, World!") 42)))) (is (eql 43 (foo/mock))) (is (eql 43 (foo/mock "HELLO, WORLD!"))))
You are a Common Lisp macro expert. Given this code pattern:
(with-reader-syntax (set) (let ((set (er "#{'a 'b 1 '(1) '(1) :test #'equal}"))) (is-true (alexandria:setp set)) (is-true (member 'a set)) (is-true (member 'b set)) (is-true (member 1 set)) (is-false (member 2 set)) (is (= 1 (count '(1) set :test #'equal)))))

Write a macro that addresses: Macro call that should be transformed by with-reader-syntax

Macro definition:
(defmacro with-reader-syntax (reader-macro-identifiers &body body)
  "This macro is only made for use by read-and-eval functionality,
and rather directed towards tests than users. So, do not export."
  (let ((identifiers (loop :for identifier :in reader-macro-identifiers
                           :collect `(quote ,identifier))))
    `(let ((*array-function*         'make-t-array-from-initial-contents)
           (*hash-table-function*    'alexandria:plist-hash-table)
           (*get-val-function*       'get-val)
           (*get-val-array-function* 'cl:aref)
           (*set-function*           'cl:remove-duplicates)
           (*alists-are-lists*       nil)
           (*plists-are-lists*       nil)
           (*readtable*             (%enable-reader-syntax *readtable* ,@identifiers)))
       ,@body)))

Macroexpansion:
(let ((*array-function* (quote make-t-array-from-initial-contents)) (*hash-table-function* (quote alexandria:plist-hash-table)) (*get-val-function* (quote get-val)) (*get-val-array-function* (quote aref)) (*set-function* (quote remove-duplicates)) (*alists-are-lists* nil) (*plists-are-lists* nil) (*readtable* (%enable-reader-syntax *readtable* (quote set)))) (let ((set (er "#{'a 'b 1 '(1) '(1) :test #'equal}"))) (is-true (alexandria:setp set)) (is-true (member (quote a) set)) (is-true (member (quote b) set)) (is-true (member 1 set)) (is-false (member 2 set)) (is (= 1 (count (quote (1)) set :test (function equal))))))
You are a Common Lisp macro expert. Given this code pattern:
(scond ((= 1 2) :no!))

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

Macro definition:
(defmacro scond (&body clauses)
  "Like COND, except each test-form is bound to IT (via SYMBOL-MACROLET) for the
scope of the corresponsing clause. IT can be set with SETF."
  (labels ((rec (clauses)
	     (if clauses
		 (destructuring-bind ((test &body body) . rest) clauses
		   (if body
		       `(symbolic if ,test (progn ,@body) ,(rec rest))
		       `(symbolic if ,test it ,(rec rest))))
		 nil)))
    (rec clauses)))

Macroexpansion:
(symbolic if (= 1 2) (progn :no!) nil)
Create a Common Lisp macro for the following transformation. Before code:
(defvar-unbound *pair-level* "")

What needs to change: 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 *pair-level*) (setf (documentation (quote *pair-level*) (quote variable)) ""))
Create a Common Lisp macro for the following transformation. Before code:
(match maybe m ((just x) (funcall f x)) (nothing nothing))

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

Macro definition:
(defmacro match (adt obj &body clauses)
  "Perform pattern matching on OBJ with (adt-type) ADT.

Each clause must have the following syntax:

<var> := <symbol> | '_'
<lhs> := '_'
       | (<symbol> <var>*)
<clause> := (<lhs> <lisp code>)

The symbol '_' denotes a wildcard, as well as a fallthough.

Note that pattern matching is only shallow (patterns are one-level
deep).
"
  (assert (symbolp adt)
          (adt)
          "MATCH requires a symbol for the first argument. Given ~S."
          adt)

  (let ((ctors (mapcar #'car (get-constructors adt)))
        (types (mapcar (lambda (clause)
                         (ensure-car (car clause)))
                       clauses))
        (once (gensym "OBJ-")))

    ;; Check for duplicate matches.
    (let ((dupes (duplicates types)))
      (when dupes
        (warn "Duplicate matching clauses exist. Duplicate pattern ~
               constructors:~{ ~S~}"
              dupes)))

    ;; Check for match exhaustiveness.
    (unless (some #'wild? types)
      (let ((diff (set-difference ctors types)))
        (when diff
          (warn "Non-exhaustive match on ~A data ~
                 type. Missing cases:~{ ~S~}" adt diff))))

    ;; Generate the matching code.
    `(let ((,once ,obj))
       (check-type ,once ,adt)
       (etypecase ,once
         ,@(loop :for (bindings . body) :in clauses
                 :collect (let ((type (ensure-car bindings)))
                            (if (wild? type)
                                `(t ,@body)
                                `(,type
                                  (with-data ,(ensure-list bindings)
                                             ,once
                                    ,@body)))))))))

Macroexpansion:
(let ((#:obj-148 m)) (check-type #:obj-148 maybe) (etypecase #:obj-148 (just (with-data (just x) #:obj-148 (funcall f x))) (nothing (with-data (nothing) #:obj-148 nothing))))
Generate a defmacro form that transforms code like this:
(slet (car x) (incf it) (values it x))

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

Macro definition:
(defmacro slet (form &body body)
  "Binds the FORM to IT (via SYMBOL-MACROLET) in the scope of the BODY. IT can
be set with SETF."
  `(symbolic ignore-first ,form (progn ,@body)))

Macroexpansion:
(symbolic ignore-first (car x) (progn (incf it) (values it x)))
Generate a defmacro form that transforms code like this:
(defpackage nil nil)

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

Macro definition:
(defmacro DEFPACKAGE ...)

Macroexpansion:
(common-lisp:defpackage nil
  (:use :adhoc :closer-mop :cl)
  (:shadowing-import-from :closer-mop
                          #:defmethod
                          #:standard-generic-function
                          #:defgeneric
                          #:standard-method
                          #:standard-class)
  (:shadowing-import-from :adhoc #:defpackage #:variable #:the)
  ())
Write a Common Lisp macro to handle this code pattern:
(dotimes (quote some-name))

Problem: Macro call that should be transformed by DOTIMES

Macro definition:
(defmacro DOTIMES ...)

Macroexpansion:
(do ((quote 0 (1+ quote))
     (#:g163 (the integer some-name)))
    ((>= quote #:g163) nil)
  (declare (type unsigned-byte quote)))
You are a Common Lisp macro expert. Given this code pattern:
(define-value-binding as ((var value) value) (declare (ignorable value)) (values NIL var))

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

Macro definition:
(defmacro define-value-binding (name (var &rest args) &body body)
  (let ((vars (lambda-fiddle:extract-lambda-vars (lambda-fiddle:remove-aux-part args))))
    (emit-binding-definition name var args body :extra-vars vars)))

Macroexpansion:
(define-direct-binding as (var value) (let ((#:value132 (gensym #A((5) base-char . "VALUE")))) (values* (sb-int:quasiquote (with-interleaving (let* #S(sb-impl::comma :expr (list* (list #:value132 value) (loop for #:var131 in (lambda-fiddle:extract-lambda-vars (enlist var)) collect (list #:var131 #:value132))) :kind 0) (declare (ignorable #S(sb-impl::comma :expr #:value132 :kind 0)))) #S(sb-impl::comma :expr nil :kind 0))) (let ((value #:value132)) (declare (ignorable value)) (declare (ignorable value)) (values nil var)))))