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: thunk.el: Document that thunk-force == funcall? Date: Thu, 19 Nov 2020 00:05:27 +0100 Message-ID: <87ima21d1k.fsf@logand.com> References: <871rgs3tdx.fsf@web.de> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="19443"; 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 Nov 19 00:06:46 2020 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 1kfWXG-0004yE-62 for ged-emacs-devel@m.gmane-mx.org; Thu, 19 Nov 2020 00:06:46 +0100 Original-Received: from localhost ([::1]:56776 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kfWXF-0008Qp-0B for ged-emacs-devel@m.gmane-mx.org; Wed, 18 Nov 2020 18:06:45 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:39216) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kfWWD-000806-22 for emacs-devel@gnu.org; Wed, 18 Nov 2020 18:05:42 -0500 Original-Received: from logand.com ([37.48.87.44]:47944) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kfWWA-0007gS-MN for emacs-devel@gnu.org; Wed, 18 Nov 2020 18:05:40 -0500 Original-Received: by logand.com (Postfix, from userid 1001) id 5DBDC1A8570; Thu, 19 Nov 2020 00:05:33 +0100 (CET) X-Mailer: emacs 26.3 (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-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/18 17:19:48 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 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:259401 Archived-At: On Tue 17 Nov 2020 at 09:32, Drew Adams wrote: >> `thunk-force' is equivalent to `funcall' - thunks are functions. I >> wonder if we could/should officially document that fact? > FWIW, that makes sense to me. Why not tell users this? > It's fine to have an abstraction, but in Lisp it can > help to know the implementation, especially in a > straightforward case like this. what is the reason for thunk.el in the first place? it is not used in emacs at all. it does not work in buffers without lexical-binding: (setq delayed (thunk-delay (message "this message is delayed"))) (thunk-force delayed) -> Debugger entered--Lisp error: (void-variable forced) (setq lexical-binding t) (setq delayed (thunk-delay (message "this message is delayed"))) (thunk-force delayed) -> "this message is delayed" (this is probably general problem with macros which assume lexical-binding) thunk is about delaying computation. thunk.el mixes in memoization. it obscures the essence: (setq delayed (lambda () (message "this message is delayed"))) (funcall delayed) memoization would be better separate: (let ((void (list nil))) (defun memoize (thunk) (let ((z void)) (lambda () (when (eq z void) (setq z (funcall thunk))) z)))) (let* ((i 0) (f (lambda () (message "hi %d" (incf i))))) (funcall f) (funcall f) (funcall f)) (let* ((i 0) (f (memoize (lambda () (message "hi %d" (incf i)))))) (funcall f) (funcall f) (funcall f))