{"id":11392,"date":"2023-05-30T13:42:22","date_gmt":"2023-05-30T17:42:22","guid":{"rendered":"https:\/\/irreal.org\/blog\/?p=11392"},"modified":"2023-05-30T13:42:22","modified_gmt":"2023-05-30T17:42:22","slug":"psa-elisp-has-builtin-threading-macros","status":"publish","type":"post","link":"https:\/\/irreal.org\/blog\/?p=11392","title":{"rendered":"PSA: Elisp Has Builtin Threading Macros"},"content":{"rendered":"<p>I\u2019ve written about Clojure\u2019s threading macros and their implementation in Elisp before [<a href=\"https:\/\/irreal.org\/blog\/?p=3322\">1<\/a>, <a href=\"https:\/\/irreal.org\/blog\/?p=9325\">2<\/a>, <a href=\"https:\/\/irreal.org\/blog\/?p=9366\">3<\/a>, <a href=\"https:\/\/irreal.org\/blog\/?p=9338\">4<\/a>, <a href=\"https:\/\/irreal.org\/blog\/?p=10992\">5<\/a>]. I like them but almost always use the traditional composition of functions instead. That\u2019s probably because being a mathematician it seems natural to me. Still, the threading macros are easier to read and understand.<\/p>\n<p>Most people who care about such things know about Magnar Sveen\u2019s implementation of these macros in his <a href=\"https:\/\/github.com\/magnars\/dash.el\">Dash library<\/a>. They have the advantage of using the same names, <code>-&gt;<\/code>, <code>-&gt;&gt;<\/code>, etc. as clojure. Of course, you have to install Dash to use them. That\u2019s not much of a problem because so many packages use Dash that it\u2019s probably already installed.<\/p>\n<p>But what if you don\u2019t want the dependency? It turns out that Elisp has the most important of these macros built in and has since at least Emacs 25. The first, <code>thread-first<\/code> corresponds to <code>-&gt;<\/code> and the second, <code>thread-last<\/code>, corresponds to <code>-&gt;&gt;<\/code>. They live in the <code>sub-x.el<\/code> file if you want to check out there definition.<\/p>\n<p>Ruslan Bekenev has a <a href=\"https:\/\/codelearn.me\/2023\/05\/28\/emacs_thread_macros.html\">page that explains all this<\/a> and even gives a short explanation of how to use the macros. If you\u2019re interested in the threading macros, take a look at his post.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I\u2019ve written about Clojure\u2019s threading macros and their implementation in Elisp before [1, 2, 3, 4, 5]. I like them but almost always use the traditional composition of functions instead. That\u2019s probably because being a mathematician it seems natural to &hellip; <a href=\"https:\/\/irreal.org\/blog\/?p=11392\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[18],"class_list":["post-11392","post","type-post","status-publish","format-standard","hentry","category-general","tag-emacs"],"_links":{"self":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/11392","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=11392"}],"version-history":[{"count":1,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/11392\/revisions"}],"predecessor-version":[{"id":11393,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/11392\/revisions\/11393"}],"wp:attachment":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=11392"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=11392"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=11392"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}