unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Michael Heerdegen <michael_heerdegen@web.de>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: Nicolas Petton <nicolas@petton.fr>,
	Emacs Development <emacs-devel@gnu.org>
Subject: Re: thunk.el: Document that thunk-force == funcall?
Date: Fri, 27 Nov 2020 18:22:38 +0100	[thread overview]
Message-ID: <87im9qhfz5.fsf@web.de> (raw)
In-Reply-To: <87v9dtttbr.fsf@web.de> (Michael Heerdegen's message of "Wed, 25 Nov 2020 15:16:40 +0100")

Michael Heerdegen <michael_heerdegen@web.de> writes:

> I don't have any concrete real-life examples. [...]

Actually I have one real-life example:

#+begin_src emacs-lisp
(defun el-search--change-p (posn revision)
  ;; Non-nil when sexp after POSN is part of a change
  (if (buffer-modified-p)
      (if (eq this-command 'el-search-pattern)
          (user-error "Buffer is modified - please save")
        nil)
    (save-restriction
      (widen)
      (let ((changes (el-search--changes-from-diff-hl revision))
            (sexp-end (el-search--end-of-sexp posn))
            (atomic? (thunk-delay (el-search--atomic-p
                                   (save-excursion (goto-char posn)
                                                   (el-search-read (current-buffer)))))))
        (while (and changes (or (< (cdar changes) posn)
                                (and
                                 ;; a string spanning multiple lines is a change even when not all
                                 ;; lines are changed
                                 (< (cdar changes) sexp-end)
                                 (not (thunk-force atomic?)))))
          (pop changes))
        (and changes (or (<= (caar changes) posn)
                         (and (thunk-force atomic?)
                              (<= (caar changes) sexp-end))))))))
#+end_src

I can live with `thunk-force' here; being able to use it as a function
would make the code a bit more readable.  Although, hiding the
function's nature as a thunk might not be good OTOH.

A thunk or fbound function have the advantage that they can be passed
without forcing.  Contrary to symbols bound with `thunk-let'; a thunk
passed to a function this way is forced before that function is called,
even when the thunk's result is never used.  That's why I'm wondering
whether `thunk-let' is as cool as I had thought.

Ok, anything else to say, apart from the empty string?


Regards,

Michael.



  reply	other threads:[~2020-11-27 17:22 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
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 [this message]
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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=87im9qhfz5.fsf@web.de \
    --to=michael_heerdegen@web.de \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    --cc=nicolas@petton.fr \
    /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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).