2 Class 0
#lang class/0 | package: base |
The class/0 language is the most basic version of the class system. In essence, it extends Intermediate Student with Lambda with the ability to define classes, construct objects that are instances of classes, and to send such objects messages to call methods.
syntax
(require module-name ...)
syntax
(define-class class-name field-names method-or-test ...)
field-names =
| (fields field-name ...) method-or-test = method | test method = (define (method-name variable ...) body)
A method is defined with (define (method-name variable ...) body). Such a definition extends the set of messages every instance of class-name understands. When an object is sent a method-name message and some values, the body of the method definition is evaluated with the values of the arguments in place of the variables. Within a method, this refers to the current object, i.e. the object whose method was called. Every class implicitly defines an accessor methods for each field, so (send this field-name) refers to the value of the field named field-name of this.
A test can be any form of check-expect. Conceptually, each test is lifted out of the class definition and does not exist inside any instance of class-name, therefore tests cannot reference this.
syntax
(new class-name expression ...)
syntax
(send object method-name expression ...)
syntax
(define (method-name variable ...) body)
Outside of a class definition, this form defines a function; it is equivalent to define in ISL/λ.
syntax
syntax
(fields id ...)