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


12 Friend functions

Friend functions are used to access private, public and protected members of a record–type from outside of the record–type’s methods.

Syntax: define/friend (?typed-who (brace ?subject ?type) . ?formals) . ?body

Define a function like define/checked would do, but give private access to the members of the record–type ?type for the argument ?subject.

The new function is not a member of the record–type, so it does not influence the compliance of the record–type with interface types.

Usage example:

(define-record-type <duo>
  (private
    (fields one two)))

(define/friend ({add <number>} {O <duo>})
  (+ (.one O) (.two O)))

(define O
  (new <duo> 1 2))

(add O)  ⇒ 3