coalton
coalton copied to clipboard
draft `StringBuilder` interface to encode mutable string operations
It's Java's StringBuilder
. But in Coalton.
After thinking about #635 , I realized that it would be nice to have a way for the library to implement efficient string-wrangling operations like join
without allocating and copying a bunch of intermediate strings. We could write all those algorithms in lisp
blocks, or we could chicken out and offer mutable operations on String
, but I think I'd rather have a type to encode mutable strings, and pretend String
is immutable.
Open questions:
- What operations do we want to offer on
StringBuilder
? I wrote justpush-char!
andpush-str!
, but it seems sensible at the very least to offercapitalize!
,upcase!
anddowncase!
, since CL makes them super easy for us. There are probably others I'm forgetting, too.- I'd prefer not to offer operations for which
(vector character)
has poor performance as an implementation of strings, like left-trim, push-front or insert-at. The point ofStringBuilder
is to be an efficiency hack, so I think it should only offer operations for which it's actually efficient.
- I'd prefer not to offer operations for which
- Should this be its own package, or a part of
coalton-library/string
? The latter is appealing because it would make it possible to define string operations (likejoin
) in that package in terms ofStringBuilder
, where currently I fear we'd have to have another package downstream of both. Or we could moveStringBuilder
earlier in the library system so that string.lisp depends on it instead of vice-versa.