[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: thunk.el: Document that thunk-force == funcall?
From: |
Michael Heerdegen |
Subject: |
Re: thunk.el: Document that thunk-force == funcall? |
Date: |
Fri, 27 Nov 2020 18:22:38 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
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.
Re: thunk.el: Document that thunk-force == funcall?, Stefan Monnier, 2020/11/17