From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Tomas Hlavaty Newsgroups: gmane.emacs.devel Subject: using finalizers Date: Thu, 30 Dec 2021 23:43:11 +0100 Message-ID: <878rw1pvcw.fsf@logand.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="6906"; mail-complaints-to="usenet@ciao.gmane.io" To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Dec 30 23:44:13 2021 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1n349d-0001ee-ES for ged-emacs-devel@m.gmane-mx.org; Thu, 30 Dec 2021 23:44:13 +0100 Original-Received: from localhost ([::1]:35436 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n349b-0000t0-PR for ged-emacs-devel@m.gmane-mx.org; Thu, 30 Dec 2021 17:44:11 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:49046) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n348j-0000D2-Iu for emacs-devel@gnu.org; Thu, 30 Dec 2021 17:43:17 -0500 Original-Received: from logand.com ([37.48.87.44]:34370) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n348h-0001X7-TU for emacs-devel@gnu.org; Thu, 30 Dec 2021 17:43:17 -0500 Original-Received: by logand.com (Postfix, from userid 1001) id 3452719EC86; Thu, 30 Dec 2021 23:43:13 +0100 (CET) X-Mailer: emacs 27.2 (via feedmail 11-beta-1 I) Received-SPF: pass client-ip=37.48.87.44; envelope-from=tom@logand.com; helo=logand.com X-Spam_score_int: 0 X-Spam_score: -0.0 X-Spam_bar: / X-Spam_report: (-0.0 / 5.0 requ) SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:283685 Archived-At: 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