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: Re: using finalizers Date: Sat, 01 Jan 2022 23:55:37 +0100 Message-ID: <8735m7kqvq.fsf@logand.com> References: <878rw1pvcw.fsf@logand.com> <875yr5p9t3.fsf@logand.com> <877dbjkxui.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="1631"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Jan 01 23:57:40 2022 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 1n3nJk-0000Fc-L0 for ged-emacs-devel@m.gmane-mx.org; Sat, 01 Jan 2022 23:57:40 +0100 Original-Received: from localhost ([::1]:45710 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n3nJi-0002zH-Ft for ged-emacs-devel@m.gmane-mx.org; Sat, 01 Jan 2022 17:57:38 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:36168) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n3nHq-0001l1-U7 for emacs-devel@gnu.org; Sat, 01 Jan 2022 17:55:42 -0500 Original-Received: from logand.com ([37.48.87.44]:39542) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n3nHp-0005Mg-8Y for emacs-devel@gnu.org; Sat, 01 Jan 2022 17:55:42 -0500 Original-Received: by logand.com (Postfix, from userid 1001) id 149BF19EC87; Sat, 1 Jan 2022 23:55:39 +0100 (CET) X-Mailer: emacs 27.2 (via feedmail 11-beta-1 I) In-Reply-To: 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:283829 Archived-At: On Sat 01 Jan 2022 at 15:47, Stefan Monnier 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.