# Data Types

FISH variables can be of many types. These include:

1. Integer: exact numbers in the range -9,223,372,036,854,775,807 to +9,223,372,036,854,775,807
2. Floating-point: approximate numbers with about fourteen decimal digits of precision, with a range of approximately $$10^{-308}$$ to $$10^{308}$$
3. Boolean: either a value of true or false.
4. String: a sequence of any printable characters; the sequence may be any length, but it may be truncated when printed. Strings are denoted in FISH and FLAC3D by a sequence of characters enclosed by single or double quotes (e.g., 'Have a nice day' or "Have a nice day"). See the Strings topic for further details. Iterable.
5. Pointer: machine address used when looping through a list and marking references to an object. They have an associated type from the object to which the pointer refers, except for the null pointer. See the Pointers topic for further details. In general when the value of a pointer is listed you get the type name and the ID number of the object being pointed to. Pointers to containers are iterable.
6. Vector: 2D or 3D vector of floating-point types. See the Vectors topic for further details. Iterable.
7. Tensor: a symmetric tensor. See the Tensors topic for further details. Iterable.
8. Matrix: A two dimensional matrix of numeric values. See the Matrices topic for further details. Iterable.
9. List: A linear container of general FISH values. See the Lists topic for further details. Iterable.
10. Map: an associative array made of key-value pairs. See the Maps topic for further details. Iterable.
11. Structure: a structure may be defined by the user and contains multiple named FISH variables. See the Structures topic for further details.
12. Array: a collection of FISH variables with specified dimensionality. Arrays differ from lists in two respects: They can be of more than one dimension, and they are passed by reference rather than value. See the Arrays topic for further details. Iterable.

A variable in FISH can change its type dynamically, depending on the type of the expression to which it is set. To make this clear, consider the assignment statement:

var1 = var2


If var1 and var2 are of different types, then two things are done: first, var1’s type is converted to var2’s type; second, var2’s data are transferred to var1. In other languages, such as FORTRAN or C, the type of var1 is not changed, although data conversion is done. By default, all variables in FISH start as integers with the value 0; however, a statement such as:

var1 = 3.4


causes var1 to become a floating-point variable when it is executed. The current types of all variables may be determined with the fish list command.

The dynamic typing mechanism in FISH was devised to make programming easier for non-programmers. In languages such as BASIC, numbers are stored in floating-point format, which can cause difficulties when integers are needed for loop counters, for example. In FISH, the type of the variable adjusts naturally to the context in which it is used. For example, in the code fragment:

n  = n + 2
xx = xx + 3.5


the variable n will be an integer and will be incremented by exactly 2, and the variable xx will be a floating-point number, subject to the usual truncation error but capable of handling a much larger dynamic range. The rules governing type conversion in arithmetic operations are explained in Arithmetic: Expressions and Type Conversions. The type of a variable is determined by type precedent rules govering the operators used, in general types are promoted to the most flexible required.

On an explicit assignment to a constant value the following rules are applied:

1. An integer assignment (digits 0-9 only) will cause the variable to become an integer:

var1 = 334

2. If the assigned number has a decimal point or an exponent denoted by “e” or “E,” then the variable will become a floating-point number:

var1 = 3e5
var2 = -1.2

3. If the assignment is delimited by single or double quotes, the variable becomes a string, with the “value” taken to be the list of characters inside the quotes:

var1 = 'Have a nice day'

4. If the assignment is delimited by parentheses and contains one or two internal commas, then the variable will become a 2D or 3D vector:

var3 = (0.3,1,2)
var2 = (0.1,0.2)