title: Various forms of looping and iteration in Elisp
body: <p>I am trying to understand all the looping constructs in Emacs Lisp.
  In one example I am trying to iterate over a list of symbols and print them to the <code>*message*</code> buffer like so:</p>
  <pre class="lang-lisp prettyprint-override"><code>(let* ((plist package-activated-list) ;; list of loaded packages
         (sorted-plist (sort plist 'string&lt;)))
    (--map (message (format &quot;%s&quot; it)) sorted-plist))
  </code></pre>
  <p><code>--map</code> is a function from the package <code>dash.el</code>.</p>
  <h2>How to do this in pure Elisp?</h2>
  <p>Now how do I iterate over a list in Elisp, without using other packages.</p>
  <p>I have seen some examples using <code>while</code> and <code>dolist</code> macro, for example here:</p>
  <p><a href="https://www.gnu.org/software/emacs/manual/html_node/elisp/Iteration.html" rel="nofollow noreferrer">https://www.gnu.org/software/emacs/manual/html_node/elisp/Iteration.html</a></p>
  <p>But those are destructive, non-functional ways to express a loop.</p>
  <p>Coming from <code>Scheme</code> (having worked with it and with SICP some twenty years ago!), I tend to prefer functional, non destructive (does that always lead to recursive?) ways to express ideas.</p>
  <p>So what are idiomatic ways to loop over a list of items in Emacs Lisp?</p>
  <p>Also: Are there ways to express loops in a functional fashion in Emacs Lisp?</p>
  <h2>What I have found so far</h2>
  <ol>
  <li><strong>Loop Macros</strong> (from Common Lisp?) prefixed with &quot;cl-*&quot;</li>
  </ol>
  <p><a href="https://www.gnu.org/software/emacs/manual/html_node/cl/Loop-Facility.html" rel="nofollow noreferrer">https://www.gnu.org/software/emacs/manual/html_node/cl/Loop-Facility.html</a></p>
  <ol start="2">
  <li><strong>Iteration Clauses</strong></li>
  </ol>
  <p><a href="https://www.gnu.org/software/emacs/manual/html_node/cl/Iteration-Clauses.html#Iteration-Clauses" rel="nofollow noreferrer">https://www.gnu.org/software/emacs/manual/html_node/cl/Iteration-Clauses.html#Iteration-Clauses</a></p>
  <ol start="3">
  <li><strong><code>Dash.el</code></strong></li>
  </ol>
  <p><a href="https://github.com/magnars/dash.el" rel="nofollow noreferrer">https://github.com/magnars/dash.el</a></p>
  <p>Magnar Sveen's excellent package marketed as &quot;A modern list api for Emacs. No 'cl required.&quot;</p>
  <p>What else is there? Any recommended reading?</p>