Simulating inheritance with a metainterpreter
From: seguso (look_at_in.signature)
Date: 04/20/04
- Next message: Cesar Rabak: "Re: Simulating inheritance with a metainterpreter"
- Previous message: seguso: "Re: Again on polymorphism."
- Next in thread: Cesar Rabak: "Re: Simulating inheritance with a metainterpreter"
- Reply: Cesar Rabak: "Re: Simulating inheritance with a metainterpreter"
- Reply: Paul Tarau: "Re: Simulating inheritance with a metainterpreter"
- Reply: Stephan Lehmke: "Re: Simulating inheritance with a metainterpreter"
- Reply: Andrew Eremin: "Re: Simulating inheritance with a metainterpreter"
- Reply: Alan Bal jeu: "Re: Simulating inheritance with a metainterpreter"
- Reply: Paulo Moura: "Re: Simulating inheritance with a metainterpreter"
- Reply: Bill Spight: "Re: Simulating inheritance with a metainterpreter"
- Reply: Lex Spoon: "Re: Simulating inheritance with a metainterpreter"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 20 Apr 2004 18:12:25 GMT
Hi there you gurus. This is more difficult. :-)
Having made sure that prolog does support polymorphism, I would like to
decrease the amount of code to be written in the following typical
situation:
Suppose I have a semantic domain made of "boxes" and "activeBoxes". A "box"
has 4 predicates defined over it (say size/2, color/2, setSize/2 and
setColor/2). An "activeBox" is a "box" with a speed. So it has an
additional predicate speed/2. But ANY predicate which works when passed a
box must continue to work if passed and activeBox. And work as intended :-)
In C++ and similar I would use inheritance. So I would define the four
predicates only once. In prolog I must define all the predicates twice
(once for box and once for abox):
size(box(Siz, _), Siz).
color(box(_, C), C).
setSize(box(_, C), Siz, box(Siz, C)).
setColor(box(S, _), C, box(S, C)).
size(abox(Siz, _, _), Siz).
color(abox(_, C, _), C).
setSize(abox(_, C, Sp), Siz, abox(Siz, C, Sp)).
setColor(abox(S, _, Sp), C, abox(S, C, Sp)).
speed(abox(_, _, Sp), Sp). %unique to abox
It is quite boring to redefine all predicates that can be applied to box for
activeBox. In C++ I just need to say
class ActiveBox : public Box
and this is done almost automatically (with some effort in the constructor).
I would like to simplify the above prolog code with something like:
size(box(Siz, _), Siz).
color(box(_, C), C).
setSize(box(_, C), Siz, box(Siz, C)).
setColor(box(S, _), C, box(S, C)).
speed(abox(_, _, Sp), Sp). % I define only this one for abox.
inherits(abox, box).
and write a metainterpreter that, when it encounters inherits, behaves as if
the four predicates were defined for abox too.
Of course writing inherits(abox, box) is not enough: it doesn't tell the
arity, and it doesn't define the correspondence between the size/color of a
box and the size/color of an abox. But how can we tell those info to the
metainterpreter?
PS: I would also be interested in the performance loss of using such a
metainterpreter.
Thank you very much for any idea!
-- Best Regards, Maurizio Colucci Please remove the uppercase letters "S,P,A,M": seSgPuAsMo.forever@tin.it
- Next message: Cesar Rabak: "Re: Simulating inheritance with a metainterpreter"
- Previous message: seguso: "Re: Again on polymorphism."
- Next in thread: Cesar Rabak: "Re: Simulating inheritance with a metainterpreter"
- Reply: Cesar Rabak: "Re: Simulating inheritance with a metainterpreter"
- Reply: Paul Tarau: "Re: Simulating inheritance with a metainterpreter"
- Reply: Stephan Lehmke: "Re: Simulating inheritance with a metainterpreter"
- Reply: Andrew Eremin: "Re: Simulating inheritance with a metainterpreter"
- Reply: Alan Bal jeu: "Re: Simulating inheritance with a metainterpreter"
- Reply: Paulo Moura: "Re: Simulating inheritance with a metainterpreter"
- Reply: Bill Spight: "Re: Simulating inheritance with a metainterpreter"
- Reply: Lex Spoon: "Re: Simulating inheritance with a metainterpreter"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|