WAL Programmer Manual

0.8.1

6. Arrays

This section describes array functions. In WAL, arrays are a hashmap data structure.
(array (id expr)*) ↦ (array?)
  id : WAL value
  expr : WAL expression
Constructs an array initialized with the data passed as tuples to this function. Keys are always stored as strings. When printed, arrays are shown in curly braces {} and the entries are shown in parentheses ().
Examples
>-> (array)
{}
>-> (array ['x 10] ['y 20])
{("x" 10) ("y" 20)}
>-> (array [5 5])
{("5" 5)}
(seta array key value) ↦ WAL value
  array : (array?)
  key : WAL value
  value: WAL expression
Evaluates key, converts the result to string and inserts/updates value in array.
Examples
>-> (seta (array) 'x 10)
{("x" 10)}
>-> (seta (array ['x 10]) 'y 20)
{("x" 10) ("y" 20)}
>-> (define some-array (array))
{}
>-> (define data '("test" "data"))
("test")
>-> (seta some-array 0 data)
{("0" ("test" "data"))}
(geta array key) ↦ WAL value
  array : (array?)
  key : WAL value
Evaluates key, converts the result to string and returns the value at key from array.
Examples
>-> (geta (array ['x 10]) 'x)
10
>-> (define i 5)
5
>-> (geta (array ['i 0] [5 "test"]) i)
"test"
(geta/default array default key) ↦ WAL value
  array : (array?)
  default : WAL expression
  key : WAL value
Evaluates key, converts the result to string and returns the value at key from array if key is in array else evaluates and returns default.
Examples
>-> (geta/default (array ['x 10]) 5 'x)
10
>-> (geta/default (array ['x 10]) 5 'y)
5
(dela array key) ↦ WAL value
  array : (array?)
  key : WAL value
Evaluates key, converts the result to string and removes the value at key from array.
Examples
>-> (dela (array ['x 10] ['y 20]) 'x)
{["y" 20]}
(mapa f array) ↦ (list?)
  f : (fn?) (fn [key value] ...)
  array : (array?)
Applies function f to every (key value) pair in array. f must take exactly two parameters with the first being the key and the seconds being the value. Returns a list.
Examples
>-> (mapa (fn [k v] (list k v)) (array ['x 10] ['y 20]) 'x)
{["y" 20]}