The IntrinsicClass Intrinsic Class

Each intrinsic class that a program uses is represented by an instance of the intrinsic class IntrinsicClass.  If you didn't major in college in computer science, don't worry if contemplating the circularity of this notion induces a slight spinning sensation; the IntrinsicClass intrinsic class has only a couple of practical applications, which are pretty straightforward.

 

Each time you use the "intrinsic class" statement to define an intrinsic class, the compiler implicitly creates an instance of IntrinsicClass to represent the intrinsic class.  The compiler gives the instance the same name as the class.  For example, consider the following statement:

 

  intrinsic class BigNumber 'bignumber' { }

 

This defines an intrinsic class called BigNumber.  It also creates an object of intrinsic class IntrinsicClass, and calls the object BigNumber.

Using IntrinsicClass Instances

The purpose of an IntrinsicClass instance is to identify the class of an instance of the associated intrinsic class.  This is useful in two situations:

 

The ofKind() method

The ofKind() method returns true if the second argument is the IntrinsicClass object representing the intrinsic class of the first argument.  For example:

 

  local x = new BigNumber('100');
  
  tadsSay(x.ofKind(BigNumber) ? 'yes' : 'no'); "; ";
  tadsSay(x.ofKind(Dictionary) ? 'yes' : 'no'); "\n";

 

This will display "yes; no", because the object is an instance of the BigNumber intrinsic class, and is not an instance of the Dictionary intrinsic class.

The getSuperclassList function

The getSuperclassList() method returns a list of the immediate superclasses of a given object.  If the object is an instance of an intrinsic class, the list will have one element, which is the IntrinsicClass object representing the intrinsic class.  For example:

 

  x = new BigNumber('100');
  y = x.getSuperclassList();

 

The value of y will be [BigNumber].

 

Most intrinsic classes derive from an "abstract" intrinsic class called Object, so BigNumber.getSuperclassList() will return [Object].  Object has no superclass, so Object.getSuperclassList() will return an empty list.