ChezScheme icon indicating copy to clipboard operation
ChezScheme copied to clipboard

define-record-type methods and interfaces

Open dybvig opened this issue 3 years ago • 6 comments

This pull request extends define-record-type with methods, effectively converting define-record-type into a class-definition form in support of object-oriented programming. It adds a define-interface form and a define-record-type implements clause to support multiple interface inheritance. While object-oriented programming obscures control flow, tends to encourage an overly imperative style of programming, and is often overused when it's available, it has its uses when used judiciously. This particular OOP subsystem, at least, supports a functional style of programming: allocation and initialization is inexpensive as well as functional, and fields are immutable by default. The essentials of the implementation come from a define-class form that Oscar Waddel and I designed and implemented many years ago, the code for which had been sitting in mats/oop.ss; only its recasting into an extension of define-record-type is new.

The pull request adds a couple of other things that are useful independently of the support for methods and interfaces; these are described in the LOG.

dybvig avatar Dec 04 '21 04:12 dybvig

Will there be a way to ask if an object implements an interface without walking the result of record-type-interfaces? An auto-generated procedure named interface-name? like what define-record-type does would be nice. Also, when specifying either a methods or implements clause, I can't seem to retrieve rtd information with record-type-descriptor; it says unrecognized record: Foo. Is that intentional?

gwatt avatar Dec 06 '21 20:12 gwatt

已收到

Sshanfeng avatar Dec 07 '21 15:12 Sshanfeng

@jltaylor-us I will add csug updates and a release note when and if we decide to proceed with this. Thanks for the fixes, which will be incorporated in my next commit.

dybvig avatar Dec 07 '21 15:12 dybvig

@gwatt record-type-descriptor should work for record types with methods but didn't due to a missing call to unwrap-drtinfo. Thanks for pointing that out and for the suggestion for interface-name? predicates. Both changes will be in my next commit.

dybvig avatar Dec 07 '21 15:12 dybvig

Would the facilities for custom readers, writers, hash functions, and equality tests that are currently present in Chez Scheme be made part of this interface facility?

sunderroy avatar Jan 22 '22 07:01 sunderroy

@sunderroy Yes, there's nothing preventing operations on records in general from working on records with methods.

dybvig avatar Feb 04 '22 17:02 dybvig