epicours/Algo/CM/Lists.md

39 lines
1.2 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

List is the most fundamental data type. Is a sequencial argument, is a final sequence of element. It is no possible to have more than one element per box.
There is two different way to declare a list, the recursive one and the iterative one.
## Recursive list
- The first box is the **head of the list**
- The rest of the list is **the tail of the list**
- The signature of the recursive list is the following:
```
TYPES
list, box
USES
element
OPERATIONS
emptylist : -> list (* Internal operations of list*)
cons : element x list -> list (* Internal operations of list *)
tail : list -> list (* Internal operations of list *)
head : list -> box (* Internal operations of box *)
contents : box -> element (* Observer of box *)
first : list -> element (* Observer of list *)
next : box -> box (* Internal operation of box *)
PRECONDITIONS
tail(l) is-defined-iaoi l ≠ emptylist
head(l) is-defined-iaoi l ≠ emptylist
first(l) is-defined-iaoi l ≠ emptylist
AXIOMS
first(_l_) = contents(head(l))
tail(cons(_e,l_)) = l
first(cons(_e,l_)) = e
next(head(_l_)) = head(tail(l))
WITH
list l
element e
```