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
|
|
|
|
|
2003-03-22 17:22:15 -05:00
|
|
|
;;; some sequence procedures for specific types (for lists, actually)
|
2003-02-11 19:23:30 -05:00
|
|
|
;;; list-set! sublist list-fill!
|
|
|
|
|
|
|
|
;; unspecified return value as usual
|
|
|
|
(define (list-set! xs k x)
|
|
|
|
(set-car! (drop xs k) x))
|
|
|
|
|
|
|
|
(define (sublist xs start end)
|
|
|
|
(take (drop xs start) (- end start)))
|
|
|
|
|
2003-02-16 17:39:24 -05:00
|
|
|
;; unspecified return value -- no [start end] for now
|
2003-03-22 17:22:15 -05:00
|
|
|
; (define (list-fill! xs x)
|
|
|
|
; (pair-for-each (lambda (p) (set-car! p x)) xs))
|
|
|
|
|
|
|
|
;; unspecified return value
|
|
|
|
(define (list-fill! xs x . opts)
|
|
|
|
(let-optionals* opts ((start 0 (<= 0 start))
|
|
|
|
;; the default value is only used to make the
|
|
|
|
;; check work. Don't want to compute xs' length.
|
|
|
|
(end start (<= start end) end-supplied?))
|
|
|
|
(let loop ((xs xs) (i 0))
|
|
|
|
(cond ((null? xs)
|
|
|
|
(assert (or (not end-supplied?)
|
|
|
|
(= i end))
|
|
|
|
list-fill!))
|
|
|
|
((< i start)
|
|
|
|
(loop (rest xs) (+ i 1)))
|
|
|
|
((if end-supplied? (< i end) #t)
|
|
|
|
(set-car! xs x)
|
|
|
|
(loop (rest xs) (+ i 1)))))))
|