SLSH Library Reference (version 2.3.0): Set Functions

Next Previous Contents

## 11. Set Functions

These functions manipulate arrays and lists as sets.

## 11.1 complement

Synopsis

  Extract the elements of a set that are not contained in other sets.

Usage

  `indices = complement (a, b, ..., c)`

Description

  This function computes the elements of the first argument (`a`) that are not contained in the sets given by the other arguments (`b,...,c`) and returns them in the form of indices into the first argument.

Example

  > `

  >        a = {"foo", PI, 7};
  >        b = [1,2,3,PI];
  >        indices = complement (a, b);

  > `

  Upon return, `indices` will have the value `[0, 2]` since `a[0]` and `a[2]` are not contained in `b`.
Notes

  A set may either be an Array_Type or a List_Type object. For a homogeneous collection of objects, it is better to use an Array_Type. i.e., `[1,2,3]` instead of `{1,2,3}`.

See Also

  `intersection, ismember, union, unique`

## 11.2 intersection

Synopsis

  Extract the common elements of two or more sets

Usage

  `indices = complement (a, b, ..., c)`

Description

  This function computes the common elements of two or more sets and returns them in the form of indices into the first argument.

Example

  > `

  >        a = {"foo", 7, PI};
  >        b = {PI, "bar", "foo"};
  >        indices = intersection (a, b);

  > `

  Upon return, `indices` will have the value `[0, 2]` since `a[0]` and `a[2]` are the common elements of the sets.
Notes

  A set may either be an Array_Type or a List_Type object. For a homogeneous collection of objects, it is better to use an Array_Type. i.e., `[1,2,3]` instead of `{1,2,3}`.

See Also

  `complement, ismember, union, unique`

## 11.3 ismember

Synopsis

  test to see if the elements of one set are members of another

Usage

  `val = ismember (a, b)`

Description

  This function may be used to see which of the elements of the set `a` are members of the set `b`. It returns a boolean array indicating whether or not the corresponding element of `a` is a member of `b`.

Notes

  A set may either be an Array_Type or a List_Type object. For a homogeneous collection of objects, it is better to use an Array_Type. i.e., `[1,2,3]` instead of `{1,2,3}`.

See Also

  `complement, intersection, union, unique`

## 11.4 union

Synopsis

  Form a set of the unique elements of one ore more subsets

Usage

  `abc = union (a, b,..., c)`

Description

  This function interprets each of its arguments as a set, then merges them together and returns only the unique elements. The returned value may either be an `Array_Type` or a `List_Type` object.

Notes

  A set may either be an Array_Type or a List_Type object. For a homogeneous collection of objects, it is better to use an Array_Type. i.e., `[1,2,3]` instead of `{1,2,3}`.

See Also

  `complement, intersection, ismember, unique`

## 11.5 unique

Synopsis

  Get the indices of the unique elements of a set

Usage

  `indices = unique (A)`

Description

  This function returns an array of the indices of the unique elements of a set.

Notes

  A set may either be an Array_Type or a List_Type object. For a homogeneous collection of objects, it is better to use an Array_Type. i.e., `[1,2,3]` instead of `{1,2,3}`.

See Also

  `complement, intersection, ismember, union`

Next Previous Contents