|[ < ]||[ > ]||[ << ]||[ Up ]||[ >> ]||[Top]||[Contents]||[Index]||[ ? ]|
Gauche has a special hook to make an arbitrary object applicable.
This can be explained better by examples.
For example, suppose you try to evaluate the following expression:
The operator evaluates to a string, which is neither a procedure nor a generic fuction. So Gauche interpretes the expression as if it were like this:
(object-apply "abcde" 2)
Gauche doesn't define a method of
object-apply that takes
<integer> by default, so this signals an error.
However, if you define such a method:
(define-method object-apply ((s <string>) (i <integer>)) (string-ref s i))
Then the first expression works as if a string is applied on the integer:
("abcde" 2) => #\c
This mechanism works on almost all occasions where a procedure is allowed.
(apply "abcde" '(1)) => (#\b) (map "abcde" '(3 2 1)) => (#\d #\c #\b)
Among Gauche built-in objects,
<regexp> object and
<regmatch> object have
See section 6.11 Regular expression.
set!form, this method is called, that is:
(set! (object arg ...) value) => ((setter object-apply) object arg ... value)