j14i/cl-macros huggingface dataset:
Write a Common Lisp macro to handle this code pattern:
(match list ((list x) unless (evenp x) x))

Problem: 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:
(%or (%if (consp list) (let ((#:g142 (car list)) (#:g143 (cdr list))) (declare (ignorable #:g142 #:g143)) (%if (%equals #:g143 nil) (%or (let ((x #:g142)) (if (not (evenp x)) x (fail))) (fail)) (fail))) (fail)) nil)
Generate a defmacro form that transforms code like this:
(builder (if t (lambda (app) (lambda (env) (funcall app env))) nil) *app*)

Pattern to recognize: 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 (let ((#:res168 (if t (lambda (app) (lambda (env) (funcall app env))) nil))) (typecase #:res168 (keyword (find-middleware #:res168)) (cons (if (keywordp (car #:res168)) (let ((#:res-mw167 (find-middleware (car #:res168)))) (lambda (#:app166) (apply #:res-mw167 #:app166 (cdr #:res168)))) #:res168)) (standard-object (lambda (#:app166) (funcall (intern (string :wrap) :clack.middleware) #:res168 #:app166))) (otherwise #:res168))))) :initial-value (to-app *app*) :from-end t)
You are a Common Lisp macro expert. Given this code pattern:
(define-simple-definition-resolver declaration (designator) (sb-int:info :source-location :declaration designator))

Write a macro that addresses: Macro call that should be transformed by define-simple-definition-resolver

Macro definition:
(defmacro define-simple-definition-resolver (class lookup-function &body body)
  (let ((package (gensym "PACKAGE")))
    `(define-definition-resolver ,class (,class ,package)
       (when (ignore-errors ,(if body
                                 `(let ((,(first lookup-function) ,class))
                                    ,@body)
                                 `(,lookup-function ,class)))
         (list (make-instance ',class :designator ,class :package ,package))))))

Macroexpansion:
(define-definition-resolver declaration (declaration #:package152) (when (ignore-errors (let ((designator declaration)) (sb-int:info :source-location :declaration designator))) (list (make-instance (quote declaration) :designator declaration :package #:package152))))
You are a Common Lisp macro expert. Given this code pattern:
(draw scene (:ellipse :cx (random 500) :cy (random 500) :rx (+ 10 (random 65)) :ry (+ 10 (random 65))) :stroke "rgb(232, 229, 148)" :fill (one-of *groovy-test-colors*))

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

Macro definition:
(defmacro draw (scene (shape &rest params) &rest opts)
  (let ((element (gensym)))
    `(let ((,element (funcall #'make-svg-element ,shape (append (list ,@params) (list ,@opts)))))
       (add-element ,scene ,element)
       ,element)))

Macroexpansion:
(let ((#:g146 (funcall (function make-svg-element) :ellipse (append (list :cx (random 500) :cy (random 500) :rx (+ 10 (random 65)) :ry (+ 10 (random 65))) (list :stroke "rgb(232, 229, 148)" :fill (one-of *groovy-test-colors*)))))) (add-element scene #:g146) #:g146)
Write a Common Lisp macro to handle this code pattern:
(accase (car x) (:y :no) (:x (list it :yes)))

Problem: Macro call that should be transformed by accase

Macro definition:
(defmacro accase (keyform &body cases)
  "Like CCASE, except binds the result of the keyform to IT (via LET) for the
scope of the cases. Unlike CCASE, the keyform/place doesn't receive new values
possibly stored with STORE-VALUE restart; the new value is received by IT."
  `(anaphoric ccase ,keyform ,@cases))

Macroexpansion:
(anaphoric ccase (car x) (:y :no) (:x (list it :yes)))
Create a Common Lisp macro for the following transformation. Before code:
(make-name-transformer 'some-name)

What needs to change: Macro call that should be transformed by MAKE-NAME-TRANSFORMER

Macro definition:
(defmacro MAKE-NAME-TRANSFORMER ...)

Macroexpansion:
(lambda (name definition)
  (declare (ignorable definition))
  (concatenate-symbol 'some-name))
You are a Common Lisp macro expert. Given this code pattern:
(emit 'some-name)

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

Macro definition:
(defmacro EMIT ...)

Macroexpansion:
(let ((#:ast182 'some-name))
  (progn
   (assert (typep #:ast182 'delayed-emitting) nil
           "Something went awry around the quasi quoted stuff, EMIT got a ~S."
           #:ast182)
   (funcall #:ast182)))
You are a Common Lisp macro expert. Given this code pattern:
(when (eql (top-sign) 'first-initializer) (pop-sign))

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 (eql (top-sign) (quote first-initializer)) (pop-sign))
Define a macro that eliminates this repetitive pattern:
(letrec ((f (constantly t)) (a (funcall f))) a)

Issue: Macro call that should be transformed by letrec

Macro definition:
(defmacro letrec ((&rest bindings) &body body)
  "Recursive LET.
The idea is that functions created in BINDINGS can close over one
another, and themselves.

Note that `letrec' only binds variables: it can define recursive
functions, but can't bind them as functions. (But see `fbindrec'.)"
  `(letrec-with psetq ,bindings
     ,@body))

Macroexpansion:
(letrec-with psetq ((f (constantly t)) (a (funcall f))) a)
Write a Common Lisp macro to handle this code pattern:
(enable-infix-syntax)

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

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

Macroexpansion:
(use-syntax :mexpr)
Write a Common Lisp macro to handle this code pattern:
(var nil)

Problem: Macro call that should be transformed by VAR

Macro definition:
(defmacro VAR ...)

Macroexpansion:
(defparameter nil nil)
Generate a defmacro form that transforms code like this:
(define-option-expander import-from (package import-package &rest symbols) (import (collect-symbols-from import-package symbols) package))

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

Macro definition:
(defmacro define-option-expander (name (package &rest arguments) &body body)
  (let ((args (gensym "ARGS")))
    `(defmethod expand-option ((,(gensym "TYPE") (eql ,(intern (string name) "KEYWORD"))) ,package ,args)
       (destructuring-bind ,arguments ,args
         ,@body))))

Macroexpansion:
(defmethod expand-option ((#:type132 (eql :import-from)) package #:args131) (destructuring-bind (import-package &rest symbols) #:args131 (import (collect-symbols-from import-package symbols) package)))
Write a Common Lisp macro to handle this code pattern:
(defclause accumulating-to (vars &key initially by finally) "Specifies an accumulation clause. Refer to the manual for details." (labels ((make-finally-form (var function) `(setf ,var (funcall ,function ,var))) (make-one-accumulation (var) (cons (make-simple-iteration :var var :init initially) (if by (list* (make-accumulator :var var :function by) (when finally (list (make-finalization :form (make-finally-form var finally))))) (list (make-accumulator :var var :function '(function cons)) (make-finalization :form (make-finally-form var (or finally '(function nreverse))))))))) (mapcan #'make-one-accumulation (ensure-list vars))))

Problem: 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 accumulating-to (vars &key initially by finally) "Specifies an accumulation clause. Refer to the manual for details." (labels ((make-finally-form (var function) (sb-int:quasiquote (setf #S(sb-impl::comma :expr var :kind 0) (funcall #S(sb-impl::comma :expr function :kind 0) #S(sb-impl::comma :expr var :kind 0))))) (make-one-accumulation (var) (cons (make-simple-iteration :var var :init initially) (if by (list* (make-accumulator :var var :function by) (when finally (list (make-finalization :form (make-finally-form var finally))))) (list (make-accumulator :var var :function (quote (function cons))) (make-finalization :form (make-finally-form var (or finally (quote (function nreverse)))))))))) (mapcan (function make-one-accumulation) (ensure-list vars)))) (pushnew (quote accumulating-to) *clauses*))
You are a Common Lisp macro expert. Given this code pattern:
(defsynonym leave :leave)

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

Macro definition:
(defmacro defsynonym (symbol synonym)
  "Set SYNONYM for a SYMBOL. "
  `(eval-always
     (setf (get ',symbol 'synonym) ',synonym)))

Macroexpansion:
(eval-always (setf (get (quote leave) (quote synonym)) (quote :leave)))
You are a Common Lisp macro expert. Given this code pattern:
(maybe-once-only 'some-name)

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

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

Macroexpansion:
(let* ((#:g185 nil)
       (quote
        (let ((form (ps-macroexpand quote)))
          (if (atom form)
              form
              (let ((var1 (ps-gensym 'quote)))
                (push (list var1 form) #:g185)
                var1))))
       (some-name
        (let ((form (ps-macroexpand some-name)))
          (if (atom form)
              form
              (let ((var1 (ps-gensym 'some-name)))
                (push (list var1 form) #:g185)
                var1)))))
  `(let* ,(nreverse #:g185)))
Generate a defmacro form that transforms code like this:
(with-path curvy (smooth-quadratic-curve-to (random 500) (random 500)))

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

Macro definition:
(defmacro with-path (path &body cmds)
  (let ((s (gensym "stream"))
        (n (gensym)))
    `(flet ((assert-string (s)
              (error-unless-string s)))
       (with-output-to-string (,s ,path)
         ;; Do trivial breaking up of the path data - SVG does not have
         ;; to accept indefinitely long lines of data.
         (let ((,n 0))
           (dolist (inst (mapcar #'assert-string (list ,@cmds)) (format ,s "~&"))
             (format ,s "~@{~A~}" inst)
             (incf ,n)
             (when (= (mod ,n 10) 0)
               (format ,s "~&"))))))))

Macroexpansion:
(flet ((assert-string (s) (error-unless-string s))) (with-output-to-string (#:|stream138| curvy) (let ((#:g139 0)) (dolist (inst (mapcar (function assert-string) (list (smooth-quadratic-curve-to (random 500) (random 500)))) (format #:|stream138| "~&")) (format #:|stream138| "~@{~A~}" inst) (incf #:g139) (when (= (mod #:g139 10) 0) (format #:|stream138| "~&"))))))
You are a Common Lisp macro expert. Given this code pattern:
(define-error keyword-in-function-position () (form) "Keyword cannot appear in function name position : ~s" form)

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

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

Macroexpansion:
(defcondition keyword-in-function-position (:error-type varjo-error :prefix "Varjo") (form) "Keyword cannot appear in function name position : ~s" form)
Create a Common Lisp macro for the following transformation. Before code:
(define-element-maker :polyline "polyline" '(:points))

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

Macro definition:
(defmacro define-element-maker (element name required-attributes)
  `(progn
     (defmethod assert-required-attributes ((element (eql ,element)) attributes)
       (declare (ignore element))
       (unless (evenp (length attributes))
         (warn "attribute list may be missing data: ~A" attributes))
       (let ((missing (set-difference ,required-attributes attributes)))
	 (when missing
	   (error 'missing-attributes :message (format nil "~A missing attributes: ~{~A~^ ~}" ,element missing)))))
     (defmethod make-svg-element ((element (eql ,element)) attributes)
       (when *check-required-attributes*
         (assert-required-attributes element attributes))
       (make-instance 'svg-element :name ,name :attributes attributes))))

Macroexpansion:
(progn (defmethod assert-required-attributes ((element (eql :polyline)) attributes) (declare (ignore element)) (unless (evenp (length attributes)) (warn "attribute list may be missing data: ~A" attributes)) (let ((missing (set-difference (quote (:points)) attributes))) (when missing (error (quote missing-attributes) :message (format nil "~A missing attributes: ~{~A~^ ~}" :polyline missing))))) (defmethod make-svg-element ((element (eql :polyline)) attributes) (when *check-required-attributes* (assert-required-attributes element attributes)) (make-instance (quote svg-element) :name "polyline" :attributes attributes)))
Write a Common Lisp macro to handle this code pattern:
(answer (foo 1) 42)

Problem: Macro call that should be transformed by answer

Macro definition:
(defmacro answer (call &body forms)
  (let ((name (if (listp call) (car call) call))
        (sym (gensym)))
    `(if-called
      ',name
      (let ((,sym (fdefinition ',name)))
        (declare (ignorable ,sym))
        (let ((times 0))
          (lambda (&rest args)
            (declare (ignorable args))
            ,(let ((cases
                     `(case (prog1 times (incf times))
                        ,.(loop
                            for i from 0
                            for (form . rest) on forms
                            collect `(,(if rest i T) ,form)))))
               (if (listp call)
                   `(trivia:match args
                     ((list . ,(cdr call)) ,cases)
                     (_ (unhandled)))
                   cases))))))))

Macroexpansion:
(if-called (quote foo) (let ((#:g158 (fdefinition (quote foo)))) (declare (ignorable #:g158)) (let ((times 0)) (lambda (&rest args) (declare (ignorable args)) (trivia.level2:match args ((list 1) (case (prog1 times (incf times)) (t 42))) (_ (unhandled)))))))
Create a Common Lisp macro for the following transformation. Before code:
(c? (incf delta-ct) (trc nil "syn-b rule firing!!!!!!!!!!!!!!" delta-ct) (eko (nil "syn-b rule returning") (f-delta :syna-1 (:sensitivity 2) (^m-syn-a))))

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

Macro definition:
(defmacro c? (&body body)
  `(make-c-dependent
    :code ',body
    :value-state :unevaluated
    :rule (c-lambda ,@body)))

Macroexpansion:
(make-c-dependent :code (quote ((incf delta-ct) (trc nil "syn-b rule firing!!!!!!!!!!!!!!" delta-ct) (eko (nil "syn-b rule returning") (f-delta :syna-1 (:sensitivity 2) (^m-syn-a))))) :value-state :unevaluated :rule (c-lambda (incf delta-ct) (trc nil "syn-b rule firing!!!!!!!!!!!!!!" delta-ct) (eko (nil "syn-b rule returning") (f-delta :syna-1 (:sensitivity 2) (^m-syn-a)))))
Create a Common Lisp macro for the following transformation. Before code:
(with-yield-binds (format nil "~A ~A ~A" (slot-value clause 'name) (yield (distinct-on-clause-columns clause)) (yield (statement-clause-statement 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 ~A" (slot-value clause (quote name)) (yield (distinct-on-clause-columns clause)) (yield (statement-clause-statement clause)))) (loop for bind in (reverse *bind-values*) append bind)))
Define a macro that eliminates this repetitive pattern:
(define-global-parameter* nil nil)

Issue: Macro call that should be transformed by DEFINE-GLOBAL-PARAMETER*

Macro definition:
(defmacro DEFINE-GLOBAL-PARAMETER* ...)

Macroexpansion:
(progn
 (setf (get 'nil +value-key+) nil)
 (sb-ext:define-load-time-global nil (get 'nil +value-key+))
 (setf nil (get 'nil +value-key+))
 (remprop 'nil +value-key+)
 'nil)
You are a Common Lisp macro expert. Given this code pattern:
(with-store-entry (key store) (trc "looked up dead item -- resetting to nil" key store) (setf (item key store) nil))

Write a macro that addresses: Macro call that should be transformed by with-store-entry

Macro definition:
(defmacro with-store-entry ((key store &key quiet) &body body)
  `(prog1
       (progn
	 ,@body)
     (unless ,quiet
       (kick-c-link ,key ,store))))

Macroexpansion:
(prog1 (progn (trc "looked up dead item -- resetting to nil" key store) (setf (item key store) nil)) (unless nil (kick-c-link key store)))
Generate a defmacro form that transforms code like this:
(js-inline nil :key nil)

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

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

Macroexpansion:
(js-inline* '(progn nil :key nil))
You are a Common Lisp macro expert. Given this code pattern:
(do-generator-value-list (vars (apply #'multi-gen generators)) (apply #'yield (mapcar #'car vars)))

Write a macro that addresses: Macro call that should be transformed by do-generator-value-list

Macro definition:
(defmacro do-generator-value-list ((var generator) &body body)
  "Like do-generator, except all values emitted by the generator are placed in a list under the user defined variable."
  (let ((g (gensym)))
    `(let ((,g ,generator))
       (loop 
	  do (if-generator (,var ,g)
			   (progn ,@body)
			   (return))))))

Macroexpansion:
(let ((#:g179 (apply (function multi-gen) generators))) (loop do (if-generator (vars #:g179) (progn (apply (function yield) (mapcar (function car) vars))) (return))))
Write a Common Lisp macro to handle this code pattern:
(define-case-aware-token-p-function pp-with-c-syntax-pragma-p find-pragma-name with-c-syntax.pragma-name:|WITH_C_SYNTAX|)

Problem: Macro call that should be transformed by define-case-aware-token-p-function

Macro definition:
(defmacro define-case-aware-token-p-function (function-name find-symbol-function symbol)
  `(defun ,function-name (token &optional (readtable-case (readtable-case *readtable*)))
     (and (symbolp token)
          (eq (,find-symbol-function (string token) readtable-case)
              ',symbol))))

Macroexpansion:
(defun pp-with-c-syntax-pragma-p (token &optional (readtable-case (readtable-case *readtable*))) (and (symbolp token) (eq (find-pragma-name (string token) readtable-case) (quote with-c-syntax.pragma-name:with_c_syntax))))
Create a Common Lisp macro for the following transformation. Before code:
(make-stream-method pp-xml-attr (s (kw symbol) &optional colon-p at-p) (declare (ignore colon-p at-p)) (format s "~A" (xmlify-keyword kw)))

What needs to change: Macro call that should be transformed by make-stream-method

Macro definition:
(defmacro make-stream-method (name (s &rest args) &body body)
  `(progn
     (defmethod ,name ((,s stream) ,@args)
       ,@body)
     #+abcl
     (defmethod ,name ((,s xp::xp-structure) ,@args)
       ,@body)))

Macroexpansion:
(progn (defmethod pp-xml-attr ((s stream) (kw symbol) &optional colon-p at-p) (declare (ignore colon-p at-p)) (format s "~A" (xmlify-keyword kw))))
You are a Common Lisp macro expert. Given this code pattern:
(define-global-var nil :key nil)

Write a macro that addresses: Macro call that should be transformed by DEFINE-GLOBAL-VAR

Macro definition:
(defmacro DEFINE-GLOBAL-VAR ...)

Macroexpansion:
(sb-ext:defglobal nil :key nil)
Write a Common Lisp macro to handle this code pattern:
(defclass/std prefix () ((without-prefix)))

Problem: Macro call that should be transformed by defclass/std

Macro definition:
(defmacro defclass/std (name direct-superclasses direct-slots &rest options
                        &environment env)
  "Shortcut macro to the DEFCLASS macro.

  (defclass/std example ()
    ((slot1 slot2 slot3)))

  expands to:

  (DEFCLASS EXAMPLE ()
    ((SLOT1 :ACCESSOR SLOT1 :INITARG :SLOT1 :INITFORM NIL)
    (SLOT2 :ACCESSOR SLOT2 :INITARG :SLOT2 :INITFORM NIL)
    (SLOT3 :ACCESSOR SLOT3 :INITARG :SLOT3 :INITFORM NIL)))

  Each slot definition accepts options:

    :std 1 => changes the :initform to 1. It can be :unbound.
    :with or :with-prefix => creates accessors with the class name as prefix.

  See the README for more.

  See also `class/std' and `print-object/std'.
  "
  `(defclass ,name ,direct-superclasses
     ,(process-slots env direct-slots name)
     ,@options))

Macroexpansion:
(defclass prefix nil ((without-prefix :accessor without-prefix :initarg :without-prefix :initform nil)))
Define a macro that eliminates this repetitive pattern:
(defsynonym :as :for)

Issue: Macro call that should be transformed by defsynonym

Macro definition:
(defmacro defsynonym (symbol synonym)
  "Set SYNONYM for a SYMBOL. "
  `(eval-always
     (setf (get ',symbol 'synonym) ',synonym)))

Macroexpansion:
(eval-always (setf (get (quote :as) (quote synonym)) (quote :for)))
Generate a defmacro form that transforms code like this:
(-> :g (a) (+ 1 a))

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

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

Macroexpansion:
(atomically :g (a) (+ 1 a))
You are a Common Lisp macro expert. Given this code pattern:
(collect-length nil)

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

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

Macroexpansion:
(common-lisp:let* ((#:generator-462 (generator nil)) (#:number-459 0))
  (declare (type generator #:generator-462)
           (type fixnum #:number-459))
  (tagbody
   #:ll-463
    (next-in #:generator-462 (go end))
    (incf #:number-459)
    (go #:ll-463)
   end)
  #:number-459)