From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Drew Adams Newsgroups: gmane.emacs.help Subject: Lazy functional programming [was: Advantage using mapc over dolist] Date: Tue, 3 Dec 2024 20:08:06 +0000 Message-ID: References: <87ed2qpo3o.fsf@gnu.org> <871pyqfl62.fsf@web.de> <87r06por3q.fsf@neko.mail-host-address-is-not-set> <8734j5lpbt.fsf@neko.mail-host-address-is-not-set> <87plm9s4cr.fsf@neko.mail-host-address-is-not-set> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="14158"; mail-complaints-to="usenet@ciao.gmane.io" Cc: "help-gnu-emacs@gnu.org" To: Tomas Hlavaty , Heime , Michael Heerdegen Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Tue Dec 03 21:08:38 2024 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1tIZCH-0003Wj-IQ for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 03 Dec 2024 21:08:37 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tIZC3-0006GL-HZ; Tue, 03 Dec 2024 15:08:24 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tIZBy-0006AJ-OD for help-gnu-emacs@gnu.org; Tue, 03 Dec 2024 15:08:18 -0500 Original-Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tIZBv-00038V-1w for help-gnu-emacs@gnu.org; Tue, 03 Dec 2024 15:08:18 -0500 Original-Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4B3K2xM1004102; Tue, 3 Dec 2024 20:08:12 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s= corp-2023-11-20; bh=xdlde9fYbHBJbJGzo3P+YrzL0MDiOxZJcY+vsSYjvwo=; b= AD3Cn1K6VBidLMOUhgGSGKKFXPTZmHGgOWboPCMfs8PI0hf47Z5HUB+2P+KBLn9v ekjBRDi9XOv7tIqjDBes+iJ6ZiifnM9/OFeFmFEwoHXjE5YDhee5Kaaul2XVNYhH gfbU5gn5NTzi5dVDvbuR95vnEiaXuJhDGJzdS7S7CW5CpRrAfhGudl02wk3yjFXX 2MuQrvaY90spvypuFjFxt2z/8Z9NBw6cJfInR6LTcsSeqAX5FxVyW8zyyq0jLlcg fb4YpSs/xUaI69z+5upUlh1/i8jDEx0DJGN/+SgrlWayEXCL+np+cIb1SSapsLkz tpLJ6xHFfnlDWq6gzGRz4A== Original-Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 437tk8xru5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 Dec 2024 20:08:11 +0000 (GMT) Original-Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 4B3Ip6br037166; Tue, 3 Dec 2024 20:08:10 GMT Original-Received: from nam10-bn7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2043.outbound.protection.outlook.com [104.47.70.43]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 437s58vqgv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 Dec 2024 20:08:10 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=wFwa4TOzxvzUGp3VfEkLWE9ajUwp2axeLq37kXKBM8FKV9iWRPQ9rZ6wJ96KG6DRVQXrbG1YJu+Q5HW8TIh9ZJOUl2mcjgumEe9xjGcF9CSWa59fmRa/3+wCrCwHk5tbP4nXMnHKhvmbHvrXXBtGRcU0++6Od+UKdcxOukL+KXAx/DjjYM5JunYp44XrB8FNEn4lPXMnhuRWYDplKdJGdWqIMOPbJlF8cOTtgZSdRc+RQ/hG8O5dTuXXCvajJ9rb5BjeFutsVDvUTo7aMmzDmWF51PhWzqHep/WwheVq0jjJOf7GZDsfDQ4RDJojXSmcHW5XxFAQp2YbFxW2es0R4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=xdlde9fYbHBJbJGzo3P+YrzL0MDiOxZJcY+vsSYjvwo=; b=uj5MUAa0I0L2TkrxE5BcWMfncRTLvZx5zlN8JjRAW7GT6xMA2oeA1cC9ZuFA1ekQ5WsA5ujvR4T9Vsb/qgzuIV6OfkVxBeX813vMPFJLU8RmjVlP8b62AUHl/FQjjUXZVL00EEi0FQl0R9eUDN3+6FY2srfoaCdtgZMl7bLJ777GXK4HO7dgyfCdb9NUUa4xrpn2YLi7p54D33xQdFjDO0/6/z3b8vueCRij4jM4eT+iGSQ4uZncFHRgKrRG82LYCmfTGLtw9LsIL5YaRBD4+wDE4RiyK5lYgTmnWA8bk04Xw6wKfg2YmvCclsTAXIpf7zF4FGmxOfIb53Q4E/YyCw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=xdlde9fYbHBJbJGzo3P+YrzL0MDiOxZJcY+vsSYjvwo=; b=Wn5aH7nQeZKIJTroD0yAzq/zu0rCEMNNHnVo8LfULtAsffO1/X9j60M0xSlHe7rSKLEA3MRQX3tEvxjlbxDvBhTggH/7OVkm6j/67hRgSXLu4BVEB538dTgANeLBur3bp68fwaZb8WIkXY2BV4Qhhza9c3p8fv18zJIZaY0eRm0= Original-Received: from DS7PR10MB5232.namprd10.prod.outlook.com (2603:10b6:5:3aa::24) by PH7PR10MB5748.namprd10.prod.outlook.com (2603:10b6:510:131::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8207.18; Tue, 3 Dec 2024 20:08:06 +0000 Original-Received: from DS7PR10MB5232.namprd10.prod.outlook.com ([fe80::8303:658f:14f8:2324]) by DS7PR10MB5232.namprd10.prod.outlook.com ([fe80::8303:658f:14f8:2324%5]) with mapi id 15.20.8207.017; Tue, 3 Dec 2024 20:08:06 +0000 Thread-Topic: Lazy functional programming [was: Advantage using mapc over dolist] Thread-Index: AdtFvaY/X9j7xX1+QtyRS/FIoa0FNw== In-Reply-To: <87plm9s4cr.fsf@neko.mail-host-address-is-not-set> Accept-Language: en-US Content-Language: en-US x-ms-publictraffictype: Email x-ms-traffictypediagnostic: DS7PR10MB5232:EE_|PH7PR10MB5748:EE_ x-ms-office365-filtering-correlation-id: a38fbb03-94ba-4b86-099b-08dd13d6335b x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; ARA:13230040|366016|376014|1800799024|38070700018; x-microsoft-antispam-message-info: =?us-ascii?Q?ofEGP2G9DaTEp7FKB/EaXKZ0YWbMgS2o66YkF8KuzGjk7cbj4VV0GOcGsGoq?= =?us-ascii?Q?tkJu2ezXnn17rnEVYpXevaCqREbPvB//UJdTFu5xt+gN8SrmEhSA6Q2FuoEU?= =?us-ascii?Q?C4yyJRsVtMlicpCHoT+CIaH9RFc2Qie1p3jbx4eB4tQpmWOuwRfuYsf4qUz7?= =?us-ascii?Q?u+xWrQ5LTcX/8zlA+gy2Y/szk7Y+5045Lo62hhQCPdEFMIb6fKVTB1ZYa731?= =?us-ascii?Q?AgdzLW0UpGM2QSDdry4jRmwr5GNYdZKPW7VyoTYBcdwH+Gt/I72cMwh48XY8?= =?us-ascii?Q?U5ktuoQk1wcuHnH4PZOcPd8Pj57PZoAWjsvANHI6dxjUkiZENjt/gQ2Bi2tp?= =?us-ascii?Q?k9gelhubnVRekpY1TKl7JZerH0KtjaWvP+Pj+yUHbgGvHcxQZReXO+oUKegf?= =?us-ascii?Q?5TEXS5ovWCvFup2Rkfbs/0CGiwDbiI6/abMpY8JCTCMraVP0Z5PLRcWb491x?= =?us-ascii?Q?QtmBxL4Cc1tZyRtbWMH3e8sdmuu47SU5rShbHcLct68qJx6ezWvNk9dIE2LA?= =?us-ascii?Q?Gyz+ffCXSF7mJYm2dQbxaGQ5yvZJe7S94XkNimZ6b+QVKHblvxK7/gO5hmdt?= =?us-ascii?Q?bilvDhAjk/O0R5eqZSRkQol8ErO+S+KOBVBAoEqD5K8EX4Nhwt4/+69JZt3R?= =?us-ascii?Q?6Mjly x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DS7PR10MB5232.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(366016)(376014)(1800799024)(38070700018); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?EqrnXREIempfvTKvOvAS+6oFoBcct2kP0VlBpWlMe8xh82iSbm1Svofm+Ny1?= =?us-ascii?Q?+nrS6v2bjuS3Wy14bd78J5rQ55ZGqhJLBIG7J5zr0QeGA1s7T+BAhxEwWE5k?= =?us-ascii?Q?0OwmLS281mKJLUQfNX1N654RlbJPl0ZahGU6JdAS2oNTUwXK5t6hHXT4mS8f?= =?us-ascii?Q?GH1IeXyuPHkttckp22qGeVYmmezi0OMRbUbVW6oTvpGOCk5VSpiQJPx4Vez/?= =?us-ascii?Q?EBs9GqOd8u/ZD91aiWGrrpSHulg6piL9HeAux1l85b+kp6YkFtasTKeCnLK/?= =?us-ascii?Q?9jt4ucsEbrUnfwHtQyYV4CBFHTGkeROuWfA13rycjpiWTc/XXx9Trwot4kD2?= =?us-ascii?Q?GlBkPmIKydaxIJTotHOqIJp+JtqKIf/uoKzHOaYGLq6Gua2SRlYiSawzDaHq?= =?us-ascii?Q?mgmDOQjBDpG1gh94sUcMYCscJd7vwVhtqrJwx6Vvi/FiIu53yQZg9x9tvBCC?= =?us-ascii?Q?iZzaqbqYE+WDH8fX7sUKEdeqccgTTUhbAjN63YrmRr+irFu6QSCK7Dk80Leo?= =?us-ascii?Q?pEjp13ARrIKuYrzzRzJwZZnhagI/ZlUbPlAmOucn3FcnsIQwxxrfgjVEEhE1?= =?us-ascii?Q?1wj6t4de2roL2PCoU/3w8LzsCcBzjNoH4QEtnx5AZsdRCHWE2FOvRDDIGNiZ?= =?us-ascii?Q?zE X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: 8piayYCVp+758mh1moQkVVuJ3R4LyBQCPfwH3ASDukMMFs+7mvcGA/AC2Krf9VH9SF/0MQB7H2QNqt7+TwWev4azxYxxQ4ho6dKt9rAjTqxGA8EwYAHIj4Xr2NBlFpvVoKA6ULMYpCG1iqNKCE/etKJWm05b+SRdZ1tJHOXCxb++6fLhXIqbJgUB2MRF3HVPYfl4YRRSA7rYBLzA6eK0+dtjFQ9Dn6kP+Hh0isbnAyKAps0J8VtQo6ixeBkNZVcE5iCkhYgMkDq3gD7xw3x2CrQgxCtPh1Lr8DZ7LXcr/mfXAO+vQV0LwuQW3RVk89v5vuHTyUS8VzckyNh4gmkVcKcLZbFSp/9p7SPPsWyMtsXKRy4xrk6o9LyNut/7xLQy5Q7Pl0fx9iLsjLMdeOhDyw5So2R71hf5LeeqNE45/HaiJxGeET4bwn1XX20FhRVYyHegRf4buqCXf8Q+/6pxi435s0g4IwykmadFr1FCSJZokz3+EFLUfHaaLQMMxGUkpMsQY9RwYLZIJmb8Lv1WiQMeq4DOr87oJRnyyDbzvjVIU+PCPXseucgmlc/tOKx/6ScLPymKuScSYIbVgBW/msQvvw7ub1DlJ3uljGadHfs= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DS7PR10MB5232.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: a38fbb03-94ba-4b86-099b-08dd13d6335b X-MS-Exchange-CrossTenant-originalarrivaltime: 03 Dec 2024 20:08:06.1722 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 0ydcF6VQziQBA/oOOO1HWoMCZ37elyjwO21hDJz2EvnFIVk+QQB456CWYxLyMrfc0YFhWHGKJB4d6QCiYPmn9A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR10MB5748 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2024-12-03_08,2024-12-03_03,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 mlxscore=0 bulkscore=0 malwarescore=0 mlxlogscore=999 spamscore=0 adultscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2411120000 definitions=main-2412030166 X-Proofpoint-ORIG-GUID: lfhRH2FgTmkmHqu-057U71Ku71t0RIfT X-Proofpoint-GUID: lfhRH2FgTmkmHqu-057U71Ku71t0RIfT Received-SPF: pass client-ip=205.220.165.32; envelope-from=drew.adams@oracle.com; helo=mx0a-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.help:148563 Archived-At: > 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=20 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=20 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=20 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