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: Sun, 02 Jan 2022 00:26:42 +0100

On Sat 01 Jan 2022 at 23:55, Tomas Hlavaty <tom@logand.com> wrote:
> 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.

For comparison in Common Lisp, my object would not need to reference the
finalizer.  Something like this:

(defun finito ()
  (let* ((x '(a b c))
         (close (lambda () (print "close-resource")))
         (object (lambda () (pop x))))
    (finalize object close)
    object))



reply via email to

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