Create a Common Lisp macro for the following transformation. Before code:
(def-iter iterator-permutations (r n pool indices stopped cycles) (permutations (s0 &optional (s1 'no-arg)) "`r`-permutations of input iterable, returned as vectors in lexicographic order. When a single argument is given, it should be an iterable and `r` will default to its length. When two arguments are given, the first corresponds to `r` and the second to the iterable ``` (permutations '(1 2 3)) ;; #(1 2 3), #(1 3 2), #(2 1 3), #(2 3 1), #(3 1 2), #(3 2 1) (permutations 2 '(1 2 3)) ;; #(1 2), #(1 3), #(2 1), #(2 3), #(3 1), #(3 2) ```" (labels ((helper (ivec r) (let ((n (length ivec))) (if (> r n) (empty-iterator) (init-state r n (pool ivec) (indices (iter-to-vec (range 0 (length ivec) 1))) (cycles (iter-to-vec (range n (- n r) -1)))))))) (if (equalp s1 'no-arg) (let* ((ivec (iter-to-vec s0)) (r (length ivec))) (helper ivec r)) (let* ((ivec (iter-to-vec s1)) (r s0)) (helper ivec r))))) (if stopped (values nil nil) (multiple-value-prog1 (loop with ret = (make-array r) for i below r do (setf (aref ret i) (aref pool (aref indices i))) finally (return (values ret t))) (loop for i from (1- r) downto 0 do (decf (aref cycles i)) (if (zerop (aref cycles i)) (progn (loop with curr = (aref indices i) for j from i below (1- n) do (setf (aref indices j) (aref indices (1+ j))) finally (setf (aref indices (1- n)) curr)) (setf (aref cycles i) (- n i))) (let ((j (aref cycles i))) (rotatef (aref indices i) (aref indices (- n j))) (return))) finally (setf stopped t)))))

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

Macro definition:
(defmacro def-iter (name state-vars (constructor-name constructor-params &body constructor-body)
                    &body next-body)
  "An anaphoric convenience macro which can be re-implemented to change how iterators are
  structured. Exposes the local `init-state` macro within `constructor-body`

  If you don't want to-use this macro (which I totally understand) just write constructors for your
  iterators returning 0-argument closures representing the `next` function and you'll be fine. This
  macro just helped me get through a lot of waffling during development

  Parameters
  ----------
  `name` is a synbol naming the iterator's backing state. However it's actually
  ignored, since PICL doesn't currently expose iterators' backing state

  `state-vars` is a list of symbols naming the iterator's state variables.

  The `constructor-name/params/body` will be `defun`'d to create the user-facing constructor
  function. In `constructor-body`, the return value should be an iterator or a call to local
  `init-state` macro

  `next-body` The definition of the `next` function for this iterator, which will be run in a
   lexical environment consisting of the state vars

  Both `constructor-body` and `next-body` are defined in the lexical environment of the `def-iter`
  form, and as such can access any lexical bindings not shadowed by the `constructor-params` and
  `state-vars` respectively

  The local `init-state` macro.
  ----------------------------
  The arguments to `init-state` should be of the form `(statevar-symbol value-form)`or
  `statevar-symbol`. In the first case, the value of `value-form` will be used to initialize the
  state variable named by `symbol`. In the second case, `statevar-symbol` is also used as the
  corresponding `value-form`

  Example
  -------
  What follows is a sample implementation of the `count` iterator using this macro
  ```
  (def-iter ignored-backing-name (curr-val step)
    (count (start step)
      (init-state (curr-val start) step))
    (prog1 curr-val (incf curr-val step))))
  ````"

  (declare (ignore name))
  (alexandria:with-gensyms (next-fname)
    (let ((docstring "Function had no docstring, so this one was inserted"))
      (when (and (cdr constructor-body) (stringp (car constructor-body)))
        (setf docstring (car constructor-body)
              constructor-body (cdr constructor-body)))
      `(labels ((,next-fname (&key ,@state-vars)
                  (labels ((self () ,@next-body)) #'self)))
         (defun ,constructor-name ,constructor-params
           ,docstring
           (macrolet
               ((init-state (&rest argspecs)
                  (list 'apply '#',next-fname
                        (apply #'append
                               '(list )
                               (mapcar (lambda (aspec)
                                         (if (symbolp aspec)
                                             (list (alx:make-keyword aspec) aspec)
                                             (destructuring-bind (aname adef) aspec
                                               (list (alx:make-keyword aname) adef))))
                                       argspecs)))))
             ,@constructor-body))))))

Macroexpansion:
(labels ((#:next-fname127 (&key r n pool indices stopped cycles) (labels ((self nil (if stopped (values nil nil) (multiple-value-prog1 (loop with ret = (make-array r) for i below r do (setf (aref ret i) (aref pool (aref indices i))) finally (return (values ret t))) (loop for i from (1- r) downto 0 do (decf (aref cycles i)) (if (zerop (aref cycles i)) (progn (loop with curr = (aref indices i) for j from i below (1- n) do (setf (aref indices j) (aref indices (1+ j))) finally (setf (aref indices (1- n)) curr)) (setf (aref cycles i) (- n i))) (let ((j (aref cycles i))) (rotatef (aref indices i) (aref indices (- n j))) (return))) finally (setf stopped t)))))) (function self)))) (defun permutations (s0 &optional (s1 (quote no-arg))) "`r`-permutations of input iterable, returned as vectors in lexicographic order. When a single argument is given, it should be an iterable and `r` will default to its length. When two arguments are given, the first corresponds to `r` and the second to the iterable ``` (permutations '(1 2 3)) ;; #(1 2 3), #(1 3 2), #(2 1 3), #(2 3 1), #(3 1 2), #(3 2 1) (permutations 2 '(1 2 3)) ;; #(1 2), #(1 3), #(2 1), #(2 3), #(3 1), #(3 2) ```" (macrolet ((init-state (&rest argspecs) (list (quote apply) (quote (function #:next-fname127)) (apply (function append) (quote (list)) (mapcar (lambda (aspec) (if (symbolp aspec) (list (alx:make-keyword aspec) aspec) (destructuring-bind (aname adef) aspec (list (alx:make-keyword aname) adef)))) argspecs))))) (labels ((helper (ivec r) (let ((n (length ivec))) (if (> r n) (empty-iterator) (init-state r n (pool ivec) (indices (iter-to-vec (range 0 (length ivec) 1))) (cycles (iter-to-vec (range n (- n r) -1)))))))) (if (equalp s1 (quote no-arg)) (let* ((ivec (iter-to-vec s0)) (r (length ivec))) (helper ivec r)) (let* ((ivec (iter-to-vec s1)) (r s0)) (helper ivec r)))))))