j14i/cl-macros huggingface dataset:
You are a Common Lisp macro expert. Given this code pattern:
(defclause-sequence in-string index-of-string :access-fn 'char :size-fn 'length :sequence-type 'string :element-type 'character :element-doc-string "Characters in a string" :index-doc-string "Indices of a string")

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

Macro definition:
(defmacro defclause (clause-template &body body)
  (define-clause 'defun clause-template body nil))

Macroexpansion:
(progn (defclause-driver (for var in-string seq &sequence) "Characters in a string" (return-sequence-code :element-var var :sequence seq :access-fn (quote char) :size-fn (quote length) :element-type (quote character) :sequence-type (quote string))) (defclause-driver (for var index-of-string seq &sequence) "Indices of a string" (cond (with-index (clause-error "WITH-INDEX should not be specified for this clause")) (t (setq with-index var) (return-sequence-code :sequence seq :size-fn (quote length) :sequence-type (quote string))))))
Create a Common Lisp macro for the following transformation. Before code:
(match 1 (2 2))

What needs to change: 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 ((#:var149 1)) (declare (ignorable #:var149)) (%or (%if (%equals #:var149 2) (%or 2 (fail)) (fail)) nil))
Write a Common Lisp macro to handle this code pattern:
(defsynonym else :else)

Problem: 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 else) (quote synonym)) (quote :else)))
Write a Common Lisp macro to handle this code pattern:
(with-reader-syntax (run-program)- (is (string= "hello world" (er "(with-output-to-string (*standard-output*) #!echo -n hello world )"))))

Problem: 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 run-program)))) - (is (string= "hello world" (er "(with-output-to-string (*standard-output*) #!echo -n hello world )"))))
Write a Common Lisp macro to handle this code pattern:
(prepend (default-driver-code) body)

Problem: Macro call that should be transformed by prepend

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

