* Added vector-fill! and string-fill!

* Fixed a bug in (string 10) returning an uninitialized string.
This commit is contained in:
Abdulaziz Ghuloum 2007-09-02 02:22:23 -04:00
parent d515520bd7
commit 9e066f4d4c
5 changed files with 31 additions and 7 deletions

Binary file not shown.

View File

@ -2,7 +2,7 @@
(library (ikarus strings) (library (ikarus strings)
(export string-length string-ref string-set! make-string string->list string=? (export string-length string-ref string-set! make-string string->list string=?
string-append substring string list->string uuid string-append substring string list->string uuid
string-copy string-for-each) string-copy string-for-each string-fill!)
(import (import
(ikarus system $strings) (ikarus system $strings)
(ikarus system $fx) (ikarus system $fx)
@ -11,7 +11,8 @@
(ikarus system $pairs) (ikarus system $pairs)
(except (ikarus) string-length string-ref string-set! make-string (except (ikarus) string-length string-ref string-set! make-string
string->list string=? string-append substring string string->list string=? string-append substring string
list->string uuid string-copy string-for-each)) list->string uuid string-copy string-for-each
string-fill!))
(define string-length (define string-length
@ -62,7 +63,7 @@
[(n) [(n)
(unless (and (fixnum? n) (fx>= n 0)) (unless (and (fixnum? n) (fx>= n 0))
(error 'make-string "~s is not a valid length" n)) (error 'make-string "~s is not a valid length" n))
($make-string n)] (fill! ($make-string n) 0 n (integer->char 0))]
[(n c) [(n c)
(unless (and (fixnum? n) (fx>= n 0)) (unless (and (fixnum? n) (fx>= n 0))
(error 'make-string "~s is not a valid length" n)) (error 'make-string "~s is not a valid length" n))
@ -300,6 +301,16 @@
(f i ($cdr v*)))))) (f i ($cdr v*))))))
(f p v0 v1 v* ($fxadd1 i) n)])))]))) (f p v0 v1 v* ($fxadd1 i) n)])))])))
(define (string-fill! v fill)
(unless (string? v)
(error 'string-fill! "~s is not a vector" v))
(unless (char? fill)
(error 'string-fill! "~s is not a character" fill))
(let f ([v v] [i 0] [n ($string-length v)] [fill fill])
(unless ($fx= i n)
($string-set! v i fill)
(f v ($fxadd1 i) n fill))))
(define uuid (define uuid
(lambda () (lambda ()
(let ([s ($make-bytevector 16)]) (let ([s ($make-bytevector 16)])

View File

@ -1,11 +1,13 @@
(library (ikarus vectors) (library (ikarus vectors)
(export make-vector vector vector-length vector-ref vector-set! (export make-vector vector vector-length vector-ref vector-set!
vector->list list->vector vector-map vector-for-each) vector->list list->vector vector-map vector-for-each
vector-fill!)
(import (import
(except (ikarus) make-vector vector (except (ikarus) make-vector vector
vector-length vector-ref vector-set! vector-length vector-ref vector-set!
vector->list list->vector vector-map vector-for-each) vector->list list->vector vector-map vector-for-each
vector-fill!)
(ikarus system $fx) (ikarus system $fx)
(ikarus system $pairs) (ikarus system $pairs)
(ikarus system $vectors)) (ikarus system $vectors))
@ -252,4 +254,13 @@
(cons ($vector-ref ($car v*) i) (cons ($vector-ref ($car v*) i)
(f i ($cdr v*)))))) (f i ($cdr v*))))))
(f p v0 v1 v* ($fxadd1 i) n)])))]))) (f p v0 v1 v* ($fxadd1 i) n)])))])))
(define (vector-fill! v fill)
(unless (vector? v)
(error 'vector-fill! "~s is not a vector" v))
(let f ([v v] [i 0] [n ($vector-length v)] [fill fill])
(unless ($fx= i n)
($vector-set! v i fill)
(f v ($fxadd1 i) n fill))))
) )

View File

@ -342,6 +342,7 @@
[make-string i r] [make-string i r]
[string-ref i r] [string-ref i r]
[string-set! i r] [string-set! i r]
[string-fill! i r]
[string-length i r] [string-length i r]
[string=? i r] [string=? i r]
[string-ci=? i unicode] [string-ci=? i unicode]
@ -358,6 +359,7 @@
[make-vector i r] [make-vector i r]
[vector-ref i r] [vector-ref i r]
[vector-set! i r] [vector-set! i r]
[vector-fill! i r]
[vector? i r] [vector? i r]
[vector-length i r] [vector-length i r]
[list->vector i r] [list->vector i r]

View File

@ -224,7 +224,7 @@
[values C ba se] [values C ba se]
[vector C ba se] [vector C ba se]
[vector->list C ba se] [vector->list C ba se]
[vector-fill! S ba se] [vector-fill! C ba se]
[vector-for-each C ba] [vector-for-each C ba]
[vector-length C ba se] [vector-length C ba se]
[vector-map C ba] [vector-map C ba]
@ -524,7 +524,7 @@
[set-cdr! C mp se] [set-cdr! C mp se]
;;; ;;;
[string-set! C ms se] [string-set! C ms se]
[string-fill! S ms se] [string-fill! C ms se]
;;; ;;;
[command-line C pr] [command-line C pr]
[exit C pr] [exit C pr]