[comp.lang.modula3] names of methods and instance variables of OBJECTs

buschman@tubsibr.uucp (Andreas Buschmann) (04/21/91)

Hello,

If I declare a type A beeing an OBJECT with a field named x and a
method named y, am I allowed to declare B beeing A OBJECT with a field
named y and a method named x, or only one of them?

In the report I find:

	The names introduced in FieldList and MethodList must be	(1)
	distinct.

	...

	A field or method in a subtype masks any field or method with	(2)
	the same name in the supertype. To access such a masked field,
	use NARROW to view the subtype variable as a member of the
	supertype. 

The following example compiles ok, but terminates while running with:
fatal error: can't open display ''

MODULE Main;

TYPE O1 = OBJECT i : INTEGER; METHODS m () := p; END;

TYPE O2 = O1 OBJECT m : INTEGER; END;

TYPE O3 = O1 OBJECT METHODS i (); END;

PROCEDURE p (self : O1) =
BEGIN END p;

BEGIN
  EVAL NEW (O2, m := 2);
  EVAL NEW (O3, i := p);
END Main.

this is SRC Modula-3 v1.5 running on a SUN3
on a SUN4 running v1.6 ther is no error message, it just runs.

so does (1) include the names used in the super classes or not? And
why? 

						Tschuess
							Andreas


 /|)			Andreas	Buschmann
/-|)			TU Braunschweig, Germany (West)	
						  ^^^^  was

bitnet: buschman%tubsibr@dbsinf6.bitnet
uucp:   buschman@tubsibr.uucp

kalsow (Bill Kalsow) (04/22/91)

>  If I declare a type A beeing an OBJECT with a field named x and a
>  method named y, am I allowed to declare B beeing A OBJECT with a field
>  named y and a method named x, or only one of them?

Yes, the following is legal:

    TYPE A =   OBJECT x: INTEGER METHODS y () END;
    TYPE B = A OBJECT y: INTEGER METHODS x () END;

>  In the report I find:
>  
>  	The names introduced in FieldList and MethodList must be	(1)
>  	distinct.
>  
>  	...
>  
>  	A field or method in a subtype masks any field or method with	(2)
>  	the same name in the supertype. To access such a masked field,
>  	use NARROW to view the subtype variable as a member of the
>  	supertype. 

>  so does (1) include the names used in the super classes or not? And
>  why? 

No, "FieldList" and "MethodList" are names for syntactic pieces of an object
declaration.  They are not the set of all field or method names in the object.

>  The following example compiles ok, but terminates while running with:
>  fatal error: can't open display ''

Usually, "can't open display" indicates that your program cannot contact
an X server.  I doubt it's a Modula-3 problem.


  - Bill Kalsow