j14i/cl-macros huggingface dataset:
Create a Common Lisp macro for the following transformation. Before code:
(define-modf-rewrite cadar (expr) `(car (cdar ,(second expr))))

What needs to change: 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 cadar) *modf-rewrites*) (lambda (expr) (sb-int:quasiquote (car (cdar #S(sb-impl::comma :expr (second expr) :kind 0)))))))
Write a Common Lisp macro to handle this code pattern:
(->*
  nil
  nil)

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

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

Macroexpansion:
(let* ((#:var190 nil) (#:var191 (nil #:var190)))
  #:var191)
Generate a defmacro form that transforms code like this:
(define SEEK_END 2)

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

Macro definition:
(defmacro define (name value &rest docstring)
  "Like a #define but also visible to Lisp code."
  `(progn
     (eval-when (:compile-toplevel :load-toplevel :execute)
       (defvar ,(pp-defines *package*) (make-hash-table))
       (setf (gethash ',name ,(pp-defines *package*)) ,(prin1-to-string value)))
     (defparameter ,name ,value ,@docstring)))

Macroexpansion:
(progn (eval-when (:compile-toplevel :load-toplevel :execute) (defvar *preprocessor-defines* (make-hash-table)) (setf (gethash (quote seek_end) *preprocessor-defines*) #A((1) base-char . "2"))) (defparameter seek_end 2))
Create a Common Lisp macro for the following transformation. Before code:
(quasiquote nil (progn))

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

Macro definition:
(defmacro QUASIQUOTE ...)

Macroexpansion:
(let ((#:source123 nil))
  (%append #:source123 (common-lisp:list (%quote #:source123 'progn))
           (%quote #:source123 'nil)))
Create a Common Lisp macro for the following transformation. Before code:
(def-neo4j-fun set-node-properties (node-id properties) :put (:encode properties :string) (:uri-spec (format nil "node/~A/properties" node-id)) (:status-handlers (204 (values t body)) (400 (error 'invalid-data-sent-error :uri uri :json json)) (404 (error 'node-not-found-error :uri uri))))

What needs to change: Macro call that should be transformed by def-neo4j-fun

Macro definition:
(defmacro def-neo4j-fun (name lambda-list method &rest args)
  `(progn
     (defun ,name (&key ,@lambda-list)
       (let ((uri ,(cadr (assoc :uri-spec args)))
             (json (encode-neo4j-json-payload ,@(aif (assoc :encode args)
                                                     (cdr it)
                                                     (list '() :string)))))
         (make-neo4j-request ,method uri json
                             (list ,@(mapcar (lambda (handler)
                                               `(list ,(car handler) (lambda (body uri json)
                                                                  ,(cadr handler))))
                                             (cdr (assoc :status-handlers args)))))))))

Macroexpansion:
(progn (defun set-node-properties (&key node-id properties) (let ((uri (format nil "node/~A/properties" node-id)) (json (encode-neo4j-json-payload properties :string))) (make-neo4j-request :put uri json (list (list 204 (lambda (body uri json) (values t body))) (list 400 (lambda (body uri json) (error (quote invalid-data-sent-error) :uri uri :json json))) (list 404 (lambda (body uri json) (error (quote node-not-found-error) :uri uri))))))))
You are a Common Lisp macro expert. Given this code pattern:
(define-cruft %list-all-readtable-names () "Return a list of all available readtable names." #+ :common-lisp (list* :standard :current :modern (loop for name being each hash-value of *readtable-names* collect name)))

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

Macro definition:
(defmacro define-cruft (name lambda-list &body (docstring . alternatives))
  (assert (typep docstring 'string) (docstring) "Docstring missing!")
  (assert (not (null alternatives)))
  `(progn
     (declaim (inline ,name))
     (defun ,name ,lambda-list ,docstring ,(first alternatives))))

Macroexpansion:
(progn (declaim (inline %list-all-readtable-names)) (defun %list-all-readtable-names nil "Return a list of all available readtable names." (list* :standard :current :modern (loop for name being each hash-value of *readtable-names* collect name))))
Create a Common Lisp macro for the following transformation. Before code:
(define-shared-method nil
    :key
  nil)

What needs to change: Macro call that should be transformed by DEFINE-SHARED-METHOD

Macro definition:
(defmacro DEFINE-SHARED-METHOD ...)

Macroexpansion:
(define-incongruent-method incongruent-methods.methods::nil
    :key
  nil)
Write a Common Lisp macro to handle this code pattern:
(defun-compile-time self-evaluating? (thing) (and (not (consp thing)) (or (not (symbolp thing)) (null thing) (eq thing t) (eq (symbol-package thing) (symbol-package :x)))))

Problem: 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 self-evaluating? (thing) (and (not (consp thing)) (or (not (symbolp thing)) (null thing) (eq thing t) (eq (symbol-package thing) (symbol-package :x))))) (eval-when (:compile-toplevel) (compile (quote self-evaluating?))))
Generate a defmacro form that transforms code like this:
(alist-bind (name fields) form (let ((sym (foreign-type-symbol name :cunion *package*))) (let ((cunion-fields (parse-fields fields))) (when (symbol-package sym) (pushnew `(:union (,sym)) *foreign-record-list* :test #'equal)) `(define-foreign-record ',sym :union ,(aval :bit-size form) ,(aval :bit-alignment form) ',cunion-fields))))

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

Macro definition:
(defmacro alist-bind ((&rest vars) alist &body body)
  "Inefficient but doesn't really matter here"
  (once-only (alist)
    `(let (,@(mapcar (lambda (x)
                       (if (consp x)
                           `(,(car x) (aval ,(cadr x) ,alist))
                           `(,x (aval ,(make-keyword x) ,alist))))
                     vars))
       ,@body)))

Macroexpansion:
(let ((#:alist242 form)) (let ((name (aval :name #:alist242)) (fields (aval :fields #:alist242))) (let ((sym (foreign-type-symbol name :cunion *package*))) (let ((cunion-fields (parse-fields fields))) (when (symbol-package sym) (pushnew (sb-int:quasiquote (:union (#S(sb-impl::comma :expr sym :kind 0)))) *foreign-record-list* :test (function equal))) (sb-int:quasiquote (define-foreign-record (quote #S(sb-impl::comma :expr sym :kind 0)) :union #S(sb-impl::comma :expr (aval :bit-size form) :kind 0) #S(sb-impl::comma :expr (aval :bit-alignment form) :kind 0) (quote #S(sb-impl::comma :expr cunion-fields :kind 0))))))))
Create a Common Lisp macro for the following transformation. Before code:
(define-global-parameter nil :key nil)

What needs to change: Macro call that should be transformed by DEFINE-GLOBAL-PARAMETER

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

Macroexpansion:
(progn
 (store-in-symbol-plist nil :key .value-key.)
 (sb-ext:defglobal nil (get 'nil +value-key+))
 (eval-when (:compile-toplevel :load-toplevel :execute)
   (setf nil (get 'nil +value-key+)))
 (remprop 'nil +value-key+)
 'nil)
Write a Common Lisp macro to handle this code pattern:
(deferror "08003" connection-does-not-exist)

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 connection-does-not-exist (database-error) nil) (setf (gethash "08003" *error-table*) (quote connection-does-not-exist)))
Define a macro that eliminates this repetitive pattern:
(*> (take-while (lambda (c) (eql #\a c))) (take-while (lambda (c) (or (eql #\b c) (eql #\c c) (eql #\d c)))))

Issue: Macro call that should be transformed by *>

Macro definition:
(defmacro *> (parser &rest parsers)
  "Combination of parsers yielding the result of the rightmost one."
  (let ((offset (gensym "*>-OFFSET")))
    `(lambda (,offset)
       ,(reduce (lambda (i p)
                  (let ((res  (gensym "*>-RES"))
                        (next (gensym "*>-NEXT")))
                    `(multiple-value-bind (,res ,next) ,i
                       (if (ok? ,res)
                           (funcall ,p ,next)
                           (fail ,next)))))
                parsers
                :initial-value `(funcall ,parser ,offset)))))

Macroexpansion:
(lambda (#:*>-offset212) (multiple-value-bind (#:*>-res213 #:*>-next214) (funcall (take-while (lambda (c) (eql #\LATIN_SMALL_LETTER_A c))) #:*>-offset212) (if (ok? #:*>-res213) (funcall (take-while (lambda (c) (or (eql #\LATIN_SMALL_LETTER_B c) (eql #\LATIN_SMALL_LETTER_C c) (eql #\LATIN_SMALL_LETTER_D c)))) #:*>-next214) (fail #:*>-next214))))
Define a macro that eliminates this repetitive pattern:
(define SEEK_CUR 1)

Issue: Macro call that should be transformed by define

Macro definition:
(defmacro define (name value &rest docstring)
  "Like a #define but also visible to Lisp code."
  `(progn
     (eval-when (:compile-toplevel :load-toplevel :execute)
       (defvar ,(pp-defines *package*) (make-hash-table))
       (setf (gethash ',name ,(pp-defines *package*)) ,(prin1-to-string value)))
     (defparameter ,name ,value ,@docstring)))

Macroexpansion:
(progn (eval-when (:compile-toplevel :load-toplevel :execute) (defvar *preprocessor-defines* (make-hash-table)) (setf (gethash (quote seek_cur) *preprocessor-defines*) #A((1) base-char . "1"))) (defparameter seek_cur 1))
Generate a defmacro form that transforms code like this:
(receive (k v) (apply fn args) (setf (gethash k hash-table) v))

Pattern to recognize: 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 (k v) (setf (gethash k hash-table) v)) (apply fn args))
Define a macro that eliminates this repetitive pattern:
(define-element-maker :clip-path "clipPath" '(:id))

Issue: 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 :clip-path)) attributes) (declare (ignore element)) (unless (evenp (length attributes)) (warn "attribute list may be missing data: ~A" attributes)) (let ((missing (set-difference (quote (:id)) attributes))) (when missing (error (quote missing-attributes) :message (format nil "~A missing attributes: ~{~A~^ ~}" :clip-path missing))))) (defmethod make-svg-element ((element (eql :clip-path)) attributes) (when *check-required-attributes* (assert-required-attributes element attributes)) (make-instance (quote svg-element) :name "clipPath" :attributes attributes)))
Define a macro that eliminates this repetitive pattern:
(lambda* nil
  nil)

Issue: Macro call that should be transformed by LAMBDA*

Macro definition:
(defmacro LAMBDA* ...)

Macroexpansion:
(lambda ()
  (with-yield
    nil))
Define a macro that eliminates this repetitive pattern:
(match* (pattern qualifiers) (('* _) t) ((nil nil) t) (((type symbol) (type symbol)) (eql pattern qualifiers)) (((list* pfirst prest) (list* qualifier qualifiers)) (and (matches? qualifier pfirst) (matches? qualifiers prest))))

Issue: Macro call that should be transformed by match*

Macro definition:
(defmacro match* ((&rest things) &body clauses)
  `(multiple-value-match (values ,@things)
     ,@clauses))

Macroexpansion:
(multiple-value-match (values pattern qualifiers) (((quote *) _) t) ((nil nil) t) (((type symbol) (type symbol)) (eql pattern qualifiers)) (((list* pfirst prest) (list* qualifier qualifiers)) (and (matches? qualifier pfirst) (matches? qualifiers prest))))
Create a Common Lisp macro for the following transformation. Before code:
(*> +octothorp+ +skip-til-end+)

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

Macro definition:
(defmacro *> (parser &rest parsers)
  "Combination of parsers yielding the result of the rightmost one."
  (let ((offset (gensym "*>-OFFSET")))
    `(lambda (,offset)
       ,(reduce (lambda (i p)
                  (let ((res  (gensym "*>-RES"))
                        (next (gensym "*>-NEXT")))
                    `(multiple-value-bind (,res ,next) ,i
                       (if (ok? ,res)
                           (funcall ,p ,next)
                           (fail ,next)))))
                parsers
                :initial-value `(funcall ,parser ,offset)))))

Macroexpansion:
(lambda (#:*>-offset224) (multiple-value-bind (#:*>-res225 #:*>-next226) (funcall +octothorp+ #:*>-offset224) (if (ok? #:*>-res225) (funcall +skip-til-end+ #:*>-next226) (fail #:*>-next226))))
You are a Common Lisp macro expert. Given this code pattern:
(define-custom-var (:beginning-of-string *beginning-of-string-handler*))

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

Macro definition:
(defmacro define-custom-var ((key name) &rest other-args)
  `(eval-when (:compile-toplevel :load-toplevel :execute)
     (progn (pushnew '(,name . ,key) *custom-vars* :test #'equal)
            (defvar ,name ,@other-args))))

Macroexpansion:
(eval-when (:compile-toplevel :load-toplevel :execute) (progn (pushnew (quote (*beginning-of-string-handler* . :beginning-of-string)) *custom-vars* :test (function equal)) (defvar *beginning-of-string-handler*)))
Define a macro that eliminates this repetitive pattern:
(sunless x (setf it :ok))

Issue: Macro call that should be transformed by sunless

Macro definition:
(defmacro sunless (test &body body)
  "Like UNLESS, except binds the test form to IT (via SYMBOL-MACROLET) for the
scope of the body. IT can be set with SETF."
  `(symbolic unless ,test ,@body))

Macroexpansion:
(symbolic unless x (setf it :ok))
Write a Common Lisp macro to handle this code pattern:
(with-space (call-next-method))

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

Macro definition:
(defmacro with-space (&body body)
  (with-thunk (body)
    `(call-with-space ,body)))

Macroexpansion:
(flet ((#:stack-fn-body1 nil (call-next-method))) (declare (dynamic-extent (function #:stack-fn-body1))) (symbol-macrolet ((#:stack-fn-body1 (function #:stack-fn-body1))) (call-with-space #:stack-fn-body1)))
Define a macro that eliminates this repetitive pattern:
(with-active-layers nil)

Issue: Macro call that should be transformed by WITH-ACTIVE-LAYERS

Macro definition:
(defmacro WITH-ACTIVE-LAYERS ...)

Macroexpansion:
(progn)
Write a Common Lisp macro to handle this code pattern:
(serially (atomically nil () (decf counter)))

Problem: Macro call that should be transformed by serially

Macro definition:
(defmacro serially (&body flow)
  "Executes child elements serially (but possibly in different threads)
returning a value of the last atomic block or flow. Non-consing."
  (with-flow-let-macro (flow-list flow)
    (flow-lambda-macro (flow-context)
      `(dispatch-serially ,flow-context ,flow-list))))

Macroexpansion:
(let ((#:flow-list162 (list (atomically nil nil (decf counter))))) (%flow-lambda (#:flow-context163) (dispatch-serially #:flow-context163 #:flow-list162)))
Define a macro that eliminates this repetitive pattern:
;; Accessing pandoric variables requires verbose funcall
(let ((sum (funcall box :pandoric-get 'sum))
      (count (funcall box :pandoric-get 'count)))
  (format t "sum=~a count=~a~%" sum count))

;; Setting is even worse:
(progn
  (funcall box :pandoric-set 'sum new-value)
  new-value)

;; Want: regular variable syntax for pandoric access

Issue: Pandoric get/set requires verbose keyword funcalls — want transparent variable syntax using symbol-macrolet

Macro definition:
(defun get-pandoric (box sym)
  (funcall box :pandoric-get sym))

(defsetf get-pandoric (box sym) (val)
  `(progn
     (funcall ,box :pandoric-set ,sym ,val)
     ,val))

(defmacro with-pandoric (syms box &rest body)
  (let ((g!box (gensym "box")))
    `(let ((,g!box ,box))
       (declare (ignorable ,g!box))
       (symbol-macrolet
         (,@(mapcar #`(,a1 (get-pandoric ,g!box ',a1))
                    syms))
         ,@body))))

Macroexpansion:
;; (with-pandoric (sum count) #'counter
;;   (format t "sum=~a count=~a~%" sum count)
;;   (incf sum 10)
;;   (setf count 0))
;;
;; Expands to:
;; (SYMBOL-MACROLET
;;   ((SUM (GET-PANDORIC #:BOX123 'SUM))
;;    (COUNT (GET-PANDORIC #:BOX123 'COUNT)))
;;   (FORMAT T "sum=~a count=~a~%" SUM COUNT)
;;   (INCF SUM 10)
;;   (SETF COUNT 0))
;;
;; Reading SUM expands to (GET-PANDORIC ... 'SUM)
;; Writing SUM expands to setf -> get-pandoric setf expander
You are a Common Lisp macro expert. Given this code pattern:
(define-interpreter oid:+int2+ "int2" int 2)

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

Macro definition:
(defmacro define-interpreter (oid name fields &body value)
  "Shorthand for defining binary readers."
  (declare (ignore name)) ;; Names are there just for clarity
  `(set-sql-reader ,oid (binary-reader ,fields ,@value) :binary-p t))

Macroexpansion:
(set-sql-reader cl-postgres-oid:+int2+ (binary-reader int 2) :binary-p t)
Create a Common Lisp macro for the following transformation. Before code:
(define-column-type enum (&rest candidates) `(:enum ,@(mapcar #'(lambda (candidate) (if (symbolp candidate) (symbol-name-literally candidate) candidate)) candidates)))

What needs to change: Macro call that should be transformed by define-column-type

Macro definition:
(defmacro define-column-type (type-symbol lambda-list &body body)
  (let ((type (gensym "TYPE"))
        (args (gensym "ARGS")))
    `(defmethod cltype-to-dbtype ((,type (eql ',type-symbol)) &rest ,args)
       (declare (ignore ,type))
       (destructuring-bind ,lambda-list ,args
         ,@body))))

Macroexpansion:
(defmethod cltype-to-dbtype ((#:type228 (eql (quote enum))) &rest #:args229) (declare (ignore #:type228)) (destructuring-bind (&rest candidates) #:args229 (sb-int:quasiquote (:enum #S(sb-impl::comma :expr (mapcar (function (lambda (candidate) (if (symbolp candidate) (symbol-name-literally candidate) candidate))) candidates) :kind 2)))))
Write a Common Lisp macro to handle this code pattern:
(-<>> nil :key nil)

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

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

Macroexpansion:
((:key nil))
Write a Common Lisp macro to handle this code pattern:
(defgeneric* nil
    (progn))

Problem: Macro call that should be transformed by DEFGENERIC*

Macro definition:
(defmacro DEFGENERIC* ...)

Macroexpansion:
(defgeneric (progn))
Create a Common Lisp macro for the following transformation. Before code:
(with-decoder-simple-clos-semantics (setf x (decode-json-from-string "{\"x\":1}")) (is (equal (symbol-package (first-bound-slot-name x)) (find-package :json-test))))

What needs to change: Macro call that should be transformed by with-decoder-simple-clos-semantics

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

Macroexpansion:
(with-shadowed-custom-vars (set-decoder-simple-clos-semantics) (setf x (decode-json-from-string "{\"x\":1}")) (is (equal (symbol-package (first-bound-slot-name x)) (find-package :json-test))))
You are a Common Lisp macro expert. Given this code pattern:
(defvariant 'some-name)

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

Macro definition:
(defmacro DEFVARIANT ...)

Macroexpansion:
(progn
 (defstruct (quote (:constructor nil) some-name))
 (defmacro match-quote (expr &body match-cases)
   #A((36) base-char . "Match values of variant type: QUOTE.")
   (let ((expr-var (gensym "-val")))
     `(let ((,expr-var ,expr))
        ,(build-dispatch `,'quote `,'nil match-cases expr-var)))))
Create a Common Lisp macro for the following transformation. Before code:
(assoc-cdr "state" parameters #'equal)

What needs to change: Macro call that should be transformed by assoc-cdr

Macro definition:
(defmacro assoc-cdr (key alist &optional (test '#'eql))
  `(cdr (assoc ,key ,alist :test ,test)))

Macroexpansion:
(cdr (assoc "state" parameters :test (function equal)))