In expressions within a class definition, the initialization variables, fields, and methods of the class are all part of the environment. Within a method body, only the fields and other methods of the class can be referenced; a reference to any other class-introduced identifier is a syntax error. Elsewhere within the class, all class-introduced identifiers are available, and fields and initialization variables can be mutated with set! .
Method names used within a class can only be used in the procedure position of an application expression; any other use is a syntax error.
To allow methods to be applied to lists of arguments, a method application can have the following form:
(method-idarg.... arg-list-expr)
This form calls the method in a way analogous to (apply method-idarg... arg-list-expr). The arg-list-expr must not be a parenthesized expression.
Methods are called from outside a class with the send , send/apply , and send/keyword-apply forms.
If obj-expr does not produce an object, the exn:fail:contract exception is raised. If the object has no public method named method-id, the exn:fail:object exception is raised.
syntax
( send/apply obj-exprmethod-idarg...arg-list-expr)
syntax
keyword-list-exprvalue-list-exprarg...arg-list-expr)
syntax
( send* obj-exprmsg...+)
msg = (method-idarg...)| (method-idarg.... arg-list-expr)
For example,
(insert"Hello")(insert#\newline)(end-edit-sequence))
is the same as
syntax
( send+ obj-exprmsg...)
msg = (method-idarg...)| (method-idarg.... arg-list-expr)
This is the functional analogue of send* .
'(17 . 7)
syntax
body...+)
Example:
[pop(spop!)])(push10)(push9)(pop)))
is the same as
syntax
( get-field idobj-expr)
If obj-expr does not produce an object, the exn:fail:contract exception is raised. If the object has no id field, the exn:fail:object exception is raised.
procedure
( dynamic-get-field field-nameobj)→any/c
field-name:symbol?obj:object?
syntax
( set-field! idobj-exprexpr)
If obj-expr does not produce an object, the exn:fail:contract exception is raised. If the object has no id field, the exn:fail:object exception is raised.
procedure
( dynamic-set-field! field-nameobjv)→void?
field-name:symbol?obj:object?v:any/c
syntax
( field-bound? idobj-expr)
If obj-expr does not produce an object, the exn:fail:contract exception is raised.
syntax
( class-field-accessor class-exprfield-id)
If class-expr does not produce a class, the exn:fail:contract exception is raised. If the class has no field-id field, the exn:fail:object exception is raised.
syntax
( class-field-mutator class-exprfield-id)
If class-expr does not produce a class, the exn:fail:contract exception is raised. If the class has no field-id field, the exn:fail:object exception is raised.
A generic can be used instead of a method name to avoid the cost of relocating a method by name within a class.
syntax
( generic class-or-interface-exprid)
If class-or-interface-expr does not produce a class or interface, the exn:fail:contract exception is raised. If the resulting class or interface does not contain a method named id, the exn:fail:object exception is raised.
syntax
( send-generic obj-exprgeneric-exprarg...)
If obj-expr does not produce an object, or if generic-expr does not produce a generic, the exn:fail:contract exception is raised. If the result of obj-expr is not an instance of the class or interface encapsulated by the result of generic-expr, the exn:fail:object exception is raised.
procedure
( make-generic typemethod-name)→generic?
method-name:symbol?