Next: methods virtual, Up: methods [Contents][Index]
We can think of method as acting like define/checked
with regard to the syntax of arguments to function; the first argument
to a method is the record itself, but it is implicit: we can access it
using the fluid syntax this. For example, using the procedural
coding style:
(define-record-type <duo>
(strip-angular-parentheses)
(fields one two)
(method (sum-them)
(+ (duo-one this)
(duo-two this)))
(method (mul-them)
(* (duo-one this)
(duo-two this))))
(define O
(make-duo 1 2))
(method-call sum-them O) ⇒ 3
and using the object–oriented syntax style:
(define-record-type <duo>
(fields one two)
(method (sum-them)
(+ (.one this)
(.two this)))
(method (mul-them)
(* (.one this)
(.two this))))
(define O
(new <duo> 1 2))
(.sum-them O) ⇒ 3
The syntax method-call searches for a record–type’s methods by
using eq? to search for the method’s name, as symbol, in the
record–type’s internal table of methods (it does not use the
syntactic identifiers with free-identifier=?). Calling object–type methods.
| • methods concrete overloaded: | Overloaded methods. | |
| • methods concrete fields: | Field methods. | |
| • methods concrete override: | Overriding methods. |