Site hosted by Build your free website today!

Object Oriented Programming

Object Oriented Programing (OOP) is very powerfull. Try it!

Adding just a few procedures to your LOGO will enable you to create object programs.

NEW version 2 / 18 /1099

Revisited 1 / 30/ 2019 (just 20 years after :-)

Now destroy and !s are correct

descendants builds the tree of the descendants.

Create creates a descendant link named children

The file object.txt is compatible for both UCB and MSWLOGO.

The method destroy is no more asking any comfirmation !.


Main file:
object.txt (for MSWLOGO or UCBLOGO)
ucbobject.txt (for UCBLOGO)

For UCBLOGO: Click, select all the text, copy it and paste it in the editor.

For MSWLOGO: remove the .txt and put it in your logolib folder. Using the command ! for the first time will load OOP from the librairy.

Usefull utility:

listprint.txt This librairy procedure made by Daniel Ajoy will pretty print a list.


helpoop.txt, the help file; put it in the UCBLOGO or MSWLOGO directrory.


oo.txt ;You can click and read it in your brother.
To try the commands, copy them and paste them at the prompt into logo.
With MSWLOGO if the file is in the directory, it can be opened with the command windowfileedit "oo.txt [],

I just receive the first comment about OO program. And I have now corrected the procedure ancestors which is now working, descendants that uses ancestors is now working too, thanks to Daniel.

I have added the methods "ancestors , descendants and destroy.

Here is a short example how make, remove, add and er are working.

! "object [create "human]
! "human [create "man]
! "human [create "woman]
! "man [create "Peter]
! "woman [create "Mary]

; If you down load the new corrected version ancestors and descendants act as method too.

show ! "mary "ancestors
[woman human object]

show ! "object "descendants
[human man mary peter woman]

! "human [make "food [milk meat vegetables]]

; Puts the value [milk meat vegetables] for food into the object human

show ! "Peter "food
[milk meat vegetables]

; Value inherited by Peter from human

show ! "Mary "food
[milk meat vegetables]

; Value inherited by Mary from human

! "Peter [remove "food "meat]

; Removes meat from the list of values at the level of Peter

; Peter has own food value without meat

show ! "Peter "food
[milk vegetables]

! "Mary [add "food "fruits]

; Adds value fruits to the list of food for Mary , Mary has now own value food.

show ! "Mary "food
[milk meat vegetables fruits]

! "man [create "John ]

show ! "John "food
[milk meat vegetables]

; Value inherited from human.

show ! "Peter "food
[milk vegetables]

; Own value .

! "Peter [er "food]

; Erase the own value of food in Peter

show ! "Peter "food
[milk meat vegetables]

; Value inherited from human since the own value is erased.

! "human "destroy

; Will destroy "human and all descendants.

; Only in the new version .

show last contents
[human man mary peter woman]

! "human "destroy

show last contents

Don'nt hesitate to send me your comments,