guile-user
[Top][All Lists]
Advanced

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

hidden feature of vector-copy or bug?


From: Damien Mattei
Subject: hidden feature of vector-copy or bug?
Date: Sun, 6 Aug 2023 11:13:29 +0200

hello,

i'm maintaining and developing some code i wrote which is using
something is a hidden feature or bug in vector-copy?

here is the code but there no need to understand it, the problem is
explained after

;; scheme@(guile-user)> (define gva (growable-vector 1 2 3 4 5))
;; scheme@(guile-user)> (define gva2 (growable-vector-resize gva 8))
;; growable-vector-resize : new-vector :#(1 2 3 4 5 #<unspecified>
#<unspecified> #<unspecified>)
;; scheme@(guile-user)> (describe gva2)
;; #<<growable-vector> 10394d640> is an instance of class <growable-vector>
;; Slots are:
;;      v = #(1 2 3 4 5 #<unspecified> #<unspecified> #<unspecified>)
(define-method (growable-vector-resize (gv <growable-vector>)
(new-size <integer>)) ;; fill unspecified
  (define actual-size (vector-length gv))
  (define old-vector (growable-vector-v gv))
  (define new-vector (vector-copy old-vector 0 new-size))
  ;;(display "growable-vector-resize : new-vector :") (display
new-vector) (newline)
  (growable-vector-set-v! gv new-vector))

it seems that vector-copy when given a end-index greater than the
length of vector to copy does not return an error but create a new
vector of the good size indeed:

scheme@(guile-user)> (define v (make-vector 7 1)
)
scheme@(guile-user)> v
$2 = #(1 1 1 1 1 1 1)
scheme@(guile-user)> (vector-copy v)
$3 = #(1 1 1 1 1 1 1)
scheme@(guile-user)> (vector-copy v 0 10)
$4 = #(1 1 1 1 1 1 1 #<unspecified> #<unspecified> #<unspecified>)

here 10 is greater than (length v) but it works and return:
#(1 1 1 1 1 1 1 #<unspecified> #<unspecified> #<unspecified>)

but the doc does not specify that:
"Scheme Procedure: vector-copy vec [start [end]]C Function:
scm_vector_copy (vec)

Returns a freshly allocated vector containing the elements of vec in
the range [start ... end). start defaults to 0 and end defaults to the
length of vec."

by default end is length of vec, so if i specify an end greater than
length of vec should it not be normal to return an error?

Damien



reply via email to

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