| Prev | Next | Start of Chapter | End of Chapter | Contents | Glossary | Index | Comments | (4 out of 16)

Evaluating Expressions

G2 evaluates each expression to a single item or to a single value of a specific type. G2 evaluates an expression either successfully or unsuccessfully. When G2 evaluates an expression successfully, the expression produces an item or a value, as specified for that expression.

When G2 cannot evaluate an expression successfully, G2 produces a no value condition. Producing a no value condition also causes G2 to signal an error. G2 displays a no value condition as the reserved symbol none.


Tip: To avoid generating error conditions due to non-existing items or values, you can use G2's existence expressions to test for a no value condition, as described in Existence of an Item or Value, Using the Has a Value Expression for variables, and Referring to Items or Values.

G2 produces a no value condition in these circumstances:

Never Obtaining a Value

If no possibility exists of obtaining a value for an expression, evaluating that expression produces a no value condition. This occurs when:

Not Obtaining a Value at This Time

If an expression refers to a variable whose current value has expired, evaluating that expression produces a no value condition.

G2 can also produce a no value condition after evaluating a conditional expression whose if-clause expression produces the truth-value false, but has no else-clause. Conditional expressions are described in Conditional Evaluation.

Finding a Type Mismatch

When an expression specifies an operator, a mismatch can exist between the operator and the type of any expression term, or among the expression terms. This occurs, for instance, when an expression specifies the + (addition) operator for a numeric value and a symbol value.

When a type mismatch prevents G2 from evaluating an expression, G2 signals an error.

| Prev | Next | Start of Chapter | End of Chapter | Contents | Glossary | Index | Comments | (4 out of 16)

Copyright © 1997 Gensym Corporation, Inc.