aboutsummaryrefslogtreecommitdiffstats
path: root/lib/cuprate/implementation/alist-eq-map.scm
blob: f9841e77cc37c3e9d86e031ab67d4f821c4a390d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
(define (make-eq-map)
  (define alist '())
  (define interned-alist '())
  (define counter 0)
  (lambda (msg obj)
    (case msg
      ((contains?) (assq obj alist))
      ((cycle-counter)
       (set! interned-alist (cons obj interned-alist))
       (let ((num (cdr (assq obj alist))))
         (string->symbol (string-append
                          "#"
                          (number->string num)
                          "#"))))
      ((cycle-used?) (memq obj interned-alist))
      ((intern!)
       (set! alist (cons (cons obj counter) alist))
       (set! counter (+ counter 1)))
      (else (error 'make-eq-map
                   "invalid message"
                   msg)))))