Data Types

FISH variables can be of many types. These include:

  1. Integer: Exact numbers in the range -2,147,483,648 to +2,147,483,647.
  2. Boolean: Either a value of true or false.
  3. Floating-point: Approximate numbers with about fourteen decimal digits of precision, with a range of approximately 10-308 to 10308.
  4. String: Packed sequence of any printable characters; the sequence may be any length, but it may be truncated when printed. Strings are denoted in FISH and PFC 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” section for further details.
  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” section for further details.
  6. Vector: 2D or 3D vector of floating-point types. See the “Vectors” section for further details.
  7. Array: A collection of FISH variables with specified dimensionality. See the “Arrays” section for further details.
  8. Matrix: Matrix of numeric values with specified dimensionality. See the “Matrices” section for further details.
  9. Tensor: A symmetric tensor. See the “Tensors” section for further details.
  10. Map: An associative array with string or number key and any FISH variable as value. See the “Maps” section for further details.
  11. Structure: A structure may contain multiple FISH variables. See the “Structures” section for further details.

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; 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 symbols 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 the type of the object on the right-hand side of an assignment statement; this applies both to FISH statements and to assignments made with the fish set command. Both types of assignment may be used to change the type of a variable according to the value specified, as follows:

1. An integer assignment (digits 0-9 only) will cause the variable to become an integer (e.g., 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 (e.g., 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 (e.g., var1 = 'Have a nice day').

The following sections detail specifics of the data types introduced above: