emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A generalization of `thunk-let'


From: Stefan Monnier
Subject: Re: A generalization of `thunk-let'
Date: Fri, 08 Dec 2017 16:16:48 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

> 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]