Adding more vector functions

This commit is contained in:
Justin Ethier 2015-06-02 22:39:53 -04:00
parent 1edd3939a4
commit a7fce12fdd
3 changed files with 26 additions and 5 deletions

View file

@ -1136,7 +1136,7 @@ void _string_91append(object cont, object args) {
dispatch(argc.value, (function_type)dispatch_string_91append, cont, cont, args); }
void _string_91_125list(object cont, object args) {
string2list(lst, car(args));
return_funcall1(cont, &lst);}
return_funcall1(cont, lst);}
void _make_91vector(object cont, object args) {
integer_type argc = Cyc_length(args);
if (argc.value >= 2) {

View file

@ -40,8 +40,11 @@
Cyc-obj=?
make-string
vector
vector-append
vector-copy
vector->list
vector->string
string->vector
error
raise
raise-continuable
@ -163,11 +166,28 @@
(cons (vector-ref vec i) lst))))))
(loop start '())))
(define (vector->string vec . opts)
TODO
)
(let ((lst (apply vector->list (cons vec opts))))
(list->string lst)))
;; TODO: need to extend string->list to take optional start/end args,
;; then modify this function to work with optional args, too
(define (string->vector str . opts)
TODO
)
(list->vector
(string->list str)))
(define (vector-append . vecs)
vecs) ; TODO
(define (vector-copy vec . opts)
(letrec ((len (vector-length vec))
(start (if (> (length opts) 0) (car opts) 0))
(end (if (> (length opts) 1) (cadr opts) len))
(loop (lambda (i new-vec)
(cond
((= i end)
new-vec)
(else
(vector-set! new-vec i (vector-ref vec i))
(loop (+ i 1) new-vec))))))
(loop start (make-vector (- end start) #f))))
(define (boolean=? b1 b2 . bs)
(Cyc-obj=? boolean? b1 (cons b2 bs)))

View file

@ -6,3 +6,4 @@
(write `(read ,@(list 1 2 3)))
;`(read ,
(write (make-vector 4 #t))
(write (string->list "abc"))