Last active
December 21, 2015 11:49
-
-
Save sgrove/6301866 to your computer and use it in GitHub Desktop.
Real keywords 00001
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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}> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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