[System] You are an expert Common Lisp macro programmer. Think step by step before writing the macro. Always explain your reasoning in <think>...</think> tags, then provide the defmacro form.

[User]
Create a Common Lisp macro for the following transformation. Before code:
(gen-lambda-with-sticky-stop () (loop for g in generators for v in valfuncs do (let ((data (multiple-value-list (funcall v g)))) (if (car data) (progn (push (car data) sigs) (push (cdr data) stor)) (sticky-stop)))) (when (= 0 (length (remove-if (lambda (x) (eq x :filled)) sigs))) (sticky-stop)) (let ((tmp stor)) (setf stor nil) (setf sigs nil) (apply #'values (nreverse tmp))))

What needs to change: Macro call that should be transformed by gen-lambda-with-sticky-stop

[Assistant]
<think>
The user wants to create a Common Lisp macro named `gen-lambda-with-sticky-stop`.
The macro takes a body of code and wraps it in a lambda expression.
The lambda should have a special behavior: if the symbol `sticky-stop` is called, it should signal an error or condition that can be caught by the caller.
Looking at the example transformation:
Input: `(gen-lambda-with-sticky-stop () (loop ... (sticky-stop) ...))`
The macro expands to a lambda.
Inside the lambda, calls to `sticky-stop` need to be transformed.
The example shows `(sticky-stop)` appearing in the code.
The macro needs to intercept calls to `sticky-stop` and replace them with something that signals a specific condition, likely a `sticky-stop` condition.
Also, the macro needs to wrap the body in a `block` or `handler-case` or simply replace `sticky-stop` calls with `(signal 'sticky-stop)`.
Wait, the example shows `(sticky-stop)` being used as a form.
The macro should probably define a condition `sticky-stop` and replace calls to `(sticky-stop)` with `(signal 'sticky-stop)` or `(error 'sticky-stop)`.
Or maybe it just signals a condition that the caller catches.
Let's assume the macro expands to:
`(lambda (args) (block sticky-stop (let ((sticky-stop (lambda () (return-from sticky-stop nil)))) body)))`
Or maybe it uses `handler-case`?
Actually, a common pattern for "sticky stop" in Lisp macros is to define a local function or macro `sticky-stop` that returns from a named block, or signals a condition.
Given the name `gen-lambda-with-sticky-stop`, it likely generates a lambda where `sticky-stop` is a special form.
Let's look at the structure: `(gen-lambda-with-sticky-stop (args) body...)`
It should expand to `(lambda (args) (block sticky-stop (let ((sticky-stop (lambda () (return-from sticky-stop nil)))) body...)))`
Or maybe it uses `multiple-value-bind` or similar?
Wait, the example code has `(sticky-stop)` called in two places.
If we define `sticky-stop` as a macro that expands to `(return-from sticky-stop nil)`, that would work.
Let's try:
`(defmacro gen-lambda-with-sticky-stop ((&rest args) &body body)
  `(lambda ,args
     (block sticky-stop
       (macrolet ((sticky-stop () '(return-from sticky-stop nil)))
         ,@body))))`
But `macrolet` inside `lambda` is valid.
Alternatively, we can use `let` to bind `sticky-stop` to a function that signals a condition, but `macrolet` is cleaner for code transformation.
Wait, the prompt says "Macro call that should be transformed by gen-lambda-with-sticky-stop". It implies the macro itself performs the transformation.
Let's stick to `macrolet` or `labels` or just replacing `sticky-stop` with `(signal 'sticky-stop)`.
Actually, a simpler approach: `(defmacro gen-lambda-with-sticky-stop ((&rest args) &body body) `(lambda ,args (block sticky-stop (let ((sticky-stop (lambda () (return-from sticky-stop nil)))) ,@body))))`
But `let` binding a function name shadows the macro if we use `macrolet`. `macrolet` is better.
Wait, `macrolet` inside a `lambda` form is perfectly valid in Common Lisp.
Let's refine:
</think>
(defmacro gen-lambda-with-sticky-stop (&rest rest)
  `(make-instance
    'basic-generator
    :function (sticky-stop-lambda ,@rest)))


[System] You are an expert Common Lisp macro programmer. Think step by step before writing the macro. Always explain your reasoning in <think>...</think> tags, then provide the defmacro form.

[User]
You are a Common Lisp macro expert. Given this code pattern:
;; Sorting multiple places requires manual compare-and-swap
(when (> b a) (rotatef a b))
(when (> c a) (rotatef a c))
(when (> c b) (rotatef b c))
;; This is a sorting network but manually written - error-prone
;; For more than 3 elements, the network is complex

Write a macro that addresses: Sorting multiple values in-place requires compare-and-swap networks — want automatic sorting network generation

[Assistant]
<think>
The user wants a Common Lisp macro that generates a sorting network for a given list of places.
A sorting network is a fixed sequence of compare-and-swap operations that sorts any input.
For N elements, a sorting network has a specific structure of comparators.
The user provided an example for 3 elements:
(when (> b a) (rotatef a b))
(when (> c a) (rotatef a c))
(when (> c b) (rotatef b c))
Wait, this example sorts a, b, c in ascending order? Let's trace:
Initially: a, b, c
1. (when (> b a) (rotatef a b)) -> ensures a <= b
2. (when (> c a) (rotatef a c)) -> ensures a <= c. Now a is min(a,b,c).
3. (when (> c b) (rotatef b c)) -> ensures b <= c. Now order is a <= b <= c.
Yes, it sorts ascending.

The macro should take a list of places and generate the appropriate sorting network code.
Sorting networks for small N are well-known.
N=1: trivial
N=2: compare 0,1
N=3: (0,1), (0,2), (1,2)
N=4: (0,1), (2,3), (0,2), (1,3), (1,2)
N=5: more complex.
Actually, generating sorting networks algorithmically is non-trivial (BKM algorithm, etc.).
But for a macro, we can either hardcode known networks for small N, or implement a simple generator.
Given it's a macro, hardcoding up to maybe 8 or 10 elements is feasible, or we can implement a simple odd-even mergesort network generator, which is known and relatively straightforward to implement in Lisp.
Odd-even mergesort network depth is O(log^2 N), which is fine.
Alternatively, we can just use a simple bubble sort network? Bubble sort network for N elements does N-1 passes, each pass compares adjacent pairs. That's O(N^2) comparators, but trivial to generate.
Wait, the prompt says "want automatic sorting network generation". It doesn't strictly require optimal networks. A bubble sort network is a valid sorting network and very easy to generate.
But maybe the user expects something closer to optimal, or at least a standard one.
Let's consider implementing a simple generator for odd-even transposition sort (which is essentially bubble sort network) or just hardcode small cases.
Actually, generating a sorting network algorithmically in a macro is a known problem. I'll implement a simple odd-even transposition sort generator, or maybe just a straightforward recursive generator for small N.
Wait, odd-even transposition sort for N elements:
For pass = 1 to N-1:
  For i = 1 to N-pass:
    Compare (i-1, i)
This generates a valid sorting network. It's simple and correct.
But let's think about typical Lisp macro patterns. Often, for sorting networks, people just hardcode the comparators for N <= 8 or so, or use a library.
Given the prompt is about "automatic sorting network generation", I will write a macro that generates the comparators. I'll implement a simple odd-even transposition sort network generator because it's concise and correct for any N.
Actually, odd-even transposition sort is:
(repeat N times)
  if phase is odd: compare (0,1), (2,3), ...
  if phase is even: compare (1,2), (3,4), ...
This is exactly the odd-even transposition sort. It's a sorting network.
Let's verify: N=3
phase 1 (odd): compare (0,1)
phase 2 (even): compare (1,2)
phase 3 (odd): compare (0,1)
Total: (0,1), (1,2), (0,1). Does this sort 3 elements?
Input: 3, 2, 1
(0,1) -> 2, 3, 1
(1,2) -> 2, 1, 3
(0,1) -> 1, 2, 3. Yes.
Input: 2, 3, 1
(0,1) -> 2, 3, 1
(1,2) -> 2, 1, 3
(0,1) -> 1, 2, 3. Yes.
It works. It's a known sorting network (odd-even transposition sort).
Number of comparators: N*(N-1)/2
</think>
(defun build-batcher-sn (n)
  (let* (network
         (tee (ceiling (log n 2)))
         (p (ash 1 (- tee 1))))
    (loop while (> p 0) do
      (let ((q (ash 1 (- tee 1)))
            (r 0)
            (d p))
        (loop while (> d 0) do
          (loop for i from 0 to (- n d 1) do
            (if (= (logand i p) r)
              (push (list i (+ i d))
                    network)))
          (setf d (- q p)
                q (ash q -1)
                r p)))
      (setf p (ash p -1)))
    (nreverse network)))

(defmacro! sortf (comparator &rest places)
  (if places
    `(tagbody
       ,@(mapcar
           #`(let ((,g!a #1=,(nth (car a1) places))
                   (,g!b #2=,(nth (cadr a1) places)))
               (if (,comparator ,g!b ,g!a)
                 (setf #1# ,g!b
                       #2# ,g!a)))
           (build-batcher-sn (length places))))))


[System] You are an expert Common Lisp macro programmer. Think step by step before writing the macro. Always explain your reasoning in <think>...</think> tags, then provide the defmacro form.

[User]
Generate a defmacro form that transforms code like this:
(when (node-slot type) (del-proxy type))

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

[Assistant]
<think>
The user wants a macro that transforms a specific pattern: `(when (node-slot type) (del-proxy type))`.
However, the prompt is a bit ambiguous. It says "Macro call that should be transformed by when".
Usually, `when` is a standard Common Lisp special operator.
Perhaps the user wants a macro that *generates* this pattern, or perhaps a macro that *replaces* a specific custom form with this `when` form.
Given the instruction "Generate a defmacro form that transforms code like this", it implies the user wants a macro definition that, when called, expands into the provided code snippet.
Let's assume the user wants a macro named `delete-proxy-if-node-slot` (or similar) that takes `type` as an argument and expands to `(when (node-slot type) (del-proxy type))`.

Wait, looking at the pattern `(when (node-slot type) (del-proxy type))`, it looks like a specific idiom.
Maybe the user wants a macro that generalizes this? Like `(safe-del-proxy type)` -> `(when (node-slot type) (del-proxy type))`.
Or maybe the user wants a macro that *is* `when` but handles this specific case? No, `when` is standard.

Let's re-read carefully: "Generate a defmacro form that transforms code like this: `(when (node-slot type) (del-proxy type))`".
This phrasing is tricky. "Transforms code like this" could mean:
1. The macro *input* looks like this, and it transforms it into something else.
2. The macro *output* looks like this, transforming some other input into this.

Given the context of "Pattern to recognize: Macro call that should be transformed by when", it sounds like the user might be asking for a macro that *is* `when` but perhaps optimized or specialized? No, that's unlikely.

Most likely interpretation: The user has a specific intent, e.g., "Delete proxy if node slot exists". They want a macro that expands to the `when` form.
Let's create a macro named `delete-proxy-if-slot` that takes a `type` argument.
Expansion: `(when (node-slot type) (del-proxy type))`.

Let's consider variable capture. `type` is a parameter. The expansion uses `type`.
We need to ensure `type` is evaluated once if it's an expression, though usually in these patterns, it's a variable.
Standard macro hygiene: use `type` as the parameter name in the macro definition.

Let's assume the macro name is `delete-proxy-if-node-slot`.
Arguments: `type`.
Body: `(when (node-slot type) (del-proxy type))`.

Wait, is there a possibility the user wants a macro that *parses* the `when` form?
"Pattern to recognize: Macro call that should be transformed by when"
This might mean the user wants a macro that *replaces* a call to `when` with something else?
Or maybe the user wants a macro that *creates* a `when` form?

Let's look at the "Pattern to recognize" line again.
"Macro call that should be transformed by when"
This sounds like the user is describing the *output* of the macro they want.
They want a macro that results in a `when` form.
The specific code snippet is `(when (node-slot type) (del-proxy type))`.

Let's provide a macro `with-safe-proxy-deletion` or `delete-proxy-if-present` that takes `type`.
Actually, looking at the snippet, `type` is likely a variable or symbol.
Let's define a macro `delete-proxy-if-node-slot` that takes `type`.

Step 1: Pattern matching. The macro call will be `(delete-proxy-if-node-slot type)`.
Step 2: Constructs needed. `when`, `node-slot`, `del-proxy`.
Step 3: Quasiquote. `` `(when (node-slot ,type) (del-proxy ,type)) ``.
Step 4: Variable capture. `type` is a parameter. We should evaluate it once?
If `type` is an expression, `(node-slot type)` and `(del-proxy type)` would evaluate it twice.
Better to bind it: `(let ((temp ,type)) (when (node-slot temp) (del-proxy temp)))`.
But the original snippet doesn't have a `let`. The original snippet is `(when (node-slot type) (del-proxy type))`.
If the user wants an exact transformation to that snippet, we should just emit that.
However, good macro practice suggests avoiding double evaluation.
But the prompt asks to "transform code like this", implying the output should look like that.
I will provide a macro that generates exactly that
</think>
(defmacro when (test &body forms)
  `(if ,test
	   ,(cl:if (cadr forms)
			   `(progn ,@forms)
			   (car forms))))


[System] You are an expert Common Lisp macro programmer. Think step by step before writing the macro. Always explain your reasoning in <think>...</think> tags, then provide the defmacro form.

[User]
Define a macro that eliminates this repetitive pattern:
(switch (13) ((+ 12 2) :oops) ((- 13 1) :oops2) (t :yay))

Issue: Macro call that should be transformed by switch

[Assistant]
<think>
The user wants to define a macro named `switch` that replaces a repetitive pattern.
The pattern is: `(switch (13) ((+ 12 2) :oops) ((- 13 1) :oops2) (t :yay))`
This looks like a `cond` expression where the first element is the test value, and subsequent elements are pairs of test expressions and results.
Wait, let's look at the structure: `(switch <test-value> (<test-expr> <result>) ...)`
Actually, the first argument is `(13)`, which is a list containing the value to test against. Or maybe it's just `(switch <value> (<test> <result>) ...)`?
The example shows `(switch (13) ((+ 12 2) :oops) ((- 13 1) :oops2) (t :yay))`.
It seems like `switch` takes a value, and then a series of clauses. Each clause has a test expression and a result. If the test expression evaluates to the value, it returns the result. The last clause is `(t :yay)`, which acts as the default.
This is essentially a `cond` where each test checks for equality with the switch value.
So `(switch val (test1 res1) (test2 res2) ... (t default))` should expand to:
`(cond ((= val test1) res1) ((= val test2) res2) ... (t default))`
Wait, `=` might not work for all types. `eql` is safer for symbols and numbers, or `equal`. Let's stick to `eql` or `=`. Usually, switch/case uses `eql`. I'll use `eql`.
But wait, the first argument is `(13)`. It's quoted in the example? Or is it just a list containing the expression? The example says `(switch (13) ...)`. Maybe it's `(switch 13 ...)` but the user wrote `(13)` by mistake, or maybe it's `(switch (value) ...)`? I'll assume the first argument is the value expression. If it's wrapped in a list in the example, it might just be a typo in the prompt, or maybe it's `(switch <val> ...)`. I'll treat the first argument as the value to compare against.
Let's assume the macro signature is `(switch value (&rest clauses))`.
Each clause is `(test result)`.
The expansion should be:
`(cond ,@(loop for (test result) in clauses
               collect (if (eq test 't)
                           `(t ,result)
                           `(,(if test `(eql ,value ,test) test) ,result))))`
Wait, if the test is `t`, it's the default. Otherwise, it's `(eql value test)`.
Let's refine:
`(defmacro switch (value &rest clauses)
  `(cond ,@(loop for clause in clauses
                 for (test result) = clause
                 collect (if (eq test 't)
                             `(t ,result)
                             `(,(if (listp test) test `(eql ,value ,test)) ,result)))))`
Actually, Common Lisp's `case` macro does exactly this, but it expects quoted constants. Here, the tests are expressions like `(+ 12 2)`. So `ecase` or `case` won't work directly because they require constants. `cond` is the way to go.
We can just expand to `(cond ((eql value test1) result1) ... (t default))`.
What about variable capture? `value` is an expression, so we should quote it or evaluate it once. In `cond`, we can evaluate `value` once using `let`:
`(let ((switch-value value))
  (cond ((eql switch-value test1) result1) ... (t default)))`
This avoids evaluating `value` multiple times and avoids capture issues if `value` contains gensyms, but `value` is user code, so we just quote it in the `let` binding.
Let's write it out carefully.

Structure:
</think>
(defmacro switch (&whole whole (object &key (test 'eql) (key 'identity))
                         &body clauses)
  "Evaluates first matching clause, returning its values, or evaluates and
returns the values of T or OTHERWISE if no keys match."
  (generate-switch-body whole object clauses test key))


[System] You are an expert Common Lisp macro programmer. Think step by step before writing the macro. Always explain your reasoning in <think>...</think> tags, then provide the defmacro form.

[User]
Create a Common Lisp macro for the following transformation. Before code:
(is-true t)

What needs to change: Macro call that should be transformed by is-true

[Assistant]
<think>
The user wants me to create a Common Lisp macro named `is-true`.
The example given is:
Before code: `(is-true t)`
The user asks "What needs to change: Macro call that should be transformed by is-true".
Wait, the prompt is a bit ambiguous. "Create a Common Lisp macro for the following transformation. Before code: (is-true t) What needs to change: Macro call that should be transformed by is-true"

Usually, these prompts come from a dataset where the "Before code" is the macro invocation, and the "After code" is the expanded form. But here, only "Before code" is given, and the question is "What needs to change: Macro call that should be transformed by is-true". This looks like a fill-in-the-blank or a request to define the macro itself.
Actually, the prompt says "Create a Common Lisp macro for the following transformation."
It gives `(is-true t)` as the before code.
It asks "What needs to change: Macro call that should be transformed by is-true".
This is slightly confusing. Maybe it means: Define the macro `is-true` such that `(is-true t)` expands to something? Or maybe it's asking for the macro definition itself.
Given the instruction "Create a Common Lisp macro...", I should provide the `defmacro` form.
What does `is-true` usually do? It probably checks if a form is true. Like `(is-true form)` expands to `(assert form)` or `(if form t (error ...))` or simply evaluates the form and returns it, or maybe it's a testing macro like `(is-true (some-predicate))`.
Wait, in many Lisp testing frameworks, `is-true` or `is` checks truthiness.
But without the "after" code, I have to guess the intent.
Let's re-read carefully: "Create a Common Lisp macro for the following transformation. Before code: (is-true t) What needs to change: Macro call that should be transformed by is-true"
This might be a prompt from a code generation dataset where the target is just the macro definition.
Perhaps `is-true` is meant to expand to a conditional or an assertion.
Actually, `is-true` could just be a synonym for `when` or `if`, or it could be a macro that evaluates its argument and signals an error if false.
Let's assume it's a simple macro that checks truthiness, maybe expanding to `(if ,form t (error "Expected true"))` or just evaluating the form.
Wait, maybe it's from a specific library? `is-true` is not standard CL.
Could it be `(defmacro is-true (form) (if ,form t (error "Not true")) )`? No.
Let's think about typical macro exercises. Often, `is-true` might just be `(defmacro is-true (x) x)`? That's trivial.
Or maybe it's `(defmacro is-true (form) (assert form))`?
Actually, the prompt might be asking to define the macro `is-true` that simply evaluates its argument and returns it, or perhaps it's a placeholder for a test assertion.
Given the ambiguity, I will define a macro `is-true` that takes a form and evaluates it, possibly asserting it's true. A common pattern in testing is `(is-true form)` -> `(if form t (error "Assertion failed"))`.
But wait, the prompt says "What needs to change: Macro call that should be transformed by is-true". This might mean the user wants the macro definition that transforms `(is-true t)` into something else.
I'll provide a straightforward macro definition. I'll assume it's a simple truth-checking macro.
`(defmacro is-true (form) '(if ,form t (error "Expected true")))`? No, quasiquote is better: `(if ,form t (error "Expected true"))`.
Actually, maybe it's just `(defmacro is-true (x) x)`? That's too simple.
Let's look at similar prompts online. Sometimes "is-true" is used in examples like `(is-true (eq a b))`.
I will write a macro that expands to a conditional that signals an error if the form is false, which is typical for `is-true` in test suites.
`(defmacro is-true (form) (list 'if form 't (list 'error "Expected true, got: ~S" form)))`
Or simpler: `(defmacro is-true (form) (assert form))` but `assert` is a macro itself.
Wait, the prompt might be from a specific coding challenge. "Create a Common Lisp
</think>
(defmacro is-true (condition &rest reason-args)
  "Like IS this check generates a pass if CONDITION returns true
  and a failure if CONDITION returns false. Unlike IS this check
  does not inspect CONDITION to determine how to report the
  failure."
  `(if ,condition
       (add-result 'test-passed :test-expr ',condition)
       (process-failure ',condition
                        ,@(or reason-args
                              `("~S did not return a true value" ',condition)))))


[System] You are an expert Common Lisp macro programmer. Think step by step before writing the macro. Always explain your reasoning in <think>...</think> tags, then provide the defmacro form.

[User]
You are a Common Lisp macro expert. Given this code pattern:
(do-matches (s e regex target-string count :start start :end end) (incf count))

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

[Assistant]
<think>
The user wants a macro named `do-matches` that iterates over matches of a regular expression in a string.
The syntax provided is: `(do-matches (s e regex target-string count :start start :end end) (incf count))`
Wait, looking at the syntax `(s e regex target-string count :start start :end end)`, it seems `s` and `e` are the loop variables for start and end positions of the match. `regex` is the pattern, `target-string` is the string to search. `count` is an accumulator variable initialized to 0? Or is `count` just a variable? The example shows `(incf count)`, implying `count` is a local variable initialized to 0.
Actually, standard CL regex libraries (like CL-PPCRE) use `scan` or `do-matches` macros.
Let's analyze the binding list: `(s e regex target-string count :start start :end end)`.
Usually, `do-matches` binds `start` and `end` (or `s` and `e`) to the positions of the match.
The user's syntax suggests:
`(do-matches (match-start match-end regex string [init-value] [:start start] [:end end]) body...)`
Wait, the example has `count` in the binding list. This implies `count` is initialized to 0.
Let's assume the signature is:
`(do-matches (s e regex string [init] &key start end) body...)`
Actually, the example is `(do-matches (s e regex target-string count :start start :end end) (incf count))`.
This looks like `count` is the initial value for the counter, but it's placed before `:start`.
Let's look at CL-PPCRE's `do-matches`.
CL-PPCRE `do-matches` signature: `(do-matches (start end regex string) body...)`
It doesn't have an accumulator.
Maybe the user wants a custom macro that mimics a specific style.
Let's break down the binding list: `(s e regex target-string count :start start :end end)`.
`s` and `e` are the match start and end.
`regex` is the pattern.
`target-string` is the string.
`count` is a variable initialized to 0.
`:start` and `:end` are optional keywords specifying search boundaries.

Let's design the macro expansion.
We need to generate a loop that calls a regex scanning function. Since I cannot assume a specific library, I will use a generic placeholder or assume `cl-ppcre:scan` or similar, but usually, in these exercises, we just generate the loop structure assuming a `scan` function exists, or we use `cl-ppcre:do-matches` logic.
Actually, the prompt asks to "Write a macro that addresses: Macro call that should be transformed by do-matches".
I will assume the environment has a function `regex-scan` or similar, or I will just write the loop structure using `loop` or `tagbody`.
However, to be safe and standard, I'll use `cl-ppcre`'s `scan` as the underlying mechanism, or just write a generic loop.
Let's assume the user wants the macro to expand into a loop using `cl-ppcre:scan`.
Wait, the prompt says "You are a Common Lisp macro expert... Write a macro that addresses: Macro call that should be transformed by do-matches".
I will define `do-matches` to expand into a `loop` or `tagbody` that repeatedly calls a scanning function.
Let's assume a function `scan-regex` exists, or I'll use `cl-ppcre:scan`. To be library-agnostic, I'll use a placeholder `scan` or just describe the loop. But macros must compile. I'll use `cl-ppcre:scan` as it's the standard, or I'll just write the expansion assuming a `scan` function is available in the scope.
Actually, I can just use `loop` with `while` and `scan`.
Let's look at the binding list again: `(s e regex target-string count :start start :end end)`.
This is a destructuring bind style.
The macro should handle:
1. `s`, `e`: match start/end.
2. `regex`: pattern.
3. `target-string`: string.
4. `count`: accumulator, init 0.
5. `:start`, `:end`: search bounds.

Expansion plan:
`(let ((,count 0) (,start (or ,start 0)) (,end (or ,end (length ,target-string
</think>
(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)))


[System] You are an expert Common Lisp macro programmer. Think step by step before writing the macro. Always explain your reasoning in <think>...</think> tags, then provide the defmacro form.

[User]
Define a macro that eliminates this repetitive pattern:
(quasiquote-unexpand-1 #-quasiquote-strict-append 'unquote-splicing #+quasiquote-strict-append 'x-unquote (car (last x)))

Issue: Macro call that should be transformed by quasiquote

[Assistant]
<think>
The user wants a macro that eliminates a repetitive pattern involving `quasiquote-unexpand-1` with conditional features.
The pattern is:
`(quasiquote-unexpand-1 #-quasiquote-strict-append 'unquote-splicing #+quasiquote-strict-append 'x-unquote (car (last x)))`

Wait, `quasiquote-unexpand-1` is likely a function or macro from a specific library (maybe related to Clozure CL or similar, or a custom quasiquote implementation).
The pattern has conditional compilation directives `#-quasiquote-strict-append` and `#+quasiquote-strict-append`.
Actually, the pattern looks like it's trying to call `quasiquote-unexpand-1` with different second arguments depending on the feature `quasiquote-strict-append`.
If `quasiquote-strict-append` is present, it uses `'x-unquote`.
If not, it uses `'unquote-splicing`.
And the third argument is `(car (last x))`.

Let's look at the pattern carefully:
`(quasiquote-unexpand-1 #-quasiquote-strict-append 'unquote-splicing #+quasiquote-strict-append 'x-unquote (car (last x)))`

This is a single form. The `#-...` and `#+...` are reader conditionals.
So depending on the feature, the form expands to either:
`(quasiquote-unexpand-1 'unquote-splicing (car (last x)))`
or
`(quasiquote-unexpand-1 'x-unquote (car (last x)))`

The user wants a macro that eliminates this repetitive pattern.
Maybe the macro should be named `quasiquote-unexpand-last` or something similar? Or maybe `qq-unexpand-last`?
The prompt says: "Define a macro that eliminates this repetitive pattern: ..."
It doesn't specify the macro name. I'll choose a descriptive name like `quasiquote-unexpand-last` or `qq-unexpand-last`. Let's stick to `quasiquote-unexpand-last` or maybe just `unexpand-last`. Actually, the pattern is specifically about unquoting the last element. I'll name it `quasiquote-unexpand-last`.

Wait, the pattern has `x` as a variable. The macro should probably take `x` as an argument.
So `(quasiquote-unexpand-last x)` would expand to the conditional form.

Let's construct the macro:
</think>
(defmacro quasiquote (x) (quasiquote-expand x))


[System] You are an expert Common Lisp macro programmer. Think step by step before writing the macro. Always explain your reasoning in <think>...</think> tags, then provide the defmacro form.

[User]
Define a macro that eliminates this repetitive pattern:
(define-error for-loop-only-one-var () () "for loops can only iterate over one variable")

Issue: Macro call that should be transformed by define-error

[Assistant]
<think>
The user wants a macro `define-error` that simplifies the definition of error conditions in Common Lisp.
The example call is: `(define-error for-loop-only-one-var () () "for loops can only iterate over one variable")`.

I need to figure out what this macro should expand into.
Usually, defining an error in Common Lisp involves:
1. Defining a condition class using `defcondition`.
2. Optionally defining a function to signal the error.

Let's look at the arguments:
1. `for-loop-only-one-var`: The name of the error.
2. `()`: Likely the `:report` function or format string arguments? Or maybe slot definitions?
3. `()`: Maybe more slot definitions?
4. `"for loops can only iterate over one variable"`: The error message.

Standard way to define a simple error with a message:
</think>
(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))


[System] You are an expert Common Lisp macro programmer. Think step by step before writing the macro. Always explain your reasoning in <think>...</think> tags, then provide the defmacro form.

[User]
Generate a defmacro form that transforms code like this:
(sif it it)

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

[Assistant]
<think>
The user wants a Common Lisp macro named `sif`.
The example provided is `(sif it it)`.
This looks like a shorthand for a conditional expression (if).
Usually, `if` takes three arguments: test, then, else.
Here, `it` is used twice.
If `it` is a variable, `(sif it it)` likely expands to `(if it it)`.
Wait, `(if it it)` is equivalent to `(if it it nil)` or just `it` if `it` is true?
Actually, `(if test then)` is valid in Common Lisp, equivalent to `(if test then nil)`.
So `(sif it it)` -> `(if it it)`.

Let's look at the pattern `(sif it it)`.
Maybe `sif` stands for "short if" or "self if"?
If the first argument is the same as the second, it might be a specific optimization or just a standard if.
However, usually macros are defined to handle general cases.
The prompt asks to "Generate a defmacro form that transforms code like this: (sif it it)".
It doesn't give other examples.
If I assume `sif` is a macro that expands to `if`, the definition is trivial:
`(defmacro sif (test then) '(if ,test ,then))`
But the example `(sif it it)` has two identical symbols.
Maybe `sif` is meant to handle a case where the test and the result are the same?
Or maybe `sif` is a macro that takes two arguments and expands to an if statement where the test is the first arg and the body is the second arg.

Let's consider the context of "sif".
In some contexts, `sif` might be a macro for "safe if" or "symbolic if".
But without more context, the most logical transformation for `(sif test then)` is `(if test then)`.
If the user specifically wrote `(sif it it)`, maybe they want to emphasize that the variable `it` is being tested and returned.
In that case, `(if it it)` is the expansion.

Let's consider if `sif` might be a macro that handles multiple arguments or a different pattern.
If the pattern is just `(sif it it)`, maybe `sif` is a macro that checks if the symbol is bound? No, that's too complex for a simple macro request.

Let's assume the standard interpretation: `sif` is a macro that simplifies `if`.
Perhaps it's a macro that allows omitting the `else` part, which standard `if` already does.
Maybe `sif` is a macro that quotes the arguments? `(sif it it)` -> `(if 'it 'it)`? Unlikely.

Let's look at the phrasing: "Pattern to recognize: Macro call that should be transformed by sif".
This implies I need to define `sif`.
The example `(sif it it)` suggests two arguments.
Let's assume the macro takes two arguments: `test` and `consequent`.
The expansion is `(if test consequent)`.

Is there any risk of variable capture?
If I write:
`(defmacro sif (test then) '(if ,test ,then))`
This is safe because `test` and `then` are expressions, not bindings. `if` is a special form.

However, maybe `sif` is a macro that expands to a `let`?
Like `(sif it it)` -> `(let ((it it)) (if it it))`? No.

Let's consider the possibility that `sif` is a macro for "string if" or something specific?
No, Common Lisp macros usually follow standard naming conventions.
Maybe `sif` is a macro that handles a single argument?
`(sif it)` -> `(if it it)`?
But the example has two arguments: `(sif it it)`.

Let's stick to the simplest interpretation: `sif` is a macro that wraps `if`.
Why would someone write `(sif it it)` instead of `(if it it)`?
Maybe `sif` adds side effects? Or logging?
Or maybe `sif` is a macro that ensures the test is evaluated only once?
`(defmacro sif (test then) '(let ((it ,test)) (if it ,then)))`
This is a common pattern for macros that want to avoid evaluating the test twice if it has side effects or is expensive.
If the user writes `(sif it it)`, and `it` is a variable, `(let ((it it)) ...)` would shadow the variable `it`.
This is a variable
</think>
(defmacro sif (test then &optional else)
  "Like IF, except binds the test form to IT (via SYMBOL-MACROLET) for
the scope of the then and else expressions. IT can be set with SETF"
  `(symbolic if ,test ,then ,else))


[System] You are an expert Common Lisp macro programmer. Think step by step before writing the macro. Always explain your reasoning in <think>...</think> tags, then provide the defmacro form.

[User]
Create a Common Lisp macro for the following transformation. Before code:
(defjs map3() (emit this.name (ps:create :count 1)))

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

[Assistant]
<think>
The user wants a Common Lisp macro named `defjs` that transforms the given code:
`(defjs map3() (emit this.name (ps:create :count 1)))`

Let's analyze the input:
- `defjs` is the macro name.
- `map3` is the function name.
- `()` are the arguments.
- `(emit this.name (ps:create :count 1))` is the body.

The user says "What needs to change: Macro call that should be transformed by defjs". This implies I need to write a macro `defjs` that takes a name, argument list, and body, and expands into something. But the user didn't specify exactly what it should expand into. Usually, `defjs` macros in Lisp-to-JS compilers expand into a function definition or a JS-specific construct. Since the prompt is a bit open-ended, I'll assume it's meant to define a JavaScript function using some underlying Lisp mechanism, perhaps `defun` or a custom `js-defun` or just emit JS code. However, looking at the pattern `(defjs name args body)`, it closely resembles `defun`.

Wait, the prompt says "Create a Common Lisp macro for the following transformation. Before code: ... What needs to change: Macro call that should be transformed by defjs". This is a typical prompt format where the user wants the macro definition that handles this syntax. I will assume it expands to a standard `defun` or a JS-specific definition. Since I don't have the target language specification, I'll make it expand to a `defun` or a `js-function` definition, or simply wrap it in a way that makes sense for a JS generator. Often, `defjs` macros in libraries like `cl-js` or `lisp-js` expand to something like `(defun name args (js ...))` or just `(defun name args body)`.

Actually, the prompt might be from a specific context or just a generic request. I will write a macro that captures the name, args, and body, and expands into a `defun` or a custom form. To be safe, I'll expand it to `(defun ,name ,args ,@body)` or similar, but since it's `defjs`, maybe it should emit JavaScript. I'll stick to a simple expansion that defines a function, perhaps using `defun` and tagging it for JS, or just `(defun ,name ,args ,@body)`. Wait, the body is a single form `(emit ...)`. So `,@body` or just `,body`.

Let's think about standard macro patterns:
`(defmacro defjs (name args &body body)
  (defun ,name ,args ,@body))`

But maybe `defjs` is supposed to generate JS code. Without more context, I'll make it expand to a `defun` that calls some JS emitter, or just `(defun ,name ,args ,@body)`. Actually, many Lisp-to-JS macros just use `defun` syntax. I'll provide a macro that expands to `(defun ,name ,args ,@body)` but note that it's for JS. Alternatively, it could expand to `(js-defun ,name ,args ,@body)`. I'll stick to `(defun ,name ,args ,@body)` for simplicity, or maybe `(export ,name)` etc.

Wait, the prompt says "What needs to change: Macro call that should be transformed by defjs". This is likely a fill-in-the-blank style. I will just write the macro.

Let's structure the macro carefully:
1. Pattern: `(defjs name args &body body)`
2. Constructs: `defmacro`, `defun` (or `js-defun`), quasiquote/unquote.
3. Variable capture: `name` is a symbol, `args` is a list, `body` is a list of forms. No lexical variable capture issues since it's a definition macro.
4. Structure:
</think>
(defmacro defjs (name args &body body)
  "Define client side javascript. Works like defun; body is in lisp, with parenscript
   additions, like return. So (defjs hello (x y) (return (+ x y))) defines an adder.
   macro creates a lisp function which sends the javascript function over to the mongo
   server to be evaluated. Result is processed and returned to the reader.
   This will execute 10 times on the server :
   (mapcar (lambda (x) (hello 10 x)) (list 1 2 3 4 5 6 7 8 9 10))"
  `(let* ((js-body (parenscript:ps (lambda ,args ,@body))))
     (setf (gethash ',name *js-definitions*) js-body)
     (defun ,name ,args
       (get-element "retval" (car (docs (db.eval js-body ,@args)))))))


[System] You are an expert Common Lisp macro programmer. Think step by step before writing the macro. Always explain your reasoning in <think>...</think> tags, then provide the defmacro form.

[User]
Create a Common Lisp macro for the following transformation. Before code:
(with-yield (dolist (x data) (yield x)))

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

[Assistant]
<think>
The user wants a Common Lisp macro named `with-yield`.
The example usage is `(with-yield (dolist (x data) (yield x)))`.
This looks like a generator pattern. `with-yield` wraps some code that calls `yield`.
In Common Lisp, generators are often implemented using `alexandria:define-generator` or similar, but here I need to write a macro that transforms the code.

Wait, the prompt says "Create a Common Lisp macro for the following transformation. Before code: (with-yield (dolist (x data) (yield x)))".
It asks what needs to change: "Macro call that should be transformed by with-yield".
Actually, the prompt implies I should write the `defmacro` for `with-yield`.
How does `with-yield` usually work? It typically expands into a lambda that returns a closure, or uses `call/cc` or `alexandria:define-generator` style.
But since it's a macro exercise, maybe it expands to a `lambda` that uses `block` and `return-from`, or it uses `alexandria:define-generator`? No, standard CL doesn't have generators.
Perhaps `with-yield` expands to something like:
`(lambda () (block nil (dolist (x data) (return-from nil x))))`? No, that only yields once.
Generators in CL usually rely on continuations or thread suspension.
However, a common pattern for `with-yield` in macros (like in `iterate` or `alexandria`) is to expand into a `lambda` that captures the yield point.
Actually, a very common way to implement `with-yield` in a macro is to expand it into a `lambda` that uses `call/cc` or `si:with-call/cc` if available, but that's implementation-specific.
Wait, maybe it's simpler: `with-yield` expands the body into a form that sets up a yield mechanism.
Often, `with-yield` is implemented as:
</think>
(defmacro with-yield (&body body)
  (let ((point (gensym))
        (current (gensym)))
    `(let (,point ,current)
       (with-call/cc
	 (labels ((yield (&rest values)
		    (setf ,current values)
		    (let/cc k
		      (setf ,point k))))
	   ,@body
	   (setf ,point nil)))
       (gen-lambda ()
	 (cond ((null ,point)
		'generator-stop)
	       (t
		(let ((current ,current))
		  (funcall ,point nil)
		  ;values-handler: see gen-lambda
		  (apply #'values (funcall values-handler current)))))))))


[System] You are an expert Common Lisp macro programmer. Think step by step before writing the macro. Always explain your reasoning in <think>...</think> tags, then provide the defmacro form.

[User]
You are a Common Lisp macro expert. Given this code pattern:
(is (plusp 1))

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

[Assistant]
<think>
The user wants a macro named `is` that takes a form like `(is (plusp 1))` and transforms it.
Looking at the pattern `(is (plusp 1))`, it seems like a testing or assertion macro.
Common patterns for such macros:
1. It might be a simple assertion that checks if the form is true.
2. It might be from a specific testing framework like `FiveAM` or `Parachute`, but I should write a generic one or a simple one.
3. Usually, `is` macros evaluate the form and signal an error if it's false, or they might check equality if there's a second argument, but here there's only one argument.
4. Let's assume it's a simple assertion macro that checks if the result is true.
5. Wait, the prompt says "Macro call that should be transformed by is". It might just want a basic transformation.
6. Let's think about typical `is` macro in Lisp testing frameworks. Often it's `(is form expected)` or just `(is form)`. Here it's `(is (plusp 1))`.
7. I will write a macro that evaluates the form and signals an error if it returns nil, or perhaps wraps it in a `when` or `unless`, or uses `assert`.
8. Actually, `assert` is a standard Common Lisp macro: `(assert (plusp 1))`. But the user explicitly asks for a macro named `is`.
9. Let's make it simple: `(defmacro is (form) '(assert ,form))` or something similar.
10. But to be more robust and idiomatic for a testing macro, it might want to capture the form and its evaluation, or just use `assert`.
11. Let's consider variable capture: `form` is evaluated in the macro's environment. Using `assert` directly handles it.
12. Another possibility: `is` is from `Clojure` or `Racket` where it checks truthiness. In Clojure, `(is (plusp 1))` would just check truthiness.
13. I'll write a macro that uses `assert` but maybe adds a message or just passes through.
14. Actually, a common pattern for `is` in Lisp is:
    ```lisp
    (defmacro is (form)
      `(assert ,form (,form) "Assertion failed: ~S" ,form))
    ```
    But that evaluates `form` twice. Better to use a `let` or just `assert`.
    Wait, `assert` takes optional `datum` and `format-control`.
    Let's stick to a simple transformation that evaluates the form and signals an error if false.
    Or maybe it's meant to be a simple equality check? No, only one argument.
    I'll write a macro that wraps the form in a `when` or uses `assert`.
    Let's go with a standard assertion macro pattern:
    ```lisp
    (defmacro is (form)
      `(assert ,form))
    ```
    But that's trivial. Maybe the user wants something that prints the form if it fails?
    Let's think about typical macro exercises. Often they want to show quasiquote/unquote and variable binding.
    I'll write:
    ```lisp
    (defmacro is (form)
      `(assert ,form (,form) "Test failed: ~S" ,form))
    ```
    Wait, evaluating `,form` twice is bad. I'll use `let`:
    ```lisp
    (defmacro is (form)
      `(let ((result ,form))
         (assert result (result) "Assertion failed: ~S" result)))
    ```
    This is safer.
    Let's reconsider the prompt: "Macro call that should be transformed by is". It's very open-ended.
    I will explain the reasoning: pattern matching a single form, using `assert` for truthiness checking, handling evaluation once with `let`, avoiding variable capture by using a generated symbol or just `result` (which is fine since it's local to the generated `let`).
    Actually, `result` is fine, but to be strictly hygienic, I could use `gensym`, but it's overkill for this simple case. I'll stick to `result` or `it`.
    Wait, `assert` is standard. I'll just use `assert`.
    Let's draft the explanation and macro.
    Steps:
    1. Pattern: `(is <form>)`
    2. Constructs: `let` to evaluate once, `assert` to check truthiness.
    3. Quasiquote: `` `(let ((it ,
</think>
(defmacro is (test &rest reason-args)
  "The DWIM checking operator.

If TEST returns a true value a test-passed result is generated,
otherwise a test-failure result is generated. The reason, unless
REASON-ARGS is provided, is generated based on the form of TEST:

 (predicate expected actual) - Means that we want to check
 whether, according to PREDICATE, the ACTUAL value is
 in fact what we EXPECTED.

 (predicate value) - Means that we want to ensure that VALUE
 satisfies PREDICATE.

 Wrapping the TEST form in a NOT simply produces a negated reason
 string."
  (assert (listp test)
          (test)
          "Argument to IS must be a list, not ~S" test)
  (let (bindings effective-test default-reason-args)
    (with-gensyms (e a v)
      (flet ((process-entry (predicate expected actual &optional negatedp)
               ;; make sure EXPECTED is holding the entry that starts with 'values
               (when (and (consp actual)
                          (eq (car actual) 'values))
                 (assert (not (and (consp expected)
                                   (eq (car expected) 'values))) ()
                                   "Both the expected and actual part is a values expression.")
                 (rotatef expected actual))
               (let ((setf-forms))
                 (if (and (consp expected)
                          (eq (car expected) 'values))
                     (progn
                       (setf expected (copy-list expected))
                       (setf setf-forms (loop for cell = (rest expected) then (cdr cell)
                                              for i from 0
                                              while cell
                                              when (eq (car cell) '*)
                                              collect `(setf (elt ,a ,i) nil)
                                              and do (setf (car cell) nil)))
                       (setf bindings (list (list e `(list ,@(rest expected)))
                                            (list a `(multiple-value-list ,actual)))))
                     (setf bindings (list (list e expected)
                                          (list a actual))))
                 (setf effective-test `(progn
                                         ,@setf-forms
                                         ,(if negatedp
                                              `(not (,predicate ,e ,a))
                                              `(,predicate ,e ,a)))))))
        (list-match-case test
          ((not (?predicate ?expected ?actual))
           (process-entry ?predicate ?expected ?actual t)
           (setf default-reason-args
                 (list "~2&~S~2% evaluated to ~2&~S~2% which is ~2&~S~2%to ~2&~S~2% (it should not be)"
                       `',?actual a `',?predicate e)))
          ((not (?satisfies ?value))
           (setf bindings (list (list v ?value))
                 effective-test `(not (,?satisfies ,v))
                 default-reason-args
                 (list "~2&~S~2% evaluated to ~2&~S~2% which satisfies ~2&~S~2% (it should not)"
                       `',?value v `',?satisfies)))
          ((?predicate ?expected ?actual)
           (process-entry ?predicate ?expected ?actual)
           (setf default-reason-args
                 (list "~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%"
                       `',?actual a `',?predicate e)))
          ((?satisfies ?value)
           (setf bindings (list (list v ?value))
                 effective-test `(,?satisfies ,v)
                 default-reason-args
                 (list "~2&~S~2% evaluated to ~2&~S~2% which does not satisfy ~2&~S~2%"
                       `',?value v `',?satisfies)))
          (?_
           (setf bindings '()
                 effective-test test
                 default-reason-args (list "~2&~S~2% was NIL." `',test)))))
      `(let ,bindings
         (if ,effective-test
             (add-result 'test-passed :test-expr ',test)
             (process-failure ',test
                              ,@(or reason-args default-reason-args)))))))


[System] You are an expert Common Lisp macro programmer. Think step by step before writing the macro. Always explain your reasoning in <think>...</think> tags, then provide the defmacro form.

[User]
You are a Common Lisp macro expert. Given this code pattern:
(*> #'space #'rest)

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

[Assistant]
<think>
The user wants a macro `*>` that transforms a call like `(*> #'space #'rest)` into something else.
Looking at the pattern `(*> #'space #'rest)`, this looks like a threading macro, similar to `->` in Clojure or `thread-first` in some Lisp libraries.
In `->`, the form is threaded through the functions. `(*> #'space #'rest)` likely means `(funcall #'rest (funcall #'space ...))` or something similar.
Wait, `*>` is often used for "thread-last" or just a specific threading macro. Let's assume it's a macro that threads the result of the first function into the second function.
Actually, `*>` might be a macro that expands to `(compose #'rest #'space)` or `(lambda (x) (funcall #'rest (funcall #'space x)))`.
Or maybe it's from a specific library like `iterate` or `lisp-unit`? No, `*>` is commonly used in `clojure`-inspired macros or `fiasco` or `alexandria`.
Wait, the prompt says: "Macro call that should be transformed by *>". It gives `(*> #'space #'rest)`.
This looks like function composition. `(*> f g)` usually means `(compose g f)` or `(lambda (x) (g (f x)))`.
Let's think about how `*>` is typically defined in Common Lisp. Sometimes it's defined as:
`(defmacro *> (&rest forms) (reduce (lambda (a b) `(funcall ,b ,a)) forms))`
Wait, if it's `(*> #'space #'rest)`, it might expand to `(funcall #'rest (funcall #'space))`? That doesn't make sense without an argument.
Maybe it's `(lambda (x) (funcall #'rest (funcall #'space x)))`?
Or maybe `*>` is just a macro that reverses the order for `funcall`? Like `(funcall #'rest (funcall #'space arg))`? But there's no `arg`.
Actually, in many Lisp libraries, `*>` is a macro for threading. For example, in `clojure`, `->>` is thread-last. But `*>` might be from `iterate` or `lisp` packages.
Wait, the prompt says: "Given this code pattern: `(*> #'space #'rest)` Write a macro that addresses: Macro call that should be transformed by *>".
This is a bit vague. It might be asking for a macro that expands `(*> f1 f2 ... fn)` into `(fn (f1 (f2 ...)))` or similar.
Let's consider a simple composition macro:
`(defmacro *> (&rest functions)
  (if (null functions)
      #'identity
      (reduce (lambda (accum func)
                `(lambda (x) (funcall ,func (funcall ,accum x))))
              (cdr functions)
              :initial-value `(lambda (x) (funcall ,(car functions) x)))))`
But that's complex.
Maybe `*>` is just a macro that expands to `(compose #'rest #'space)`? But `compose` isn't standard.
Let's look at the exact wording: "Macro call that should be transformed by *>". This implies `*>` is the macro being defined.
Perhaps it's from a known library like `fiasco` or `alexandria`? `alexandria` has `compose`.
Wait, `*>` is often used in `iterate` or `lisp` for "pipe". Actually, in `clojure`, `->` is thread-first, `->>` is thread-last. In Common Lisp, `-->` or `->>` is common. `*>` might be from `lisp-unit` or `parachute`? No.
Let's think of a simpler interpretation: `(*> f1 f2)` expands to `(lambda (x) (funcall f2 (funcall f1 x)))`.
Or maybe it's just `(funcall #'rest (funcall #'space))`? That would be a partial application or just composition without arguments.
Actually, there's a well-known macro `*>` in some Lisp codebases that expands to a composition. For example:
`(defmacro *> (&rest fns)
  (labels ((compose (fns)
             (cond ((null fns) #'identity)
                   ((null (cdr fns)) (car fns))
                   (t `(lambda (&rest args)
                         (funcall ,(car (last fns))
                                  (apply ,(compose (butlast fns)) args)))))))
    (compose fns)))`
But that's too complicated for
</think>
(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)))))


[System] You are an expert Common Lisp macro programmer. Think step by step before writing the macro. Always explain your reasoning in <think>...</think> tags, then provide the defmacro form.

[User]
Write a Common Lisp macro to handle this code pattern:
(define-test fixture :fix (*read-default-float-format*) (is = 0.0f0 (read-from-string "0.0")) (setf *read-default-float-format* 'double-float) (is = 0.0d0 (read-from-string "0.0")))

Problem: Macro call that should be transformed by define-test

[Assistant]
<think>
The user wants a Common Lisp macro named `define-test` that handles a specific code pattern.
Let's analyze the pattern:
</think>
(defmacro define-test (name &body arguments-and-body)
  (destructuring-bind (nparent name) (if (listp name) name (list NIL name))
    (form-fiddle:with-body-options (body options parent home (test-class 'test) (compile-at :compile-time) defun) arguments-and-body
      (let ((body (remove 'define-test body :key (lambda (a) (when (listp a) (car a))) :test #'eql))
            (defs (remove 'define-test body :key (lambda (a) (when (listp a) (car a))) :test-not #'eql))
            (home-form (or home `(find-package ,(package-name *package*)))))
        (when (and parent nparent)
          (error "Cannot specify parent through name and through a keyword argument at the same time!"))
        `(let ((*package* (find-package ,(package-name *package*)))) ; Make sure package stays consistent throughout initialisation.
           (setf (find-test ',name ,home-form)
                 (ensure-test ',test-class
                              :name ',name
                              :home ,home-form
                              :tests (list ,@(loop for form in body
                                                   collect (ecase compile-at
                                                             (:compile-time `(lambda () ,form))
                                                             (:execute `(lambda () (call-compile ',form))))))
                              :parent ',(or parent nparent)
                              ,@(loop for option in options
                                      collect `',option)))
           ,@(loop for (def subname . body) in defs
                   collect `(,def (,name ,subname)
                              :home ,home
                              ,@body))
           ,@(when defun
               `((defun ,(if (stringp name) (read-symbol name) name) (&rest test-args)
                   (apply #'test (find-test ',name ,home-form) test-args))))
           ',name)))))


[System] You are an expert Common Lisp macro programmer. Think step by step before writing the macro. Always explain your reasoning in <think>...</think> tags, then provide the defmacro form.

[User]
Create a Common Lisp macro for the following transformation. Before code:
(define-test override (true T) (skip "Not ready yet" (false T) (is = 5 6)) (with-forced-status (:failed) (false NIL)))

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

[Assistant]
<think>
The user wants a Common Lisp macro named `define-test` that transforms a specific test definition syntax into standard Common Lisp code.
Let's analyze the input:
`(define-test override (true T) (skip "Not ready yet" (false T) (is = 5 6)) (with-forced-status (:failed) (false NIL)))`

The macro takes:
1. A test name: `override`
2. A list of test cases/bodies:
   - `(true T)`
   - `(skip "Not ready yet" (false T) (is = 5 6))`
   - `(with-forced-status (:failed) (false NIL))`

Wait, this looks like a test framework syntax. Probably similar to `fiveam` or `stest` or a custom one.
`true`, `false`, `skip`, `is`, `with-forced-status` seem to be test assertions or modifiers.
`true T` probably asserts that T is true.
`false T` asserts that T is false (which will fail).
`is = 5 6` asserts equality.
`skip "Not ready yet"` skips the test with a message.
`with-forced-status (:failed)` forces the test status to failed.

The macro `define-test` likely expands into a function or a test registration form.
In Common Lisp test frameworks like `fiveam`, tests are defined with `deftest`.
But here, the syntax is custom. I need to generate a macro that wraps these forms in a test body.
Usually, `define-test` expands to something like:
`(deftest override ...)` or `(defun override () ...)` or registers a test.
Since the prompt doesn't specify the exact expansion target, I should assume a standard pattern: it probably expands to a function definition or a test registration macro call.
Let's look at the structure: `(define-test name &rest bodies)`
Each body is a list of forms. They should probably be executed sequentially, or each is a separate subtest.
Given `(skip "Not ready yet" (false T) (is = 5 6))`, it seems like forms inside a body are grouped. `skip` might wrap the rest, or it's just a sequence.
Actually, in many Lisp test frameworks, `define-test` is just an alias for `deftest` or similar, but here it seems to parse a DSL.
Wait, `true`, `false`, `is` look like assertions. `skip` and `with-forced-status` look like control flow/modifiers.
Maybe the macro simply expands to a function that runs these forms, or it expands to a call to a test runner.
Let's assume it expands to a standard `defun` or `deftest` that groups the bodies.
Actually, a common pattern for such macros is to expand each body into a block, or just concatenate them into the test body.
But `skip` and `with-forced-status` are likely macros themselves that wrap subsequent forms.
If `define-test` just needs to wrap the bodies in a test definition, it might look like:
`(defmacro define-test (name &rest bodies) ...)`
It should probably expand to:
`(deftest ,name ,@bodies)` or `(defun ,name () ,@(mapcan #'identity bodies))`
Wait, `fiveam` uses `deftest`. But `true`, `false`, `is` are not standard fiveam. They look like `stest` or `parachute` or a custom DSL.
Actually, this looks exactly like the syntax for `fiveam` extended with some helpers, or maybe `cl-test-grid`.
Alternatively, it might be from `prove` or `let-test`.
Let's think about what `define-test` typically does in such contexts. It usually defines a test function.
I will assume it expands to a `defun` that wraps the bodies in a `progn`, or perhaps each body is a separate assertion group.
Actually, a safer bet: `define-test` expands to a test registration form. Since I don't know the target framework, I'll make it expand to a standard Common Lisp `defun` that executes the forms, or I'll assume it's meant to expand to a `deftest`-like form.
Wait, the prompt says: "Macro call that should be transformed by define-test". It asks me to create the macro.
I should probably expand it to a function definition that runs the test cases.
Let's look at the structure again:
`(define-test override (true T) (skip "Not ready yet" (false T) (is = 5 6)) (with-forced-status (:failed) (false NIL)))`
It
</think>
(defmacro define-test (name &body arguments-and-body)
  (destructuring-bind (nparent name) (if (listp name) name (list NIL name))
    (form-fiddle:with-body-options (body options parent home (test-class 'test) (compile-at :compile-time) defun) arguments-and-body
      (let ((body (remove 'define-test body :key (lambda (a) (when (listp a) (car a))) :test #'eql))
            (defs (remove 'define-test body :key (lambda (a) (when (listp a) (car a))) :test-not #'eql))
            (home-form (or home `(find-package ,(package-name *package*)))))
        (when (and parent nparent)
          (error "Cannot specify parent through name and through a keyword argument at the same time!"))
        `(let ((*package* (find-package ,(package-name *package*)))) ; Make sure package stays consistent throughout initialisation.
           (setf (find-test ',name ,home-form)
                 (ensure-test ',test-class
                              :name ',name
                              :home ,home-form
                              :tests (list ,@(loop for form in body
                                                   collect (ecase compile-at
                                                             (:compile-time `(lambda () ,form))
                                                             (:execute `(lambda () (call-compile ',form))))))
                              :parent ',(or parent nparent)
                              ,@(loop for option in options
                                      collect `',option)))
           ,@(loop for (def subname . body) in defs
                   collect `(,def (,name ,subname)
                              :home ,home
                              ,@body))
           ,@(when defun
               `((defun ,(if (stringp name) (read-symbol name) name) (&rest test-args)
                   (apply #'test (find-test ',name ,home-form) test-args))))
           ',name)))))


[System] You are an expert Common Lisp macro programmer. Think step by step before writing the macro. Always explain your reasoning in <think>...</think> tags, then provide the defmacro form.

[User]
Generate a defmacro form that transforms code like this:
($> "l" -900)

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

[Assistant]
<think>
The user wants a Common Lisp macro named `$>` that transforms a specific pattern of code.
The example provided is `($> "l" -900)`.
However, the prompt is slightly ambiguous about what the transformation should be. Usually, `$>` is associated with turtle graphics (like Logo) where it might mean "turn right" or similar. Or it could be a generic operator.
Let's look at the example: `($> "l" -900)`.
If this is turtle graphics, "l" usually means left, and -900 might be degrees.
But without a specific target language or context (like "transform to turtle commands"), I have to make a reasonable assumption or create a generic transformation.
Often, these requests come from users trying to recreate Logo syntax in Lisp.
In Logo, `lt 90` turns left. `rt 90` turns right.
Maybe `$>` is a shorthand for something?
Let's consider the pattern: `($> arg1 arg2)`.
If I assume this is a request to generate a macro that simply evaluates arguments or transforms them into a function call, I need to decide on the target form.
Since the prompt asks "transforms code like this", but doesn't specify the target, I should probably define a macro that captures the arguments and perhaps prints them or calls a generic function, or maybe it's a specific syntax sugar.

Wait, looking at the pattern `($> "l" -900)`, it looks like a function call.
Maybe the user wants a macro that expands into a function call to a different name?
Or maybe it's a "do" block?
Let's look at the structure.
`($> "l" -900)` -> 2 arguments.
Perhaps it's a specific DSL.
Let's assume the user wants a macro that takes these arguments and wraps them in a standard function call, maybe `turtle-turn` or similar, or perhaps just evaluates them.
However, without the target, the most helpful response is to provide a macro that demonstrates the pattern matching and expansion mechanism, perhaps expanding to a generic function call like `(turn "l" -900)` or similar, or simply evaluating the arguments.

Actually, looking at common Lisp macro exercises, often `$>` is used to denote a specific operator.
Let's assume the user wants to transform `($> arg1 arg2)` into `(some-function arg1 arg2)`.
But which function?
Maybe the user implies a specific transformation like "turn left" or "turn right".
Let's consider the possibility that `$>` is a typo for `>`? No, it's a macro name.
Let's consider the possibility that this is related to a specific library or context I'm unaware of.
Given the ambiguity, I will write a macro that accepts the arguments and expands to a generic form, perhaps `(apply-turn arg1 arg2)` or similar, to show the structure.
However, a safer bet is to look at the "l" and "-900".
Maybe it's `($> direction angle)`.
Let's create a macro that transforms `($> dir angle)` into `(turtle-turn dir angle)`.
Or, if I want to be purely syntactic, I can just evaluate the arguments.

Let's step back. The user asks to "Generate a defmacro form that transforms code like this".
They didn't say "into what".
I should probably ask for clarification, but as an AI, I must provide a complete answer.
I will assume the macro is meant to be a wrapper for a function, say `turn-turtle`.
Or maybe it's a specific syntax for a DSL.
Let's try to interpret `$>` as "greater than"? No, it's a macro.
Let's interpret it as a command.
I will write a macro that takes `arg1` and `arg2` and expands to a call to a function `process-command`.
This demonstrates the macro mechanics.

Wait, is there a standard meaning?
In some contexts, `$>` might be a pipe operator? No.
Let's stick to the structure.
Pattern: `($> arg1 arg2)`.
Expansion: `(some-function arg1 arg2)`.
I'll use a placeholder function name like `execute-command` to make it clear that it's a transformation.

Alternatively, maybe the user wants to transform it into a `progn` or `let`?
Let's look at the arguments. "l" is a string. -900 is a number.
Maybe it's `($> "l" -900)` -> `(turn "l" -900)`.
I'll go with a generic transformation to a function call `turtle-move` or similar to give it flavor,
</think>
(defmacro $> (&rest args)
  `($op "$gt" ,@args))


[System] You are an expert Common Lisp macro programmer. Think step by step before writing the macro. Always explain your reasoning in <think>...</think> tags, then provide the defmacro form.

[User]
Create a Common Lisp macro for the following transformation. Before code:
(with-decoder-simple-list-semantics (let ((*json-symbols-package* (find-package :keyword)) (*json-identifier-name-to-lisp* #'simplified-camel-case-to-lisp)) (is (equalp '((:hello-key . "hej") (:hi-starts-with-upper-case . "tjena") (:jsonall-capitals . "totae majusculae") (:two_words . "duo verba") (:camel-case_mixed_4_parts . "partes miscella quatuor")) (decode-json-from-string " { \"helloKey\" : \"hej\" , \"HiStartsWithUpperCase\" : \"tjena\", \"JSONAllCapitals\": \"totae majusculae\", \"TWO_WORDS\": \"duo verba\", \"camelCase_Mixed_4_PARTS\": \"partes miscella quatuor\" }")))))

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

[Assistant]
<think>
The user wants a macro `with-decoder-simple-list-semantics` that transforms the given code.
Let's analyze the input code:
</think>
(defmacro with-decoder-simple-list-semantics (&body body)
  "Execute BODY in a dynamic environement where the decoder semantics
is such as set by SET-DECODER-SIMPLE-LIST-SEMANTICS."
  `(with-shadowed-custom-vars
     (set-decoder-simple-list-semantics)
     ,@body))


[System] You are an expert Common Lisp macro programmer. Think step by step before writing the macro. Always explain your reasoning in <think>...</think> tags, then provide the defmacro form.

[User]
Write a Common Lisp macro to handle this code pattern:
(with-wcs-math-error-handling (ret (fround x)) (check-wcs-math-result))

Problem: Macro call that should be transformed by with-wcs-math-error-handling

[Assistant]
<think>
The user wants a Common Lisp macro named `with-wcs-math-error-handling`.
The pattern provided is: `(with-wcs-math-error-handling (ret (fround x)) (check-wcs-math-result))`.
This looks like a binding macro, similar to `let` or `let*`, but likely intended to handle errors or specific math results.
However, the prompt asks to "handle this code pattern" and mentions "Macro call that should be transformed".
This implies the macro needs to expand into a form that binds the variable `ret` to the result of `(fround x)` and then executes the body `(check-wcs-math-result)`.
Usually, "math error handling" macros might check for floating-point exceptions or NaN/Infinity.
However, without specific semantics on *how* to handle the error, I should infer the standard behavior for such a macro name or provide a generic structure that fits the pattern.
The pattern `(var expr)` suggests a binding.
The body is `(check-wcs-math-result)`.

Let's assume the macro intends to:
1. Evaluate the expression `(fround x)`.
2. Bind the result to `ret`.
3. Execute the body.
4. Perhaps check for errors (though the implementation of the check is up to the user or the macro's hidden logic).

Given the "Expert Common Lisp macro programmer" persona, I should consider hygiene and standard expansion techniques.
The pattern `(with-wcs-math-error-handling (binding) body...)` suggests a `let`-like structure.

Let's refine the "error handling" aspect. Often, these macros wrap the computation in a condition handler or check the result.
Since the prompt doesn't specify the exact error handling logic (e.g., signaling an error, returning nil, etc.), I will implement a structure that:
1. Binds the result.
2. Performs a check (represented by a call to a function or macro, likely `check-wcs-math-result` is the body, or the macro injects a check).
Wait, looking at the example: `(with-wcs-math-error-handling (ret (fround x)) (check-wcs-math-result))`.
It looks like `check-wcs-math-result` is the body passed by the user.
So the macro should simply bind `ret` to `(fround x)` and execute the body. The "error handling" might be implicit in the binding or the macro name implies a context where errors are trapped.
However, to be a "macro to handle this code pattern", it essentially acts as a specialized `let`.

Let's draft the pattern matching:
</think>
(defmacro with-wcs-math-error-handling
    ((var-or-var-list
      (function x &optional (y nil y-supplied-p))
      &rest keyargs
      &key underflow-value)
     &body body)
  (declare (ignorable underflow-value))
  (let ((x_ (gensym)) (y_ (gensym)) (args_ (gensym))
        (var-list (ensure-list var-or-var-list)))
    `(let* ((,x_ ,x)
            (,y_ ,y)
            (,args_ (list ,x_ ,@(if y-supplied-p `(,y_)))))
       (declare (ignorable ,y_)
                (type list ,args_)
                (dynamic-extent ,args_))
       (catch 'return-from-with-wcs-math-error-handling
         (multiple-value-bind ,var-list
             (call-with-wcs-math-error-handler ',function ,args_
                                               ,@keyargs)
           (flet ((check-wcs-math-result
                      (&optional (ret ,(first var-list))
                                 (arg-list ,args_))
                    (check-wcs-math-result ret arg-list)))
             ,@body))))))


[System] You are an expert Common Lisp macro programmer. Think step by step before writing the macro. Always explain your reasoning in <think>...</think> tags, then provide the defmacro form.

[User]
Create a Common Lisp macro for the following transformation. Before code:
(defvar-unbound *start-char* "Bound to the opening outer delimiter while parsing a string.")

What needs to change: Macro call that should be transformed by defvar-unbound

[Assistant]
<think>
The user wants a Common Lisp macro named `defvar-unbound`.
The input form is:
`(defvar-unbound *start-char* "Bound to the opening outer delimiter while parsing a string.")`

The macro should transform this into a `defvar` form where the variable is initially unbound, but has a documentation string.
In Common Lisp, `defvar` takes a variable name, an optional initial value, and an optional documentation string.
If the initial value is omitted, the variable remains unbound if it was previously unbound.
However, the user explicitly says "defvar-unbound", implying the intent is to ensure the variable is unbound or to define it without an initial value but with documentation.

Standard `defvar` usage:
`(defvar *start-char* nil "doc")` -> initializes to nil if unbound.
`(defvar *start-char* "doc")` -> syntax error, `defvar` expects value before doc.
Actually, `defvar` syntax is `(defvar name [initform] [documentation])`.
If we want it unbound, we usually just do `(defvar *start-char* "doc")`? No, that's invalid syntax for standard `defvar` in many implementations if the second arg is a string, it might be treated as initform.
Wait, `defvar` allows omitting the initform. `(defvar *start-char* "doc")` is ambiguous. Some implementations might accept the string as documentation if the initform is omitted, but the standard says the initform comes before the doc.
To explicitly make it unbound with documentation, one might use `(defvar *start-char* (error "unbound") "doc")`? No.
The standard way to define a variable with documentation but no initial value is:
`(defvar *start-char* nil "doc")` and then `makunbound`? No.
Actually, `(defvar *start-char* "doc")` is often valid in practice where the second argument is the doc string if the initform is missing, but strictly speaking, the initform is required if a doc is provided?
Let's check CLHS. `defvar` is a macro. `(defvar name [initform] [documentation])`.
If `initform` is omitted, the variable is not initialized.
So `(defvar *start-char* "doc")` might be interpreted as initform="doc".
To get unbound with doc, we need `(defvar *start-char* (values) "doc")`? No.
The standard way is `(defvar *start-char* nil "doc")` and accept nil, OR use a macro that expands to `(defvar name (error "unbound") doc)`?
Actually, the most robust way to ensure unbound is `(defvar name (progn (error "unbound")) doc)`?
Or simply `(defvar name nil doc)` and let the user know it's nil?
The name `defvar-unbound` suggests the variable should remain unbound.
In Common Lisp, if you do `(defvar x "doc")`, it sets x to "doc".
If you do `(defvar x)`, x is unbound (if it was).
To have doc and unbound, you can do:
`(defvar x (error "unbound") "doc")` -> this errors on eval if initform is evaluated. `defvar` only evaluates initform if the variable is unbound.
So `(defvar-unbound x "doc")` -> `(defvar x (error "unbound") "doc")` works. If x is bound, initform is not evaluated. If x is unbound, initform is evaluated, causing an error? That's not "unbound", that's "error on access".
Maybe the user just wants `(defvar name doc)` where the macro handles the syntax?
Some implementations allow `(defvar name doc)` directly.
But to be portable, `(defvar name (values) doc)`? No.
The standard pattern for "defvar with doc but no init" is:
`(defvar name nil doc)`
But if the user insists on "unbound", maybe they mean `(defvar name (error "unbound") doc)`?
Or maybe they just want `(defvar name doc)` and rely on implementation behavior?
Let's assume the standard interpretation: `defvar-unbound` expands to `defvar` with a dummy initform that ensures unbound status or just omits it if the implementation allows.
Actually, the cleanest expansion for "unbound with doc" is:
`(defvar name (error "unbound") doc)` -> This makes it error if accessed while unbound.
Or `(defvar name nil doc)`
</think>
(defmacro defvar-unbound (variable-name documentation)
  "Like DEFVAR, but the variable will be unbound rather than getting
an initial value.  This is useful for variables which should have no
global value but might have a dynamically bound value."
  ;; stolen from comp.lang.lisp article <k7727i3s.fsf@comcast.net> by
  ;; "prunesquallor@comcast.net"
  `(eval-when (:load-toplevel :compile-toplevel :execute)
    (defvar ,variable-name)
    (setf (documentation ',variable-name 'variable)
            ,documentation)))


[System] You are an expert Common Lisp macro programmer. Think step by step before writing the macro. Always explain your reasoning in <think>...</think> tags, then provide the defmacro form.

[User]
Write a Common Lisp macro to handle this code pattern:
(fmap #'1+ (ok (in "") 1))

Problem: Macro call that should be transformed by fmap

[Assistant]
<think>
The user wants a Common Lisp macro to handle a specific code pattern: `(fmap #'1+ (ok (in "") 1))`.

Let's analyze the pattern:
1. The pattern involves `fmap` which is typically a function in functional programming (like in Haskell) that maps a function over a functor.
2. In Common Lisp, `fmap` might be a macro or a function. The user says "Macro call that should be transformed by fmap".
3. The example is `(fmap #'1+ (ok (in "") 1))`.
4. `(ok ...)` looks like it might be a monad/functor constructor (like Maybe or Either). `(in "")` might be some input/validation function. `1` is a value.
5. Wait, the prompt says: "Write a Common Lisp macro to handle this code pattern: `(fmap #'1+ (ok (in "") 1))`".
6. It's asking for a macro named `fmap`? Or a macro that transforms calls to `fmap`?
7. Usually, in CL, one might define `fmap` as a macro that expands into something more efficient or idiomatic, or perhaps it's about handling a specific DSL.
8. Let's think about what `fmap` does in functional programming: `(fmap func container)` applies `func` to the value inside `container`.
9. If `ok` is a constructor for a "success" type (like `Maybe` or `Result`), then `(fmap #'1+ (ok 1))` should evaluate to `(ok 2)`.
10. If `fmap` is a macro, it might be used to inline the operation or handle specific types.
11. However, the prompt is quite open-ended: "Write a Common Lisp macro to handle this code pattern: `(fmap #'1+ (ok (in "") 1))`".
12. Maybe it's about a specific library or pattern? "ok" and "in" suggest a validation or parsing library. `in` might be "input", `ok` might be "success".
13. Actually, this looks like it could be from a specific Lisp library, maybe `cl-maybe` or `cl-continuations` or a custom DSL. But without more context, I should design a general `fmap` macro that works for a functor-like structure, or perhaps the user wants a macro that expands `(fmap func form)` into something like `(if (ok-p form) (ok (funcall func (ok-value form))) form)`.
14. Wait, the prompt says "Macro call that should be transformed by fmap". This might mean the user wants a macro named `fmap` that transforms the call.
15. Let's consider a typical `fmap` macro for a simple `ok`/`err` type (like Haskell's `Either` or `Maybe`).
    If we have a type `result` with constructors `ok` and `err`.
    `(fmap #'1+ (ok 1))` -> `(ok 2)`
    `(fmap #'1+ (err "msg"))` -> `(err "msg")`
    A macro could expand to a `cond` or `typecase` or use a generic function. But macros usually expand to standard CL code.
    Maybe the user wants a macro that desugars `(fmap func form)` into `(let ((val form)) (if (ok-p val) (ok (funcall func (ok-val val))) val))`.
16. Alternatively, maybe `fmap` is supposed to be a macro that handles backtracking or monadic bind? No, `fmap` is map.
17. Let's look at the exact pattern: `(fmap #'1+ (ok (in "") 1))`.
    `(in "")` might be a function call returning something. `ok` takes two arguments? `(ok (in "") 1)` -> `ok` takes a context and a value? Or maybe `ok` is a macro itself?
    Actually, this looks like it might be from a specific codebase. "in" and "ok" are often used in validation libraries.
    Wait, could it be `cl-functor` or `monads` library?
    Let's assume a simple structure: `fmap` applies a function to the value inside a wrapper.
    I will write a macro `fmap` that takes a function and a form, and expands to code that checks if the form is an `ok` instance, and if so, applies the function to its value, reconstructing the `ok`. Otherwise, it returns the form unchanged (handling `err` or other functors).
    But to
</think>
(defmacro fmap (f thing)
  "Apply a pure function to the inner contents of some parsing operation, if the
parsing itself was successful."
  `(multiple-value-bind (res next) ,thing
     (if (failure? res)
         (fail next)
         (values (funcall ,f res) next))))


[System] You are an expert Common Lisp macro programmer. Think step by step before writing the macro. Always explain your reasoning in <think>...</think> tags, then provide the defmacro form.

[User]
Create a Common Lisp macro for the following transformation. Before code:
(with-wcs-math-error-handling ((quot rem) (ftruncate x y)) (check-wcs-math-result) rem)

What needs to change: Macro call that should be transformed by with-wcs-math-error-handling

[Assistant]
<think>
The user wants me to create a Common Lisp macro named `with-wcs-math-error-handling`.
Looking at the example usage:
`(with-wcs-math-error-handling ((quot rem) (ftruncate x y)) (check-wcs-math-result) rem)`

This looks like a macro that wraps a computation in error handling.
The syntax seems to be:
`(with-wcs-math-error-handling (bindings form) error-handling-form* result-form)`
Wait, let's look closer at the example:
`(with-wcs-math-error-handling ((quot rem) (ftruncate x y)) (check-wcs-math-result) rem)`

It seems to bind `(quot rem)` to the result of `(ftruncate x y)`.
Then it executes `(check-wcs-math-result)` and returns `rem`.
Actually, `ftruncate` returns two values: quotient and remainder.
So `((quot rem) (ftruncate x y))` is a multiple-value binding.
The macro probably expands to something like:
`(multiple-value-bind (quot rem) (ftruncate x y) (check-wcs-math-result) rem)`
But with error handling. Maybe it catches errors from `ftruncate` or `check-wcs-math-result`?
Or maybe it's just a convenience macro that expands to `multiple-value-bind` plus some error checking logic.
Wait, "wcs-math-error-handling" suggests it handles math errors in a specific way (maybe WCS library?).
But I don't have the exact error handling logic. I should probably just expand it to `multiple-value-bind` and wrap the body in a `handler-case` or `ignore-errors`, or maybe just `multiple-value-bind` if the error handling is implicit.
Actually, looking at the pattern, it's very likely just a macro that expands to `multiple-value-bind` with some error handling wrapper.
Let's assume it expands to:
`(multiple-value-bind (quot rem) (ftruncate x y) (check-wcs-math-result) rem)`
But with error handling, maybe:
`(handler-case (multiple-value-bind (quot rem) (ftruncate x y) (check-wcs-math-result) rem) (error (e) ...))`
Since I don't know the exact error handling, I'll make a reasonable macro that captures the structure.
Actually, the prompt says "Create a Common Lisp macro for the following transformation."
It gives "Before code:" which is the macro call itself.
So the macro should expand that call into something else.
What is the "After code"? It's not provided. I need to infer it or just write a macro that matches the syntax.
Wait, maybe it's from a specific library? "wcs-math" might refer to Something with WCS (World Coordinate System?).
Or maybe it's just a generic macro pattern: `(with-wcs-math-error-handling (bindings form) body...)`
I will write a macro that takes `(bindings form) &body body` and expands to `(multiple-value-bind bindings form (handler-case (progn body) (arithmetic-error (e) ...)))` or similar.
Actually, a safer bet is to just expand to `multiple-value-bind` and wrap in `handler-case` for `arithmetic-error` or `division-by-zero` etc.
But I'll keep it simple: `(multiple-value-bind bindings form (handler-case (progn ,@body) (error (e) (error e))))` or just `(multiple-value-bind ,bindings ,form ,@body)` if the error handling is just a name.
Wait, the prompt says "Macro call that should be transformed by with-wcs-math-error-handling". This implies the macro *is* `with-wcs-math-error-handling`.
I will define it to expand to `multiple-value-bind` with a `handler-case` that catches `arithmetic-error` and signals it or handles it. But since I don't know the exact handling, I'll just use `handler-case` with a placeholder or standard error propagation.
Actually, many such macros just expand to `multiple-value-bind` and maybe check for `most-negative-double-float` or NaN.
I'll stick to a straightforward expansion:
`(defmacro with-wcs-math-error-handling ((bindings form) &body body)
  `(multiple-value-bind ,bindings ,form
     (handler-case (progn ,@body)
       (arithmetic-error (e) ,@body))))` -> No.
Let's think about typical math error handling macros. They often catch `division-by-zero` or `invalid-number`.
I'll just write a macro that expands to `multiple-value-bind` and wraps the body in `handler-case` to catch `arithmetic-error` and re-signal or handle
</think>
(defmacro with-wcs-math-error-handling
    ((var-or-var-list
      (function x &optional (y nil y-supplied-p))
      &rest keyargs
      &key underflow-value)
     &body body)
  (declare (ignorable underflow-value))
  (let ((x_ (gensym)) (y_ (gensym)) (args_ (gensym))
        (var-list (ensure-list var-or-var-list)))
    `(let* ((,x_ ,x)
            (,y_ ,y)
            (,args_ (list ,x_ ,@(if y-supplied-p `(,y_)))))
       (declare (ignorable ,y_)
                (type list ,args_)
                (dynamic-extent ,args_))
       (catch 'return-from-with-wcs-math-error-handling
         (multiple-value-bind ,var-list
             (call-with-wcs-math-error-handler ',function ,args_
                                               ,@keyargs)
           (flet ((check-wcs-math-result
                      (&optional (ret ,(first var-list))
                                 (arg-list ,args_))
                    (check-wcs-math-result ret arg-list)))
             ,@body))))))


[System] You are an expert Common Lisp macro programmer. Think step by step before writing the macro. Always explain your reasoning in <think>...</think> tags, then provide the defmacro form.

[User]
Define a macro that eliminates this repetitive pattern:
(with-log-error-handling () (with-wcs-math-error-handling (ret (log1+ x)) (check-wcs-math-result)))

Issue: Macro call that should be transformed by with-log-error-handling

[Assistant]
<think>
The user wants to define a macro that simplifies a repetitive pattern involving `with-log-error-handling` and `with-wcs-math-error-handling`.
The pattern is:
`(with-log-error-handling () (with-wcs-math-error-handling (ret (log1+ x)) (check-wcs-math-result)))`

Let's break down the components:
1. `with-log-error-handling` takes no arguments in this example (or maybe it's just a wrapper).
2. `with-wcs-math-error-handling` takes a binding `(ret (log1+ x))` and a body `(check-wcs-math-result)`.
3. The goal is to combine these into a single macro, let's call it `with-wcs-math-and-log-error-handling` or similar, that takes the binding and the body.

Wait, the prompt says "Define a macro that eliminates this repetitive pattern". It doesn't specify the macro name. I'll choose a descriptive name like `with-wcs-math-and-log-error-handling` or `with-wcs-math-log-error`.

Let's assume the macro should look like:
`(with-wcs-math-log-error (ret (log1+ x)) (check-wcs-math-result))`
which expands to:
`(with-log-error-handling () (with-wcs-math-error-handling (ret (log1+ x)) (check-wcs-math-result)))`

Step 1: Identify the pattern.
Outer: `(with-log-error-handling () ...)`
Inner: `(with-wcs-math-error-handling (var expr) body...)`

Step 2: Determine macro parameters.
`defmacro (with-wcs-math-log-error (var expr) &body body)`

Step 3: Quasiquote/unquote.
`` `(with-log-error-handling () (with-wcs-math-error-handling (,var ,expr) ,@body)) ``

Step 4: Variable capture.
`var` is a lexical binding introduced by `with-wcs-math-error-handling`. Since it's a macro parameter representing a symbol, it's fine. We just pass it through. No gensym needed unless `with-wcs-math-error-handling` expects a gensym, but usually it's a binding macro like `let`. We'll assume standard macro hygiene applies or that the inner macro handles it. Since we are just passing `var` and `expr` to the inner macro, capture is not an issue here.

Step 5: Structure.
</think>
(defmacro with-log-error-handling (() &body body)
  `(handler-case
      (progn ,@body)
    #+allegro
    ;; TODO: rewrite other `simple-error' handler to use arithmetic-error.
    (arithmetic-error (e)
      (let ((operands (arithmetic-error-operands e)))
        (cond ((zerop (first operands))
               (wcs-raise-fe-exception FE_DIVBYZERO :errno ERANGE)
               (- HUGE_VAL))
              (t
               (error e)))))))


[System] You are an expert Common Lisp macro programmer. Think step by step before writing the macro. Always explain your reasoning in <think>...</think> tags, then provide the defmacro form.

[User]
Define a macro that eliminates this repetitive pattern:
(defannotation annotation (options function-definition-form) (:arity 2) (let ((name (definition-form-symbol (progn-form-last function-definition-form)))) `(progn (set-annotation-options ',name ',options) ,function-definition-form)))

Issue: Macro call that should be transformed by defannotation

[Assistant]
<think>
The user wants me to define a macro called `defannotation` that eliminates a repetitive pattern.
Looking at the provided pattern:
</think>
(defmacro defannotation (name lambda-list options &body body)
  `(progn
     (set-annotation-options ',name ',options)
     (defmacro ,name ,lambda-list ,@body)))


[System] You are an expert Common Lisp macro programmer. Think step by step before writing the macro. Always explain your reasoning in <think>...</think> tags, then provide the defmacro form.

[User]
Create a Common Lisp macro for the following transformation. Before code:
(with-prepared-query query (*connection* sql :use-prepare-cached *use-prepare-cached*) (setf query (execute-with-retry query binds)) (query-row-count query))

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

[Assistant]
<think>
The user wants to create a Common Lisp macro named `with-prepared-query`.
Looking at the example usage:
</think>
(defmacro with-prepared-query (query (conn sql &key use-prepare-cached) &body body)
  `(call-with-prepared-query ,conn ,sql (lambda (,query) ,@body) :use-prepare-cached ,use-prepare-cached))


[System] You are an expert Common Lisp macro programmer. Think step by step before writing the macro. Always explain your reasoning in <think>...</think> tags, then provide the defmacro form.

[User]
Define a macro that eliminates this repetitive pattern:
(defclause summing-to-and-returning (vars &optional result-processor) "Same as summing-to, but also returns the value of each <vars> at the end of the loop." `((summing-to ,vars ,result-processor) ,@(mapcar (lambda (var) `(returning ,var)) (ensure-list vars))))

Issue: Macro call that should be transformed by defclause

[Assistant]
<think>
The user wants to define a macro that expands a call to `defclause` into a specific pattern.
Looking at the provided code snippet, it seems to be an example of what `defclause` should expand to, or perhaps the user is asking to define `defclause` such that it generates this code.
Wait, the prompt says: "Define a macro that eliminates this repetitive pattern: (defclause summing-to-and-returning (vars &optional result-processor) ...)"
Actually, the code provided looks like the *expansion* or the *body* of the macro, but it's wrapped in backticks.
Let's analyze the pattern:
`(defclause name (args) docstring expansion-form)`
The expansion form is:
`` `((summing-to ,vars ,result-processor) ,@(mapcar (lambda (var) `(returning ,var)) (ensure-list vars))) ``
Wait, the prompt says "Issue: Macro call that should be transformed by defclause". This implies the user wants a macro `defclause` that takes a name, arguments, a docstring, and a body, and generates a function or another macro? Or maybe it's defining a clause for a loop macro?
Actually, this looks like code from a library like `loop` or a custom iteration macro. `defclause` might be defining a new clause for a loop-like macro.
Let's assume `defclause` is a macro that defines a function or a transformation rule.
However, the prompt is a bit ambiguous. "Define a macro that eliminates this repetitive pattern". The pattern is a call to `defclause`.
Maybe the user wants a macro that generates the `defclause` call? No, that doesn't make sense.
Maybe the user wants to define `defclause` itself?
Let's look at the structure: `(defclause summing-to-and-returning (vars &optional result-processor) "doc" body)`
If I define `defclause`, it probably expands to `(defun clause-name (args) docstring body)` or something similar.
But the body contains backticks and unquotes. If `defclause` is a macro, the body is evaluated at macro-expansion time? Or is it quoted?
Usually, macros like `defclause` in loop libraries take the body as a template.
Let's assume the user wants a macro `defclause` that expands to a `defun` or `defmacro`. Given the backticks in the example, it's likely the body is meant to be a template that gets evaluated when the clause is used, or maybe `defclause` is just a wrapper around `defun`.
Wait, the prompt says "Issue: Macro call that should be transformed by defclause". This might mean the user has a repetitive pattern of writing `defclause` calls, and wants a helper macro? Or maybe they just want the definition of `defclause`.
Let's re-read carefully: "Define a macro that eliminates this repetitive pattern: (defclause summing-to-and-returning (vars &optional result-processor) "Same as summing-to, but also returns the value of each <vars> at the end of the loop." `((summing-to ,vars ,result-processor) ,@(mapcar (lambda (var) `(returning ,var)) (ensure-list vars))))"
This looks like a single example call. The "repetitive pattern" might be the structure of defining such clauses.
I will define `defclause` as a macro that expands to a `defun` (or `defmacro`) that returns the quoted expansion form, or maybe it defines a function that returns the expansion.
Actually, in many Lisp loop implementations, clauses are defined as functions that return lists of code.
So `(defclause name args doc body)` could expand to `(defun name args doc body)`.
But the body in the example uses backticks. If it's a function definition, the backticks will be evaluated at runtime when the clause is invoked. That makes sense.
So `defclause` is just a synonym for `defun` but with a specific naming convention or integration into a loop parser.
However, to be safe, I'll define `defclause` as a macro that expands to `defun`.
Wait, maybe the user wants a macro that generates the `defclause` form? No.
Let's assume `defclause` is meant to be defined. I will write a `defmacro defclause` that expands to `(defun name (args) docstring body)`.
But wait, the example has backticks inside the body. If `defclause` is a macro, the body is passed as is.
Let's just define `defclause` as:
</think>
(defmacro defclause (name arglist &body body)
  "Same as cl:defmacro, but additionally records <name> in *clauses* as a known clause macro."
  `(progn
     (defmacro ,name ,arglist ,@body)
     (pushnew ',name *clauses*)))