Skip to content

Commit

Permalink
kludged compile-special for `def'
Browse files Browse the repository at this point in the history
  • Loading branch information
athos committed Apr 11, 2012
1 parent 10e753f commit ffbac8c
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/syntactic_closure/specials.clj
@@ -1,6 +1,6 @@
(in-ns 'syntactic-closure)

(use '[syntactic-closure.environment :only [extend-environment]])
(use '[syntactic-closure.environment :only [extend-environment add-to-environment]])

(def ^:private %specials
'#{def if let* fn* quote do loop* recur var})
Expand All @@ -10,13 +10,16 @@

(defmulti ^:private compile-special (fn [env [op & _]] op))

;; FIXME:
;; DEF's init expr should be evaluated in the environment extended to include
;; defining variable.
;;; NB:
;;; I don't know how (qq (def foo bar)) or (qq (def ~(make-syntactic-closure env nil 'foo) bar))
;;; should behave.
;;; For the time being, the first argument of `def' is never renamed.
(defmethod compile-special 'def [env exp]
(let [[_ name init] exp]
`(def ~(compile env name)
~(compile env init))))
(let [[_ var init] exp]
(let [var' (compile env var)
var' (if (namespace var') (symbol (name var')) var')
env' (add-to-environment env var' var')]
`(def ~var' ~(compile env' init)))))

(defmethod compile-special 'if [env exp]
(let [[_ test then else] exp]
Expand Down

0 comments on commit ffbac8c

Please sign in to comment.