Tutorial: Use Statements

How to load and interact with library classes.

Format and Finding Libraries

In many fields, it is impossible to understand the nuances of every aspect of a discipline. Mathematicians can be experts, but not know how every equation works. Carpenters can be master builders, but not know how to build everything. Computer scientists, similarly, may be excellent programmers, but that does not mean they know everything. As such, programmers make use of what are called libraries. Libraries are code, typically written by other people, that solve a particular kind of problem for us.

An example of a library might be for math. We may not know, and it is understandable why, how to solve all possible math equations. Solving some of them might require a doctorate to even understand the question. Further, once one person solves the problem, if it can be written into a library, no one else must. Thus, we use libraries to save ourselves time and if we did not, programming would be incredibly tedious. Programming languages vary in how we access libraries. In Quorum, the word ‘use’ tells the system to go find a library. The names of the libraries look similar to web addresses. Here is an example:

use Libraries.Compute.Random

One important thing to remember about the use statement is that it must be placed at the top of file. A class definition and action must always come after the list of use statements. In order to find a library in the Quorum standard library we can use code completion if we are offline If we are using Windows or OSX the shortcut is CTRL + SPACE, to find any available library classes. In addition to code completion there is a Quorum Standard Library Reference available.

Random Number Example

A complete solution to the above problem is as follows:

use Libraries.Compute.Random
class Main
     action Main
          Random random
          output random:RandomIntegerBetween(1, 100)
     end
end

The .all Command

Sometimes we may want to use all of the classes under a given file. For example, suppose we wanted to include all of the classes in "Libraries.Compute", this includes the Random class and other Math related class. We can add all to the end of the use statement to include all of the classes within a file:

use Libraries.Compute.all
class Main
     action Main
          Random random
          Math math
          output random:RandomIntegerBetween(1, 100)
          output math:SquareRoot(6)
     end
end

Next Tutorial

In the next tutorial, we will discuss inheritance, which describes how to use the inheritance and polymorphism.