« Home » « Learn » « Download » « Github » ## Cello High Level C

### Examples

Construction & Deletion

``````var x = new(Array, Int);
push(x, \$I(32));
push(x, \$I(6));

/* <'Array' At 0x0000000000414603 [32, 6]> */
show(x);
``````

Element Access

``````var x = new(Array, 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(Array, 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(Array, String,
\$S("Hello"), \$S("Bonjour"), \$S("Hej"));

foreach(greet in greetings) {
show(greet);
}
``````

# Array

Sequential Container

The `Array` type is data structure containing a sequence of a single type of object. It can dynamically grow and shrink in size depending on how many elements it contains. It allocates storage for the type specified. It also deallocates and destroys the objects inside upon destruction.

Elements are copied into an Array using `assign` and will initially have zero'd memory.

Elements are ordered linearly. Elements are accessed by their position in this sequence directly. Addition and removal of elements at the end of the sequence is fast, with memory movement required for elements in the middle of the sequence.

This is largely equivalent to the C++ construct std::vector

### Derives

• Alloc`\$` `alloc` `dealloc`
• Cast`cast`
• Copy`copy`
• Size`size`
• Swap`swap`

### Implements

• Assign`assign`
• Cmp`cmp` `eq` `neq` `gt` `lt` `ge` `le`
• Concat`append` `concat`
• Doc`name` `brief` `description` `definition`
• Get`get` `set` `mem` `rem` `key_type` `val_type`
• Hash`hash` `hash_data`
• Iter`foreach` `iter_init` `iter_next` `iter_type`
• Len`len`
• Mark`mark`
• New`new` `del` `construct` `destruct`
• Push`push` `pop` `push_at` `pop_at`
• Resize`resize`
• Show`show` `look` `print` `scan`
• Sort`sort` `sort_by`