all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Tomas Hlavaty <tom@logand.com>
To: emacs-devel@gnu.org
Subject: RE: thunk.el: Document that thunk-force == funcall?
Date: Thu, 19 Nov 2020 00:05:27 +0100	[thread overview]
Message-ID: <87ima21d1k.fsf@logand.com> (raw)
In-Reply-To: <f80ba58e-b24b-4735-9c94-fda42b88cba7@default>

On Tue 17 Nov 2020 at 09:32, Drew Adams <drew.adams@oracle.com> 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))



  reply	other threads:[~2020-11-18 23:05 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-17 15:17 thunk.el: Document that thunk-force == funcall? Michael Heerdegen
2020-11-17 17:08 ` Tomas Hlavaty
2020-11-17 17:38   ` Michael Heerdegen
2020-11-17 18:09     ` Tomas Hlavaty
2020-11-17 21:07       ` Michael Heerdegen
2020-11-17 22:42         ` Tomas Hlavaty
2020-11-17 23:52           ` Stefan Monnier
2020-11-18  8:01             ` Tomas Hlavaty
2020-11-18 14:04               ` Stefan Monnier
2020-11-18 22:19                 ` Tomas Hlavaty
2020-11-18 22:49                   ` Stefan Monnier
2020-11-18 23:13                     ` Tomas Hlavaty
2020-11-18 23:40                       ` Stephen Leake
2020-11-18  9:04   ` Alfred M. Szmidt
2020-11-18 22:21     ` Tomas Hlavaty
2020-11-17 17:32 ` Drew Adams
2020-11-18 23:05   ` Tomas Hlavaty [this message]
2020-11-18 23:25     ` Tomas Hlavaty
2020-11-19 11:50       ` Mattias Engdegård
2020-11-19 18:14         ` Tomas Hlavaty
2020-11-19 17:18     ` Tomas Hlavaty
2020-11-19  9:49   ` Nicolas Petton
2020-11-17 21:51 ` Stefan Monnier
2020-11-25 14:16   ` Michael Heerdegen
2020-11-27 17:22     ` Michael Heerdegen
2020-12-17  4:37       ` Michael Heerdegen
2020-12-18  2:58         ` Adam Porter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ima21d1k.fsf@logand.com \
    --to=tom@logand.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.