6.2 Strings
6.2.1 String Creation and Copying
The following are built-in string creation and copying functions:
(allocate-string SIZE:integer): string expr
Constructs and returns a string with SIZE characters. The contents of the
string are not initialized.
(make-string SIZE:integer INITVAL:integer): string expr
Constructs and returns a string with SIZE characters, each initialized to the
ASCII code INITVAL.
(mkstring UPLIM:integer INITVAL:integer): string expr
An old form of make-string. Returns a string of characters all initialized to
INITVAL, with upper bound UPLIM. The returned string contains a total of
(add1 UPLIM) characters.
(string [ARGS:integer]): string nexpr
Create string of elements from a list of ARGS.
1 lisp> (string 65 66 67)
"ABC"
(copystringtofrom NEW:string OLD:string): NEW:string expr
Copy all characters from old into new. This function is destructive.
(copystring S:string): string expr
Copy to new string, allocating space.
6.2.2 About the Basic String Operations
The representation of strings is very similar to that of vectors. Due to this similarity, there are
functions which may be applied to either data type. Such functions provide primitive operations
on strings. PSL provides many other functions specific to strings which are defined in various
library modules.
6.2.3 The Operations
This section documents functions in the library module slow-strings (s-strings). There is
another library module called fast-strings (f-strings). The fast-strings module provides alternate
definitions for these functions. When the switch fast-strings is non-nil the compiler will use
these alternate definitions to produce efficient code. However, there will not be any verification
that arguments are of correct type (in addition, it is assumed that numeric arguments are
within a proper range). If invalid arguments are used, then at best your code will not
generate correct results, you may actually damage the PSL system. There are two side
effects to loading fast-strings The slow-strings module will be loaded and the switch
fast-strings will be set to t. For more information on the switch fast-strings see Chapter
19.
(string-fetch S:string I:integer): any expr
Accesses an element of a PSL string. Indexes are zero based. The ASCII
character stored in that position of the string is returned.
Characters are represented by inums. You should not rely on this when you write code. Such
code cannot be easily transported to other systems where either the encoding is different or
where characters are a seperate data type.
(string-store S:string I:integer X:char): None Returned expr
Stores into a PSL string. String indexes start with 0.
(string-length S:string): integer expr
Returns the number of elements in a PSL string. Since indexes start with
index 0, the size is one larger than the greatest legal index. Compare this
function with string-upper-bound, documented below.
(string-upper-bound S:string): integer expr
Returns the greatest legal index for accessing or storing into a PSL string.
Compare this function with string-length, documented above.
(string-empty? S:string): boolean expr
True if the string has no elements (its size is 0), otherwise nil.