8.10
3.5 Info Data Structure
(require cpsc411/info-lib) | package: cpsc411-lib |
This library defines the info datatype.
An info is a datatype used to represent dictionaries or maps in a
convenient readable way.
It is similar to an association list, but uses proper lists rather than pairs.
This makes it more memory intensive, but means we do not need to introduce
dotted pair notation.
Examples:
> (info? '()) #t
> (info? '((a . 5))) #f
> (info? '((a 5))) #t
Creates an info contract?, specifying that the info must
contain a mapping for each key-name, and the value for each key must
satsify spec.
The spec language is roughly the same as the BNF pattern language used
in this course, except all terminals must be contract?s.
Examples:
> (require racket/contract) > ((info/c) '()) #t
> ((info/c) 5) #f
> ((info/c (locals (aloc? ...))) '()) #f
> ((info/c (locals (aloc? ...))) '((locals ()))) #t
> ((info/c (locals (aloc? ...))) '((locals (x.1)))) #t
> ((info/c (locals (aloc? ...))) '((locals (5)))) #f
> ((info/c (locals (aloc? ...))) '((locals (x.1)) (assignments ((x.1 5))))) #t
> (define loc? (or/c register? fvar?))
> ((info/c (locals (aloc? ...)) (assignment ((aloc? loc?) ...))) '((locals (x.1)) (assignment ((x.1 5))))) #f
> ((info/c (locals (aloc? ...)) (assignment ((aloc? loc?) ...))) '((locals (x.1)) (assignment ((x.1 rax))))) #t
> ((info/c (locals (aloc? ...)) (assignment ((aloc? loc?) ...))) '((assignment ((x.1 rax) (y.3 fv1) (x.2 rax))) (locals (x.1 x.2 y.3)))) #t
Returns the value associated with key in v.
Examples:
> (info-ref '((assignment ((x.1 rbx) (y.2 r)))) 'assignment) '((x.1 rbx) (y.2 r))
> (info-ref (info-ref '((assignment ((x.1 rbx) (y.2 r)))) 'assignment) 'x.1) 'rbx
Adds a mapping from key to value in the info v.
Examples:
> (info-set '() 'x.1 'rbx) '((x.1 rbx))
> (info-set (info-set '() 'x.1 'rbx) 'y.2 'r9) '((x.1 rbx) (y.2 r9))
> (info-set '() 'assignment '((x.1 rbx) (y.2 r9))) '((assignment ((x.1 rbx) (y.2 r9))))
procedure
v : info? key : any/c
Removed a mapping for key in the info v.