2003-02-11 19:23:30 -05:00
|
|
|
; Copyright (c) 2003 RT Happe <rthappe at web de>
|
|
|
|
; See the file COPYING distributed with the Scheme Untergrund Library
|
|
|
|
|
|
|
|
;;; general sequences
|
|
|
|
;;; the sequence protocol -- elementary procedures
|
|
|
|
;;; sequence predicate, basic accessors, length, and even a constructor
|
|
|
|
|
|
|
|
(define (sequence? s)
|
|
|
|
(or (string? s)
|
|
|
|
(byte-vector? s)
|
|
|
|
(vector? s)
|
|
|
|
(list? s)
|
2003-02-15 19:32:31 -05:00
|
|
|
(absequence? s)))
|
2003-02-11 19:23:30 -05:00
|
|
|
|
|
|
|
(define (sequence-length s)
|
|
|
|
(gen-dispatch
|
|
|
|
((string? string-length)
|
|
|
|
(byte-vector? byte-vector-length)
|
|
|
|
(vector? vector-length)
|
|
|
|
(list? length)
|
2003-02-15 19:32:31 -05:00
|
|
|
(absequence? absequence-length))
|
2003-02-11 19:23:30 -05:00
|
|
|
s))
|
|
|
|
|
|
|
|
|
|
|
|
(define (sequence-ref s k)
|
|
|
|
(gen-dispatch
|
|
|
|
((string? string-ref)
|
|
|
|
(byte-vector? byte-vector-ref)
|
|
|
|
(vector? vector-ref)
|
|
|
|
(list? list-ref)
|
2003-02-15 19:32:31 -05:00
|
|
|
(absequence? absequence-ref))
|
2003-02-11 19:23:30 -05:00
|
|
|
s k))
|
|
|
|
|
|
|
|
|
|
|
|
(define (sequence-set! s k x)
|
|
|
|
(gen-dispatch
|
|
|
|
((string? string-set!)
|
|
|
|
(byte-vector? byte-vector-set!)
|
|
|
|
(vector? vector-set!)
|
|
|
|
(list? list-set!)
|
2003-02-15 19:32:31 -05:00
|
|
|
(absequence? absequence-set!))
|
2003-02-11 19:23:30 -05:00
|
|
|
s k x))
|
|
|
|
|
|
|
|
|
|
|
|
(define (make-another-sequence s len . maybe-fill)
|
|
|
|
(cond ((string? s) (apply make-string len maybe-fill))
|
|
|
|
((byte-vector? s) (make-byte-vector len
|
|
|
|
;; mbv requires 2nd arg
|
|
|
|
(:optional maybe-fill 0)))
|
|
|
|
((vector? s) (apply make-vector len maybe-fill))
|
|
|
|
((list? s) (apply make-list len maybe-fill))
|
2003-02-15 19:32:31 -05:00
|
|
|
((absequence? s)
|
|
|
|
(apply make-absequence/behavior
|
|
|
|
(absequence:behavior s) len maybe-fill))
|
2003-02-13 19:47:58 -05:00
|
|
|
(else (error "make-another-sequence : first arg not a sequence?"
|
|
|
|
s))))
|
2003-02-11 19:23:30 -05:00
|
|
|
|