[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Function value changes after running function?
From: |
Okam |
Subject: |
Re: Function value changes after running function? |
Date: |
Fri, 05 Feb 2021 17:27:34 +0000 |
On 2/5/21 10:48 AM, Stefan Monnier wrote:
>
>> No, I wrote a macro like `cl-loop` here:
>>
>> https://github.com/okamsn/loopy
>>
>> I received a bug report that said that the above function would raise an
>> error after running a second time here:
>
> In the current situation, the problem is:
>
> (setq loopy--main-body (nreverse loopy--main-body)
> loopy--with-vars (nreverse loopy--with-vars))
>
> which reverses the "with vars" received as arguments.
> If you replace `nreverse` with `reverse` here, this particular problem
> should disappear.
>
> This said, this `nreverse` reverses the order of the bindings in (with ....)
> which maybe isn't what you intended (I suspect that the `nreverse` here
> is meant to reverse the bindings added to `loopy--with-vars` via
> `push`).
> So maybe a better solution is to replace
>
> (setq loopy--with-vars (cdr arg)))
>
> with
>
> (setq loopy--with-vars (reverse (cdr arg))))
>
> so that the subsequent `nreverse` puts them back in the original order.
>
>
> Stefan
>
>
Thank you. That does prevent the error, but would you please explain
(or point me to where I could learn) how `nreverse` causes this error?
Why would invoking the function a second time change what the function
does? The return value of `symbol-function` makes it look like the
function passes different arguments to the macro after the first
invocation. Is that a misleading return value, or is that actually
happening? If that is what happens, why does that happen?