(define (init-counter)
(local
((define counter 0)
(define (inc) (set! counter (add1 counter)))
(define (dec) (set! counter (sub1 counter)))
(define (current-count) counter))
(values inc dec current-count)))
Then you can just import this code into wherever you want to use it and do something like: (define-values (counter++ counter-- current-count) (init-counter))
Plenty of people have said data structures are a poor mans functions. I think it's in that famous list of programmer quotes collected by alan perlis that everyone inevitably comes across at some point.In many cases where you want object orientation something like this will be sufficient. No need to go the whole way with inheritance and whatnot.