Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

define-record-type methods and interfaces #596

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

dybvig
Copy link
Member

@dybvig dybvig commented Dec 4, 2021

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.

Copy link
Contributor

@jltaylor-us jltaylor-us left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool! CSUG updates coming?

I suppose theoretically all of the edited files that have the standard copyright / license header should have the copyright date updated.

LOG Outdated Show resolved Hide resolved
LOG Outdated Show resolved Hide resolved
LOG Outdated Show resolved Hide resolved
LOG Show resolved Hide resolved
s/record-defn.ss Outdated Show resolved Hide resolved
@gwatt
Copy link
Contributor

gwatt commented Dec 6, 2021

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?

@Sshanfeng
Copy link

Sshanfeng commented Dec 7, 2021 via email

@dybvig
Copy link
Member Author

dybvig commented Dec 7, 2021

@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
Copy link
Member Author

dybvig commented Dec 7, 2021

@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.

@sunderroy
Copy link

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?

interfaces; added new open-interface form; various other changes.
see LOG for details.
@dybvig
Copy link
Member Author

dybvig commented Feb 4, 2022

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

LOG Outdated Show resolved Hide resolved
s/record-defn.ss Outdated Show resolved Hide resolved
Copy link

@genericist genericist left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a little typo I spotted :)

(error? ; invalid syntax
(define-interface (rat israt?) (methods a b c)))
(error? ; invalid syntax
(define-interface rat (mehtods)))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(define-interface rat (mehtods))

should be

(define-interface rat (methods))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants