unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* using finalizers
@ 2021-12-30 22:43 Tomas Hlavaty
  2021-12-31  2:46 ` LdBeth
  2021-12-31 14:39 ` LdBeth
  0 siblings, 2 replies; 42+ messages in thread
From: Tomas Hlavaty @ 2021-12-30 22:43 UTC (permalink / raw)
  To: emacs-devel

Hi,

I am trying to understand finalizers in Emacs Lisp but I am unable to
triger it.

Here is an example (with lexical-binding):

(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))))))
(setq foo (finito))
(equal '(a b c nil nil) (mapcar (lambda (x) (funcall foo)) '(1 2 3 4 5)))
(setq foo nil)
(garbage-collect)

After garbage collection, I would expect to see close-resource text in
the *Messages* buffer but there is none.

The interface is different from Common Lisp, where make-finalizer
usually expects object and thunk, not thunk only but I guess the problem
lies somewhere else.

What is the expected example usage of finalizers in Emacs Lisp?
How can I verify, that my finalizer works?

Thanks in advance

Tomas



^ permalink raw reply	[flat|nested] 42+ messages in thread

end of thread, other threads:[~2022-01-04  3:08 UTC | newest]

Thread overview: 42+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-30 22:43 using finalizers Tomas Hlavaty
2021-12-31  2:46 ` LdBeth
2021-12-31  3:29   ` Stefan Monnier
2021-12-31  3:36     ` Stefan Monnier
2021-12-31  4:30     ` LdBeth
2021-12-31  4:43       ` LdBeth
2021-12-31  6:28   ` Tomas Hlavaty
2021-12-31 10:59     ` LdBeth
2021-12-31 11:18       ` Tomas Hlavaty
2021-12-31 11:41         ` LdBeth
2021-12-31 12:01           ` Tomas Hlavaty
2022-01-01 17:00     ` Stefan Monnier
2022-01-01 20:25       ` Tomas Hlavaty
2022-01-01 20:47         ` Stefan Monnier
2022-01-01 22:55           ` Tomas Hlavaty
2022-01-01 23:18             ` Stefan Monnier
2022-01-01 23:47               ` Tomas Hlavaty
2022-01-01 23:26             ` Tomas Hlavaty
2021-12-31  7:50   ` Eli Zaretskii
2021-12-31  9:31     ` Tomas Hlavaty
2021-12-31 12:27       ` Eli Zaretskii
2022-01-01 17:58         ` Tomas Hlavaty
2022-01-01 18:20           ` Eli Zaretskii
2022-01-01 20:55             ` Stefan Monnier
2022-01-01 23:05               ` Tomas Hlavaty
2022-01-01 23:21                 ` Stefan Monnier
2021-12-31 14:23       ` Rudolf Schlatte
2021-12-31 16:21         ` Stefan Monnier
2022-01-01 17:37           ` Tomas Hlavaty
2022-01-01 22:36         ` Tomas Hlavaty
2022-01-02  6:54           ` Eli Zaretskii
2022-01-02  7:53             ` Tomas Hlavaty
2022-01-02  8:33               ` Eli Zaretskii
2022-01-02 13:10                 ` Tomas Hlavaty
2022-01-02 14:42                   ` Eli Zaretskii
2022-01-02 15:16                     ` Eli Zaretskii
2022-01-02 17:18                       ` Tomas Hlavaty
2022-01-02 18:11           ` Rudolf Schlatte
2022-01-03  0:37             ` Tomas Hlavaty
2022-01-04  3:08               ` Richard Stallman
2021-12-31 14:39 ` LdBeth
2022-01-01 17:59   ` Tomas Hlavaty

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).