3

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?

RuvenS
  • 109
  • 7
  • 2
    Emacs Lisp does not evaluate the first element of a list, like it's done in Scheme. See: https://www.gnu.org/software/emacs/manual/html_node/elisp/Forms.html#Forms And, yes, Emacs Lisp is not a 'Lisp-1' like Scheme. – Rainer Joswig May 31 '19 at 12:16

1 Answers1

5

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

(funcall (if 1 '+ '-) 3 2)
Óscar López
  • 232,561
  • 37
  • 312
  • 386