2

Here is an example config to demonstrate the problem I am facing:

(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/"))
(package-initialize)
(package-refresh-contents)
(package-install 'use-package)
(setq use-package-always-ensure t)
(use-package cider)

Previously, this would cause use-package to install CIDER just fine; however, since I removed my ~/.emacs.d/elpa directory today to update my packages, I now get this error when I run emacs --debug-init:

Debugger entered--Lisp error: (void-function if-let)
  (if-let ((cons (assoc car alist))) (setcdr cons (list cadr)) (set symbol (cons (list car cadr) alist)))
  (let ((alist (symbol-value symbol))) (if-let ((cons (assoc car alist))) (setcdr cons (list cadr)) (set symbol (cons (list car cadr) alist))))
  cider-add-to-alist(cider-jack-in-dependencies "org.clojure/tools.nrepl" "0.2.12")
  byte-code("\300\301\302\303#\210\304\301\305\306#\207" [put cider-jack-in-dependencies risky-local-variable t cider-add-to-alist "org.clojure/tools.nrepl" "0.2.12"] 4)
  require(cider nil t)
  (not (require (quote cider) nil (quote t)))
  (if (not (require (quote cider) nil (quote t))) (ignore (message (format "Cannot load %s" (quote cider)))))
  (progn (progn (require (quote package)) (use-package-ensure-elpa (quote cider))) (if (not (require (quote cider) nil (quote t))) (ignore (message (format "Cannot load %s" (quote cider))))))
  eval-buffer(#<buffer  *load*> nil "/home/sam/.emacs" nil t)  ; Reading at buffer position 228
  load-with-code-conversion("/home/sam/.emacs" "/home/sam/.emacs" t t)
  load("~/.emacs" t t)
  #[0 "\205\262

If I close Emacs and run emacs --debug-init again, I get a slightly different error:

Debugger entered--Lisp error: (invalid-function (cons (assoc car alist)))
  (cons (assoc car alist))()
  cider-add-to-alist(cider-jack-in-dependencies "org.clojure/tools.nrepl" "0.2.12")
  byte-code("\300\301\302\303#\210\304\301\305\306#\207" [put cider-jack-in-dependencies risky-local-variable t cider-add-to-alist "org.clojure/tools.nrepl" "0.2.12"] 4)
  require(cider nil t)
  (not (require (quote cider) nil (quote t)))
  (if (not (require (quote cider) nil (quote t))) (ignore (message (format "Cannot load %s" (quote cider)))))
  (progn (progn (require (quote package)) (use-package-ensure-elpa (quote cider))) (if (not (require (quote cider) nil (quote t))) (ignore (message (format "Cannot load %s" (quote cider))))))
  eval-buffer(#<buffer  *load*> nil "/home/sam/.emacs" nil t)  ; Reading at buffer position 228
  load-with-code-conversion("/home/sam/.emacs" "/home/sam/.emacs" t t)
  load("~/.emacs" t t)
  #[0 "\205\262

What exactly is causing this regression? Is it an error in the definition of cider-add-to-alist, or in one of that function's usages (with cider-jack-in-dependencies, cider-jack-in-dependencies-exclusions, or cider-jack-in-lein-plugins)? Or is it an error in use-package? Is there any workaround for this error that will allow me to continue using all my packages until it gets fixed?

  • I get the same error Invalid function (cons (assoc car alist)) in spacemacs. – nha Nov 22 '16 at 10:00
5

Commit 70971d0a918053d86e76e4ff8248b25a8646940e removed support for emacs 24.3 and below. This removed a file called cider-compat.el and replaced it with an emacs core file subr-x.el Supposedly this allowed the if-let macro to be from subr-x.el, with the thinking being that this file stayed the same from 24.4+ to 25+. It seems like the if-let macros did not make it into the emacs branch for 24.x.

So long story short, the if-let macro is undefined. Some people aren't running into this issue as some other projects define if-let. Some have old .elc files laying around which might be swept up in how emacs reads in files.

But the quick fix is to install CIDER (edited used to be emacs) from melpa-stable. Another fix is to upgrade emacs. Another fix is for you to run your own copy of cider locally but without the offending commit. And finally, if you can get this function into your personal emacs directory and it loads before cider, you should be good.

(defmacro if-let (bindings then &rest else)
  "Process BINDINGS and if all values are non-nil eval THEN, else ELSE.
Argument BINDINGS is a list of tuples whose car is a symbol to be
bound and (optionally) used in THEN, and its cadr is a sexp to be
evalled to set symbol's value.  In the special case you only want
to bind a single value, BINDINGS can just be a plain tuple."
  (declare (indent 2)
           (debug ([&or (&rest (symbolp form)) (symbolp form)] form body)))
  (when (and (<= (length bindings) 2)
             (not (listp (car bindings))))
    ;; Adjust the single binding case
    (setq bindings (list bindings)))
  `(let* ,(internal--build-bindings bindings)
     (if ,(car (internal--listify (car (last bindings))))
         ,then
       ,@else)))

Please note that the above is my copy of if-let from emacs. I did not write this code and I hope that the sharing of this code in this venue is fine. I'm happy to take it down if anyone thinks that it is out of place.

You can find an issue tracking all of this at cider issue 1882

If you want to run emacs locally you can use this

;; load local version of cider
(add-to-list 'load-path "~/projects/cider")
(load "cider")

and then run git checkout 3be082ae4a3d0b40d360648b20fb7caa14c0a9fc to get the commit right before it borked.

  • "But the quick fix is to install emacs from melpa-stable." - That sounds terribly convenient, but rather impossible to do. ITYM cider. – wasamasa Nov 23 '16 at 8:44
  • You are correct. I definitely meant install CIDER from melpa-stable :) – dpsutton Nov 23 '16 at 13:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.