template.scm 676 B

123456789101112131415161718192021222324
  1. ; -*- Mode: Scheme; Syntax: Scheme; Package: Scheme; -*-
  2. ; Part of Scheme 48 1.9. See file COPYING for notices and license.
  3. ; Authors: Richard Kelsey, Jonathan Rees
  4. ; Templates implemented as vectors.
  5. (define *template-marker* (list '*template-marker*))
  6. (define (make-template len init)
  7. (let ((t (make-vector (+ len 1) init)))
  8. (vector-set! t 0 *template-marker*)
  9. t))
  10. (define (template? obj)
  11. (and (vector? obj)
  12. (> (vector-length obj) 0)
  13. (eq? (vector-ref obj 0) *template-marker*)))
  14. (define (template-length t) (- (vector-length t) 1))
  15. (define (template-ref t i) (vector-ref t (+ i 1)))
  16. (define (template-set! t i x) (vector-set! t (+ i 1) x))