sunterlib/s48/sequences/packages.scm

108 lines
4.1 KiB
Scheme
Raw Normal View History

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
;;; refers to structure KRIMS from sunterlib/s48/krims
;; sequences as data + behaviour
2003-02-15 19:32:31 -05:00
(define-structure absequences absequences-face
(open srfi-9+ ; define-record-type -discloser
2003-02-14 21:48:52 -05:00
krims ; assert
let-opt ; let-optionals [ from scsh ]
2003-02-11 19:23:30 -05:00
scheme)
(files uniseqs))
2003-02-13 19:47:58 -05:00
;; specialists for lists, vectors, strings
2003-02-11 19:23:30 -05:00
(define-structure sequence-specifics sequence-specifics-face
2003-02-13 19:47:58 -05:00
(open srfi-1 ; list procs
srfi-13 ; string procs
2003-02-11 19:23:30 -05:00
scheme)
(files specseqs))
;; basic sequence accessors etc.
(define-structure sequence-basics sequence-basics-face
(open krims ; gen-dispatch
2003-02-13 19:47:58 -05:00
let-opt ; :optional [ from scsh ]
2003-02-11 19:23:30 -05:00
sequence-specifics ; list-set! make-list
2003-02-15 19:32:31 -05:00
absequences
2003-02-11 19:23:30 -05:00
byte-vectors
2003-02-13 19:47:58 -05:00
srfi-1 ; make-list
2003-02-11 19:23:30 -05:00
srfi-23 ; error
scheme)
(files baseqs))
;; sequence operations defined in terms of the basic protocol
(define-structure sequence-extras sequence-extras-face
(open sequence-basics
krims ; assert
2003-02-12 16:48:40 -05:00
util ; unspecific
srfi-1 ; append!
srfi-23 ; error
2003-02-13 19:47:58 -05:00
let-opt ; let-optionals [ from scsh ]
2003-02-11 19:23:30 -05:00
scheme)
(files genseqs))
2003-02-13 19:47:58 -05:00
;; sequence procedures specialised to vectors
(define-structure vector-lib vector-lib-face
(open krims ; assert
util ; unspecific
let-opt ; let-optionals [ from scsh ]
2003-02-14 21:48:52 -05:00
srfi-1+ ; append! first rest
2003-02-13 19:47:58 -05:00
scheme)
;; bind the basic operations to vector specialists
(begin
(define sequence? vector?)
(define sequence-length vector-length)
(define sequence-ref vector-ref)
(define sequence-set! vector-set!)
(define (make-another-sequence v k . maybe-fill)
(apply make-vector k maybe-fill)))
(files genseqs)
2003-02-14 21:48:52 -05:00
;; rename extras not supplied by scheme and def list->vector with opts
2003-02-13 19:47:58 -05:00
(begin
(define subvector subsequence)
(define vector-copy sequence-copy)
2003-02-14 21:48:52 -05:00
(define vector-fill! sequence-fill!) ; with opt. start & end
2003-02-13 19:47:58 -05:00
(define vector-append sequence-append)
(define vector-map sequence-map)
(define vector-for-each sequence-for-each)
(define vector-fold sequence-fold)
(define vector-fold-right sequence-fold-right)
(define vector-any sequence-any)
(define vector-every sequence-every)
(define vectors-map sequences-map)
(define vectors-for-each sequences-for-each)
(define vectors-fold sequences-fold)
(define vectors-fold-right sequences-fold-right)
(define vectors-any sequences-any)
(define vectors-every sequences-every)
2003-02-14 21:48:52 -05:00
(define (list->vector xs . opts)
(let-optionals opts ((start 0) (end (length xs)))
(assert (<= 0 start end))
(let ((v (make-vector (- end start))))
(do ((i start (+ i 1))
(ys xs (rest ys)))
((= i end) v)
(vector-set! v (- i start) (first ys))))))
2003-02-13 19:47:58 -05:00
))
2003-02-11 19:23:30 -05:00
;; elementary and other general sequence operations, typically dispatching
;; early on the sequence type in order to make use of built-ins or special
;; code (notably for lists)
(define-structure sequence-lib (compound-interface sequence-basics-face
sequence-extras-face
2003-02-15 19:32:31 -05:00
absequences-face)
(open (with-prefix sequence-extras contiguous-)
2003-02-11 19:23:30 -05:00
sequence-basics
2003-02-15 19:32:31 -05:00
absequences
2003-02-11 19:23:30 -05:00
sequence-specifics
2003-02-13 19:47:58 -05:00
vector-lib
srfi-1 ; list procs
srfi-13 ; string procs
2003-02-15 19:32:31 -05:00
byte-vectors
2003-02-13 19:47:58 -05:00
let-opt ; let-optionals [ from scsh ]
2003-02-11 19:23:30 -05:00
scheme)
(files composeqs))