This prints :bar
in Clojure as I would expect:
(println (:foo (clojure.tools.reader.edn/read-string "{:foo :bar}")))
;=> :bar
But this prints nil
in ClojureScript:
(println (:foo (cljs.reader/read-string "{:foo :bar}")))
;=> nil
To make things stranger, this prints :bar
in ClojureScript as I would expect:
(let [data (cljs.reader/read-string "{:foo :bar}")]
(println ((first (keys data)) data )))
;=> :bar
How do I access a value in a map that was created by the reader? Is this a character encoding thing?
Edit
Here's the namespace as requested in the comments:
(ns clojuresite.homepage
(:require-macros [hiccups.core :as hiccups])
(:require [hiccups.runtime :as hiccupsrt]
[cljs.nodejs :as node]
[cljs.reader :as reader]))
Try this:
(.log js/console
((keyword "foo") (cljs.reader/read-string "{:foo :bar}")))
If that works, and generates :bar
, you have old generated code hanging around and you should run a lein cljsbuild clean
.
There was a change in 0.0-1877
that switched keywords, in the generated javascript, from :foo
to cljs.core.Keyword
.