From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Philip Kaludercic Newsgroups: gmane.emacs.devel Subject: Re: Elisp threading macros Date: Wed, 28 Aug 2024 19:54:04 +0000 Message-ID: <87mskws9sz.fsf@posteo.net> References: <87v7zksety.fsf@posteo.net> 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="37575"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Garklein Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Aug 28 21:55:05 2024 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 1sjOky-0009aM-Vs for ged-emacs-devel@m.gmane-mx.org; Wed, 28 Aug 2024 21:55:05 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sjOk9-0006Wv-Jj; Wed, 28 Aug 2024 15:54:13 -0400 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 1sjOk7-0006WX-UU for emacs-devel@gnu.org; Wed, 28 Aug 2024 15:54:11 -0400 Original-Received: from mout01.posteo.de ([185.67.36.65]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sjOk5-0002GK-CL for emacs-devel@gnu.org; Wed, 28 Aug 2024 15:54:11 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id 93686240027 for ; Wed, 28 Aug 2024 21:54:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1724874846; bh=v1ZZpwNYTVjBTmBYm0LjMkybj5b4hg/CJoGKYxZI5K0=; h=From:To:Cc:Subject:Autocrypt:OpenPGP:Date:Message-ID:MIME-Version: Content-Type:Content-Transfer-Encoding:From; b=F2hF2vvnc8xuoCb13pALsQsx+WqSPVZrqRIXYEDorxf8vcSlB2YOjGmH4FaWKtC2S OkDiSZZi3xOmP3KajzIF8lBfw68R1D75RcChbw0Rtnboqc3b0JiAfKmbY2v8a77MpP pAgCMwtSFS/b1oYJM0CiCIqSnSwAvzPjFvF/8I4OQWv3mX827i9t7RkdHVavI5YbjM t5chU/K5h5kUaX4Mq+UInyOzv768ZJ7974L7byC6y3flIDcgEaaiBfhgtaEJus8VUZ Jc0SHT3XaEkgJA25WFE9LkMAagt/VnNWsVcNbSf7lyEDlieou1qS6KR1IgSPXbsMFE 7r8IYQ5roQbQA== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4WvFV56g3Qz9rxG; Wed, 28 Aug 2024 21:54:05 +0200 (CEST) In-Reply-To: (Garklein's message of "Wed, 28 Aug 2024 15:43:51 -0400") Autocrypt: addr=philipk@posteo.net; keydata= mDMEZBBQQhYJKwYBBAHaRw8BAQdAHJuofBrfqFh12uQu0Yi7mrl525F28eTmwUDflFNmdui0QlBo aWxpcCBLYWx1ZGVyY2ljIChnZW5lcmF0ZWQgYnkgYXV0b2NyeXB0LmVsKSA8cGhpbGlwa0Bwb3N0 ZW8ubmV0PoiWBBMWCAA+FiEEDg7HY17ghYlni8XN8xYDWXahwukFAmQQUEICGwMFCQHhM4AFCwkI BwIGFQoJCAsCBBYCAwECHgECF4AACgkQ8xYDWXahwulikAEA77hloUiSrXgFkUVJhlKBpLCHUjA0 mWZ9j9w5d08+jVwBAK6c4iGP7j+/PhbkxaEKa4V3MzIl7zJkcNNjHCXmvFcEuDgEZBBQQhIKKwYB BAGXVQEFAQEHQI5NLiLRjZy3OfSt1dhCmFyn+fN/QKELUYQetiaoe+MMAwEIB4h+BBgWCAAmFiEE Dg7HY17ghYlni8XN8xYDWXahwukFAmQQUEICGwwFCQHhM4AACgkQ8xYDWXahwukm+wEA8cml4JpK NeAu65rg+auKrPOP6TP/4YWRCTIvuYDm0joBALw98AMz7/qMHvSCeU/hw9PL6u6R2EScxtpKnWof z4oM OpenPGP: id=7126E1DE2F0CE35C770BED01F2C3CC513DB89F66; url="https://keys.openpgp.org/vks/v1/by-fingerprint/7126E1DE2F0CE35C770BED01F2C3CC513DB89F66"; preference=signencrypt Received-SPF: pass client-ip=185.67.36.65; envelope-from=philipk@posteo.net; helo=mout01.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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:323164 Archived-At: Garklein writes: >> Can you explain what, ->>, --> and -some-> do generally? > > Of course! > > `->' takes in a value and a variable amount of forms, "threading" the > value through them by inserting it as the first argument in the first > form, inserting the result of that as the first argument in the next > form, etc. > > For example, `(-> foo x (y 3) z)' is equivalent to `(z (y (x foo) 3))'. Right, this is what we already have with thread-first, right? > `->>' does the same thing, but inserts each value as the last argument > of each form, instead of the first. Oh, I wouldn't have guessed that from the symbol name. > `-->' substitutes the symbol `it' in each form as the previous value. > `(-> x (* it it) (+ it 9) (sqrt it))' is equivalent to `(sqrt (+ (* x > x) 9))', and can be read as "take `x', multiply it by itself, add nine > to it, and take its square root". Hmm, anaphoric macros are somewhat controversial they have an even greater cognitive overhead than every day macros, let alone threading macros. > `-some->' is like `->', except that it will short-circuit the whole > `-some->' expression with `nil' whenever any form returns `nil'. Here I have to agree with others in the thread that when-let* seems more maintainable, as it forces the programmer to introduce names that hopefully indicate what is being done. --- Generally this seems like a cultural clash between traditional Lisps and newer languages like Clojure that derive some inspired from Lisps, but have intentionally broken with the existing "Lisp tradition". Backporting concepts like these is certainly technically feasible, but it feels forced and foreign for people like me who don't work with Closure or related languages. > On Wed, Aug 28, 2024 at 2:05=E2=80=AFPM Philip Kaludercic wrote: >> >> Garklein writes: >> >> > Hello, >> > >> > Would it be possible to have the dash.el macros `->', `->>', `-->', >> > and `-some->' in subr-x.el? I find them to be really useful, and would >> > love to see them in the base language. >> > >> > I know that `thread-first' and `thread-last' exist, but I find that my >> > eyes can recognize `->' and `->>' much easier. `-->' is really nice >> > for more complex threading. >> >> This sounds more like a matter of habit. FWIW I find a symbol like ->> >> or --> very unusual for Elisp. All in all, there are not that many if I >> run this snippet >> >> (mapatoms >> (lambda (sym) >> (when (string-match-p (rx bos (+ (not alnum)) eos) >> (symbol-name sym)) >> (message "Note %S" sym)))) >> >> and most of the appear to be part of some DSL like rx, and not Lisp >> functions (in my case only 18 out of 57). >> >> > `-some->' is useful in cases like this: >> >> Can you explain what, ->>, --> and -some-> do generally? >> > >> > (let (foo (function-which-may-return-nil)) >> > (when foo >> > (bar foo))) >> > >> > which can be rewritten, much cleaner, as >> > >> > (-some-> foo function-which-may-return-nil bar) >> >> [citation needed] >> >> > Thank you, >> > Garklein >> > >> > >> >> -- >> Philip Kaludercic on peregrine --=20 Philip Kaludercic on peregrine