arb
From the SETL Wiki
| arb | |
|---|---|
| Category | set |
| Syntax | prefix |
| Compatibility | |
| CIMS SETL | yes |
| SETL-S | yes |
| SETL2 | yes |
| GNU SETL | yes |
Contents |
Purpose
Retrieve an arbitrary element from a set.
Synopsis
e := arb s
Description
If the set x is not empty, an element is non-deterministically chosen and assigned to e.
If x is empty, e is assigned om.
Examples
-
s := arb {1};s becomes 1
-
s := arb {};s becomes om
-
s := arb {1, 2};s becomes either 1 or 2
Notes
- Although the selection of the returned element is specified to be non-deterministic, in practice it may be predictable, e.g. always returning the smallest element would be a valid implementation of the arb function, but it would be poor practice to write a program that relied on this. Use of arb is appropriate in the following situations:
- The set s is known to contain at most one element
- If s contains 2 or more elements then the program will work equally well whichever element is selected

