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


4.4 Slots operations for records

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

(define-syntax-rule ($struct-size ?stru)
  (##sys#size ?stru))

(define-syntax-rule ($struct-slot ?stru ?slot-index)
  (##sys#slot ?stru ?slot-index))

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

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

(define-record <spiffy>
  one two)

(define instance
  (make-<spiffy> 'a 'b))

($struct-size instance)         ⇒ 3

($struct-slot instance 0)       ⇒ current-module-name#<spiffy>
($struct-slot instance 1)       ⇒ a
($struct-slot instance 2)       ⇒ b

($struct-slot-set! instance 1 'x)
($struct-slot-set! instance 2 'y)

($struct-slot instance 1)       ⇒ x
($struct-slot instance 2)       ⇒ y

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