From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: A generalization of `thunk-let' Date: Fri, 08 Dec 2017 16:16:48 -0500 Message-ID: References: <87infp9z6j.fsf@web.de> <87r2s5ez0t.fsf@web.de> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1512767844 25043 195.159.176.226 (8 Dec 2017 21:17:24 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 8 Dec 2017 21:17:24 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Dec 08 22:17:09 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eNQ13-00063F-W9 for ged-emacs-devel@m.gmane.org; Fri, 08 Dec 2017 22:17:06 +0100 Original-Received: from localhost ([::1]:39054 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eNQ1B-0007Uh-B2 for ged-emacs-devel@m.gmane.org; Fri, 08 Dec 2017 16:17:13 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:34027) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eNQ12-0007Tg-LA for emacs-devel@gnu.org; Fri, 08 Dec 2017 16:17:05 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eNQ0z-0007KW-HB for emacs-devel@gnu.org; Fri, 08 Dec 2017 16:17:04 -0500 Original-Received: from [195.159.176.226] (port=40140 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eNQ0z-0007KQ-A7 for emacs-devel@gnu.org; Fri, 08 Dec 2017 16:17:01 -0500 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1eNQ0q-0005ea-5j for emacs-devel@gnu.org; Fri, 08 Dec 2017 22:16:52 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 64 Original-X-Complaints-To: usenet@blaine.gmane.org Cancel-Lock: sha1:KBKJXr/G2fivtGp2vRtgBINppes= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 195.159.176.226 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 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.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:220801 Archived-At: > Say, you write a user interface, and it includes some toggle commands. > When one of these toggle commands is called, the code will probably need > to recompute some variables to adopt their bindings to the new set of > options. So the code needs to introduce some functions to recompute the > variables, and the developer must keep an eye on where these functions > need to be called - it's something that makes code changes a bit > painful. Another way to do that is to create a new kind of object which is like a spreadsheet-cell: it comes with an expression to compute it, and remembers its current value. Internally it also keeps track of the other spreadsheet-cells used during the computation of the current value (i.e. the dependencies are automatically tracked for you). You also get to choose whether to check the current value's validity lazily (like you do in your code), or to eagerly mark dependencies "dirty" when a cell is modified. > Here are some very simple > #+begin_src emacs-lisp > ;;; Examples: > (let ((a 1) > (b 2)) > (dep-let ((sum-of-a-and-b (a b) (progn (message "Calculating %d + %d" a b) (+ a b)))) Here you'd need to something like (let* ((a (make-sscell 1)) (b (make-sscell 2)) (sum-of-a-and-b (make-sscell (progn (message "Calculating %d + %d" a b) (+ (sscell-get a) (sscell-get b)))))) ...) tho you could provide a `sscell-let` to do the symbol-macrolet danse and let you write (sscell-let* ((a 1) (b 2) (sum-of-a-and-b (progn (message "Calculating %d + %d" a b) (+ a b)))) ...) > ;; Dependencies can be recursive: > (let ((a 1) > (b 2) > (c 3)) > (dep-let ((a+b (a b) (+ a b)) > (a+b+c (a+b c) (+ a+b c))) > (list a+b > a+b+c > (progn (setq a 10) a+b+c)))) I'm not sure I see the recursion, here. Are you talking about the fact that a+b+c depends on a but only mentions a+b in its dependencies? Stefan