| Prev | Next | Start of Chapter | End of Chapter | Contents | Glossary | Index | Comments | (6 out of 8)

Working With Specific Types

The G2 specific types are integer, float, symbol, text, and truth-value. Each value that your KB directly manipulates has a specific type. Your KB cannot create user-defined specific types.

For example, when you declare a local name in a procedure with the type integer, an action or procedure statement can assign into that local name only a value that meets the requirements for integer numbers.

Using the Integer Type

A value of type integer represents an integral number. G2 integer values are signed with 30-bit precision. A G2 integer value can range from -229to (229 - 1).


Note: For actions that update the value of an integer value, G2 does not check for integer overflow or underflow because of the performance penalty such checking would impose.

Using the Float Type

A value of type float represents a real number with a floating-point representation. Due to the limitations of the floating-point representation for real numbers, it is possible for a particular float value to represent an approximation of a real number. This only occurs for very large and very small numbers.

Float values in G2 are signed, with a 64-bit, floating-point representation. On most platforms that G2 supports, a float value can range from ±1.79 x 10308 to ±2.22 x 10-308 with approximately 16 digits of precision.


Note: On a VAX/VMS platform, a float value can range from ±8.9 x 10307 to ±5.5 x 10-309.

G2 restores and manipulates float values in conformance with the IEEE's Standard for Binary Floating-Point Arithmetic (ANSI/IEEE Standard 754-1985). For G2 to conform to this standard, the computer on which G2 runs must also support that standard. For example, the VAX/VMS platform does not support floating-point arithmetic as defined in ANSI/IEEE Std. 754-1985.

Working With Exceptional Float Values

Arithmetic operations on float values can result in these exceptional float values:

Exceptional Float Value Display of Value in G2 Causes
Negative infinity
-Inf
Negative overflow; divide a negative value of any numeric type by zero (0 or 0.0)
Positive infinity
+Inf
Positive overflow; divide a positive value of any numeric type by zero (0 or 0.0)
Not a number
NaN
Divide zero (0 or 0.0) by zero

The ANSI/IEEE Standard 754-1985 document specifies how exceptional floating point values participate in arithmetic operations. G2 conforms to this standard on platforms that support it.

For example, in a numeric expression, if an exceptional float value participates in any G2 arithmetic operation in that expression, G2 evaluates that expression as that same exceptional float value. Also, in a truth-value expression, if an exceptional float value participates in a comparison operation in that expression, G2 evaluates that expression as false.


Note: If G2 produces a NaN (not a number) value, the VAX/VMS, OpenVMS, and Alpha OSF platforms signal an error.

Coercing Numeric Values

Some G2 arithmetic and relational operators require G2 to coerce an integer value to a float value. This means that G2 automatically creates a temporary copy of a value in a different type, for use in evaluating an expression.

For example, in an expression that compares an integer value to a float value, G2 automatically coerces the integer value to a float value, then compares the two values.


Tip: For the details about how G2 coerces numeric values when applying arithmetic and relational operators, see Coercion of Values Returned from Arithmetic Operators.

Using Units of Measure for Numeric Values

You can create your own set of symbols to represent units of measure, such as meters, pounds, and liters, that G2 does not provide. You define these symbols in a UNITS-OF-MEASURE-DECLARATION item.

In a numeric value, such as in an attribute that stores a number or in a variable whose value is an integer or float value, you can use the symbols defined in a units of measure declaration. Doing so indicates that the numeric value represents a measurement.

A value's unit of measure symbols only affect how G2 displays that numeric value. When G2 assigns a value that uses a user-defined unit of measure into an attribute, procedure local name, or variable or parameter, that value's unit of measure is also assigned.

To create a unit of measure:

  1. Choose KB Workspace > New Definition > units-of-measure-declaration.

    G2 automatically invokes the Text Editor for you to declare the unit:


  2. Enter the symbol of your choice, with an optional singular version of the term, using this syntax:

For example, this units of measure declaration declares meters and centimeters:


After you declare one or more units of measure, they appear after a numeric expression in the Text Editor prompts for:

Using the Symbol Type

A symbol value contains a series of characters, each of which is a member of the Unicode character set. For more information about the Unicode character set, see Chapter 40, G2 Character Support.

Use symbol values to represent identifiers: names of items, attributes, classes, and types.

All characters in a symbol value are uppercase unless you quote them using the at sign (@) character. When creating a symbol value, the first character can consist of any Unicode character set.

Working With Characters in a Symbol Value

