aboutsummaryrefslogtreecommitdiffstats
path: root/lib/cuprate/implementation/srfi-125-eq-map.scm
diff options
context:
space:
mode:
authorGravatar Peter McGoron 2025-11-04 08:24:27 -0500
committerGravatar Peter McGoron 2025-11-04 08:24:27 -0500
commitf1c3054215f58b4a4cca3a7716993c273c87ca74 (patch)
tree1ee2cad102f87ff65f5ef12eda019c79110792a0 /lib/cuprate/implementation/srfi-125-eq-map.scm
parentstart moving implementation-dependent code into separate libraries (diff)
move rewriters to implementation file, make rewriter cycle-detecting
Diffstat (limited to 'lib/cuprate/implementation/srfi-125-eq-map.scm')
-rw-r--r--lib/cuprate/implementation/srfi-125-eq-map.scm17
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/cuprate/implementation/srfi-125-eq-map.scm b/lib/cuprate/implementation/srfi-125-eq-map.scm
new file mode 100644
index 0000000..3a1d7b9
--- /dev/null
+++ b/lib/cuprate/implementation/srfi-125-eq-map.scm
@@ -0,0 +1,17 @@
+(define (make-eq-map)
+ (define counter-table (make-hash-table (make-eq-comparator)))
+ (define used-table (make-hash-table (make-eq-comparator)))
+ (define counter 0)
+ (lambda (msg obj)
+ (case msg
+ ((contains?) (hash-table-contains? counter-table obj))
+ ((cycle-counter) (let ((num (hash-table-ref counter-table obj)))
+ (hash-table-set! used-table obj #t)
+ (string->symbol
+ (string-append "#"
+ (number->string num)
+ "#"))))
+ ((cycle-used?) (hash-table-contains? used-table obj))
+ ((intern!) (hash-table-set! counter-table obj counter)
+ (set! counter (+ counter 1)))
+ (else (error "invalid message" msg))))) \ No newline at end of file