Construction & Deletion
var x = new(List, Int);
push(x, $I(32));
push(x, $I(6));
/* <'List' At 0x0000000000414603 [32, 6]> */
show(x);
Element Access
var x = new(List, Float, $F(0.01), $F(5.12));
show(get(x, $I(0))); /* 0.01 */
show(get(x, $I(1))); /* 5.12 */
set(x, $I(0), $F(500.1));
show(get(x, $I(0))); /* 500.1 */
Membership
var x = new(List, Int, $I(1), $I(2), $I(3), $I(4));
show($I(mem(x, $I(1)))); /* 1 */
show($I(len(x))); /* 4 */
rem(x, $I(3));
show($I(mem(x, $I(3)))); /* 0 */
show($I(len(x))); /* 3 */
show($I(empty(x))); /* 0 */
resize(x, 0);
show($I(empty(x))); /* 1 */
Iteration
var greetings = new(List, String,
$S("Hello"), $S("Bonjour"), $S("Hej"));
foreach(greet in greetings) {
show(greet);
}
Linked List
The List
type is a linked list data structure. Elements can be added and removed from the list and their memory is allocated and deallocated by the structure. Additionally destructors will be called on objects once removed.
Elements are copied into the List using assign
and will initially have zero'd memory.
Lists can provide fast insertion and removal at arbitrary locations although most other operations will be slow due to having to traverse the linked list data structure.
This is largely equivalent to the C++ construct std::list
assign
cmp
eq
neq
gt
lt
ge
le
append
concat
name
brief
description
definition
get
set
mem
rem
key_type
val_type
hash
hash_data
foreach
iter_init
iter_next
iter_type
len
mark
new
del
construct
destruct
push
pop
push_at
pop_at
resize
show
look
print
scan