The Unicode character set supports alphabetic and ideographic characters from most of the world's modern and classical languages. For a discussion of Unicode, see Chapter 40, G2 Character Support.

When creating a symbol value, the first character can consist of any Unicode character. All characters in a symbol value are uppercase unless you quote them.


Tip: To quote any character, precede it with the at sign (@) character in the Text Editor.

Symbols can include lowercase characters from supported Unicode languages by quoting the characters. You can quote any Unicode character.

Each of these characters requires quoting to be included in a symbol:

These characters also require quoting:

Enter this character: By:
tab
Pressing the Tab key one or more times. Each time you press the Tab key in the editor, G2 inserts the number of spaces designated in the Number-of-spaces-to-insert-on-a-tab attribute of the Editor Parameters system table.
space character
Pressing the space bar.
line separator
Entering the Unicode character x2028.
paragraph separator
Entering the Unicode character x2029.


Note: For information about entering Unicode characters, see Entering Unicode Character Codes.

If you begin a symbol value with a period (.) or a number (0 - 9), it must also include at least one alphabetic character or quote one of its numeric characters or any of the Unicode character set symbol, punctuation, or special characters. The hyphen (-), underscore (_), period (.) , and apostrophe (') characters are exceptions, which do not require quoting.

Some examples of valid and invalid symbols are:

Valid symbols: Invalid symbols:
@!7
.777
'123
123
-._
!!$
12@3

my-object

@my-object

G2 always ignores the case of all unquoted alphabetic characters. For example, in the next procedure, G2 always executes the inform action, as shown in the message displayed:


When entering special characters in the Text Editor, first quote the character using the at sign (@), and then press Alt + i, followed by the special character you require. In this procedure example, the trademark symbol is available by entering Alt + i t.

Using the Text Type

A text value contains a series of characters, each of which must be a member of the Unicode character set. For more information about the Unicode character set, see Chapter 40, G2 Character Support.

Use text values to contain any sequence of characters, including case-sensitive alphabetic characters. The maximum number of characters in a text value is 65535.

Working With Characters in a Text Value

G2 allows any character from the Unicode character set in a text value. The case of characters is significant. G2 retains, displays, and prints the case of all alphabetic characters.

G2 allows quoted characters in a text value, though quoting is unnecessary for all characters in the Unicode character set, except:

Specifying a literal text value is described in Evaluating Expressions. For a description of the concatenation operation on text values, see Using the Concatenation Operator.

The following procedure DEMONSTRATE-EQUAL-TEXTS demonstrates these facts about text values:

Formatting Text Values

You can include a newline character in a literal text value to format lengthy text. The way to include a newline character depends on whether you are editing the text in a non-scrolling editor, such as for messages and other free text items, or a scrolling editor, such as for procedures and methods.

To enter a newline character in a text value in a non-scrolling editor:

This example illustrates the use of Control + j newline sequences in a free-text item:



Note: Any newline characters that you enter to format text values are stored as Unicode line separator characters. Such newline characters do not, therefore, translate into ASCII newline character values when exporting text from G2.

To enter a newline character in a text value within a scrolling editor:

Using the Truth-Value Type

A value of type truth-value represents a degree of certainty in the truth of a condition, comparison, or assertion. Your KB can use values of type truth-value to implement a reasoning strategy based on the principles of either boolean logic or fuzzy logic.

A value of type truth-value ranges from -1.0 true (completely false) to +1.0 true (completely true).


Tip: G2 displays a truth-value of -1.0 true simply as false, and displays a truth-value of +1.0 true simply as true. In this case the displayed values true and false represent truth-values, not symbols.

In a truth-value expression that includes a relational operator, by specifying a fuzzy truth band subexpression, you can produce a fuzzy truth value, whose decimal value is greater than -1.0 true and less than +1.0 true.

For example, the following conclude action assigns a value into a truth-value attribute of an item of a user-defined class, based on the result of evaluating the expression (the volume-in-liters of tank-1 > 100) ( +- 25 ) :

In this example, the subexpression ( +- 25 ) signifies a fuzzy truth band. The degree to which the Volume-in-liters of tank-1 is greater than, equal to, or less than the value 100, determines the fuzzy truth value that G2 assigns to the Truth-value-attribute of my-object.


Tip: For the details about specifying fuzzy truth band expressions, see Producing Fuzzy Truth Values From Relational Operations.

| Prev | Next | Start of Chapter | End of Chapter | Contents | Glossary | Index | Comments | (6 out of 8)

Copyright © 1997 Gensym Corporation, Inc.