Get the name of keyword/symbol in clojurescript

181 views
Skip to first unread message

Jonathan Fischer Friberg

unread,
Oct 17, 2011, 6:41:31 PM10/17/11
to clo...@googlegroups.com
Hi,

As I understand it, clojurescript uses some unicode characters to identify keywords/symbols.
I guess that's why (str 'a) gives me ï·‘'a
I thought that this was intentional, and that (name 'a) would give me "a", but I got the same result as with (str).

So how do I extract the name from a
symbol or keyword in clojurescript?
Also, is this behavior intentional, and if so, why?

David Nolen

unread,
Oct 17, 2011, 7:16:29 PM10/17/11
to clo...@googlegroups.com
Are you using ClojureScript HEAD? If you are and you are still seeing this under what conditions (advanced mode, browser REPL, etc.) ?

David

--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@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+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Jonathan Fischer Friberg

unread,
Oct 18, 2011, 7:22:52 AM10/18/11
to clo...@googlegroups.com
I'm on the master branch.

I compiled the file using 'cljsc file > file.js', and run it in the browser.

David Nolen

unread,
Oct 18, 2011, 10:25:45 AM10/18/11
to clo...@googlegroups.com
Does the same problem occur when trying this at the REPL (say via script/repljs) ?

David

Jonathan Fischer Friberg

unread,
Oct 18, 2011, 10:33:40 AM10/18/11
to clo...@googlegroups.com
I can't run that repl, I get

Exception in thread "main" java.lang.RuntimeException: java.lang.ClassNotFoundException: org.mozilla.javascript.Context
    at clojure.lang.Util.runtimeException(Util.java:165)
    at clojure.lang.Compiler.eval(Compiler.java:6435)
    at clojure.lang.Compiler.eval(Compiler.java:6414)
    at clojure.lang.Compiler.load(Compiler.java:6861)
    at clojure.lang.RT.loadResourceScript(RT.java:357)
    at clojure.lang.RT.loadResourceScript(RT.java:348)
    at clojure.lang.RT.load(RT.java:427)
    at clojure.lang.RT.load(RT.java:398)
    at clojure.core$load$fn__4610.invoke(core.clj:5386)
    at clojure.core$load.doInvoke(core.clj:5385)
    at clojure.lang.RestFn.invoke(RestFn.java:408)
    at clojure.core$load_one.invoke(core.clj:5200)
    at clojure.core$load_lib.doInvoke(core.clj:5237)
    at clojure.lang.RestFn.applyTo(RestFn.java:142)
    at clojure.core$apply.invoke(core.clj:602)
    at clojure.core$load_libs.doInvoke(core.clj:5271)
    at clojure.lang.RestFn.applyTo(RestFn.java:137)
    at clojure.core$apply.invoke(core.clj:602)
    at clojure.core$require.doInvoke(core.clj:5352)
    at clojure.lang.RestFn.invoke(RestFn.java:408)
    at user$eval1715.invoke(NO_SOURCE_FILE:2)
    at clojure.lang.Compiler.eval(Compiler.java:6424)
    at clojure.lang.Compiler.eval(Compiler.java:6390)
    at clojure.core$eval.invoke(core.clj:2795)
    at clojure.main$eval_opt.invoke(main.clj:296)
    at clojure.main$initialize.invoke(main.clj:315)
    at clojure.main$null_opt.invoke(main.clj:348)
    at clojure.main$main.doInvoke(main.clj:426)
    at clojure.lang.RestFn.invoke(RestFn.java:421)
    at clojure.lang.Var.invoke(Var.java:405)
    at clojure.lang.AFn.applyToHelper(AFn.java:163)
    at clojure.lang.Var.applyTo(Var.java:518)
    at clojure.main.main(main.java:37)
Caused by: java.lang.ClassNotFoundException: org.mozilla.javascript.Context
    at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
    at clojure.lang.DynamicClassLoader.findClass(DynamicClassLoader.java:61)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:186)
    at cljs.repl.rhino$eval1719$loading__4505__auto____1720.invoke(rhino.clj:9)
    at cljs.repl.rhino$eval1719.invoke(rhino.clj:9)
    at clojure.lang.Compiler.eval(Compiler.java:6424)
    ... 31 more

David Nolen

unread,
Oct 18, 2011, 11:04:48 AM10/18/11
to clo...@googlegroups.com
Have you rerun the bootstrap script since the Rhino upgrade?

Jonathan Fischer Friberg

unread,
Oct 18, 2011, 11:17:41 AM10/18/11
to clo...@googlegroups.com
It works now, and the result is as expected.

In the browser I still get the extra characters however.

David Nolen

unread,
Oct 18, 2011, 11:22:29 AM10/18/11
to clo...@googlegroups.com
Try removing the following:

file.js
out

and recompiling. I also recommend compiling one of the ClojureScript samples that you haven't checked out yet to see if the issue is reproducible.

David

Jonathan Fischer Friberg

unread,
Oct 18, 2011, 11:43:12 AM10/18/11
to clo...@googlegroups.com
I did a minimal example
https://gist.github.com/1295749

Result is in the attachment.
cljs_symbol.png

David Nolen

unread,
Oct 18, 2011, 11:52:36 AM10/18/11
to clo...@googlegroups.com
I see you're not setting the encoding. Try adding the following to the top of <head>

<meta charset="UTF-8">

David

Jonathan Fischer Friberg

unread,
Oct 18, 2011, 11:55:03 AM10/18/11
to clo...@googlegroups.com
It works!

Thanks for all the help.
Reply all
Reply to author
Forward
0 new messages