From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Joost Kremers Newsgroups: gmane.emacs.devel Subject: literal functions [was: Re: dash.el] Date: Wed, 13 May 2020 09:41:14 +0200 Message-ID: <874kski8o5.fsf@fastmail.fm> References: <0c88192c-3c33-46ed-95cb-b4c6928016e3@default> <87wo5mc04t.fsf@fastmail.fm> <873686bbl5.fsf@russet.org.uk> <87d07963ec.fsf@fastmail.fm> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="98844"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.4.4; emacs 27.0.91 Cc: emacs-devel@gnu.org To: rms@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed May 13 09:42:05 2020 Return-path: Envelope-to: ged-emacs-devel@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 1jYm1k-000Pb7-Jl for ged-emacs-devel@m.gmane-mx.org; Wed, 13 May 2020 09:42:04 +0200 Original-Received: from localhost ([::1]:51962 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jYm1j-0003lP-Jc for ged-emacs-devel@m.gmane-mx.org; Wed, 13 May 2020 03:42:03 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:55098) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jYm14-0003E1-AQ for emacs-devel@gnu.org; Wed, 13 May 2020 03:41:22 -0400 Original-Received: from wout4-smtp.messagingengine.com ([64.147.123.20]:48565) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jYm11-00069R-3s; Wed, 13 May 2020 03:41:22 -0400 Original-Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id 58B213EE; Wed, 13 May 2020 03:41:17 -0400 (EDT) Original-Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 13 May 2020 03:41:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastmail.fm; h= references:from:to:cc:subject:in-reply-to:date:message-id :mime-version:content-type:content-transfer-encoding; s=fm3; bh= /aIyNNwnOgJ8A/Sv5mcKNU/QoOwYb6GvBb7Ty+Mkoj8=; b=al5MtV8izZQ5sx/M kshzwpoMNiy497TZkW10UwUs7hMmmRz1LmziIX88kgyNKkWEEPmNDNlmW+YF0MKP T6q8nlK/KWeRlPPWQcddehbTDJwPtMTx5RaffK9WV985wa6QNyWfA7/5Nfi+ZdwI FXQ/8QF5vwAb5Y5284GCJdBkcW2aTW6cuXa4POwXWKjWl+H8XoW4O5C/+Tgt1bhE LHwAcQrRgRgvOvJZ+3JZvX38t1ZAI5TlxsLz2V7bY8YOdaWvaExXFz5g9HTMvzN9 dx0VsMSmMVZ1W4k4uiwHkL09KLzZvEEJP8r61pVih0tW/sOIQd9GIgiU6vRQ5Or1 JDl0Xw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; bh=/aIyNNwnOgJ8A/Sv5mcKNU/QoOwYb6GvBb7Ty+Mko j8=; b=GLsZKjJEp1XiDo5wIz1BLK7JE3m5hSQJG5qM+QBWAm1ny+OT58/GQ01tL 0lsbcRVUbCZ/uysA+VtNbtWoGF39vZYryrVkCgrAKpwS2pIbTOguVZ1qPXLvEpVu jFLWwKRkTMo92Ttf361mXFLTgzH/W7fsJX/RAcOSMvE2Xn64D/NH2oizhiVWAL8c K1eLJcT5yPwmkjL2naeDUOnRhaG1WkYBuydoheeSGriETtU0LSa+Yy+gy30/IJv4 k1StW9wkHofrhUd/v6PYvlkcGNdgeYtj7DaB8YUNN4A1LxCyhJ7PISyvD/Tzq0Wz +W6dt4AtEKVl7JMjrGKvK7O/tZbpA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduhedrleefgdduvddtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpehffgfhvffujgffkfggtgfgsehtqh ertddtreejnecuhfhrohhmpeflohhoshhtucfmrhgvmhgvrhhsuceojhhoohhsthhkrhgv mhgvrhhssehfrghsthhmrghilhdrfhhmqeenucggtffrrghtthgvrhhnpeetfeefheeuue etjeejiedutedvveetveelueefhefhhfevleegvdelgfffvedtleenucfkphepleehrdel tddrvddtuddriedvnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilh hfrhhomhepjhhoohhsthhkrhgvmhgvrhhssehfrghsthhmrghilhdrfhhm X-ME-Proxy: Original-Received: from Lenovo.fastmail.com (ip5f5ac93e.dynamic.kabel-deutschland.de [95.90.201.62]) by mail.messagingengine.com (Postfix) with ESMTPA id 434623280064; Wed, 13 May 2020 03:41:16 -0400 (EDT) In-reply-to: Received-SPF: pass client-ip=64.147.123.20; envelope-from=joostkremers@fastmail.fm; helo=wout4-smtp.messagingengine.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/13 03:41:17 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:250100 Archived-At: On Wed, May 13 2020, Richard Stallman wrote: > > In Clojure, a function literal is written with `#(...)`, and=20 > > it=20 > > supports `%n` for arguments, where n=3D1,2,3... (Actually, I=20 > > don't=20 > > know if Clojure supports `%10` and up or if it just goes up=20 > > to=20 > > `%9`, but I guess that doesn't matter much). A single `%` is=20 > > synonymous with `%1`, which is used when there's only one=20 > > argument. Also supported is `%&`, which is similar to `&rest=20 > > ` in Elisp, being bound to a list containing the=20 > > remaining=20 > > arguments. > > This is rather shell-like. Can we find a nicer one? Not sure what a nicer syntax would look like. If nicer means more=20 verbose, function literals might become pointless, because their=20 compactness is IMHO the main reason for having them. Using Unicode would be nice: (seq-reduce =CE=BB(* 2 (+ =CE=B1 =CE=B2)) (number-sequence 1 10) 0) But that runs into obvious problems (font support, input method).=20 Personally, I wouldn't be adverse to adopting the Clojure syntax=20 for function literals wholesale, except that `#(...)` already has=20 a meaning for the reader. Perhaps `#f(...)` can be used instead,=20 since it follows the existing pattern (`#` plus a single=20 character). > It doesn't specify how many args the literal function should=20 > accept. > Maybe there is no need for that, but if we want to do that, how=20 > could we? Something like #f2(* 2 (+ %1 %2)) with the 2 after #f indicating the number of arguments? Doable, I=20 guess. But I'm not sure it gets you anything, unless you also find=20 a way to indicate the use of an `&rest` argument. If you don't,=20 you'd need to go through the entire form anyway to search for it,=20 and then you might as well collect the other arguments as well. You could of course decide not to support `&rest` arguments. That=20 would limit a function literal's usefulness somewhat, but that=20 might be an acceptable compromise. OTOH you might want to use gensyms to represent the arguments in=20 the expanded lambda form. In that case you need to go through the=20 entire form as well, so no need to indicate the number of=20 arguments. A related question is what to do about function literals such as=20 `#f(* 2 (+ %1 %3))`. If the reader collects all %n arguments and=20 puts them in the argument list in the right order, this doesn't=20 have to be an error. OTOH if you use the #f2 syntax and let the=20 reader create an argument list without checking, a form such as ,=20 `#f2(* 2 (+ %1 %3))` would yield a void variable error upon=20 execution. My personal preference would be to just use `#f(...)` and not=20 indicate the number of arguments. > Is there ever a need for nested literal functions? To implement=20 > them > fully, we would want to use different arg names at each level. Which is probably why Clojure doesn't allow nesting them. Function=20 literals are not meant to replace lambdas in every context, they=20 are mainly meant as short, one-off function arguments to=20 higher-order predicates, so it's an acceptable compromise that=20 they're not nestable.=20 > Does anyone think this is a bad idea? I obviously don't. :-) --=20 Joost Kremers Life has its moments