From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: using finalizers Date: Thu, 30 Dec 2021 22:36:23 -0500 Message-ID: References: <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="15235"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) Cc: Tomas Hlavaty , emacs-devel@gnu.org To: LdBeth Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Dec 31 04:38:38 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 1n38kX-0003lx-Tu for ged-emacs-devel@m.gmane-mx.org; Fri, 31 Dec 2021 04:38:38 +0100 Original-Received: from localhost ([::1]:51098 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n38kV-0001l7-5v for ged-emacs-devel@m.gmane-mx.org; Thu, 30 Dec 2021 22:38:35 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:40690) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n38iU-0000Nq-B7 for emacs-devel@gnu.org; Thu, 30 Dec 2021 22:36:38 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:22137) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n38iS-0003qp-5s for emacs-devel@gnu.org; Thu, 30 Dec 2021 22:36:29 -0500 Original-Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 44478442B56; Thu, 30 Dec 2021 22:36:26 -0500 (EST) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 37C2E442B47; Thu, 30 Dec 2021 22:36:25 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1640921785; bh=Q1GGJYb4GKVgK9Lc9GIbisdQH/E93PSzL46ZSK6pH0Q=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=T1TC07Rg7y1JrXR4IwwRvFEoCgo5ZVk1TGiAr7IVSdErIzmT7C6CvyOonEZD826La H8Gw0SJH4q2JIP0sBkzXL6q04W8u/gqwMBoEbCrF81o2BCK+JBViF4Wn2rCkPt+q83 VWuBcU3G2rfER5jVdkN+Drow3eTLwUmZ31Z+FwO8essituwDJwInfYFpXLHu7GEVvN N1GimBcTPu2K7kXlyYxPseX3amPxECv7ynGhyEhAPxidNSp9hRTYWhXQ98d72u2Y6U 3e2gP+fiPLlZdkkRdZILa4v48B9rp6A9Y3qaUDo7082GULEWqJW9YQRl3TBmzLrd/g s6sAQ2xsWlztA== Original-Received: from ceviche (unknown [216.154.30.173]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id F3946120419; Thu, 30 Dec 2021 22:36:24 -0500 (EST) In-Reply-To: (Stefan Monnier's message of "Thu, 30 Dec 2021 22:29:08 -0500") Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=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:283697 Archived-At: >> (macroexpand '(letrec ((more (make-finalizer close)) >> (close (lambda () >> (setq bar t)))) >> (lambda () >> (when more >> (pop x))))) [...] > Indeed, the code needs to swap `more` and `close`. Actually, simpler: (letrec ((more (make-finalizer (lambda () (print "close-resource") (setq more nil))))) (lambda () (when more (pop x))))) -- Stefan