Macroexpansion:
(setf body (nconc (default-driver-code) body))
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))))
Define a macro that eliminates this repetitive pattern:
(unless 'some-name)

Issue: Macro call that should be transformed by UNLESS

Macro definition:
(defmacro UNLESS ...)

Macroexpansion:
(if 'some-name
    nil
    nil)
Define a macro that eliminates this repetitive pattern:
(*> (char #\a) (char #\b))

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 (#:*>-offset189) (multiple-value-bind (#:*>-res190 #:*>-next191) (funcall (char #\LATIN_SMALL_LETTER_A) #:*>-offset189) (if (ok? #:*>-res190) (funcall (char #\LATIN_SMALL_LETTER_B) #:*>-next191) (fail #:*>-next191))))
You are a Common Lisp macro expert. Given this code pattern:
(with-yield-binds (format nil (if *inside-function-op* "(~A ~{~A~^ ~})" "~A ~{~A~^ ~}") (sql-statement-name statement) (mapcar #'yield (sql-composed-statement-children statement))))

Write a macro that addresses: 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 (if *inside-function-op* "(~A ~{~A~^ ~})" "~A ~{~A~^ ~}") (sql-statement-name statement) (mapcar (function yield) (sql-composed-statement-children statement)))) (loop for bind in (reverse *bind-values*) append bind)))
Write a Common Lisp macro to handle this code pattern:
(rem-plist-val! nil (progn))

Problem: Macro call that should be transformed by REM-PLIST-VAL!

Macro definition:
(defmacro rem-plist-val! (id place &key (test '(default-test)) (key '(default-key)))
  `(setf ,place
    (rem-plist-val ,id ,place :test ,test :key ,key)))

Macroexpansion:
(setf (progn)
        (rem-plist-val nil (progn) :test (default-test) :key (default-key)))
Define a macro that eliminates this repetitive pattern:
(define-error merge-env-func-scope-mismatch () (env-a env-b) "Attempting to merge two environments with different function scopes ~s~%~s~%~s" (cons (v-function-scope env-a) (v-function-scope env-b)) env-a env-b)

Issue: 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 merge-env-func-scope-mismatch (:error-type varjo-error :prefix "Varjo") (env-a env-b) "Attempting to merge two environments with different function scopes ~s~%~s~%~s" (cons (v-function-scope env-a) (v-function-scope env-b)) env-a env-b)
You are a Common Lisp macro expert. Given this code pattern:
(any-of nil)

Write a macro that addresses: Macro call that should be transformed by ANY-OF

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

Macroexpansion:
(lc (nil) thereis)
Write a Common Lisp macro to handle this code pattern:
(insert-char-class-tester (regex (schar *string* curr-pos)) (greedy-constant-length-closure (char-class-test)))

Problem: Macro call that should be transformed by insert-char-class-tester

Macro definition:
(defmacro insert-char-class-tester ((char-class chr-expr) &body body)
  "Utility macro to replace each occurence of '\(CHAR-CLASS-TEST)
within BODY with the correct test (corresponding to CHAR-CLASS)
against CHR-EXPR."
  (with-rebinding (char-class)
    (with-unique-names (test-function)
      (flet ((substitute-char-class-tester (new)
               (subst new '(char-class-test) body
                      :test #'equalp)))
        `(let ((,test-function (test-function ,char-class)))
           ,@(substitute-char-class-tester
              `(funcall ,test-function ,chr-expr)))))))

Macroexpansion:
(let ((#:char-class157 regex)) (let ((#:test-function158 (test-function #:char-class157))) (greedy-constant-length-closure (funcall #:test-function158 (schar *string* curr-pos)))))
You are a Common Lisp macro expert. Given this code pattern:
(define-simple-definition-resolver condition designator-condition-p)

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 condition (condition #:package138) (when (ignore-errors (designator-condition-p condition)) (list (make-instance (quote condition) :designator condition :package #:package138))))
You are a Common Lisp macro expert. Given this code pattern:
(labels* nil
  nil)

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

Macro definition:
(defmacro LABELS* ...)

Macroexpansion:
(labels ()
  nil)
Generate a defmacro form that transforms code like this:
(with-component-testers (a b #'pathname-device) (components-are-member '(nil :unspecific)) (components-are-string=))

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

Macro definition:
(defmacro with-component-testers ((a b key) &body body)
  (let ((k (gensym)))
    `(let* ((,k ,key)
            (,a (funcall ,k ,a))
            (,b (funcall ,k ,b)))
       (labels ((components-are (test)
                  (and (funcall test ,a) (funcall test ,b)))
                (components-are-member (values)
                  (and (member ,a values :test #'eql)
                       (member ,b values :test #'eql)
                       (eql ,a ,b)))
                (components-are-string= ()
                  (and (stringp ,a) (stringp ,b) (string= ,a ,b)))
                (components-are-every (test)
                  (and (consp ,a)
                       (consp ,b)
                       (every test ,a ,b))))
         (declare (ignorable #'components-are #'components-are-member
                             #'components-are-string= #'components-are-every))
         (if (or ,@body)
             (values t ,a ,b)
             nil)))))

Macroexpansion:
(let* ((#:g144 (function pathname-device)) (a (funcall #:g144 a)) (b (funcall #:g144 b))) (labels ((components-are (test) (and (funcall test a) (funcall test b))) (components-are-member (values) (and (member a values :test (function eql)) (member b values :test (function eql)) (eql a b))) (components-are-string= nil (and (stringp a) (stringp b) (string= a b))) (components-are-every (test) (and (consp a) (consp b) (every test a b)))) (declare (ignorable (function components-are) (function components-are-member) (function components-are-string=) (function components-are-every))) (if (or (components-are-member (quote (nil :unspecific))) (components-are-string=)) (values t a b) nil)))
You are a Common Lisp macro expert. Given this code pattern:
(destructuring-case nil
  (progn))

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

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

Macroexpansion:
(destructuring-case-alt nil
  (progn nil))
You are a Common Lisp macro expert. Given this code pattern:
(is = (get-universal-time) 2962566000)

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

Macro definition:
(defmacro is (comp expected form &optional description &rest format-args)
  `(eval-in-context
    *context*
    (make-instance 'comparison-result
                   :expression '(is ,comp ,expected ,form)
                   :value-form ',form
                   :body (lambda () ,form)
                   :expected ,expected
                   :comparison ,(maybe-quote comp)
                   ,@(when description
                       `(:description (format NIL ,description ,@format-args))))))

Macroexpansion:
(eval-in-context *context* (make-instance (quote comparison-result) :expression (quote (is = (get-universal-time) 2962566000)) :value-form (quote 2962566000) :body (lambda nil 2962566000) :expected (get-universal-time) :comparison (quote =)))
Define a macro that eliminates this repetitive pattern:
(ƒ 'some-name)

Issue: Macro call that should be transformed by Ƒ

Macro definition:
(defmacro Ƒ ...)

Macroexpansion:
(defun 'some-name (&optional α)
  (let ((α (or α t)))
    (cond)))
Generate a defmacro form that transforms code like this:
(defun/1 fgets (str n fd) (fgets-is-dumb str n fd nil))

Pattern to recognize: Macro call that should be transformed by defun/1

Macro definition:
(defmacro defun/1 (name arglist &body body)
  "Lisp-1 defun; makes function pointers work."
  `(progn
     (defun ,name ,arglist
       (declare (optimize (speed 0) (debug 3)
                          ;; FIXME: Why do minor warnings result in load errors?
                          #+sbcl (sb-ext:inhibit-warnings 3)))
        
       ,@body)
     (defparameter ,name (vacietis.c:mkptr& (symbol-function ',name)))))

Macroexpansion:
(progn (defun fgets (str n fd) (declare (optimize (speed 0) (debug 3) (sb-ext:inhibit-warnings 3))) (fgets-is-dumb str n fd nil)) (defparameter fgets (vacietis.c:mkptr& (symbol-function (quote fgets)))))
Write a Common Lisp macro to handle this code pattern:
(builder (:auth-basic :authenticator (lambda (user pass) (when (and (string= user "nitro_idiot") (string= pass "password")) (values t "Eitaro Fukamachi")))) (lambda (env) `(200 () (,(format nil "Hello, ~A" (getf env :remote-user))))))

Problem: 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 (lambda (#:app188) (funcall (find-middleware :auth-basic) #:app188 :authenticator (lambda (user pass) (when (and (string= user "nitro_idiot") (string= pass "password")) (values t "Eitaro Fukamachi"))))))) :initial-value (to-app (lambda (env) (sb-int:quasiquote (200 nil (#S(sb-impl::comma :expr (format nil "Hello, ~A" (getf env :remote-user)) :kind 0)))))) :from-end t)
You are a Common Lisp macro expert. Given this code pattern:
(-> :g () (put 0) t)

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

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

Macroexpansion:
(atomically :g nil (put 0) t)
Write a Common Lisp macro to handle this code pattern:
(alist-bind ((type-tag :tag)) type (cond ((or (string= ":char" type-tag) (string= ":unsigned-char" type-tag)) '((:string))) (t `((:pointer ,@(parse-type type type-tag))))))

Problem: 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 ((#:alist235 type)) (let ((type-tag (aval :tag #:alist235))) (cond ((or (string= ":char" type-tag) (string= ":unsigned-char" type-tag)) (quote ((:string)))) (t (sb-int:quasiquote ((:pointer #S(sb-impl::comma :expr (parse-type type type-tag) :kind 2))))))))
Create a Common Lisp macro for the following transformation. Before code:
(define-mustache-character #\# (make-instance 'section-start-tag :text arg-text :end end :open-delimiter *open-delimiter* :close-delimiter *close-delimiter*))

What needs to change: Macro call that should be transformed by define-mustache-character

Macro definition:
(defmacro define-mustache-character (char &body body)
  `(set-mustache-character
    ,char (lambda (raw-text arg-text escapep start end)
            (declare (ignorable raw-text arg-text escapep start end)
                     (type simple-string raw-text arg-text)
                     (boolean escapep)
                     (offset start end))
            ,@body)))

Macroexpansion:
(set-mustache-character #\NUMBER_SIGN (lambda (raw-text arg-text escapep start end) (declare (ignorable raw-text arg-text escapep start end) (type simple-string raw-text arg-text) (boolean escapep) (offset start end)) (make-instance (quote section-start-tag) :text arg-text :end end :open-delimiter *open-delimiter* :close-delimiter *close-delimiter*)))
Create a Common Lisp macro for the following transformation. Before code:
(dreletf* nil
  :key
  nil)

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

Macro definition:
(defmacro DRELETF* ...)

Macroexpansion:
(progn :key nil)
Generate a defmacro form that transforms code like this:
(labels* nil
  :key
  nil)

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

Macro definition:
(defmacro LABELS* ...)

Macroexpansion:
(labels ()
  :key
  nil)
Create a Common Lisp macro for the following transformation. Before code:
(with-additional-indent (reporter stream "~& ") (with-color (:red :stream stream) (with-additional-indent (reporter stream "× ") (when (slot-value report 'description) (format/indent reporter stream "~A~%" (slot-value report 'description))) (format/indent reporter stream "Raised an error ~A (expected: ~S)" (slot-value report 'got) (slot-value report 'expected)))))

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

Macro definition:
(defmacro with-additional-indent ((reporter stream control-string &rest format-arguments) &body body)
  (declare (ignorable reporter stream control-string))
  (let* ((need-new-line (ppcre:scan "^~&" control-string))
         (string (apply #'format nil control-string format-arguments))
         (increment (length string)))
    `(with-slots (indent-space) reporter
       (let* ((first-line-indent (indent indent-space))
              (*additional-indent* ,(if need-new-line
                                        increment
                                        `(+ *additional-indent*
                                            ,increment))))
         (declare (ignorable first-line-indent))
         ,(if need-new-line
              `(progn (fresh-line stream)
                      (write-string first-line-indent ,stream)
                      ;; because we just started a new line, we
                      ;; should use format/indent to write string
                      ;; taking into account a main indentation level
                      (format/indent ,reporter ,stream ,string))
              ;; otherwise, just output our prefix
              `(write-string ,string ,stream))
       
       
         ,@body))))

Macroexpansion:
(with-slots (indent-space) reporter (let* ((first-line-indent (indent indent-space)) (*additional-indent* 1)) (declare (ignorable first-line-indent)) (progn (fresh-line stream) (write-string first-line-indent stream) (format/indent reporter stream #A((1) base-char . " "))) (with-color (:red :stream stream) (with-additional-indent (reporter stream "× ") (when (slot-value report (quote description)) (format/indent reporter stream "~A~%" (slot-value report (quote description)))) (format/indent reporter stream "Raised an error ~A (expected: ~S)" (slot-value report (quote got)) (slot-value report (quote expected)))))))
You are a Common Lisp macro expert. Given this code pattern:
(defun/1 fopen (filename mode) (handler-case (make-instance 'FILE :stream (open-stream filename mode)) (file-error () (setf errno ENOENT) NULL) (error () NULL)))

Write a macro that addresses: Macro call that should be transformed by defun/1

Macro definition:
(defmacro defun/1 (name arglist &body body)
  "Lisp-1 defun; makes function pointers work."
  `(progn
     (defun ,name ,arglist
       (declare (optimize (speed 0) (debug 3)
                          ;; FIXME: Why do minor warnings result in load errors?
                          #+sbcl (sb-ext:inhibit-warnings 3)))
        
       ,@body)
     (defparameter ,name (vacietis.c:mkptr& (symbol-function ',name)))))

Macroexpansion:
(progn (defun fopen (filename mode) (declare (optimize (speed 0) (debug 3) (sb-ext:inhibit-warnings 3))) (handler-case (make-instance (quote file) :stream (open-stream filename mode)) (file-error nil (setf errno enoent) null) (error nil null))) (defparameter fopen (vacietis.c:mkptr& (symbol-function (quote fopen)))))