There are two of lists in e language
-- Regular list
-- Keyed list Regular
Regular List
-List types hold ordered collections of data elements.
-All items in a list must be of the same type.
-List elements can be of any type.
-Items in a list can be indexed with the subscript operator [ ], by placing a non-negative integer expression in the brackets.
-List indexes start at zero. You can select an item from a list by specifying its index.
-Lists are dynamically resizable.
-Lists contain many predefined methods.
-Lists are defined by using the list of keyword in a variable or a field definition.
EXAMPLE: lis :listof int;
List Operations
size() : This is used to set the size of the list.
add(item or list) : Add an item to the end of a list
add0(item or list) : Add an item to the head of a list
clear(): Delete all items from a list
delete(index) : Delete an item from a list
insert(index,item) : Insert an item in a list at a specified index
pop(item) : Remove and return the last list item
pop0(item) : Remove and return the first list item
push(item) : Add an item to the end of a list
push0(item) : Add an item to the head of a list
resize() : Change the size of a list
A keyed list data type is similar to hash tables or association lists found in other programming languages. If the element type of the list is a scalar type or a string type, then the hash key must be the predefined implicit variable it.
A keyed list is a distinct type, different from a regular list. This means that you cannot assign a keyed list to a regular list, nor assign a regular list to a keyed list: if list_a is a keyed list and list_b is a regular list, list_a = list_b is a syntax error.
EXAMPLE: <'
extend sys { !a:list(key:it)of int(bits:3); run()isalso{ var b: int(bits:4); for i from0to10{ gen b; a.add(b); }; if a.key_exists(2) then { print a; print a.key_index(4); }; }; }; '>