Fork me on GitHub
#cljs-dev
<
2019-04-26
>
alexmiller02:04:32

should now be on the contributors list

dnolen14:04:03

@lee great, just make sure to follow the patch guidelines - when you think you've got in a good spot assign to me or @mfikes

lread16:04:48

great, thanks!

lilactown14:04:18

would we be open to considering a patch for adding printing of js/Symbol?

lilactown14:04:53

esp. with React dev, it becomes a blocker when e.g. trying to print errors related to React Elements

lilactown15:04:21

yeah I've read through the issue and it sounds like there were a number of complications with the original patch. I can't quite tell if it was due to inherent complexity of the problem or due to the way printing / str worked then (and maybe has changed?)

lilactown15:04:00

ah hm.

cljs.user=> (extend-protocol IPrintWithWriter
           js/Symbol
           (-pr-writer [sym writer _]
             (-write writer (str "\"" (.toString sym) "\""))))
#object[Function]

cljs.user=> (str (js/Symbol "foo"))
/Users/r627543/Code/fido/packages/web/app/.shadow-cljs/builds/node-repl/dev/out/cljs-runtime/cljs.core.js:10144
return [x].join("");
           ^

TypeError: Cannot convert a Symbol value to a string

cljs.user=> (js/Symbol "foo")
"Symbol(foo)"

lilactown15:04:34

looks like there's still some finnicky-ness with str

thheller15:04:53

well [Symbol("foo")].join("") this JS fails, str just happens to emit that

lilactown15:04:28

right; it sounds like I'd have to special-case js/Symbol like the convo on the issue discussed

thheller15:04:58

not really. its just something JS doesn't support so there is no way to fix that part

thheller15:04:07

pr-str is a different story though

thheller15:04:31

your extend-protocol above should make pr-str work. str is just never going to work since the engine just doesn't support it.

lilactown15:04:00

๐Ÿค” I guess I just would expect that (str x) would coerce x to string for any x. it works for any CLJS type at least, and most JS types

lilactown15:04:16

but I'll take just having pr-str

lilactown15:04:42

it would fix using the REPL

thheller15:04:46

this has nothing to do with CLJS.

$ node
> [Symbol("foo")].join("")
TypeError: Cannot convert a Symbol value to a string
    at Array.join (native)

thheller15:04:46

I don't understand why js Symbol has such weird semantics regarding toString either but thats what we have ..

lilactown15:04:30

that is how CLJS currently implements str, I understand. and if we take that as the canonical, semantically correct thing to do in all cases then I accept that calling str on a Symbol should error ๐Ÿ˜„

thheller15:04:53

@lilactown again .. this is not related to CLJS in any way. this is just JS being weird. "x" + Symbol("foo") also fails

dnolen15:04:28

@lilactown we're not going to provide any hacks around Symbol

lilactown16:04:26

understood. think you would accept extending pr-str to Symbol?

lread22:04:58

Hiya, I think I should be updating https://dev.clojure.org/jira/browse/CLJS-3074 description with my approach, my JIRA is rusty, but I donโ€™t seem to have edit privs? @dnolen

martinklepsch23:04:57

@alexmiller is usually the one handing out edit rights

lread23:04:50

thanks martin!