Adding ^:const to a var seems to change the data type sometimes: user> (def ^:const time1 (java.sql.Timestamp. 100000000) #'user/time1 user> (def time2 (java.sql.Timestamp. 100000000) #'user/time2 user> (type time1) java.util.Date user> (type time2) java.sql.Timestamp
The upshot is that while (= time1 time2) yields true, converting these two vars to strings yields different results: user> (str time1) "Thu Jan 01 22:46:40 EST 1970" user> (str time2) "1970-01-01 22:46:40.0" Daniel Gregoire pointed out that this seems be because of how the compiler quotes constant vars <https://github.com/clojure/clojure/blob/d5708425995e8c83157ad49007ec2f8f43d8eac8/src/jvm/clojure/lang/Compiler.java#L7075>. He showed met that eval-ing two different methods of quoting yields different types: user> (type (eval (quote (java.sql.Timestamp. 100000000)))) java.sql.Timestamp user> (type (eval (list 'quote (java.sql.Timestamp. 100000000)))) java.util.Date Chris Bui noted that rebinding the data readers, and then evaluating the second form above, yields the same data type as the first form: user> (prn default-data-readers) {inst #'clojure.instant/read-instant-date, uuid #'clojure.uuid/default-uuid-reader} nil user> (binding [*data-readers* {'inst #'clojure.instant/read-instant- timestamp}] (type (eval (list 'quote (java.sql.Timestamp. 100000000))))) java.sql.Timestamp Here's a gist he made <https://gist.github.com/Christopher-Bui/abaf2b9eb3b660d3c11b3495e04281fb>. I didn't expect ^:const to change the var's data type, and there wasn't any clear documentation on this behavior that I could find. Is this a bug that I should file in JIRA, or is ^:const supposed to work like this? -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.