{"id":12724,"date":"2025-01-18T11:18:58","date_gmt":"2025-01-18T16:18:58","guid":{"rendered":"https:\/\/irreal.org\/blog\/?p=12724"},"modified":"2025-01-18T11:18:58","modified_gmt":"2025-01-18T16:18:58","slug":"iterating-in-lisp","status":"publish","type":"post","link":"https:\/\/irreal.org\/blog\/?p=12724","title":{"rendered":"Iterating In Lisp"},"content":{"rendered":"<p>\nJoe Marshall has an <a href=\"https:\/\/funcall.blogspot.com\/2025\/01\/iteration.html\">interesting post on iteration for all you Lisp heads<\/a>. It&rsquo;s mostly aimed at Common Lisp and Scheme but a lot of it applies to Elisp as well so even Emacs users will be interested. The mail problem for Elisp is that tail recursion isn&rsquo;t supported.\n<\/p>\n<p>\nI almost always prefer tail recursion for explicit iteration when it&rsquo;s available but Marshall shows that it&rsquo;s often better to use one of the built-in functions or mechanisms rather than an explicit loop. For example, the map and reduce functions are a form of implicit iteration that are concise and easy to use.\n<\/p>\n<p>\nThere are also the more imperative looping mechanisms such as the <code>do<\/code>, <code>dolist<\/code>, and <code>dotimes<\/code> macros that emulate the looping mechanisms in imperative languages. I use these a lot if only for their convenience and the knowledge that their implementations will probably expand into the most efficient code possible. In the absence of tail recursion, they&rsquo;re a good choice.\n<\/p>\n<p>\nFinally, there is the series suit. I&rsquo;ve never used these so I don&rsquo;t have any firsthand experience with them. See Marshall&rsquo;s post for an explanation. You can think of them as a refinement of Map\/Reduce that does away with the generation of intermediate lists.\n<\/p>\n<p>\nMarshall also mentions the <code>loop<\/code> macro. Lispers either love it or hate. He, like me, isn&rsquo;t a fan for all the usual reasons.\n<\/p>\n<p>\nIf you like any of the various Lisp languages, take a look at Marshall&rsquo;s post. You&rsquo;ll enjoy it.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Joe Marshall has an interesting post on iteration for all you Lisp heads. It&rsquo;s mostly aimed at Common Lisp and Scheme but a lot of it applies to Elisp as well so even Emacs users will be interested. The mail &hellip; <a href=\"https:\/\/irreal.org\/blog\/?p=12724\">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,14],"class_list":["post-12724","post","type-post","status-publish","format-standard","hentry","category-general","tag-emacs","tag-lisp"],"_links":{"self":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/12724","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=12724"}],"version-history":[{"count":1,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/12724\/revisions"}],"predecessor-version":[{"id":12725,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/12724\/revisions\/12725"}],"wp:attachment":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=12724"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=12724"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=12724"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}