next up previous contents index
Next: Application of associative lists Up: Associative Lists in A++ Previous: Associative Lists in A++   Contents   Index

Abstractions for associative lists

The following examples show how a list of keys and a corresponding list of values can be combined into one associative list of pairs using the abstraction `map2', an extension of `map'.

To display an associative list using symbols as keys a new function is required, because `ldisp!' can handle only Church Numerals. We call this new function `aldisp!'.

To search for keys in the list we need another lambda abstraction, which we call `assoc'.


\begin{lstlisting}[language=Scm]{}
(define map2
(lambda(proc l1 l2)
(if (lor (...
...ns (proc (car l1) (car l2))
(map2 proc (cdr l1) (cdr l2))))))
\end{lstlisting}


\begin{lstlisting}[language=Scm]{}
(define aldisp! (lambda (l)
(if (nullp l)
...
...ey (car(car alist)))
(car alist)
(assoc key (cdr alist))))))
\end{lstlisting}

This example uses the following extensions of A++ in its original version:
next up previous contents index
Next: Application of associative lists Up: Associative Lists in A++ Previous: Associative Lists in A++   Contents   Index
domain access counter Georg P. Loczewski 2004-03-05