aboutsummaryrefslogtreecommitdiffstats
path: root/lib/cuprate/implementation/alist-eq-map.scm
blob: 42097c0ce6c2f870eaddc4bd98f44eed80bc3d73 (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?) (pair? (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)))))