guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

vector types poll


From: Daniel Llorens
Subject: vector types poll
Date: Mon, 15 Apr 2013 16:10:11 +0200

        
Let's please agree on a behavior so we can start closing bugs. These are all 
the objects accepted by the array interface. I've filled the table with some 
ready-made choices that I think are at least internally consistent.

; --

(import (rnrs bytevectors))
(define (every-two a) (make-shared-array a (lambda (i) (list (+ 1 (* 2 i)))) 2))
(define (offset1 a) (make-shared-array a (lambda (i) (list (1- i))) `(1 
,(array-length a))))

; [1] http://lists.gnu.org/archive/html/guile-devel/2013-04/msg00158.html
; [2] stable-2.0 [e006d87]
; [3] all array-type objects *are* arrays and support offsets, strides, etc.
; [4] Common ground btw D. Hartwig and I (?), functionally r5rs vectors.

; -------------------------- [1] ------------ [2] --------- [3] ------ [4]

(define a #(1 2 3 4))
(define b (every-two a))
(define c (offset1 a))
(vector? a)                  ; #t             #t            #t         #t
(vector? b)                  ; #f             #f            #t         #t
(vector? c)                  ; #f             #f            #t         #f
(vector-ref a 1)             ; 2              2             2          2
(vector-ref b 1)             ; bad type       4             4          4
(vector-ref c 1)             ; bad type       2             1          bad type
(array-ref c 1)              ; 1

(define a "1234")
(define b (every-two a))
(define c (offset1 a))
(string? a)                  ; #t             #t            #t
(string? b)                  ; #f             #f            #t
(string? c)                  ; #f             #f            #t
(string-ref a 1)             ; #\2            #\2           #\2
(string-ref b 1)             ; bad type       bad type      #\4
(string-ref c 1)             ; bad type       bad type      #\1
(array-ref c 1)              ; #\1

(define a #s8(1 2 3 4))
(define b (every-two a))
(define c (offset1 a))
(s8vector? a)                ; #t             #t            #t
(s8vector? b)                ; #f             #t            #t
(s8vector? c)                ; #f             #t            #t
(s8vector-ref a 1)           ; 2              2             2
(s8vector-ref b 1)           ; bad type       bad type      4
(s8vector-ref c 1)           ; bad type       bad type      1
(array-ref c 1)              ; 1

(define a #s8(1 2 3 4))
(define b (every-two a))
(define c (offset1 a))
(bytevector? a)              ; #t             #t            #t
(bytevector? b)              ; #f             #f            #t
(bytevector? c)              ; #f             #f            #t
(bytevector-s8-ref a 1)      ; 2              #\2           2
(bytevector-s8-ref b 1)      ; bad type       bad type      4
(bytevector-s8-ref c 1)      ; bad type       bad type      1
(array-ref c 1)              ; 1

(define a (list->bitvector '(#t #f #t #t))) ; read syntax for vectors is broken
(define b (every-two a))
(define c (offset1 a))
(bitvector? a)               ; #t             #t            #t
(bitvector? b)               ; #f             #f            #t
(bitvector? c)               ; #f             #f            #t
(bitvector-ref a 1)          ; #f             #f            #f
(bitvector-ref b 1)          ; #t [bad type]  #t            #t
(bitvector-ref c 1)          ; #f [bad type]  #f            #t
(array-ref c 1)              ; #t

should be bad type; to be fixed ------^

Regards,

        Daniel






reply via email to

[Prev in Thread] Current Thread [Next in Thread]