unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* hidden feature of vector-copy or bug?
@ 2023-08-06  9:13 Damien Mattei
  2023-08-07 13:54 ` Damien Mattei
  0 siblings, 1 reply; 2+ messages in thread
From: Damien Mattei @ 2023-08-06  9:13 UTC (permalink / raw)
  To: guile-user

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



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-08-07 13:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-06  9:13 hidden feature of vector-copy or bug? Damien Mattei
2023-08-07 13:54 ` Damien Mattei

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).