j14i/cl-macros huggingface dataset:
Write a Common Lisp macro to handle this code pattern:
(fail "This is supposed to fail")

Problem: Macro call that should be transformed by fail

Macro definition:
(defmacro fail (&rest message-args)
  "Simply generate a FAIL."
  `(process-failure ',message-args
                    ,@message-args))

Macroexpansion:
(process-failure (quote ("This is supposed to fail")) "This is supposed to fail")
You are a Common Lisp macro expert. Given this code pattern:
(define-templated-dispatch nil
    (progn))

Write a macro that addresses: Macro call that should be transformed by DEFINE-TEMPLATED-DISPATCH

Macro definition:
(defmacro DEFINE-TEMPLATED-DISPATCH ...)

Macroexpansion:
(define-type-dispatch nil
    (progn))
Create a Common Lisp macro for the following transformation. Before code:
(unwind-protect nil
    (progn))

What needs to change: Macro call that should be transformed by UNWIND-PROTECT

Macro definition:
(defmacro UNWIND-PROTECT ...)

Macroexpansion:
(common-lisp:unwind-protect (progn))
Define a macro that eliminates this repetitive pattern:
(defhandler let* (let* bindings &rest body) (if (not bindings) (e `(locally ,@body)) (destructuring-bind (first &rest rest) bindings (e `(let (,first) ,@(if rest `((,let* ,rest ,@body)) body))))))

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-let* (let* bindings &rest body) (if (not bindings) (e (sb-int:quasiquote (locally #S(sb-impl::comma :expr body :kind 2)))) (destructuring-bind (first &rest rest) bindings (e (sb-int:quasiquote (let (#S(sb-impl::comma :expr first :kind 0)) #S(sb-impl::comma :expr (if rest (sb-int:quasiquote ((#S(sb-impl::comma :expr let* :kind 0) #S(sb-impl::comma :expr rest :kind 0) #S(sb-impl::comma :expr body :kind 2)))) body) :kind 2))))))) (setf (gethash (quote let*) *form-handler*) (quote hander-let*)))
You are a Common Lisp macro expert. Given this code pattern:
(disable-curly-syntax)

Write a macro that addresses: Macro call that should be transformed by DISABLE-CURLY-SYNTAX

Macro definition:
(defmacro DISABLE-CURLY-SYNTAX ...)

Macroexpansion:
(eval-when (:compile-toplevel :load-toplevel :execute)
  (unless *original-readtable* (error "Curly syntax not enabled."))
  (setf *readtable* *original-readtable*
        *original-readtable* nil))
Write a Common Lisp macro to handle this code pattern:
(ct-let nil)

Problem: Macro call that should be transformed by CT-LET

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

Macroexpansion:
(cond
 (*within-captured-dynenv*
  (let ()
    (let ((#:new-var-space146
           (reduce
            (lambda (#:accum147 #:item148)
              (destructuring-bind
                  (#:name149 . #:value150)
                  #:item148
                (update-alist #:name149 #:value150 #:accum147)))
            (list) :initial-value *var-space*)))
      `(symbol-macrolet ((var-space ,#:new-var-space146))
         ,(let ((*var-space* #:new-var-space146)))))))
 (t
  (error
   "No macrodynamic environment has been captured to establish CT-LET bindings.")))
Write a Common Lisp macro to handle this code pattern:
(define-screamer-package :screamer-tests (:use :cl :hu.dwim.stefil) (:export #:test-screamer #:screamer-tests))

Problem: Macro call that should be transformed by define-screamer-package

Macro definition:
(defmacro define-screamer-package (defined-package-name &body options)
  "Convenience wrapper around DEFPACKAGE. Passes its argument directly
to DEFPACKAGE, and automatically injects two additional options:

    \(:shadowing-import-from :screamer :defun :multiple-value-bind :y-or-n-p)
    \(:use :cl :screamer)"
  `(defpackage ,defined-package-name
     ,@options
     (:shadowing-import-from :screamer :defun :multiple-value-bind :y-or-n-p)
     (:use :cl :screamer)))

Macroexpansion:
(defpackage :screamer-tests (:use :cl :hu.dwim.stefil) (:export #:test-screamer #:screamer-tests) (:shadowing-import-from :screamer :defun :multiple-value-bind :y-or-n-p) (:use :cl :screamer))
You are a Common Lisp macro expert. Given this code pattern:
(destructuring-match nil)

Write a macro that addresses: Macro call that should be transformed by DESTRUCTURING-MATCH

Macro definition:
(defmacro DESTRUCTURING-MATCH ...)

Macroexpansion:
(let ((#:form nil))
  (block #:done
    (let ((#:done
           (lambda (&rest values)
             (declare (dynamic-extent values))
             (return-from #:done (values-list values)))))
      (tagbody))))
Write a Common Lisp macro to handle this code pattern:
(do-matches-as-strings (match regex target-string (nreverse result-list) :start start :end end :sharedp sharedp) (push match result-list))

Problem: Macro call that should be transformed by do-matches

Macro definition:
(defmacro do-matches ((match-start match-end regex
                                   target-string
                                   &optional result-form
                                   &key start end)
                      &body body)
  "Iterates over TARGET-STRING and tries to match REGEX as often as
possible evaluating BODY with MATCH-START and MATCH-END bound to the
start/end positions of each match in turn.  After the last match,
returns RESULT-FORM if provided or NIL otherwise.  An implicit block
named NIL surrounds DO-MATCHES; RETURN may be used to terminate the
loop immediately.  If REGEX matches an empty string the scan is
continued one position behind this match.  BODY may start with
declarations."
  ;; this is a simplified form of DO-SCANS - we just provide two dummy
  ;; vars and ignore them
  (with-unique-names (reg-starts reg-ends)
    `(do-scans (,match-start ,match-end
                ,reg-starts ,reg-ends
                ,regex ,target-string
                ,result-form
                :start ,start :end ,end)
      ,@body)))

Macroexpansion:
(let ((#:target-string141 target-string)) (let ((#:substr-fn144 (if sharedp (function nsubseq) (function subseq)))) (do-matches (#:match-start142 #:match-end143 regex #:target-string141 (nreverse result-list) :start start :end end) (let ((match (funcall #:substr-fn144 #:target-string141 #:match-start142 #:match-end143))) (push match result-list)))))
Generate a defmacro form that transforms code like this:
(c-assert (eql :nascent (md-state 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 (eql :nascent (md-state self)) (c-break "failed assertion: ~a" (quote (eql :nascent (md-state self))))))
Write a Common Lisp macro to handle this code pattern:
(def-neo4j-fun get-paths (node-id to-node-id relationships (max-depth 3) (algorithm :shortest-path)) :post (:uri-spec (format nil "node/~A/paths" node-id)) (:encode (list (list (cons "to" to-node-id) :node-url) (list (cons "relationships" relationships)) (list (cons "max_depth" max-depth)) (list (cons "algorithm" (case algorithm (:shortest-path "shortestPath") (:all-paths "allPaths") (:all-simple-paths "allSimplePaths") (:dijkstra "dijkstra"))))) :object) (:status-handlers (200 (decode-neo4j-json-output body)) (204 (error 'path-not-found-error :uri uri))))

Problem: 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 get-paths (&key node-id to-node-id relationships (max-depth 3) (algorithm :shortest-path)) (let ((uri (format nil "node/~A/paths" node-id)) (json (encode-neo4j-json-payload (list (list (cons "to" to-node-id) :node-url) (list (cons "relationships" relationships)) (list (cons "max_depth" max-depth)) (list (cons "algorithm" (case algorithm (:shortest-path "shortestPath") (:all-paths "allPaths") (:all-simple-paths "allSimplePaths") (:dijkstra "dijkstra"))))) :object))) (make-neo4j-request :post uri json (list (list 200 (lambda (body uri json) (decode-neo4j-json-output body))) (list 204 (lambda (body uri json) (error (quote path-not-found-error) :uri uri))))))))
Define a macro that eliminates this repetitive pattern:
(defstore nxpy (y x &optional (a 1) (b 1)))

Issue: Macro call that should be transformed by defstore

Macro definition:
(defmacro defstore (store-name store-lambda-list &body body &environment env)
  (let* ((store-class-name (second (find :store-class body :key #'first)))
         (store-class (etypecase store-class-name
                        (null (find-class 'standard-store))
                        (symbol (find-class store-class-name))))
         (form (apply #'defstore-using-class store-class store-name store-lambda-list
                      :environment env
                      (mapcan #'(lambda (item)
                                  (cond ((eql (first item) :store-class)
                                         `(:store-class ',store-class-name))
                                        ((and (member (first item) '(:documentation :specialization-class)))
                                         (if (= 2 (length item))
                                             item
                                             (error "Invalid store definition option: ~W." item)))
                                        (t
                                         (list (first item) (rest item)))))
                              body))))
    `(eval-when (:compile-toplevel :load-toplevel :execute)
       ,form)))

Macroexpansion:
(eval-when (:compile-toplevel :load-toplevel :execute) (progn (ensure-store (quote nxpy) (quote (y x &optional (a 1 #:a?149) (b 1 #:b?150))))))
Define a macro that eliminates this repetitive pattern:
(define-modf-rewrite third (expr) `(caddr ,(second expr)))

Issue: 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 third) *modf-rewrites*) (lambda (expr) (sb-int:quasiquote (caddr #S(sb-impl::comma :expr (second expr) :kind 0))))))
You are a Common Lisp macro expert. Given this code pattern:
(when (not (slot-value parent 'tail-qualifiers)) (format stream " "))

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 (not (slot-value parent (quote tail-qualifiers))) (format stream " "))
You are a Common Lisp macro expert. Given this code pattern:
;; Threading a value through multiple dependent checks
(let ((user (find-user id)))
  (if user
      (let ((orders (get-orders user)))
        (if orders
            (let ((latest (first orders)))
              (if latest
                  (process latest)
                  :no-orders))
            :no-orders))
      :no-user))
;; Deeply nested ifs obscure the linear flow

Write a macro that addresses: Threading a value through dependent operations creates deep if-nesting — want linear, pipeline-like syntax

Macro definition:
(defmacro aand (&rest args)
  (cond ((null args) t)
        ((null (cdr args)) (car args))
        (t `(aif ,(car args) (aand ,@(cdr args))))))

Macroexpansion:
;; (aand (find-user id)
;;       (get-orders it)
;;       (first it)
;;       (process it))
;;
;; Each form's result is bound to 'it' for the next form.
;; If any form returns nil, the chain stops and returns nil.
;; Linear, readable, no nesting.
Generate a defmacro form that transforms code like this:
(define-op (:>= infix-op))

Pattern to recognize: 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 (>=-op (:include infix-op (name ">=")) (:constructor make->=-op (left right))))
You are a Common Lisp macro expert. Given this code pattern:
(defun+ nil
    nil)

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

Macro definition:
(defmacro DEFUN+ ...)

Macroexpansion:
(defun nil () (let+ nil))
Define a macro that eliminates this repetitive pattern:
(defun-compile-time cps-convert-function-name (function-name) (if (symbolp function-name) (intern (format nil "~A-NONDETERMINISTIC" (string function-name)) (symbol-package function-name)) `(setf ,(intern (format nil "~A-NONDETERMINISTIC" (string (second function-name))) (symbol-package (second function-name))))))

Issue: Macro call that should be transformed by defun-compile-time

Macro definition:
(defmacro defun-compile-time (function-name lambda-list &body body)
  `(eval-when (:compile-toplevel :load-toplevel :execute)
     (cl:defun ,function-name ,lambda-list ,@body)
     (eval-when (:compile-toplevel) (compile ',function-name))))

Macroexpansion:
(eval-when (:compile-toplevel :load-toplevel :execute) (common-lisp:defun cps-convert-function-name (function-name) (if (symbolp function-name) (intern (format nil "~A-NONDETERMINISTIC" (string function-name)) (symbol-package function-name)) (sb-int:quasiquote (setf #S(sb-impl::comma :expr (intern (format nil "~A-NONDETERMINISTIC" (string (second function-name))) (symbol-package (second function-name))) :kind 0))))) (eval-when (:compile-toplevel) (compile (quote cps-convert-function-name))))
Generate a defmacro form that transforms code like this:
(let-syntax common-lisp:nil (common-lisp:progn))

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

Macro definition:
(defmacro LET-SYNTAX ...)

Macroexpansion:
(common-lisp:progn (common-lisp:progn))
Create a Common Lisp macro for the following transformation. Before code:
(augment steppers step)

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

Macro definition:
(defmacro augment (var stuff)
  `(setf ,var (nconc ,var ,stuff)))

Macroexpansion:
(setf steppers (nconc steppers step))
Write a Common Lisp macro to handle this code pattern:
(destructure-specialized-lambda-list descriptive-lambda-list vanilla-lambda-list type-list specialized-lambda-list `(%lay-method-base-for-dispatch ,generic-function ,qualifier ,type-list ,descriptive-lambda-list ,@body))

Problem: Macro call that should be transformed by destructure-specialized-lambda-list

Macro definition:
(defmacro destructure-specialized-lambda-list (descriptive-lambda-list-sym vanilla-lambda-list-sym type-list-sym specialized-lambda-list &body body)
  "if specialized-lambda-list is ((a integer) b):
descriptive-lambda-list will be ((x integer) (x t))
type-list will be (integer t) and vanilla-lambda-list is (a b)"
  (let ((item (gensym)))
    `(let* ((,descriptive-lambda-list-sym
             (loop :for ,item :in ,specialized-lambda-list
                :if (listp ,item)
                :collect ,item
                :else :collect (list ,item t)))
            (,vanilla-lambda-list-sym (mapcar #'first ,descriptive-lambda-list-sym))
            (,type-list-sym (mapcar #'second ,descriptive-lambda-list-sym)))
       (declare (ignorable ,descriptive-lambda-list-sym ,vanilla-lambda-list-sym ,type-list-sym))
       ,@body)))

Macroexpansion:
(let* ((descriptive-lambda-list (loop :for #:g127 :in specialized-lambda-list :if (listp #:g127) :collect #:g127 :else :collect (list #:g127 t))) (vanilla-lambda-list (mapcar (function first) descriptive-lambda-list)) (type-list (mapcar (function second) descriptive-lambda-list))) (declare (ignorable descriptive-lambda-list vanilla-lambda-list type-list)) (sb-int:quasiquote (%lay-method-base-for-dispatch #S(sb-impl::comma :expr generic-function :kind 0) #S(sb-impl::comma :expr qualifier :kind 0) #S(sb-impl::comma :expr type-list :kind 0) #S(sb-impl::comma :expr descriptive-lambda-list :kind 0) #S(sb-impl::comma :expr body :kind 2))))
Create a Common Lisp macro for the following transformation. Before code:
(disable-infix-reader)

What needs to change: Macro call that should be transformed by DISABLE-INFIX-READER

Macro definition:
(defmacro DISABLE-INFIX-READER ...)

Macroexpansion:
(eval-when (:compile-toplevel :load-toplevel :execute)
  (setq *readtable* (pop *readtables*)))
Create a Common Lisp macro for the following transformation. Before code:
(defsynonym for :for)

What needs to change: 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 for) (quote synonym)) (quote :for)))
Define a macro that eliminates this repetitive pattern:
(signal-syntax-error* (1- (lexer-pos lexer)) "Character '~A' may not follow '(?<'." next-char )

Issue: Macro call that should be transformed by signal-syntax-error*

Macro definition:
(defmacro signal-syntax-error* (pos format-control &rest format-arguments)
  `(error 'ppcre-syntax-error
          :pos ,pos
          :format-control ,format-control
          :format-arguments (list ,@format-arguments)))

Macroexpansion:
(error (quote ppcre-syntax-error) :pos (1- (lexer-pos lexer)) :format-control "Character '~A' may not follow '(?<'." :format-arguments (list next-char))
Define a macro that eliminates this repetitive pattern:
(define BUFSIZ 512)

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 bufsiz) *preprocessor-defines*) #A((3) base-char . "512"))) (defparameter bufsiz 512))
Define a macro that eliminates this repetitive pattern:
(define-modf-rewrite cdaadr (expr) `(cdr (caadr ,(second expr))))

Issue: 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 cdaadr) *modf-rewrites*) (lambda (expr) (sb-int:quasiquote (cdr (caadr #S(sb-impl::comma :expr (second expr) :kind 0)))))))
Write a Common Lisp macro to handle this code pattern:
(letrec* ((f (constantly t)) (a (funcall f))) (is-true a))

Problem: Macro call that should be transformed by letrec*

Macro definition:
(defmacro letrec* ((&rest bindings) &body body)
  "Like LETREC, but the bindings are evaluated in order.
See Waddell et al., *Fixing Letrec* for motivation.

Cf. `fbindrec*'."
  `(letrec-with setq ,bindings
     ,@body))

Macroexpansion:
(letrec-with setq ((f (constantly t)) (a (funcall f))) (is-true a))
Write a Common Lisp macro to handle this code pattern:
(gather-next nil nil)

Problem: Macro call that should be transformed by GATHER-NEXT

Macro definition:
(defmacro GATHER-NEXT ...)

Macroexpansion:
(common-lisp:funcall nil nil nil)