unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Drew Adams <drew.adams@oracle.com>
To: Tomas Hlavaty <tom@logand.com>,
	Heime <heimeborgia@protonmail.com>,
	Michael Heerdegen <michael_heerdegen@web.de>
Cc: "help-gnu-emacs@gnu.org" <help-gnu-emacs@gnu.org>
Subject: Lazy functional programming [was: Advantage using mapc over dolist]
Date: Tue, 3 Dec 2024 20:08:06 +0000	[thread overview]
Message-ID: <DS7PR10MB52329C4E44A35A37BF5C4D18F3362@DS7PR10MB5232.namprd10.prod.outlook.com> (raw)
In-Reply-To: <87plm9s4cr.fsf@neko.mail-host-address-is-not-set>

> From: Tomas Hlavaty
> Sent: Monday, December 2, 2024 9:50 PM
>
> lazy evaluation is what those LAMBDAs and
> FUNCALLs in my examples are about.

Yes, in effect you're _implementing_ lazy
evaluation here & there by using lambdas to
delay evaluation.  That's classic, but it's
not general lazy evaluation.  Explicit
do-something-lazy-here is different from
inherent laziness.

Similarly, lazy `cons' (Friedman & Wise)
isn't general lazy evaluation.  That provides
only lazy lists.

> purely functional languages are not about
> implicit lazy-evaluation, see purescript

It's really a matter of opinion - there's no
single, formal "purely functional" definition.
Meanings usually include characteristics such
as "side-effect free" and "referentially
transparent", but there can be more.

Applicative-order (strict/eager) evaluation
isn't, and normal-order (lazy) evaluation is,
guaranteed to terminate and return a correct
result - a big  difference when it comes to 
programming with functions.

Some evaluation strategies converge and others
may not.  Using "purely functional" only for
those that do makes sense to me.  This includes
normal-order (leftmost-outermost) evaluation,
and it includes optimal call-by-need rewrite 
strategies (only necessary reductions).
___

I recommend John Hughes's classic 1984 paper
"Why Functional Programming Matters".  See here
an excerpt from it that points to laziness and
higher-order functions as the "glue" that holds
functional programs together, as well as John's
own description of the paper.

https://www.emacswiki.org/emacs/DrewAdams#WhyFunctionalProgrammingMatters

By "glue" he's talking about modularity:

 "The ways in which one can divide up the
  original problem depend directly on the ways
  in which one can glue solutions together."

It's about the modularity advantages provided
by higher-order functions and lazy evaluation.

That they play this role of glue for functional 
programming is germane to the question about
heavy use of `mapc' and the like in Lisp.

(That doesn't mean that smart compilation and
some fiddling might sometimes work around the
lack of real support for them in Lisp.)

The paper itself is here:

https://www.cse.chalmers.se/~rjmh/Papers/whyfp.pdf

See also this page:

https://www.cse.chalmers.se/~rjmh/citations/my_most_influential_papers.htm



  reply	other threads:[~2024-12-03 20:08 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-01 23:31 Advantage using mapc over dolist Heime via Users list for the GNU Emacs text editor
2024-12-02  6:26 ` Tomas Hlavaty
2024-12-02 18:30   ` Heime via Users list for the GNU Emacs text editor
2024-12-02 20:41     ` Tomas Hlavaty
2024-12-02 20:50       ` Jean Louis
2024-12-02 21:21         ` Tomas Hlavaty
2024-12-02 21:41           ` Heime via Users list for the GNU Emacs text editor
2024-12-03  6:13           ` Jean Louis
2024-12-03  7:36             ` Tomas Hlavaty
2024-12-03 19:24               ` Jean Louis
2024-12-03 20:04                 ` Tomas Hlavaty
2024-12-03 20:09                   ` Jean Louis
2024-12-03 20:12                   ` Heime via Users list for the GNU Emacs text editor
2024-12-03 20:24                     ` Jean Louis
2024-12-02 20:56       ` Heime via Users list for the GNU Emacs text editor
2024-12-03 19:26         ` Jean Louis
2024-12-03 19:39           ` Heime via Users list for the GNU Emacs text editor
2024-12-03 14:11   ` Stefan Monnier via Users list for the GNU Emacs text editor
2024-12-03 14:48     ` Tomas Hlavaty
2024-12-03 16:31       ` Stefan Monnier
2024-12-03 17:00         ` Alfred M. Szmidt
2024-12-03 17:24           ` Stefan Monnier
2024-12-03 19:27             ` Tomas Hlavaty
2024-12-03 19:35               ` Heime via Users list for the GNU Emacs text editor
2024-12-03 14:59     ` Tomas Hlavaty
2024-12-03 15:40       ` Tomas Hlavaty
2024-12-03 15:57         ` Tomas Hlavaty
2024-12-03 17:11           ` Eli Zaretskii
2024-12-03 17:33             ` Tomas Hlavaty
2024-12-03 17:40               ` Eli Zaretskii
2024-12-03 17:55                 ` Tomas Hlavaty
2024-12-03 18:05                   ` Heime via Users list for the GNU Emacs text editor
2024-12-03 18:57                     ` Alfred M. Szmidt
2024-12-03 19:06                       ` Heime via Users list for the GNU Emacs text editor
2024-12-03 20:15                       ` Tomas Hlavaty
2024-12-04  5:37                         ` Alfred M. Szmidt
2024-12-03 19:42         ` Jean Louis
2024-12-03 19:54           ` Heime via Users list for the GNU Emacs text editor
2024-12-03 20:11             ` Jean Louis
2024-12-03 16:47       ` Stefan Monnier
2024-12-03 18:01         ` Heime via Users list for the GNU Emacs text editor
2024-12-03 20:05           ` Jean Louis
2024-12-03 20:35         ` Tomas Hlavaty
2024-12-03 23:29           ` Stefan Monnier
2024-12-04  0:57             ` Heime via Users list for the GNU Emacs text editor
2024-12-04  2:20               ` Stefan Monnier via Users list for the GNU Emacs text editor
2024-12-03 19:38       ` Jean Louis
2024-12-04  4:56       ` Michael Heerdegen via Users list for the GNU Emacs text editor
2024-12-02  6:59 ` Tassilo Horn
2024-12-02 10:12   ` Michael Heerdegen via Users list for the GNU Emacs text editor
2024-12-02 17:03     ` Heime via Users list for the GNU Emacs text editor
2024-12-02 18:51       ` Tomas Hlavaty
2024-12-02 20:17         ` Heime via Users list for the GNU Emacs text editor
2024-12-02 21:07           ` Tomas Hlavaty
2024-12-03 13:19             ` Tomas Hlavaty
2024-12-02 21:15         ` [External] : " Drew Adams
2024-12-02 21:58           ` Tomas Hlavaty
2024-12-02 22:42             ` Drew Adams
2024-12-03  5:49               ` Tomas Hlavaty
2024-12-03 20:08                 ` Drew Adams [this message]
2024-12-03 21:17                   ` Lazy functional programming [was: Advantage using mapc over dolist] Tomas Hlavaty
2024-12-04  4:33         ` Advantage using mapc over dolist 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=DS7PR10MB52329C4E44A35A37BF5C4D18F3362@DS7PR10MB5232.namprd10.prod.outlook.com \
    --to=drew.adams@oracle.com \
    --cc=heimeborgia@protonmail.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=michael_heerdegen@web.de \
    --cc=tom@logand.com \
    /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.
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).