5.2.3 isInstance

Introduction

The isInstance goal is used to check whether a referent is an instance of a given type.

Signature

isInstance(I,T)

Operation

This goal checks whether I is an instance of the type T.

I must be either an identifier or a string.

Example

// Type hierarchy
Entity > Philosopher.

// Catalog of instances
Philosopher = Peirce, Whitehead, Heraclitus.

// Rule
is_philosopher(I) :- isInstance(I, Philosopher).

Explanation

First, we have the usual type-hierarchy and catalog of instances.

The type hierarchy is very simple, it only has two types, with Philosopher being the only subtype of Entity.

Then the catalog of instances specifies three instances of Philosopher, namely Peirce, Whitehead, and Heraclitus.

Then, we have a rule called "is_philosopher". It takes the formal parameter I, which the body of the rule then passes to isInstance. The isInstance goal checks whether I is an instance of the type Philosopher.

Usage

If we ask the following query:

?- is_philosopher(Peirce).

we get the following answer:

{}

This means yes. This is because in the catalog of instances, Peirce is an instance of the type Philosopher.

If we ask the following query:

?- is_philosopher(Petersen).

we get the following answer:

 no.

This is because Petersen is not an instance of Philosopher in the catalog of instances.

Summary

Thus the isInstance goal is used to check whether an identifier or a string is an instance of a given type.


PrevLite: 5.2.2 isSuperType
NextLite: 5.2.4 superTypes

Prev: 5.2.2 isSuperType
Up: 5.2 Type goals
Next: 5.2.4 superTypes