String
|
Analytic Information Server has three containers for storing ASCII characters: String, Text, and Character. When Lambda server receives an ASCII character sequence, it determines which container to save them based on the number of characters. If the character constant 7 characters or less, the constant is stored in an immediate field in a Text data type (there are certain restrictions on text items). If the character constant exceeds 7 characters, then the constant is stored in a String object. A Character container is obtained by specifically asking for one using the char function, or by indexing a character element from within a Text or String. In a String object, the characters that make up the constant are stored in the Heap and a pointer to the String constant is saved in the String object. String objects are managed by the Heap manager.
Lisp supports String constants. A String is any series of Lisp characters or symbols: (A) enclosed in double quote symbol paris (" "); (B) enclosed in left-right brace paris ({ }); or (C) enclosed in these special sequence paris ({##[ ]##}); For Example:
"This is a string \" constant" | "This is a string constant" |
{This is a string "A" constant} | {This is a string constant} |
{##[This is a string "A" constant]##} | {##[This is a string {A} constant]##} |
The initial type of a sequence of characters is determined by its size:
(setq greetings "HELLO")
(type greetings) Returns Text
(setq salutation "HELLO THERE")
(type salutation) Returns String
When a character constant is modified (expanded or contracted), Analytic Information Server handles the transition from Text to String dynamically as needed.
(setq greetings "HELLO")
(type greetings) Returns Text
(setq greetings (append greetings " WORLD"))
(writeln greetings) Prints: "HELLO WORLD"
(type greetings) Returns String
Handling of Immediate Text versus Heap or Object Data
Most of the time, the transition from Text to String or String to Text is transparent, however, the user must be aware of the radical difference between the handling of immediate data and Heap data. There are special "gotchas" that occur because of the differences in handling of Text and String types.
There is a notion of destructive and non-destructive functions. A certain class of functions performs an operation on the data itself and another group of functions performs the operation on the data, which is loaded on the stack. The append function is an example of a non-destructive function:
(setq greetings "HELLO") |
|
(setq greetings (new String: "HELLO") ) |
|
(type greetings) |
Text |
(type greetings) |
String |
(append greetings " WORLD") |
|
(append greetings " WORLD") |
|
(writeln greetings) |
"HELLO" |
|
"HELLO" |
The downcase function is an example of a destructive function:
(setq greetings "HELLO") |
|
(setq greetings (new String: "HELLO") ) |
|
(type greetings) |
Text |
(type greetings) |
String |
(downcase greetings) |
|
(downcase greetings) |
|
(writeln greetings) |
"HELLO" |
|
"hello" |
Note that for a String object, the downcase function converts the contents to lowercase and replaces the old contents with the lowercase version. The Text data type is not "destroyed" because a reference to a Text item is just like a reference to other immediate native types (Void, Boolean, Number) causes the immediate value to be loaded on the stack and any modification remains on the stack unless explicitly saved. For example:
(setq aNum 1)
(add1 aNum) ;Performs the operation on the Stack
(writeln aNum) ;Prints 1
(setq aNum (add1 aNum)) ;Performs the operation on the Stack
(writeln aNum) ;Prints 2
The String data type is used for is hold text characters of arbitrary length. Functions exist to manipulate whole Strings, as well as substrings.
The String data type is a Heap object. It is a dynamic object that will automatically grow or contract to accommodate a resize, append, or any operation that involves a size change. The maximum String object size is restricted only by the amount of available memory.
The notation #<String 1234> indicates an object Id for a String object. The numeric Id is will be a 4-digit number assigned by Analytic Information Server, and will be consistent for the life of the string object. An object Id is a reference to the location in the Heap that the actual data is placed
Analytic Information Server supports three forms for string constants: Double Quotes, Braces, and Quoted Left Brace.
Double Quotes: The double quote character ( " ) is used as a way of indicating string constants. Analytic Information Server string constants are case-sensitive, may include blanks, special characters, but not imbedded double quote characters.
"John Doe"
"This is a test string."
The backslash character ( \ ) is used as a way of accepting any character as alphabetic within a string constant and in other special situations.
"There is an imbedded double quote \" in this example."
Braces: The brace character ( { ) is used as a way of indicating string constants. The string constant ends with a matching closing brace character ( } ). Such Analytic Information Server string constants are case-sensitive, may include blanks, special characters, imbedded double quote characters, may include imbedded brace characters, and terminate with the first matching left brace character.
{John Doe}
{This phrase, " is a test ", is a string which often {but not always} is used to start a test.}
Quoted Left Brace: The quote character ( ' ) followed immediately by the left brace character ( { ) is used as a way of indicating trailing string constants. The string constant ends with the end of the input source. Such Analytic Information Server string constants are do not examine the content of the string constant. The trailing string constant begins with the '{ special character pair, and terminates with the end of the input source.
setq _x '{Form here to the end of the input source is a string constant.
Note: This form is used by Visual Basic or C++ to send long text commands (with arbitrary contents) to Analytic Information Server.
The String Data Type is an example of an AIS Object Data Type.
The Analytic Information Server Object Types are stored in the Heap and are managed by the Heap manager. The Analytic Information Server Heap manager supports object resizing, garbage collection, and anti-fragmentation algorithms so that the user may concentrate on the analysis and modeling of data rather than on memory management. Without exception, all of the Object types are identified by an object id. The object id identifies a block of memory, managed by the Analytic Information Server memory manager, in which the Object's data is stored.
The Analytic Information Server Heap Object and Native Data types can be saved and loaded to and from persistent (disk file) storage at any time. Words with immediate data are saved on disk in fixed length records equal to the size of the Word. Words with Heap object references are saved in fixed length records, which are automatically expanded to include the contents of the Heap object, and any objects referenced by the Heap object, etc. This feature is called Object Closure Management and is automatic with every Analytic Information Server database save.
Analytic Information Server Words may be loaded from any database repository record at any time. If the data in the record is immediate, the database load fills the Word with the immediate data. If the data in the record is an object closure, the database load fills the Word with a Heap object reference, and all of the objects in the record are loaded back into the Heap with the same referential relationships they had when they were saved in the repository.
The String object can be demonstrated by the following examples.