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
.
the return value of println is nil and perhaps the output from the print is likely going into another buffer if your are using emacs or being logged somewhere else. Perhaps you are seeing the return value of println
instead of it's output.
ClojureScript:cljs.user> (ns cljs.user (:require [cljs.reader :as edn]))
nil
ClojureScript:cljs.user> (println (:foo (cljs.reader/read-string "{:foo :bar}")))
:bar
nil
vs:
ClojureScript:cljs.user> (:foo (cljs.reader/read-string "{:foo :bar}"))
:bar
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With