chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Chicken-users] type extension ("inheritance") and define-record


From: Pedro Henrique Antunes de Oliveira
Subject: [Chicken-users] type extension ("inheritance") and define-record
Date: Sun, 17 Jul 2011 12:44:57 -0300

Hey.

I've thought about derived types, defined with define-record, having
the base type as a field in it. Like in

(define-record person name address other-info)

(define-record employee company person)

The employee type would extend the person type, and the person type
information is in the field person.

I've created a function make-replacer and a macro set-replacers!,
which kinda re-define the procedures defined by define-record that
give access to the fields of a type defined by it so that it would
work for derived types such as the employee and person example. So,
for example, person-name would work on an employee.

http://pastebin.com/fXu1J0iU

That is the implementation with an example of how it could be used.

The fine thing about it is that I only need to use set-replacers! on
the interface generated by define-record. All the procedures that were
made to work on the base type will work on the derived type too,
because the bindings were set!.

However, I don't quite know if that is a good thing to do. Not for
design reasons, but the implementation itself. Does it work for all
cases? Is there a problem there? I think there is, but I've tested
here at home and I couldn't find any problems.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]