Type Commands

The following commands can be used to inspect the contents of any variable or value:

TypeOf value v1.1

Returns a string indicating the underlying type of the value. If the value is an object, this will return the name of the object, eg: ‘Document’. Otherwise returns one of the following: 

Returns

For Value Type

'Undefined'

Only the @undefined value.

'Integer'

Any integer value, or the @true or @false values.

'Float'

Any float (decimal) value.

'String'

Any string that does not define attributes.

'Text'

Any string that defines attributes.

'Array'

Any array value.

'Hash'

Any hash value.

'Data'

The value is an uninterpreted block of bytes.

Defined value v1.1

Returns @true if the value is defined, otherwise @false. All values are defined (even @false) except the special @undefined value, which is returned by some commands to indicate a failure or other special circumstances.

As of v3.0.2 you may also test an undeclared variable:

If ! Defined($goal)

Prompt "We haven't yet defined our goal."

End

$goal = "give fruit"

If Defined($goal)

Prompt "Our goal is to $goal."

End

In prior versions the above code example would show a user-visible error, alerting that the variable was unknown.


Previous Chapter
Expression Limitations
<<  index  >>
 
Next Chapter
Type Casts