Next: , Previous: , Up: methods concrete   [Contents][Index]


7.1.2 Field methods

When methods are defined for record-types: method names cannot be equal to field names; field accessors and mutators are accessible as methods automatically, with a method name equal to the field name. The syntax of method-call is:

(method-call ?name ?subject-expr ?arg ...)

when there are no ?arg operand the syntax is compatible with a field accessor call; when there is a single ?arg operand the syntax is compatible with a field mutator call.

So we can access and mutate fields as follows:

(define-record-type <alpha>
  (fields (mutable a)))

(define O
  (new <alpha> 1))

(.a O)          ⇒ 1
(.a O 2)
(.a O)          ⇒ 2