Next: , Previous: , Up: slots   [Contents][Index]


4.3 Slots operations for vectors

When the block value is a Scheme vector, we could make a more descriptive use of the system operations with the following macros:

(define-syntax-rule ($vector-ref ?vector ?slot-index)
  (##sys#slot ?vector ?slot-index))

(define-syntax-rule ($vector-set! ?vector ?slot-index ?new-value)
  (##sys#setslot ?vector ?slot-index ?new-value))

(define-syntax-rule ($vector-set-immediate! ?vector ?slot-index ?new-value)
  (##sys#setislot ?vector ?slot-index ?new-value))

(define-syntax-rule ($vector-length ?vector)
  (##sys#size ?vector))

(define V
  (vector 'a 'b 'c))

($vector-set! vec 0 'x)
($vector-set! vec 1 'y)
($vector-set! vec 2 'z)

($vector-ref vec 0)     ⇒ x
($vector-ref vec 1)     ⇒ y
($vector-ref vec 2)     ⇒ z

Next: , Previous: , Up: slots   [Contents][Index]