ClojureScript - string?, symbol? and keyword?

115 views
Skip to first unread message

Jonas Enlund

unread,
Aug 4, 2011, 5:36:09 AM8/4/11
to cloju...@googlegroups.com
Hi

The string?, symbol? and keyword? functions seem to behave differently in the cljs repl and when compiled and run in the browser.

(ns a)

(js/alert (str (string? :a) " "
               (string? 'a) " "
               (symbol? 'a) " "
               (keyword? :a) " "))

The above prints "true true false false" when run in a browser. If someone can confirm this I could open a ticket on JIRA.

Cheers,
Jonas

Jonas Enlund

unread,
Aug 4, 2011, 12:57:31 PM8/4/11
to cloju...@googlegroups.com
After some more investigation the problem seems to affect unoptimized code only. For example, if I compile the "hello" program from samples/ with 

$ cljsc src/ > hello.js

open the file in chrome, and type into the console:

> cljs.core.name(cljs.core.keyword("abc"))
"ï· 'abc"

This should return "abc" if I understand things correctly?

Jonas

David Powell

unread,
Aug 5, 2011, 4:45:17 AM8/5/11
to cloju...@googlegroups.com
This is failing in unoptimized code for the reason that I discussed in the recent "character encoding issue in compiled .js" thread.  It is because Clojurescript outputs UTF-8 encoded javascript in unoptimized code, but without a properly configured web server, the browser will not understand that the script is UTF-8 encoded, and will misinterpret the code.

I think it might be best for us to replace the calls to (print) in the clojurescript compiler that emit the javascript, with calls to another function that outputs the javascript via a custom Writer that outputs us-ascii and automatically performs \u escaping on unicode values.  This would match what the closure compiler does.



Cosmin Stejerean

unread,
Aug 5, 2011, 9:52:01 AM8/5/11
to cloju...@googlegroups.com
On Fri, Aug 5, 2011 at 3:45 AM, David Powell <djpo...@djpowell.net> wrote:
> I think it might be best for us to replace the calls to (print) in the
> clojurescript compiler that emit the javascript, with calls to another
> function that outputs the javascript via a custom Writer that outputs
> us-ascii and automatically performs \u escaping on unicode values.  This
> would match what the closure compiler does.

Getting character encoding consistency between optimized and
unoptimized output seems like a good idea.


--
Cosmin Stejerean
http://offbytwo.com

Reply all
Reply to author
Forward
0 new messages