2.3 Language Elements
In every programming language we have two important concepts: data and procedures. Data comprise the entities that we wish to manipulate. Procedures describe how to manipulate those entities.
In mathematics, we can look at numbers as the data and at algebraic operations as the procedures. These operations allow us to combine numbers. For example, \(2\times 2\) is a combination. Another combination involving more data is \(2\times 2\times 2\), and using even more data \(2\times 2\times 2\times 2\). However, unless we want to spend time solving problems of elementary arithmetic, we should consider more elaborate operations that represent combination patterns. In the previous sequence of combinations, it is clear that the pattern emerging is the concept of exponentiation, which has been defined in mathematics a long time ago. Exponentiation is therefore an abstraction of a succession of multiplications.
As in mathematics, a programming language should contain data and procedures, should be capable of combining data and procedures to create more complex data and procedures, and should be able to abstract patterns, allowing the definition of new operations that represent those patterns.
Further ahead we will see how to define these abstractions in Julia. For now, let us take a closer look at the primitive elements of the language, i.e., the simplest entities that the language deals with.
2.3.1 Numbers
Numbers are one of the most primitive elements of Julia. Julia provides integers, fractions, reals, and other kinds of numbers. The syntax of the language includes different ways for the user to write those different kinds of numbers. Regarding semantics, numbers are very simple to evaluate: the value of a number is the number itself. This is visible in the following interaction:
> 1
1
> 12345
12345
> 4.5
4.5
In Julia, numbers can be exact or inexact. Exact numbers include integers, fractions and complex numbers with integer parts. Inexact numbers are all others, typically written in decimal or scientific notation, such as \(123.45\) or \(1.2345e2\).