String

 

String Overview

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.

The Dynamic Nature of Strings

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), Lambda 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

When to Use

The String data type is used for is hold text characters of arbitrary length. Functions exist to manipulate whole Strings, as well as substrings.

Visual Basic Comparison

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

 

Constant Form

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.

Object or Heap Data Type

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.

 

Data Type Functions

The String object can be demonstrated by the following functions.

addMethod append char clean
code compareEQ compareGE compareGT
compareLE compareLT compareNE compare
comparison debugDialog defmethod downcase
fileReadRecord fileResize fileSeek fileWrite
filewriteln find getHttp hashString
isCharAlphabetic isCharAlphanumeric isCharLowercase isCharName
isCharNumeric isCharUppercase isCharWhitespace isChar
isEqual isObject isString isText
isType left length loadLib
macroReplace methodsOf mid new
openLog parse postHttp readHtmlPage
ref replace rept requestHttp
right send setq sizeof
stringCiEQ stringCiGE stringCiGT stringCiLE
stringCiLT stringCiNE stringFill stringToBVector
stringToVector string substitute substringCiEQ
substringCiGE substringCiGT substringCiLE substringCiLT
substringCiNE substringEQ substringFill substringGE
substringGT substringLE substringLT substringNE
substring text trim type
upcase writeln

 

Data Type Examples

The String object can be demonstrated by the following examples.

Example_String_addMethod_001 Example_String_append_001 Example_String_append_002 Example_String_char_001
Example_String_clean_001 Example_String_code_001 Example_String_compareEQ_001 Example_String_compareGE_001
Example_String_compareGT_001 Example_String_compareLE_001 Example_String_compareLT_001 Example_String_compareNE_001
Example_String_compare_001 Example_String_comparison_001 Example_String_defMethod_001 Example_String_defmethod_002
Example_String_downcase_001 Example_String_fileReadRecord_001 Example_String_fileRead_001 Example_String_fileRead_002
Example_String_fileWrite_001 Example_String_find_001 Example_String_find_002 Example_String_hashString_001
Example_String_isCharAlphabetic_001 Example_String_isCharAlphanumeric_001 Example_String_isCharLowercase_001 Example_String_isCharName_001
Example_String_isCharNumeric_001 Example_String_isCharUppercase_001 Example_String_isCharWhitespace_001 Example_String_isChar_001
Example_String_isEqual_001 Example_String_isEqual_002 Example_String_isObject_001 Example_String_isString_001
Example_String_isText_001 Example_String_isType_001 Example_String_isType_002 Example_String_isType_003
Example_String_left_001 Example_String_length_001 Example_String_length_002 Example_String_methodsOf_001
Example_String_methodsOf_002 Example_String_methodsOf_003 Example_String_mid_001 Example_String_new_001
Example_String_parse_001 Example_String_ref_001 Example_String_ref_002 Example_String_replace_001
Example_String_rept_001 Example_String_right_001 Example_String_send_001 Example_String_setq_001
Example_String_sizeof_001 Example_String_stringCiEQ_001 Example_String_stringCiGE_001 Example_String_stringCiGT_001
Example_String_stringCiLE_001 Example_String_stringCiLT_001 Example_String_stringCiNE_001 Example_String_stringFill_001
Example_String_stringToBVector_001 Example_String_stringToBVector_002 Example_String_stringToBVector_003 Example_String_stringToVector_001
Example_String_stringToVector_002 Example_String_stringToVector_003 Example_String_stringToVector_004 Example_String_string_001
Example_String_string_002 Example_String_string_003 Example_String_substitute_001 Example_String_substitute_002
Example_String_substringCiEQ_001 Example_String_substringCiGE_001 Example_String_substringCiGT_001 Example_String_substringCiLE_001
Example_String_substringCiLT_001 Example_String_substringCiNE_001 Example_String_substringEQ_001 Example_String_substringFill_001
Example_String_substringGE_001 Example_String_substringGT_001 Example_String_substringLE_001 Example_String_substringLT_001
Example_String_substringNE_001 Example_String_substring_001 Example_String_substring_002 Example_String_text_001
Example_String_trim_001 Example_String_type_001 Example_String_upcase_001 Example_String_upcase_002
Example_String_upcase_003