On this page:
info?
info/  c
info-ref
info-set
info-remove
8.10

3.5 Info Data Structure

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.

procedure

(info? v)  any/c

  v : any/c
Returns #t if v is an info, and #f otherwise.

Examples:
> (info? '())

#t

> (info? '((a . 5)))

#f

> (info? '((a 5)))

#t

syntax

(info/c (key-name spec) ...)

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

procedure

(info-ref v key)  (or/c #f any/c)

  v : info?
  key : any/c
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

procedure

(info-set v key value)  info?

  v : info?
  key : any/c
  value : any/c
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

(info-remove v key)  info?

  v : info?
  key : any/c
Removed a mapping for key in the info v.