From: Michael Heerdegen <michael_heerdegen@web.de>
To: Eli Zaretskii <eliz@gnu.org>
Cc: nicolas@petton.fr, monnier@iro.umontreal.ca, emacs-devel@gnu.org
Subject: Re: [SUSPECTED SPAM] Re: `thunk-let'?
Date: Thu, 09 Nov 2017 15:34:30 +0100 [thread overview]
Message-ID: <87efp7cyh5.fsf@web.de> (raw)
In-Reply-To: <83zi7wr6jc.fsf@gnu.org> (Eli Zaretskii's message of "Wed, 08 Nov 2017 20:04:23 +0200")
[-- Attachment #1: Type: text/plain, Size: 321 bytes --]
Eli Zaretskii <eliz@gnu.org> writes:
> Given that "lazy evaluation" seems not to be described anywhere in the
> ELisp manual, I think we cannot get away with "---" here, and will
> have to add at least something to the manual.
Ok, here is a first draft of how I could imagine an addition to the
manual (as plain txt):
[-- Attachment #2: lazy-let-doc.txt --]
[-- Type: text/plain, Size: 2931 bytes --]
Deferred and lazy evaluation
Sometimes it is useful to delay the evaluation of an expression, for
example if you want to avoid to perform a time-consuming calculation
in the case that it turns out that the result is not needed in the
future of the program.
-- Macro: thunk-delay FORMS...
Return a thunk for evaluating the FORMS. A thunk is a closure that
evaluates the FORMS in the lexical environment present when
`thunk-delay' has been called.
-- Function: thunk-force THUNK
Force a thunk to perform the evaluation of the FORMS specified to the
`thunk-delay' that created the thunk. The result of the evaluation of
the last form is returned. The THUNK also "remembers" that it has
been forced: Any further calls of `thunk-force' on the same THUNK will
just return the same result without evaluating the FORMS again.
-- Macro: lazy-let (bindings...) forms...
This macro is analogue to `let' but creates "lazy" variable bindings.
Any binding has the form (SYMBOL VALUE-FORM). Unlike `let', the
evaluation of any VALUE-FORM is deferred until the binding of the
according SYMBOL is used for the first time when evaluating the FORMS.
Any VALUE-FORM is evaluated maximally once.
Example:
(defun f (number)
(lazy-let ((derived-number
(progn (message "Calculating 1 plus 2 times %d" number)
(1+ (* 2 number)))))
(if (> number 10)
derived-number
number)))
(f 5)
==> 5
(f 12)
|--> "Calculating 1 plus 2 times 12"
25
Because of the special nature of lazily bound variables, it is an
error to set them (e.g. with `setq').
-- Macro: lazy-let* (bindings...) forms...
This is like `lazy-let' but any expression in BINDINGS is allowed to
refer to preceding bindings in this `lazy-let*' form.
Example:
(lazy-let* ((x (prog2 (message "Calculating x...")
(+ 1 1)
(message "Finished calculating x")))
(y (prog2 (message "Calculating y...")
(+ x 1)
(message "Finished calculating y")))
(z (prog2 (message "Calculating z...")
(+ y 1)
(message "Finished calculating z")))
(a (prog2 (message "Calculating a...")
(+ z 1)
(message "Finished calculating a"))))
(* z x))
|--> Calculating z...
|--> Calculating y...
|--> Calculating x...
|--> Finished calculating x
|--> Finished calculating y
|--> Finished calculating z
==> 8
`lazy-let' and `lazy-let*' use thunks implicitly: their expansion
creates helper symbols and binds them to thunks wrapping the binding
expressions. All rerences to the original variables in the FORMS are
then replaced by an expression that calls `thunk-force' on the
according helper variable. So, any code using `lazy-let' or
`lazy-let*' could be rewritten to use thunks, but in many cases using
these macros results in nicer code than using thunks explicitly.
[-- Attachment #3: Type: text/plain, Size: 114 bytes --]
WDYT? I would definitely need a bit of help to turn this into texinfo
with good Enlish.
Thanks,
Michael.
next prev parent reply other threads:[~2017-11-09 14:34 UTC|newest]
Thread overview: 77+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-08 20:12 `thunk-let'? Michael Heerdegen
2017-10-08 22:25 ` `thunk-let'? Michael Heerdegen
2017-10-09 3:10 ` `thunk-let'? Stefan Monnier
2017-10-09 11:40 ` `thunk-let'? Michael Heerdegen
2017-10-09 14:07 ` `thunk-let'? Michael Heerdegen
2017-10-09 14:27 ` `thunk-let'? Michael Heerdegen
2017-10-09 15:38 ` [SUSPECTED SPAM] `thunk-let'? Stefan Monnier
2017-11-08 17:22 ` Michael Heerdegen
2017-11-08 18:02 ` Stefan Monnier
2017-11-09 15:14 ` Michael Heerdegen
2017-11-09 18:39 ` `thunk-let'? Michael Heerdegen
2017-11-09 18:48 ` `thunk-let'? Stefan Monnier
2017-11-22 2:50 ` `thunk-let'? Michael Heerdegen
2017-11-22 3:43 ` `thunk-let'? Eli Zaretskii
2017-11-22 16:16 ` `thunk-let'? Eli Zaretskii
2017-11-22 19:25 ` `thunk-let'? Michael Heerdegen
2017-11-22 20:00 ` `thunk-let'? Eli Zaretskii
2017-11-23 2:59 ` `thunk-let'? Michael Heerdegen
2017-11-23 4:15 ` `thunk-let'? Michael Heerdegen
2017-11-23 16:34 ` `thunk-let'? Pip Cet
2017-11-23 23:41 ` `thunk-let'? Michael Heerdegen
2017-11-24 8:37 ` `thunk-let'? Eli Zaretskii
2017-11-24 8:51 ` `thunk-let'? Stefan Monnier
2017-11-24 9:16 ` `thunk-let'? Eli Zaretskii
2017-11-24 13:33 ` `thunk-let'? Stefan Monnier
2017-11-27 5:21 ` `thunk-let'? Michael Heerdegen
2017-11-27 13:34 ` `thunk-let'? Stefan Monnier
2017-11-27 15:44 ` `thunk-let'? Eli Zaretskii
2017-11-30 15:19 ` `thunk-let'? Michael Heerdegen
2017-11-24 8:36 ` `thunk-let'? Eli Zaretskii
2017-11-30 15:17 ` `thunk-let'? Michael Heerdegen
2017-11-30 16:06 ` `thunk-let'? Eli Zaretskii
2017-12-01 8:02 ` `thunk-let'? Michael Heerdegen
2017-11-23 16:04 ` `thunk-let'? Eli Zaretskii
2017-11-22 17:44 ` `thunk-let'? Gemini Lasswell
2017-11-22 18:04 ` `thunk-let'? Noam Postavsky
2017-11-22 18:31 ` `thunk-let'? Michael Heerdegen
2017-11-22 18:29 ` `thunk-let'? Michael Heerdegen
2017-11-22 19:54 ` `thunk-let'? Stefan Monnier
2017-11-22 22:47 ` `thunk-let'? Michael Heerdegen
2017-11-10 10:01 ` [SUSPECTED SPAM] `thunk-let'? Eli Zaretskii
2017-11-08 18:04 ` Eli Zaretskii
2017-11-08 22:22 ` `thunk-let'? Michael Heerdegen
2017-11-08 23:06 ` `thunk-let'? Drew Adams
2017-11-09 17:20 ` `thunk-let'? Eli Zaretskii
2017-11-09 17:39 ` `thunk-let'? Clément Pit-Claudel
2017-11-09 18:06 ` `thunk-let'? Michael Heerdegen
2017-11-09 21:05 ` `thunk-let'? Drew Adams
2017-11-09 23:07 ` Sandbox subr-x? (was: `thunk-let'?) Michael Heerdegen
2017-11-09 23:54 ` Drew Adams
2017-11-10 7:57 ` Eli Zaretskii
2017-11-09 21:48 ` `thunk-let'? Clément Pit-Claudel
2017-11-09 22:43 ` `thunk-let'? Michael Heerdegen
2017-11-10 7:48 ` `thunk-let'? Eli Zaretskii
2017-11-09 18:14 ` `thunk-let'? Michael Heerdegen
2017-11-09 20:26 ` `thunk-let'? Eli Zaretskii
2017-11-09 23:13 ` `thunk-let'? Michael Heerdegen
2017-11-10 7:58 ` `thunk-let'? Eli Zaretskii
2017-11-11 15:20 ` `thunk-let'? Michael Heerdegen
2017-11-11 15:40 ` `thunk-let'? Eli Zaretskii
2017-11-10 10:10 ` `thunk-let'? Nicolas Petton
2017-11-09 14:34 ` Michael Heerdegen [this message]
2017-11-09 17:12 ` [SUSPECTED SPAM] `thunk-let'? Eli Zaretskii
2017-11-09 15:19 ` Michael Heerdegen
2017-10-09 8:00 ` `thunk-let'? Nicolas Petton
2017-12-08 20:38 ` A generalization of `thunk-let' (was: `thunk-let'?) Michael Heerdegen
2017-12-08 21:16 ` A generalization of `thunk-let' Stefan Monnier
2017-12-09 10:33 ` Michael Heerdegen
2017-12-10 4:47 ` Stefan Monnier
2017-12-10 5:34 ` John Wiegley
2017-12-12 14:41 ` Michael Heerdegen
2017-12-13 13:52 ` Michael Heerdegen
2017-12-13 14:09 ` Stefan Monnier
2017-12-13 14:37 ` Michael Heerdegen
2018-01-12 20:03 ` Michael Heerdegen
2017-12-09 21:59 ` A generalization of `thunk-let' (was: `thunk-let'?) Richard Stallman
2017-12-10 17:03 ` A generalization of `thunk-let' Michael Heerdegen
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=87efp7cyh5.fsf@web.de \
--to=michael_heerdegen@web.de \
--cc=eliz@gnu.org \
--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).