Search code examples
emacsschemelispelisp

Difference in function evaluation between Scheme and Elisp


While studying elisp I tried something which I know works in Scheme and discovered to my surprise that I couldn't replicate it in Elisp.

;; works in Scheme. result: 5
((if 1 + -) 3 2)

;; doesn't work in Elisp. result: error
((if 1 '+ '-) 3 2)

I would expect that the Elisp line evaluates to

(+ 3 2)

and that the evaluation of this list result in 5. However I get:

(invalid-function (if t '+ '-))

What am I missing here? Does Elisp not allow for such actions? Is this possibly related to the fact that Scheme is a lisp-1 language and Elisp a lisp-2?


Solution

  • Yes, the error is due to the fact that Emacs Lisp is a Lisp-2. This should work:

    (funcall (if 1 '+ '-) 3 2)