I am trying to convert SICP's meta-circular evaluator to Clojure. In setup-environment a call to extend-environment does not compile because I get the error "Attempting to call unbound fn". Here's part of the code:
(... loads of methods for creating and managing environment list)
(def primitive-procedures
  (list (list 'car first)
        (list 'cdr rest)
        (list 'cons conj) ;; TODO: reverse
        (list 'null? nil?)
        (list 'list list)
        (list '+ +)
        (list '- -)
        (list '* *)
        (list '/ /)
        ;;      more primitives
        ))
(def primitive-procedure-names 
  #(map [first
         primitive-procedures]))
(def primitive-procedure-objects 
  (fn [] (map (fn [p] (list 'primitive (second p)))
               primitive-procedures)))
(def the-empty-environment '())
(defn extend-environment [vars vals base-env]
  (if (= (count vars) (count vals))
    (conj base-env (make-frame vars vals))
    (if (< (count vars) (count vals))
      (throw (Throwable. "Too many arguments supplied") vars vals)
      (throw (Throwable. "Too few arguments supplied") vars vals))))
;; Added # in front here so it could be called (???)
(defn setup-environment []
  #(let [initial-env
         (extend-environment (primitive-procedure-names)
                             (primitive-procedure-objects)
                             the-empty-environment)] ;; <= that does not work
     (define-variable! 'true true initial-env)
     (define-variable! 'false false initial-env)
     initial-env)))
;; Method for interacting with the evaluator:
(defn driver-loop []
  (prompt-for-input input-prompt)
  (let [input (read)]
    (let [output (m-eval input the-global-environment)]
      (announce-output output-prompt)
      (user-print output)))
  (driver-loop))
(...)
(def the-global-environment (setup-environment))
(driver-loop)
And when I evaluate the extend-environment method I get the following error:
- Caused by java.lang.IllegalStateException
 
Attempting to call unbound fn:
#'scheme-evaluator/extend-environment
Var.java: 43 clojure.lang.Var$Unbound/throwArity
AFn.java: 40 clojure.lang.AFn/invoke
scheme-evaluator.clj: 277 scheme-evaluator/eval7808
I think I am not providing the right type of parameters or I have not created the right type of function. I tried various variations of anonymous methods and passing in parentheses or without, but I don't get it to compile.
Does anyone know what the reason is for this error and how can I fix it?