From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Short functions (was: [elpa] externals/consult 4aa49ee324 3/5: consult--async-pipeline: Convert to function) Date: Mon, 06 Jan 2025 11:52:12 -0500 Message-ID: References: <173617561349.1583674.17727386803499537943@vcs3.savannah.gnu.org> <20250106150015.2A1DD1043A07@vcs3.savannah.gnu.org> <87cygz7wl8.fsf@daniel-mendler.de> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="579"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: emacs-devel@gnu.org To: Daniel Mendler Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Jan 06 17:53:14 2025 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 1tUqLp-000AEO-Vs for ged-emacs-devel@m.gmane-mx.org; Mon, 06 Jan 2025 17:53:14 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tUqKz-0006f9-AZ; Mon, 06 Jan 2025 11:52:21 -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 1tUqKx-0006ex-Kg for emacs-devel@gnu.org; Mon, 06 Jan 2025 11:52:19 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tUqKv-00082w-0I for emacs-devel@gnu.org; Mon, 06 Jan 2025 11:52:19 -0500 Original-Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 151DC4415FF; Mon, 6 Jan 2025 11:52:14 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1736182332; bh=Kfj9szIaYDYcb97X4Y9MgGDePNRV7+gtpkGyG0ycZxw=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=VpDUCbB1Kcc+S8Fttrqxg3FPazDlMlJgU0RQDN64rGNmDSnnLo5FBukrGOLaNlqe9 nPZV03WqmcmP2Lw4OrI4iIYRsYdt5yhPS4bcWxmS6WidRhI7tU5Sw38zoyQ3qKuTVL mgf5EXSynYdqN7sHMmL40K5+hcyvG/Vs+PI1fG2zfWVZgiSwp3c3Vjxq3luaOG+Ytk hXY9hs7y8p2sEa7yTlOsM8mICTzbCgBDo1MpIqovqAcOTpNXcOaNopZAdEJwgDCgQk caBmc3XVMguF3HZr8HTaOqyQWZKFPF9xsd6jLdxbFk4HymbBLWcU6YMeBaS+uAgaKO hur0cYENc3r3A== Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id D76A84415E4; Mon, 6 Jan 2025 11:52:12 -0500 (EST) Original-Received: from alfajor (modemcable005.21-80-70.mc.videotron.ca [70.80.21.5]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id BDF6D12033B; Mon, 6 Jan 2025 11:52:12 -0500 (EST) In-Reply-To: <87cygz7wl8.fsf@daniel-mendler.de> (Daniel Mendler's message of "Mon, 06 Jan 2025 17:09:39 +0100") Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 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-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:327741 Archived-At: >> Hmm... Haskell/OCaml have `foldr` and `foldl`, maybe we should also have >> `reduceR` and `reduceL`. > Yes, please. seq-reduce-right/left would be nice to have. See also > cl-reduce which has :from-end. FWIW, I can never remember which is "right" and which is "left", so I much prefer the "from end" kind of terminology. Combined with the existence of `seq-reduce`, that would suggest the use of `seq-reduce-from-end`. [ This said, when the sequence is a list as is presumably the case here, as long as it's coded in ELisp I suspect the most efficient solution is to `reverse` and then do `seq-reduce`, just like you did. To be more efficient, we'd want to avoid both heap allocation and recursion, but sadly from ELisp the only way to allocate non-heap memory is via recursion. At the bytecode level there's some limited support for stack allocation but it's limited by the fact that the max size has to be declared in the bytecode object and that this max size is pre-allocated (so it can't be made ridiculously large). ] > There is also a lack in some combinators (flip, curry, uncurry, ...) > which are occasionally useful. Also papply and rpapply, since > apply-partially lacks conciseness and sometimes one wants apply the > arguments to the right. Same with cl-constantly. > > (papply #'f x) > (apply-partially #'f x) > (lambda (y) (f x y)) > (lambda (y z) (f x y z)) > > (lambda (_) x) > (constantly x) > (lambda (_ _) x) > (cl-constantly x) I think you're arguing for something like `llama`s ## or to expand #' to allow things like: #'(f x _) #'(f x _ _) #'(f x . _) #'(_ =E2=86=92 x) #'(_ _ =E2=86=92 x) Then again, there's (=CE=BB (y) (f x y)) (=CE=BB (y z) (f x y z)) (=CE=BB (_) x) (=CE=BB (_ _) x) I'm interested to add new meanings to `function` (aka #') but mostly for things like: #'(setf foo) #'(peg foo) to refer to the setters or the peg-matchers of a given name. It could also be used for #'(cl-lambda ...) instead of the hideous (cl-function (lambda ...)) tho this one completely depends on the reason (that completely escapes me) for the use of a `cl-function` macro instead of a `cl-lambda` macro. Stefan