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 / 99

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) , rename it ! and put it in logolib. 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. , remove the .txt and put it in your logolib folder.


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


oo.txt ; put it in the UCBLOGO or MSWLOGO directrory.
The file oo.txt can be used for tutorial.
With MSWLOGO it can be opened with the command windowfileedit "oo.txt [],
With UCBLOGO you have to use a text editor (teachtext for insrtance) to see it. With UCBLOGO , use a text editor to read it.

You can try the commands just by highlighting them and clicking on the button test of the Editor window in MSWLOGO.

With UCBLOGO use copy and paste.

I just recieve 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,