emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: using finalizers


From: Tomas Hlavaty
Subject: Re: using finalizers
Date: Sat, 01 Jan 2022 23:55:37 +0100

On Sat 01 Jan 2022 at 15:47, Stefan Monnier <monnier@iro.umontreal.ca> wrote:
> That's right: if you want an object to have a finalizer, you need to
> save that finalizer somewhere inside the object.
> IOW the object literally "has a finalizer" somewhere inside.
>
> There's no doubt that it's different.
> Do you have concrete cases where this difference introduces a difficulty?

In my original example:

(defun finito ()
  (let ((x '(a b c)))
    (letrec ((more (make-finalizer close))
             (close (lambda ()
                      (print "close-resource")
                      (setq more nil))))
      (lambda ()
        (when more
          (pop x))))))

I use a closure as my object that should have the finalizer "attached"
to.  In order to keep the reference to the finalizer, I have to use it
inside the closure for something (here I stuffed it into the variable
called more).  That is inconvenient.  Second issue is that an advanced
compiler could eliminate even my attempt at using the finalizer for
something if it determines that the finalizer is not actually used for
something.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]