(define make-buffer (lambda (_capacity) (let ((contents (make-vector _capacity)) (front 0) (back 0) (capacity _capacity) (size 0)) (lambda (command . params) (cond ((eq? command ':empty?) (<= size 0)) ((eq? command ':full?) (>= size capacity)) ((eq? command ':get!) (let ((tmp (vector-ref contents front))) (set! front (modulo (+ front 1) capacity)) (set! size (- size 1)) tmp)) ((eq? command ':put!) (vector-set! contents back (car params)) (set! back (modulo (+ back 1) capacity)) (set! size (+ size 1))) ((eq? command ':dump) (display "capacity: ") (display capacity) (newline) (display "size: ") (display size) (newline) (display "front: ") (display front) (newline) (display "back: ") (display back) (newline) (display "contents: ") (display contents) (newline)) (else (error "Undefined command")))))))