Skip to content

Instantly share code, notes, and snippets.

@sgrove
Last active December 21, 2015 11:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sgrove/6301866 to your computer and use it in GitHub Desktop.
Save sgrove/6301866 to your computer and use it in GitHub Desktop.
Real keywords 00001
(def ^:dynamic *real-keywords?* true)
(def ^:dynamic *constant-table* (atom {}))
(defn reset-constant-table! []
(reset! *constant-table* {}))
(defn register-constant! [k]
(println "Registering constant!")
(swap! *constant-table*
(fn [table]
(if (get table k)
table
(assoc table k (.hashCode k))))))
(defn analyze-keyword
[env sym]
; Track the keyword constant
(when *real-keywords?*
(register-constant! sym))
{:op :constant :env env
:form sym})
(binding [*constant-table* (atom {})
*real-keywords?* true
*cljs-ns* 'cljs.user]
(analyze (empty-env)
(forms-seq "simple2.cljs"))
*constant-table*)
Registering constant!
Registering constant!
Registering constant!
Anaylze symbol
Registering constant!
Anaylze symbol
Anaylze symbol
Anaylze symbol
#<Atom@3f86f612: {:c 1013910699, :b 1013910508, :a 1013910569}>
(ns simple2)
(let [m {:a 10 :b 100}]
(:a m)
(:c m)
(println 'a))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment