Type

Type allows inspecting, verifying and comparing data types.

Get data type#

MethodDescription
type(value)Returns the numeric identifier of the type
type.name(value)Returns the name of the type as a string
# Numeric identifiers
print type(42)
print type("hello")
print type(true)

# Type name
print type.name(42)      # "int"
print type.name("hello")  # "string"
print type.name(true)    # "bool"

Type identifiers#

ConstantDescription
type.intInteger type identifier
type.floatDecimal type identifier
type.strString type identifier
type.boolBoolean type identifier
type.arrayArray type identifier
type.objectObject type identifier
type.functionFunction type identifier
type.noneNull type identifier
type.bigintLarge integer type identifier
value = 42
type_id = type(value)

if type_id == type.int
    print "It is an integer"
elif type_id == type.str
    print "It is a string"
else
    print "Other type"
Using strings

You can also use strings to compare types. Although it may seem less efficient, the reality is that DinoCode only returns already defined constants (same performance as comparing numbers).

value = 42
type_name = type.name(value)

if type_name == "int"
    print "It is an integer"
elif type_name == "str"
    print "It is a string"
else
    print "Other type"

Type verification#

MethodDescription
type.is_primitive(value)Verifies if the value is a primitive type

Primitive types#

Primitive types include: int, float, bool, string, bigint, and none.

number = 42
list = [1 2 3]

if type.is_primitive(number)
    print "It is a primitive type"

if not type.is_primitive(list)
    print "It is not a primitive type"

Instance verification#

MethodDescription
type.instance_of(instance, class)Verifies if an object is an instance of a class

Check instance#

::Animal Object
    :new name
        self.name = name

    :make_sound
        print "GRRRRR..."

::Cat Animal
    :make_sound
        print "Meow! Meow!"

pet = Cat("Kala")
if type.instance_of(pet Cat)
    print "It is a cat"
if type.instance_of(pet Animal)
    print "It is an animal"
if type.instance_of(pet Object)
    print "It is an object"
Inheritance

instance_of follows the prototype chain, so an object of a derived class is also an instance of its base classes.