picrin
picrin copied to clipboard
immutable string by default, use `transient-string` to modify strings efficiently
code example?
No concrete code, only proposal. But the API could be like:
string-set!: completely clone the string chunk.
transient-string-set!: performed in O(1) time
also string->transient and transient->string would be provided. With this style we could use some optimization techniques like rope representation against normal strings at the tradeoff of incredibly slow string-set!.
(let* ((a "car") (b (string->transient a)))
(transient-string-set! b 1 #\d)
(list a (transient->string b)))
What about this?
Clojure's transients will show
("car" "cdr")
Clojure doesn't provide transient strings, though.
(What I said "code example" is not actual implementations but use cases in Scheme, sorry.)
@omasanori
Though they have the same name, clojure's transient structures and picrin's that are fundamentally different things. transient-string is rather similar to Java's StringBuffer, normal string to String class. And in the case of your example, that would be the right behavior. string->transient would create a newly allocated buffer to contain byte (or char) sequences.
I'm not so against to changing the name of transient object.
OK, I like it.
Hi guys, the internal representation of picrin's string is now switched to rope! ;) 8586dc9