next up previous contents index
Next: From HiLog to Prolog Up: Terms Previous: Compound Terms   Contents   Index


Lists

As in Prolog, lists form an important class of data structures in HiLog. They are essentially the same as the lists of Lisp: a list is either the atom '[]', representing the empty list, or else a compound term with functor '.' and two arguments which are the head and tail of the list respectively, where the tail of a list is also a list. Thus a list of the first three natural numbers is the structure:
                                  .
                                 / \
                                1    .
                                    / \
                                   2    .
                                       / \
                                      3   []
which could be written using the standard syntax, as:
                             .(1,.(2,.(3,[])))
but which is normally written in a special list notation, as:
                                  [1,2,3]
Two examples of this list notation, as used when the tail of a list is a variable, are:
                       [Head|Tail]      [foo,bar|Tail]
which represent the structures:
                            .                .
                           / \              / \
                       Head   Tail        foo   .
                                               / \
                                             bar  Tail
respectively.

Note that the usual list notation [H|T] does not add any new power to the language; it is simply a notational convenience and improves readability. The above examples could have been written equally well as:

                      .(Head,Tail)      .(foo,.(bar,Tail))

For convenience, a further notational variant is allowed for lists of integers that correspond to ASCII character codes. Lists written in this notation are called strings. For example,

                            "I am a HiLog string"
represents exactly the same list as:
    [73,32,97,109,32,97,32,72,105,76,111,103,32,115,116,114,105,110,103]


next up previous contents index
Next: From HiLog to Prolog Up: Terms Previous: Compound Terms   Contents   Index
Luis Fernando P. de Castro 2003-06-27