|
|
|
inherit
command to setup a base class for an LogoObject in its constructor. The constructed object will contain all member functions and local variables of the base class. Actually you have to pass the correct arguments to the base class constructor, then afterwards inherit will copy its object table to the table of the LogoObject currently being created.
Example:
be testobj ::p=Point 3 4 ::p2=Point 6 7 (show p'x p'y) (show p2'x p2'y) show (p'distance p2) ::m=Matrix_ p p2 (m'add m) m'print show m'det show (m'x)'x p'hallo p'greet p2'hallo p2'greet m'hallo (m'x)'hallo end be Halloer mytype be hallo (type [Hallo, I am\ ] mytype "\ string [.]) (print) end end be Greeter mytype be greet (type [Greetings from a\ ] mytype [!]) (print) end end be Point x y inherit Halloer "Point inherit Greeter "Point be distance b output sqrt (sqr x-b'x)+(sqr y-b'y) end be incx x=x+1 end be add p x=x+p'x y=y+p'y end be print ::print list x y end be string output list x y end end be Matrix_ x y inherit Halloer "Matrix_ be det output x'x*y'y-x'y*y'x end be add m (x'add m'x) (y'add m'y) end be print x'print y'print ::print Point::string end be string output list x'string y'string end end |
3 4 6 7 4.24264 6 8 12 14 [6 8] [12 14] -12 6 Hallo, I am point 6 8. Greetings from a point! Hallo, I am point 12 14. Greetings from a point! Hallo, I am matrix_ [6 8] [12 14] . Hallo, I am point 6 8. |
|
|
|