[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: using finalizers
From: |
Stefan Monnier |
Subject: |
Re: using finalizers |
Date: |
Thu, 30 Dec 2021 22:29:08 -0500 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) |
> You are probably taking the wrong assumption about the effect of letrec
>
> (macroexpand '(letrec ((more (make-finalizer close))
> (close (lambda ()
> (setq bar t))))
> (lambda ()
> (when more
> (pop x)))))
>
> ==> (let (more close)
> (setq more (make-finalizer close))
> (setq close (lambda nil (setq bar t)))
> (lambda nil (when more (pop x))))
Indeed, the code needs to swap `more` and `close`.
> I think Common Lisp doesn't have letrec in the standard. And you are
> proabaly taking the assumption that ELisp's letrec works as well as
> Scheme's one. But it is not.
I don't think Scheme's `letrec` works any differently in this respect,
except that instead of nil, variables get a special "void like" value
before they're initialized.
In the above code, the real bug I can see which we should fix is that
`make-finalizer` should signal an error if its arg is not a function.
Stefan