Tutorial: Advanced use of Primitive Types

Advanced Topics with Primitive Types.

Calling Actions on Primitives

Primitive types in Quorum, like integers, often have certain kinds of limitations in programming. In Quorum, while these types are sent to memory and the processor as usual in most cases, they can be used in code very similarly to how objects and classes are. Namely, we can call actions on primitive types. Let’s start with an example using integers:

integer zero = 0
integer max = zero:GetMaximumValue()
integer min = zero:GetMinimumValue()

output zero
output max
output min

In the first line, we create a regular primitive integer, which takes up 4 bytes of memory. The way this is stored in what is called two’s complement. We can read more about that here:

Wikipedia page on Two's complement

While in some programming languages, storing our integer in this way prohibits us from using the primitive to call actions, in Quorum this is not the case. Behind the scenes, Quorum uses a trick to allow actions to be called efficiently. Many actions are available that might help us, including all of them, with the exception of the actions labeled GetValue in each class, listed in the Boolean, Integer, Number, or Text documentation. That documentation and the list of actions supported can be found in the following pages:

Autoboxing

When we use containers, how primitives are handled is slightly different. Take Lists, for example. Just like in the generics tutorial, we might have code like the following:

use Libraries.Containers.List
List<integer> list
list:Add(1)
list:Add(2)
list:Add(3)
integer a = list:RemoveFromFront()
integer b = list:RemoveFromFront()
integer c = list:RemoveFromFront()
output a
output b
output c

Let us discuss what this code is doing in more detail. Notably, when the first Add action is called, Quorum takes the 1 and, behind the scenes, converts it into an Integer object, not an integer primitive. This takes up more space in memory, technically, but this issue generally only matters if the number of integers we are storing is large. The same process is used for the integers 2 and 3. When the item is later removed from the list using the RemoveFromFront action, the primitive is converted back from an object into a primitive.

Next Tutorial

In the next tutorial, we will discuss Assignment 5.1, which describes an introduction to validating input and using multiple files..