tuple
#define tuple(...)
Construct a Tuple
object on the stack.
Usage
var x = tuple($I(100), $I(200), $S("Hello"));
show(x);
var y = tuple(Int, $I(10), $I(20));
var z = new_with(Array, y);
show(z);
foreach (item in x) {
println("%$", item);
}
Basic Collection
The Tuple
type provides a basic way to create a simple collection of objects. Its main use is the fact that it can be constructed on the stack using the tuple
macro. This makes it suitable for a number of purposes such as use in functions that take a variable number of arguments.
Tuples can also be constructed on the heap and stored in collections. This makes them also useful as a simple untyped list of objects.
Internally Tuples are just an array of pointers terminated with a pointer to the Cello Terminal
object. This makes positional access fast, but many other operations slow including iteration and counting the number of elements. Due to this it is only recommended Tuples are used for small collections.
Because Tuples are terminated with the Cello Terminal
object this can't naturally be included within them. This object should therefore only be returned from iteration functions.
struct Tuple {
var* items;
};
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
sort
sort_by