# Evaluate allows for combinations whose operators are compound expressions

I find the amazing power of scheme in sicp

Exercise 1.4. Observe that our model of evaluation allows for combinations whose operators are compound expressions. Use this observation to describe the behavior of the following procedure:

`````` #+BEGIN_SRC scheme
(define (a-plus-abs-b a b)
((if (> b 0) + -) a b))
(a-plus-abs-b 9 4)
#+END_SRC

#+RESULTS:
: 13
``````

Try to rewrite it as

``````#+begin_src emacs-lisp :session sicp :lexical t
(defun a-plus-abs-b(a b)
((if (> b 0) + -) a b))
(a-plus-abs-b 9 4)
#+end_src
``````

Alternatively with

``````#+begin_src emacs-lisp :session sicp :lexical t
(defun a-plus-abs-b(a b)
(funcall (if (> b 0) + -) a b))
(a-plus-abs-b 9 4)
#+end_src
``````

Error reported as

``````funcall: Symbol’s value as variable is void: +
``````

How could write it correctly in elisp?

`funcall` takes a function as its first argument, so you need `if` to return a function symbol. You can do that by sharp-quoting its return value:

``````(defun a-plus-abs-b (a b)
(funcall (if (> b 0) #'+ #'-) a b))

(a-plus-abs-b 9 4)                  ; => 13
``````

Elisp is a Lisp-2, which means each symbol can have a function value and a variable value. When you don't quote the return value of `if`, you're asking it to return the variable value of `+` or `-`, which you could actually do if you want to:

``````(setq - "testing")
(- 1 1)                                 ; => 0
-                                       ; => "testing"
(+ 1 1)                                 ; => 2
+                                       ; => void variable "+"
``````

See:

• It's more like a brain teaser. So function is not named as the first-class citizen in elisp? Commented Dec 24, 2019 at 10:56
• It is a first-class citizen. It's just that symbols can hold a function and variable value. See this SO thread: What is the difference between Lisp-1 and Lisp-2?
– Dan
Commented Dec 24, 2019 at 11:03