Re: Simulating inheritance with a metainterpreter
From: Lex Spoon (lex_at_cc.gatech.edu)
Date: 04/26/04
- Previous message: Cl?ment: "A new solution to the N-queens problem ?"
- In reply to: seguso: "Simulating inheritance with a metainterpreter"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 25 Apr 2004 23:50:55 -0400
seguso <look@in.signature> writes:
> 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 :-)
I've been thinking about this. Instead of writing all the predicates
for all the classes, you can write abstracting routines that take a
subclass and re-represent it as the superclass. Then you can write
your predicates once each, but have them prefixed by calling the
abstraction routine.
In this case, the code would look like this:
asBox(box(Siz, Color), box(Siz, Color)) .
asBox(abox(Siz, Color, Speed), box(Siz, Color)) .
size(GenericBox, Siz) :- asBox(GenericBox, box(Siz, _)).
color(GenericBox, Color) :- asBox(GenericBox, box(_, Color)) .
Not as nice as in an OO language, but it still seems reasonable. Note
also that asBox is abstract here; you can fill in more options
whenever you write a new "class" that you want to be polymorphic with
boxes.
-Lex
- Previous message: Cl?ment: "A new solution to the N-queens problem ?"
- In reply to: seguso: "Simulating inheritance with a metainterpreter"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]