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

logo

Cello High Level C

Methods

slice

#define slice(I, ...)

Construct a Slice object on the stack over iterable I.

reverse

#define reverse(I)

Construct a Slice object that iterates over iterable I in reverse order.

Examples

Usage

var x = tuple(
  $S("Hello"), $S("There"), $S("World"), $S("!"));

/* Iterate over elements 0 to 2 */
foreach (s in slice(x, $I(2))) {
  print("%s\n", s);
}

/* Iterate over elements 1 to 2 */
foreach (s in slice(x, $I(1), $I(2))) {
  print("%s\n", s);
}

/* Iterate over every other element */
foreach (s in slice(x, _, _, $I(2))) {
  print("%s\n", s);
}

/* Iterate backwards, starting from element 3 */
foreach (s in slice(x, _, $I(2), $I(-1))) {
  print("%s\n", s);
}

Slice


Partial Iterable

The Slice type is an iterable that allows one to only iterate over part of another iterable. Given some start, stop and step, only those entries described by the Slice are returned in the iteration.

Under the hood the Slice object still iterates over the whole iterable but it only returns those values in the range given.

Definition

struct Slice {
  var iter;
  var range;
};

Derives

Implements

  • Assignassign
  • Cmpcmp eq neq gt lt ge le
  • Docname brief description definition
  • Getget set mem rem key_type val_type
  • Iterforeach iter_init iter_next iter_type
  • Lenlen
  • Newnew del construct destruct
  • Showshow look print scan

Back