j14i/cl-macros huggingface dataset:
Define a macro that eliminates this repetitive pattern:
(destructuring-bind () (progn))

Issue: Macro call that should be transformed by DESTRUCTURING-BIND

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

Macroexpansion:
(sb-int:binding* ((nil (sb-c::check-ds-list (progn) 0 0 'nil))))
Define a macro that eliminates this repetitive pattern:
(do-generator (item generator) (push (funcall function item) result))

Issue: Macro call that should be transformed by do-generator

Macro definition:
(defmacro do-generator ((var &rest vars-and-generator) &body body)
  "Steps through the specified generator, binding the value it returns to var, then executing the body for each step. If multiple variables are specified and the generator returns multiple values, the extra values will be bound to the extra variables."
  (let ((g (gensym)))
    `(let ((,g ,(car (last vars-and-generator))))
       (loop 
	  do (if-generator ((,var ,@(butlast vars-and-generator)) ,g)
			   (progn
			     ,@body)
			   (return))))))

Macroexpansion:
(let ((#:g169 generator)) (loop do (if-generator ((item) #:g169) (progn (push (funcall function item) result)) (return))))
Write a Common Lisp macro to handle this code pattern:
(and nil (progn))

Problem: Macro call that should be transformed by AND

Macro definition:
(defmacro AND ...)

Macroexpansion:
(if nil
    (progn))
Generate a defmacro form that transforms code like this:
(->)

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

Macro definition:
(defmacro -> ...)

Macroexpansion:
nil
Define a macro that eliminates this repetitive pattern:
(letrec (x) x)

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 (x) x)
Generate a defmacro form that transforms code like this:
(with-table-name nil (yield (else-op-var op)))

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

Macro definition:
(defmacro with-table-name (table-name &body body)
  `(let ((*table-name-scope* ,table-name))
     ,@body))

Macroexpansion:
(let ((*table-name-scope* nil)) (yield (else-op-var op)))
Define a macro that eliminates this repetitive pattern:
(with-package (package) (do-symbols (symbol package) (when (eql (symbol-package symbol) package) (when (fboundp symbol) (fmakunbound symbol)) (when (boundp symbol) (makunbound symbol)))) (delete-package package))

Issue: Macro call that should be transformed by with-package

Macro definition:
(defmacro with-package ((var &optional (package var)) &body body)
  `(let ((,var (ensure-package ,package)))
     ,@body))

Macroexpansion:
(let ((package (ensure-package package))) (do-symbols (symbol package) (when (eql (symbol-package symbol) package) (when (fboundp symbol) (fmakunbound symbol)) (when (boundp symbol) (makunbound symbol)))) (delete-package package))
You are a Common Lisp macro expert. Given this code pattern:
(without-trailing-space (funcall body))

Write a macro that addresses: Macro call that should be transformed by without-trailing-space

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

Macroexpansion:
(flet ((#:stack-fn-body1 nil (funcall body))) (declare (dynamic-extent (function #:stack-fn-body1))) (symbol-macrolet ((#:stack-fn-body1 (function #:stack-fn-body1))) (call-without-trailing-space #:stack-fn-body1)))
Generate a defmacro form that transforms code like this:
;; format with constant control strings interprets directives at runtime
(format nil "Value: ~a, Name: ~a" val name)
;; Every call: parse the ~a directives, resolve them, dispatch formatting
;; The format string is known at compile time but still interpreted at runtime

Pattern to recognize: format with compile-time-constant control strings wastes time interpreting directives at runtime — want compile-time compilation of format strings

Macro definition:
(defun fformat (&rest all)
  (apply #'format all))

(define-compiler-macro fformat
                       (&whole form
                        stream fmt &rest args)
  (if (constantp fmt)
    (if stream
      `(funcall (formatter ,fmt)
         ,stream ,@args)
      (let ((g!stream (gensym "stream")))
        `(with-output-to-string (,g!stream)
           (funcall (formatter ,fmt)
             ,g!stream ,@args))))
    form))

Macroexpansion:
;; (fformat t "Value: ~a, Name: ~a" val name)
;; Compiler macro sees constant fmt, expands to:
;; (FUNCALL (FORMATTER "Value: ~a, Name: ~a") T VAL NAME)
;;
;; formatter macro-expands the control string into direct
;; write-string, princ, etc. calls - no runtime parsing.
;;
;; When fmt is NOT constant: returns original form unchanged.
;; Graceful degradation - always correct, sometimes faster.
Create a Common Lisp macro for the following transformation. Before code:
(with-connection (let ((user (retrieve-one (select :* (from :user) (where (:= :name "nitro_idiot")))))) (is user `(:id 1 :name "nitro_idiot" :email "e.arrows@gmail.com" :status "normal" :created-at ,(princ-to-string *now*) :updated-at nil))))

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

Macro definition:
(defmacro with-connection (&body body)
  `(let ((*connection* (connect-cached :sqlite3 :database-name *db-path*)))
     ,@body))

Macroexpansion:
(let ((let (connect ((user (retrieve-one (select :* (from :user) (where (:= :name "nitro_idiot")))))) (is user (sb-int:quasiquote (:id 1 :name "nitro_idiot" :email "e.arrows@gmail.com" :status "normal" :created-at #S(sb-impl::comma :expr (princ-to-string *now*) :kind 0) :updated-at nil)))))) (unwind-protect (progn) (disconnect let)))
Create a Common Lisp macro for the following transformation. Before code:
(with-hamt dict (:test test :hash hash :table table) (flet ((%remove (table key) (%hamt-remove table key (funcall hash key) 0 test))) (make-instance 'hash-dict :test test :hash hash :table (reduce #'%remove keys :initial-value table))))

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

Macro definition:
(defmacro with-hamt (hamt (&key test hash table) &body body)
  "Accessing HAMT slots"
  `(with-accessors ((,test hamt-test)
                    (,hash hamt-hash)
                    (,table hamt-table))
       ,hamt
     ,@body))

Macroexpansion:
(with-accessors ((test hamt-test) (hash hamt-hash) (table hamt-table)) dict (flet ((%remove (table key) (%hamt-remove table key (funcall hash key) 0 test))) (make-instance (quote hash-dict) :test test :hash hash :table (reduce (function %remove) keys :initial-value table))))
Write a Common Lisp macro to handle this code pattern:
(destructuring-bind* nil
    (progn))

Problem: Macro call that should be transformed by DESTRUCTURING-BIND*

Macro definition:
(defmacro DESTRUCTURING-BIND* ...)

Macroexpansion:
(let (#:in-body130)
  (flet ((#:handle131 (#:condition132)
           (unless #:in-body130
             (error
              (make-condition 'destructuring-error :lambda-list 'nil
                              :expression '(progn) :reason #:condition132)))))
    (declare (ignorable (function #:handle131)))
    (let ((#:value133 (progn)))
      (handler-bind ((error #'#:handle131))
        (destructuring-bind () #:value133 (setf #:in-body130 t) (locally))))))
You are a Common Lisp macro expert. Given this code pattern:
(set-dynamic nil (progn))

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

Macro definition:
(defmacro SET-DYNAMIC ...)

Macroexpansion:
(setf (dynamic (progn)) nil)
Define a macro that eliminates this repetitive pattern:
(actypecase :foo (string (list :string it)) (keyword (list :keyword it)) (symbol (list :symbol it)))

Issue: Macro call that should be transformed by actypecase

Macro definition:
(defmacro actypecase (keyform &body cases)
  "Like CTYPECASE, except binds the result of the keyform to IT (via LET) for
the scope of the cases. Unlike CTYPECASE, new values possible stored by the
STORE-VALUE restart are not received by the keyform/place, but by IT."
  `(anaphoric ctypecase ,keyform ,@cases))

Macroexpansion:
(anaphoric ctypecase :foo (string (list :string it)) (keyword (list :keyword it)) (symbol (list :symbol it)))
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))))
Write a Common Lisp macro to handle this code pattern:
(def-launched-iter nil
    nil)

Problem: Macro call that should be transformed by DEF-LAUNCHED-ITER

Macro definition:
(defmacro DEF-LAUNCHED-ITER ...)

Macroexpansion:
(defun nil ()
  (let ((it (make-instance 'iterator :coro (lambda-coro))))
    (inext-or-error it)
    it))
Write a Common Lisp macro to handle this code pattern:
(define-value-binding on (var list &key (by NIL by-p)) (declare (type list list)) `(cond (,list ,(if by-p `(progn (update ,var ,list) (setf ,list (funcall ,by ,list))) `(progn (update ,var ,list) (setf ,list (cdr ,list))))) (T (end-for))))

Problem: Macro call that should be transformed by define-value-binding

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

Macroexpansion:
(define-direct-binding on (var list &key (by nil by-p)) (let ((#:list137 (gensym #A((4) base-char . "LIST"))) (#:by138 (gensym #A((2) base-char . "BY")))) (values* (sb-int:quasiquote (with-interleaving (let* #S(sb-impl::comma :expr (list* (list #:list137 list) (list #:by138 by) (loop for #:var136 in (lambda-fiddle:extract-lambda-vars (enlist var)) collect (list #:var136 nil))) :kind 0) (declare (ignorable #S(sb-impl::comma :expr #:list137 :kind 0) #S(sb-impl::comma :expr #:by138 :kind 0))) #S(sb-impl::comma :expr (sb-int:quasiquote (declare (type #S(sb-impl::comma :expr (quote list) :kind 0) #S(sb-impl::comma :expr #:list137 :kind 0)))) :kind 0)) #S(sb-impl::comma :expr nil :kind 0))) (let ((list #:list137) (by #:by138)) (declare (ignorable list by)) (sb-int:quasiquote (cond (#S(sb-impl::comma :expr list :kind 0) #S(sb-impl::comma :expr (if by-p (sb-int:quasiquote (progn (update #S(sb-impl::comma :expr var :kind 0) #S(sb-impl::comma :expr list :kind 0)) (setf #S(sb-impl::comma :expr list :kind 0) (funcall #S(sb-impl::comma :expr by :kind 0) #S(sb-impl::comma :expr list :kind 0))))) (sb-int:quasiquote (progn (update #S(sb-impl::comma :expr var :kind 0) #S(sb-impl::comma :expr list :kind 0)) (setf #S(sb-impl::comma :expr list :kind 0) (cdr #S(sb-impl::comma :expr list :kind 0)))))) :kind 0)) (t (end-for))))))))
Generate a defmacro form that transforms code like this:
(mvlet* nil)

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

Macro definition:
(defmacro MVLET* ...)

Macroexpansion:
(progn)
Define a macro that eliminates this repetitive pattern:
(with-trace-sql (with-prepared-query query (*connection* sql :use-prepare-cached *use-prepare-cached*) (setf query (execute-with-retry query binds)) (query-row-count query)))

Issue: Macro call that should be transformed by with-trace-sql

Macro definition:
(defmacro with-trace-sql (&body body)
  `(let ((dbi:*sql-execution-hooks* (cons #'trace-sql
                                          dbi:*sql-execution-hooks*)))
     ,@body))

Macroexpansion:
(let ((*sql-execution-hooks* (cons (function trace-sql) *sql-execution-hooks*))) (with-prepared-query query (*connection* sql :use-prepare-cached *use-prepare-cached*) (setf query (execute-with-retry query binds)) (query-row-count query)))
Write a Common Lisp macro to handle this code pattern:
(defun-compile-time cps-convert-block (name body continuation types value? environment) (let* ((c (gensym "CONTINUATION-")) (*block-tags* (cons (list name c types value?) *block-tags*))) (possibly-beta-reduce-funcall `#'(lambda (,c) (declare (magic)) ,(cps-convert-progn body c types value? environment)) '() continuation t)))

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 cps-convert-block (name body continuation types value? environment) (let* ((c (gensym "CONTINUATION-")) (*block-tags* (cons (list name c types value?) *block-tags*))) (possibly-beta-reduce-funcall (sb-int:quasiquote (function (lambda (#S(sb-impl::comma :expr c :kind 0)) (declare (magic)) #S(sb-impl::comma :expr (cps-convert-progn body c types value? environment) :kind 0)))) (quote nil) continuation t))) (eval-when (:compile-toplevel) (compile (quote cps-convert-block))))
Define a macro that eliminates this repetitive pattern:
(dletf nil)

Issue: Macro call that should be transformed by DLETF

Macro definition:
(defmacro DLETF ...)

Macroexpansion:
(special-symbol-progv (with-symbol-access
                        (list))
    (list)
  (locally (declare (special))))
Write a Common Lisp macro to handle this code pattern:
(define-error invalid-symbol-macro-form () (name form) "Symbol macros must expand to a list or atom form : ~s -> ~s~%" name form)

Problem: 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 invalid-symbol-macro-form (:error-type varjo-error :prefix "Varjo") (name form) "Symbol macros must expand to a list or atom form : ~s -> ~s~%" name form)
Generate a defmacro form that transforms code like this:
(def-dynenv-fun nil
    :key
  nil)

Pattern to recognize: Macro call that should be transformed by DEF-DYNENV-FUN

Macro definition:
(defmacro DEF-DYNENV-FUN ...)

Macroexpansion:
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defun nil (&rest #:args) (apply (dynenv-function nil) #:args))
  (defvar #:nil145 (lambda :key nil))
  (setf (get 'nil 'dynenv-fun) '#:nil145))
Generate a defmacro form that transforms code like this:
(acond ((+ 2 2) (setf foo 38) (incf foo it) foo) (t nil))

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

Macro definition:
(defmacro acond (&body clauses)
  "Like COND, except result of each test-form is bound to IT (via LET) for the
scope of the corresponding clause."
  (labels ((rec (clauses)
	     (if clauses
		 (destructuring-bind ((test &body body) . rest)  clauses
		   (if body
		       `(anaphoric if ,test (progn ,@body) ,(rec rest))
		       `(anaphoric if ,test it ,(rec rest))))
		 nil)))
    (rec clauses)))

Macroexpansion:
(let ((#:it (+ 2 2))) (if #:it (let ((it #:it)) (declare (ignorable it)) (setf foo 38) (incf foo it) foo) (acond (t nil))))
You are a Common Lisp macro expert. Given this code pattern:
(define-error assigning-to-readonly () (var-name) "Assignment failed as ~a is readonly" var-name)

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 assigning-to-readonly (:error-type varjo-error :prefix "Varjo") (var-name) "Assignment failed as ~a is readonly" var-name)
Write a Common Lisp macro to handle this code pattern:
(when (cdr head) (cons 'progn (cdr head)))

Problem: Macro call that should be transformed by when

Macro definition:
(defmacro when (test &body forms)
  `(if ,test
	   ,(cl:if (cadr forms)
			   `(progn ,@forms)
			   (car forms))))

Macroexpansion:
(if (cdr head) (cons (quote progn) (cdr head)))
Define a macro that eliminates this repetitive pattern:
(when nil (progn))

Issue: Macro call that should be transformed by WHEN

Macro definition:
(defmacro WHEN ...)

Macroexpansion:
(if nil
    (progn))
You are a Common Lisp macro expert. Given this code pattern:
(rem-bops nil nil)

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

Macro definition:
(defmacro REM-BOPS ...)

Macroexpansion:
(eval-when (:load-toplevel :compile-toplevel :execute)
  (progn (save-binfix) (mapc 'rmbop '(nil nil)) (assign-properties)))
You are a Common Lisp macro expert. Given this code pattern:
(%destructure-defhook-args args (with-effective-qualifier generic-function qualifier (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))))

Write a macro that addresses: Macro call that should be transformed by %destructure-defhook-args

Macro definition:
(defmacro %destructure-defhook-args (args &body body)
  (let ((args-sym (gensym)))
    `(let* ((,args-sym ,args)
            (qualifier
            (cond ((and (symbolp (car ,args-sym)) (not (null (car ,args-sym))))
                   (prog1 (car ,args-sym) (setf ,args-sym (cdr ,args-sym))))
                  (t :use-default))))
       (destructuring-bind (specialized-lambda-list &body body) ,args-sym
         ,@body))))

Macroexpansion:
(let* ((#:g123 args) (qualifier (cond ((and (symbolp (car #:g123)) (not (null (car #:g123)))) (prog1 (car #:g123) (setf #:g123 (cdr #:g123)))) (t :use-default)))) (destructuring-bind (specialized-lambda-list &body body) #:g123 (with-effective-qualifier generic-function qualifier (destructure-specialized-lambda-list descriptive-lambda-list vanilla-lambda-list type-list specialized-lambda-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)))))))
Write a Common Lisp macro to handle this code pattern:
(defun-compile-time walk-go (map-function form) (unless (null (rest (last form))) (error "Improper GO: ~S" form)) (unless (= (length form) 2) (error "GO must have one argument: ~S" form)) (unless (or (symbolp (second form)) (integerp (second form))) (error "TAG of GO must be a symbol or integer: ~S" form)) (funcall map-function form 'go))

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 walk-go (map-function form) (unless (null (rest (last form))) (error "Improper GO: ~S" form)) (unless (= (length form) 2) (error "GO must have one argument: ~S" form)) (unless (or (symbolp (second form)) (integerp (second form))) (error "TAG of GO must be a symbol or integer: ~S" form)) (funcall map-function form (quote go))) (eval-when (:compile-toplevel) (compile (quote walk-go))))
Write a Common Lisp macro to handle this code pattern:
(draw scene (:image :x 10 :y 10 :height 600 :width 600 :xlink-href img-url))

Problem: 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 ((#:g155 (funcall (function make-svg-element) :image (append (list :x 10 :y 10 :height 600 :width 600 :xlink-href img-url) (list))))) (add-element scene #:g155) #:g155)