boxes.scm 337 B

1234567891011121314
  1. (define (box x) (vector 'box x))
  2. (define (box? x)
  3. (and (vector? x)
  4. (= 2 (vector-length x))
  5. (eq? 'box (vector-ref x 0))))
  6. (define (unbox x)
  7. ;; TODO: check its a box
  8. (vector-ref x 1))
  9. (define (set-box! x v)
  10. ;; TODO: check its a box
  11. (vector-set! x 1 v))
  12. (define (push-box! b val)
  13. (set-box! b (cons val (unbox b))))