[comp.lang.misc] THIS virtual SIMULA question

wrc@nancy (will cook) (11/30/87)

Expires:

References:

Sender:

Followup-To:

Distribution:

Keywords:


I have a rather obscure question about SIMULA, and as there doesn't
seem to be a comp.lang.simula, I submit it here for your help.

I am interested in what happens when a prefix A with a virtual
attribute X is accessed from a subclass using `THIS A.X', where
the subclass redefines the virtual.

The intended meaning of THIS A seems to be that the object should be
accessed AS IF IT WHERE AN INSTANCE OF CLASS A, despite the fact that
it might in face be an instance of a subclass.

But I think the way virtuals are implemented will cause THIS A.X to
access the redefined value, not the original one given in A.  Could
someone fix this code and execute it to find out what happens?  Or
send comments on what you think will/should happen.  I will summarize
the results to the net, if there is any interest.

william cook    Brown University     ihnp4!brunix!wrc
-------------------------------------------------------------------
begin
    class A
        virtual : procedure X;
        begin
            procedure X; begin print "ORIGINAL"; end;

            comment execute the procedure;
            THIS A.X();
            inner;
        end

    A class B
        begin
            procedure X; begin print "REDEFINED"; end;

            comment try to run both procedures;
            THIS A.X();
            THIS B.X();
        end;

    comment try them out;
    new A;
    new B;
    comment will probably print ORIGINAL, ORIGINAL, ORIGINAL, REDEFINED;
end

lomow@calgary.UUCP (12/01/87)

COMMENT
  I compiled and ran the following program (had to add some 
  semi-colons and replaced the prints by outtext/outimage)
  and it produced the following output

	ORIGINAL
	REDEFINED
	REDEFINED
	REDEFINED

  This is consistent with my understanding of the Simula 67 Common Base
  which says (and I don't quote because the quote is quite meaningless)
  that if you redefine a virtual quantity, then only outermost definition
  is accessible and any other definitions of that quantity are inaccessible.
END COMMENT;

begin
    class A;
        virtual : procedure X;
        begin
            procedure X; begin outtext("ORIGINAL"); outimage; end;

            comment execute the procedure;
            THIS A.X;
            inner;
        end;

    A class B;
        begin
            procedure X; begin outtext("REDEFINED"); outimage; end;

            comment try to run both procedures;
            THIS A.X;
            THIS B.X;
        end;

    comment try them out;
    new A;
    new B;
    comment will probably print ORIGINAL, ORIGINAL, ORIGINAL, REDEFINED;
end

-- 
Greg Lomow
	lomow@cpsc.calgary.cdn
      or
	....![ubc-vision,ihnp4]!alberta!calgary!lomow