Search                        Top                                  Index
TEACH PAIRS                                        John Gibson, Feb 1992

Pairs are two-element data structures constructed by the procedure
*CONSPAIR. The two elements are known as the "front" and the "back" of
the pair, and can be accessed or updated with the procedures *FRONT and
*BACK. E.g.

    conspair("a", "b") -> pair;
    front(pair) =>
    ** a
    back(pair) =>
    ** b

A pair can be tested for with *ISPAIR:

    ispair(pair) =>
    ** <true>

The manner in which pairs are printed is complicated by the fact that
they are also used to represent lists. When a pair is part of a list,
its BACK is either another pair or else the empty list. Such structures
are printed as an opening square bracket, followed by the FRONTs of all
pairs in the chain followed by a closing square bracket, thus:

    conspair("a", conspair("b", conspair("c", []))) =>
    ** [a b c]

However, should the BACK of a pair not be another pair (or empty list),
the pair is printed thus:

    conspair("a", "b") =>
    ** [a|b]
    conspair("a", conspair("b", "c")) =>
    ** [a b|c]

Some pairs are used to represent 'dynamic' lists, created by *PDTOLIST.
HD and TL are like FRONT and BACK except that they can also cope with
dynamic lists. *NULL is able to recognise empty dynamic lists.

See TEACH *LISTS for a general introduction to lists. For further
information on lists and pairs in general, see REF *LISTS.


--- C.all/teach/pairs
--- Copyright University of Sussex 1992. All rights reserved. ----------