Kalandra

Learn

Arrays and maps

A functional language for parallel and distributed programming. The next chapter of Clio.

Arrays use square brackets with space-separated elements. Read and write an element with an index in square brackets. Indexes start at zero.

Transform an array

The mapped pipe -> * calls a function for each element. Here it produces [2 4 6], then the indexed assignment replaces the middle element with 42.

main.kalandra

kalandra
fn double n: n * 2

export fn main:
  values = [1 2 3] -> * double
  values[1] = 42
  values

Expected result:

text
[2,42,6]

Try in playground

Ordinary mapping and parallel mapping

This example uses ordinary local calls. Mapping alone does not start workers. The parallel lesson adds a worker target and awaits the mapped results.

Kalandra maps can pass an index and the original collection as extra callback arguments. That matters for checked functions and for the types crossing a worker boundary.

Ranges are also supported, but direct parallel range maps are rejected. Use an array for the parallel examples. Collection membership and bulk range assignment are not covered by this guide; their semantics are not supplied by the port.

Next: types and records