This is a special case behavior of clojure.core/get, as you can see in the RT.java source file at these lines: https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/RT.java#L750-L755
I have no idea if a JIRA would be accepted for any change on this or not, but if one was, I suspect it would be an addition to the doc string for clojure.core/get, mentioning that it also works on strings. Most doc strings are considered terse by many people. This appears to be considered a feature by those who maintain Clojure, not a bug, with one reason given by Stuart Halloway in his recent talk on using the scientific method in debugging [1]. Paraphrased from memory it was approximately "if you have a bug in some API you are using, you should read all of the documentation for it. That is easier if it is short." If you want longer documentation and/or examples, ClojureDocs.org and conj.io take user submissions for additional documentation, with quite low friction. Andy [1] https://www.youtube.com/watch?v=FihU5JxmnBg On Thu, Apr 21, 2016 at 8:48 AM, Mars0i <marsh...@logical.net> wrote: > The docstring for 'get' says nothing explicit about vectors ("Returns the > value mapped to key, not-found or nil if key not present.") but most of us > know that vectors can be viewed as associative data structures where > indexes are like keys: > > (get [\a \b \c] 1) > \b > > 'get' also works on strings: > > (get "abc" 1) > \b > > However, strings are not treated as vectors or maps in other contexts: > > (assoc "abc" 1 \Z) > ClassCastException java.lang.String cannot be cast to > clojure.lang.Associative > > This combination of behaviors is confusing. If strings are vectors, then > 'assoc' and other similar functions should work with them, and maybe I > should be able to do this to index into a string: > > ("abc" 1) > ClassCastException java.lang.String cannot be cast to clojure.lang.IFn > > If strings are not vectors, then they seem to be a special case for > 'get'. One might argue that the very terse docstring for 'get' should note > its use with vectors, but once you understand the sense in which vectors > are like maps, the of 'get' use with vectors is implicitly covered by what > the docstring says. However, the use of 'get' with strings is not > implicitly covered by what the docstring says. If it was, then the last > two examples I gave should work. > > (I'd be willing to file a ticket on this, but the puzzling behavior is not > new, and I suspect that there's something I'm not understanding.) > > -- > 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 unsubscribe from this group and stop receiving emails from it, send an > email to clojure+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.