            address 0]
       (if-let [func (get funcs index)]
         (let [new-funcs (update-in funcs [index] assoc :address address)
-              address (+ address (count (:code func)))]
+              address (+ address (:length func))]
           (recur new-funcs (inc index) address))
         funcs))))
 

  [[name args & body :as code] fns]
  {:pre [(list? code)]}
  (let [fns (assoc fns name {})
        [stmt & stmts] (mapcat #(compile-form args fns %) body)]
    (concat [(conj stmt (format "; define %s" name))]
            stmts
            [[:rtn]])))

(defn compile-ai
  [file]

    (loop [form (read prog false nil)
           fns {}]
      (if form
        (let [func (compile-function form fns)]
          (recur (read prog false nil) (assoc fns (:name func) func)))
        (emit-code (assign-addresses fns))))))
