SPDX-FileCopyrightText: 2009 Joo ChurlSoo SPDX-License-Identifier: MIT Title define-lambda-object Author Joo ChurlSoo Abstract This SRFI introduces a macro, DEFINE-LAMBDA-OBJECT which defines a set of procedures, that is, a group, two constructors, and a predicate. The constructors also make a group of procedures, namely lambda objects. The macro extends DEFINE-RECORD-TYPE (SRFI 9) in being more general but much less general than DEFCLASS (CLOS). The macro has no explicit field accessors and mutators but child groups, read-write fields, read-only fields, required fields, optional fields, hidden fields, virtual fields, and automatic fields. Rationale An object created by a constructor procedure is a procedure whose first argument is a symbolized field name that is used to identify fields. The lambda object plays the role of the accessor and mutator of each field. Though the average time required to access a randomly chosen field is more for the lambda object than for the accessors and mutators of most other record-defining macros that use field indices to indentify fields, the lambda object makes the troublesome explicit or implicit accessors and mutators unnecessary. In addition, this makes the accesors and mutators to be automatically `nongenerative' and reduces the role of the predicate procedure. Although DEFINE-RECORD-TYPE of R6RS can also have implicit accessors and mutators, they should know their own record name. Further more, when there are parents, they should know both their own record name and their parents' record names, whch could make users confused, though there is an advantage that a record can have another field with the same name. This macro works not only as DEFINE-RECORD-TYPE with required fields but also as DEFSTRUCT of Common Lisp with optional fields. The automatic field can be used as a procedure that modifies or handles the values of the other fields. When a group has multiple parent groups, all the fields of parent groups must exist in the field spec of the child group in contrary with DEFINE-RECORD-TYPE of R6RS. This is too much trouble in case parent groups have several tens of fields. But it also has the advantage of reconfirming the existence and properties of each field, and making the constructors to be able to be defined irrespectively the order of the parents' fields. From a practical point of view, inheritance may be superfluous in this macro as the lambda object itself has data and methods as well as their accessors and mutators. Specification (define-lambda-object ) --> | ( *) --> ;unamendable group | () ;amendable group --> * * * --> ;read-only field | () ;read-write field --> ( ) ;read-only field | (() ) ;read-write field --> ;automatic field |