title: emacs: Symbol's function definition is void: loop
body: <p>I am testing on loading packages in emacs <code>init.el</code> (Emacs 24.3). I followed <a href="http://batsov.com/articles/2012/02/19/package-management-in-emacs-the-good-the-bad-and-the-ugly/" rel="nofollow noreferrer">a blog </a> by the author of <code>emacs prelude</code> to automatically load packages, and copied the code there into my <code>init.el</code> as in the bottom. However, I got an error message about the <code>loop</code> function/symbol, which says:</p>
  
  <pre><code>Symbol's function definition is void: loop
  </code></pre>
  
  <p>Can someone please explain how to fix the code?</p>
  
  <p>I've searched around on the internet, and it seems that <code>loop</code> is a macro in <code>cl-lib</code>. My guess is that the definition for <code>loop</code> is missing, and I attempted to fix the problem by adding <code>(require 'cl-lib)</code>, as shown in the code, but the error remains. There are other SO questions on similar error messages, e.g.: <a href="https://stackoverflow.com/questions/20871056/elisp-cl-loop-for-symbols-value-as-variable-is-void">ELisp: cl-loop for &quot;Symbol&#39;s value as variable is void&quot;</a>, <a href="https://stackoverflow.com/questions/8831400/symbols-function-definition-is-void-declare-function">Symbol&#39;s function definition is void: declare-function</a>. But the error messages are different on what's missing, and the answers mostly suggest alternative routes, such as using newer version of emacs.</p>
  
  <p>-- code --</p>
  
  <pre><code>(require 'package)
  (add-to-list 'package-archives
    '("melpa-stable" . "http://stable.melpa.org/packages/") t)
  (package-initialize)
  
  ;;; check &amp; load packages
  (defvar prelude-packages
    '( haskell-mode )
    "A list of packages to ensure are installed at launch.")
  
  ;;(require 'cl-lib) ;debug
  (defun prelude-packages-installed-p ()
    (loop for p in prelude-packages
          when (not (package-installed-p p)) do (return nil)
          finally (return t)))
  
  (unless (prelude-packages-installed-p)
    ;; check for new packages (package versions)
    (message "%s" "Emacs Prelude is now refreshing its package database...")
    (package-refresh-contents)
    (message "%s" " done.")
    ;; install the missing packages
    (dolist (p prelude-packages)
      (when (not (package-installed-p p))
        (package-install p))))
  
  (provide 'prelude-packages)
  ;;; end load packages
  </code></pre>