next up previous contents
Next: Functions on type t_binding Up: Primitives Previous: Functions on Type t_text   Contents


Functions on Type t_list

t_bool
operator==(t_list l1, t_list l2)

Returns true if l1 and l2 are lists of the same length containing (recursively) equal values, and false otherwise.

t_bool
operator!=(t_list l1, t_list l2) =
  operator!(operator==(l1, l2))

t_list
_list1(t_value v)

Returns a list containing a single element whose value is v.

t_value
_head(t_list l)

Returns the first element of l. If l is empty, evaluation halts with a runtime error.

t_list
_tail(t_list l)

Returns the list consisting of all elements of l, in order, except the first. If l is empty, evaluation halts with a runtime error.

t_int
_length(t_list l)

Returns the number of (top-level) values in the list l.

t_value
_elem(t_list l, t_int i)

Returns the i-th value in the list l. If no such value exists, evaluation halts with a runtime error. The first value of a list has index 0.

t_list
operator+(t_list l1, t_list l2)

Returns the list formed by appending l2 to l1.

t_list
_sub(t_list l, t_int start = 0, t_int len = _length(l))
{
  int w = _length(l);
  int i = _min(_max(start, 0)), w);
  int j = _min(i + _max(len, 0), w);
  // 0 <= i <= j <= _length(l); extract [i..j)
  t_list r = emptylist;
  for (; i < j; i++) r = operator+(r, _elem(l, i));
  return r;
}

Returns the sub-list of l of length len starting at element start. Note the boundary cases defined by the pseudo-code; _sub produces a runtime error only if it is passed arguments of the wrong type.

t_list
_map(t_closure f, t_list l) =
{
  t_list res = emptylist;
  for (; !(l == emptylist); l = _tail(l)) {
    t_value v = f(_head(l)); // apply the closure "f"
    res = operator+(res, v);
  }
  return res;
}

Returns the list that results from applying the closure f to each element of the list l, and concatenating the results in order. The closure f should take one value (of type t_value) as argument and return a value of any type. If f has the wrong signature, the evaluation halts with a runtime error.

t_list
_par_map(t_closure f, t_list l)

Formally equivalent to _map, but the implementation may perform each application of f in a separate parallel thread. External tools invoked by _run_tool in different threads may be run simultaneously on different machines. If a runtime error occurs in one thread, the other threads may still run to completion before the evaluation terminates.


next up previous contents
Next: Functions on type t_binding Up: Primitives Previous: Functions on Type t_text   Contents
Allan Heydon, Roy Levin, Timothy Mann, Yuan Yu