keywords & symbols as proper types is probably not far off and optimizing
them doesn't need to wait for a general whole program optimization strategy.

David


On Mon, Nov 26, 2012 at 3:42 PM, Herwig Hochleitner
<hhochleit...@gmail.com>wrote:

> Encoding Keywords as Strings is a performance optimization in
> clojurescript.
> js/String is in fact extended to IFn to make it work
> https://github.com/clojure/clojurescript/blob/master/src/cljs/cljs/core.cljs#L1795
>
> I don't think it is an immutable design choice, but a replacement with
> interned Keyword objects would need to stand up against the current
> solution, performance wise.
> My feeling is that this could be tackled as soon as we have a stategy for
> whole program optimization, so that we could intern keywords at compile
> time.
>
>
> 2012/11/26 Krukow <karl.kru...@gmail.com>
>
>> Hi,
>> I'm writing my first ClojureScript program. I defined a protocol for a
>> query language which I wanted to extend to various data types, including
>> keywords.
>>
>> However keywords are strings when it comes to dispatch. Is this a bug, or
>> by design?
>>
>> ClojureScript:cljs.user> (defprotocol Foo (-a [x] "sample"))
>> nil
>> ClojureScript:cljs.user> (extend-protocol Foo
>>   Keyword
>>   (-a [x] (print "keyword")))
>> #<
>> function (x) {
>>     return cljs.core.print.call(null, "keyword");
>> }
>> >
>> ClojureScript:cljs.user> (-a :foo)
>> "Error evaluating:" (-a :foo) :as "cljs.user._a.call(null,\"\\**
>> uFDD0'foo\");\n"
>> org.mozilla.javascript.**JavaScriptException: Error: No protocol method
>> Foo.-a defined for type string: ?'foo (<cljs repl>#22)
>> at <cljs repl>:22 (anonymous)
>>  at <cljs repl>:14 (_a)
>> at <cljs repl>:7 (anonymous)
>> at <cljs repl>:7
>>
>>
>> If I extend to js/String it works.
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clojure@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+unsubscr...@googlegroups.com
>> For more options, visit this group at
>> http://groups.google.com/group/clojure?hl=en
>
>
>  --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@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+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
>

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

Reply via email to