Immutable string type
NOTE: See issue #41 for general direction and rationale.
Create a new record type implementing immutable strings.
The type will be immutable, but simply wraps a host string (which may be mutable). We can enforce immutability because there will be no way for users to directly access the host string (the slot accessor functions will not be exported), and no Cloje functions will mutate the host string.
NOTE: Host strings are implicitly converted to Cloje strings when passed to any standard Cloje function that operates on Cloje strings.
Record type
-
cloje-string record type -
Record printer ( print like a usual string, e.g.print like"foo"
#<cloje-string "foo">
to avoid confusion) -
cloje-string?
Interop functions
-
cloje-string->host-string
(returns a copy of the wrapped host string) -
host-string->cloje-string
(wraps a copy of the given host string) -
host-string?
Make sure there are tests (for both directions) proving that mutating the host string does not affect the corresponding Cloje string.
Update existing functions
Functions that operate on strings should be updated to accept both Cloje strings and host strings (implicitly converting to Cloje strings). Functions that produce a string should be updated to produce a Cloje string (even if it is the result of operating on a host string).
-
string?
(true for either Cloje strings or host strings, because host strings are implicitly converted) -
=
(true for strings with same content, regardless of type) -
hash
(same value for strings with same content, regardless of type) -
count
-
seq
-
get
-
str
-
subs
-
with-in-str
-
with-out-str
-
print
-
pr
-
string/blank?
-
string/capitalize
-
string/lower-case
-
string/upper-case
-
string/index-of
-
string/last-index-of
-
string/join
-
string/reverse
-
string/starts-with?
-
string/ends-with?
-
string/trim
-
string/triml
-
string/trimr
-
string/trim-newline
-
string/replace
-
string/replace-first
-
string/re-quote-replacement
-
cloje-version
-
symbol
-
keyword
(Other functions that work with strings are currently based on the above functions.)
Update string seqs
Update the string seq type to be based on the new string type, i.e. a string seq will hold a Cloje string instead of a host string.
-
seq
-
first
-
rest
-
count
Update regexps
Regexp functions and regexp matchers should be updated to work with Cloje strings. Matchers should store the input as a Cloje string (to avoid accidental mutation).
-
re-pattern
-
re-matcher
-
re-find
-
re-groups
-
re-matches
-
re-seq
Update tests
Go through the unit tests and update any tests that weren't updated yet (e.g. functions that are based on the functions updated above).
Don't forget:
- generic collection/sequence operations
- set operations
- other operations that work with a sequence
-
boolean
/host-boolean
list*
-
def
anddefn
docstrings (so that the tests might usefully fail when docstrings are added in the future) -
*cloje-version*
should store the qualifier as a Cloje string