DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH
 

(guile.info.gz) Vector Accessors

Info Catalog (guile.info.gz) Vector Creation (guile.info.gz) Vectors
 
 22.3.3 Accessing and Modifying Vector Contents
 ----------------------------------------------
 
 `vector-length' and `vector-ref' return information about a given
 vector, respectively its size and the elements that are contained in
 the vector.
 
  -- Scheme Procedure: vector-length vector
  -- C Function: scm_vector_length vector
      Return the number of elements in VECTOR as an exact integer.
 
  -- Scheme Procedure: vector-ref vector k
  -- C Function: scm_vector_ref vector k
      Return the contents of position K of VECTOR.  K must be a valid
      index of VECTOR.
           (vector-ref '#(1 1 2 3 5 8 13 21) 5) => 8
           (vector-ref '#(1 1 2 3 5 8 13 21)
               (let ((i (round (* 2 (acos -1)))))
                 (if (inexact? i)
                   (inexact->exact i)
                      i))) => 13
 
    A vector created by one of the dynamic vector constructor procedures
 ( Vector Creation) can be modified using the following
 procedures.
 
    _NOTE:_ According to R5RS, it is an error to use any of these
 procedures on a literally read vector, because such vectors should be
 considered as constants.  Currently, however, Guile does not detect this
 error.
 
  -- Scheme Procedure: vector-set! vector k obj
  -- C Function: scm_vector_set_x vector k obj
      Store OBJ in position K of VECTOR.  K must be a valid index of
      VECTOR.  The value returned by `vector-set!' is unspecified.
           (let ((vec (vector 0 '(2 2 2 2) "Anna")))
             (vector-set! vec 1 '("Sue" "Sue"))
             vec) =>  #(0 ("Sue" "Sue") "Anna")
 
  -- Scheme Procedure: vector-fill! v fill
  -- C Function: scm_vector_fill_x (v, fill)
      Store FILL in every position of VECTOR.  The value returned by
      `vector-fill!' is unspecified.
 
  -- Scheme Procedure: vector-move-left! vec1 start1 end1 vec2 start2
  -- C Function: scm_vector_move_left_x (vec1, start1, end1, vec2,
           start2)
      Copy elements from VEC1, positions START1 to END1, to VEC2
      starting at position START2.  START1 and START2 are inclusive
      indices; END1 is exclusive.
 
      `vector-move-left!' copies elements in leftmost order.  Therefore,
      in the case where VEC1 and VEC2 refer to the same vector,
      `vector-move-left!' is usually appropriate when START1 is greater
      than START2.
 
  -- Scheme Procedure: vector-move-right! vec1 start1 end1 vec2 start2
  -- C Function: scm_vector_move_right_x (vec1, start1, end1, vec2,
           start2)
      Copy elements from VEC1, positions START1 to END1, to VEC2
      starting at position START2.  START1 and START2 are inclusive
      indices; END1 is exclusive.
 
      `vector-move-right!' copies elements in rightmost order.
      Therefore, in the case where VEC1 and VEC2 refer to the same
      vector, `vector-move-right!' is usually appropriate when START1 is
      less than START2.
 
Info Catalog (guile.info.gz) Vector Creation (guile.info.gz) Vectors
automatically generated byinfo2html