Sequences and Strings

The objects contained in a sequence can be an arbitrary mix of atoms or sequences. A sequence is represented by a list of objects in curly braces, separated by commas. Here are some examples:
    {2, 3, 5, 7, 11, 13, 17, 19}
    {1, 2, {3, 3, 3}, 4, {5, {6}}}
    {{"John", "Smith"}, 52389, 97.25}
    {}                        -- the 0-element sequence
Sequences can be nested to any depth, i.e. you can have sequences within sequences within sequences and so on to any depth (until you run out of memory). Curly braces are used to construct sequences out of a list of expressions. These expressions can be constant or evaluated at run-time. e.g.
    {x+6, 9, y*w+2, sin(0.5)}
The term atom was chosen as a distinctive term that emphasizes their indivisible nature. Of course in the world of physics, atoms were split into smaller parts many years ago, but in phix you cannot split them. They are the basic building blocks of all the data that a phix program can manipulate.

With this analogy, sequences might be thought of as "molecules", made from atoms and other molecules. Another analogy might be that sequences are like directories, and atoms are like files. Just as a directory on your computer can contain both files and other directories, a sequence can contain both atoms and other sequences (and those sequences can contain atoms and sequences and so on). And in the same way that you can add and remove files from a directory at will, there is no need to specify the fixed size or content of a sequence.

On a practical note, as long as you have at least 2GB of physical memory, you should experience no problems whatsoever constructing a sequence with 100 million elements, and you could more than triple that by allocating things up front. However it would rarely be considered good programming style to wilfully hog memory if there is any way to discard things as soon as you reasonably can, even if that means you have to occasionally re-fetch a few things from disk at some later point. On 64-bit systems such limits, memory permitting, can be multiplied by several billion. See builtins\VM\pHeap.e for the full gory details, however be warned it is low-level, complicated stuff, that you should never really need to look at.

As you will soon discover, sequences make phix very simple and very powerful. Understanding atoms and sequences is the key to understanding phix.

See also: Strings