here is the doc about strings in clj:
if i understand that correctly a str in clj is very much like a java-str, correct?
so for example in java str literals are pooled, right?
(identical? "clj" "clj")
true
(identical? "clj" (str "c" "l" "j"))
false
also if you look at something like:
(source str/upper-case)
you get:
(defn ^String upper-case
"Converts string to all upper-case."
{:added "1.2"}
[^CharSequence s]
(.. s toString toUpperCase))
nil
now strings in java are immutable and also until ( including ) jdk8 they were backed by a char[]
… since jdk9 by a byte[]
, right? ( so i suppose you would also notice that clj programs became more memory efficient ( in many cases ) because of that internal change, correct? )
now because of how strings are implemented in java they can sometimes perform very poorly: ( this is from “effective java 3rd edition - item 63 - beware of the performance of string concatenation” )
public String statement(){
String result = "";
for( int i = 0; i < numItems(); i++)
result += lineForItem(i);
return result;
}
now seams to me that the main problem is that this is nothing like the immutable / persistent data types for sequences you get in clj. ( obviously a str being a seq of chars )
so here is a thought experiment for you. what would happen if you backed strings by such a clj data structure instead? ( obviously in practice this seams like a stupid idea… but just as a thought experiment… i suppose there would be some pros and cons to that, right?.. - as with everything -… so… hmm… idk… any thoughts? )
p.s. a few days ago a posted about some thoughts regarding enthusiasm and its role in programming… now i wasn’t able to finish that post, but still i published it for some reason, then decided to delete it in order to finish it and post it again… turns out… once i had spelled out my thoughts on the matter in more detail… it became clear that it was basically just nonsense … so i might post about that topic again… ( repost ) but that might take me a while… - just in case you were wondering / waiting - )