« Home » « Learn » « Download » « Github »

logo

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

Implements

  • Assignassign
  • Cmpcmp eq neq gt lt ge le
  • Concatappend concat
  • Docname brief description definition
  • Getget set mem rem key_type val_type
  • Hashhash hash_data
  • Iterforeach iter_init iter_next iter_type
  • Lenlen
  • Markmark
  • Newnew del construct destruct
  • Pushpush pop push_at pop_at
  • Resizeresize
  • Showshow look print scan
  • Sortsort sort_by

Back