Lesson 2-5 - Arrays (And Sequences)
Prerequesite: This lesson presumes you know how to invoke eLisp expression as shown in Lesson 2-1.
We have seen lists in eLisp. Lists are an example of a sequence - a load of things stored in another thing which we can access sequentially.
There is another type of sequence in eLisp - an array. Arrays themselves come in 2 flavours:
The relationship of all these things is shown below:
There are sets of functions that operate on all sequences, some which apply to array's only and then other sets for the actual data types themselves (lists, strings, vectors, bool-vectors and char-tables).
This lesson will look at:
The Extra Activities section will cover functions that operate on sequences.
Why Arrays And Not Lists?
The difference betweeen arrays and lists is that arrays have fixed lengths and lists have variable length. This gives them different performance characteristics - array elements are accessible in constant time, whereas the access time for lists is proportional to their length.
Difference Between Strings And Vectors
In eLisp a string is simply an array whose elements consists of the integers which represent unicode points. A vector is a general array whose elements are any valid eLisp term.
Why Only 1D Arrays?
Arrays are 1 dimensional only. Given that the elements of a vector can consist of other valid eLisp symbol, multi-dimensional arrays can be implemented as vectors of vectors.
A array is delimied by square brackets (
]). You can create them inline:
You can create vectors using the
string does the same for strings. To create a string you need array elements that are the integers which represent characters - a full set of unicode values is supported.
(96 is ascii for
What You Have Learned
You have learned about additional types of sequences and see how they are constructed.