A string is an object that represent a sequence of characters (for now, only ASCII is supported in klisp, in the future, full UNICODE will be supported). The external representation of strings consists of a leading “"”, the characters of the string and a closing “"”. Both double quote and backslash should be escaped to appear withing strings. Some other characters also have an escaped form for convenience. All of these are written with a leading slash (“\”). In klisp these are: double quote (“\"”), backslash (“\\”), null (“\0”), alarm (“\a”), backspace (“\b”), tab (“\t”), newline (“\n”), return (“\r”), vertical tab (“\v”), and formfeed (“\f”). You can also use inline hex escapes to include arbitary unicode codepoints (only ASCII range supported for now). The syntax is “\x<hex codepoint>;”. New lines can be escaped to simplify the accomodation of literal strings in source code, to do this: use “\” followed by any ammount of intraline whitespace, a new line and another ammount of intraline whitespace. All of that intraline whitespace and the newline, together with the leading slash is discarded by the reader and doesn't end up in the string being read.
A string has a length that is fixed at creation time, and as many
characters, indexed from
Strings may be mutable or immutable. If an attempt is made to
mutate an immutable string, an error is signaled. Two immutable
strings are “eq?” iff they are “equal?”. Two mutable strings are
“eq?” if they were created by the same constructor call. Two
mutable strings are “equal?” iff they are “string=?”. For now it
is undefined if a mutable and an immutable strings that are
“string=?” are “equal?” or not. The only exception is the empty
string. There is only one empty string (all empty strings are “eq?”
to each other) and it should be considered immutable. Even if an
attempt is made to return a new empty string (like calling
(string), the canonical immutable empty string is returned.
The string type is encapsulated.
SOURCE NOTE: This section is still missing from the report. The features defined here were taken mostly from r7rs scheme. It is possible that in the future, klisp only admits immutable strings (like lua and java), and that operations for contructing strings are moved to a new type (like Java's StringBuilder/StringBuffer). But for now, compatibility with r7rs was preferred/simpler.
The primitive type predicate for type string.
string?returns true iff all the objects in
objectsare of type string.
The primitive type predicates for types immutable string and mutable string. These return true iff all the objects in
objectsare of type immutable string or mutable string respectively.
SOURCE NOTE: these aren't provided in the Kernel report, but added for convenience. These can be implemented in standard kernel by using guards.
These predicates compare any number of strings by their lexicographic order.
These predicates convert the strings to lowercase and then compare them using their lexicographic order.
make-stringconstructs and returns a new mutable string of length
charis specified, then all characters in the returned string are
char, otherwise the content of the string is unspecified.
stringcontructs and return a new mutable string composed of the character arguments.
string-lengthreturns the length of
string-refreturns the character of
kis out of bounds (i.e. less than
0or greater or equal than
(string-length string)) an error is signaled.
string-set!replaces the character with index
kis out of bounds, or
stringis immutable, an error is signaled.
string-fill!replaces all the characters in
stringis an immutable string, an error is signaled.
k2-1should be valid indexes in
string. Also it should be the case that
k1 <= k2.
substringconstructs and returns a new mutable string with length
k2 - k1, with the characters from
string, starting at index
k1(inclusive) and ending at index
string-appendconstructs and returns a new mutable string consisting of the concatenation of all its arguments.
string-copyconstructs and returns a new mutable string with the same length and characters as
string->immutable-stringconstructs and returns a new immutable string with the same length and characters as
These applicatives convert between strings and list of characters, vectors of characters, and bytevectors of characters. The objects returned by these applicatives are always mutable.
These applicatives perform the respective case folding on the passed
stringand return a new mutable strings as a result. The original
stringis not modified. For now in klisp only ASCII is implemented, and so
string-foldcaseis the same as