template.scm 647 B

12345678910111213141516171819202122
  1. ; -*- Mode: Scheme; Syntax: Scheme; Package: Scheme; -*-
  2. ; Copyright (c) 1993-2007 by Richard Kelsey and Jonathan Rees. See file COPYING.
  3. ; Templates implemented as vectors.
  4. (define *template-marker* (list '*template-marker*))
  5. (define (make-template len init)
  6. (let ((t (make-vector (+ len 1) init)))
  7. (vector-set! t 0 *template-marker*)
  8. t))
  9. (define (template? obj)
  10. (and (vector? obj)
  11. (> (vector-length obj) 0)
  12. (eq? (vector-ref obj 0) *template-marker*)))
  13. (define (template-length t) (- (vector-length t) 1))
  14. (define (template-ref t i) (vector-ref t (+ i 1)))
  15. (define (template-set! t i x) (vector-set! t (+ i 1) x))