The procedure ! sends a message to an object. Object is a name Message is either a name (method 's name or value's name) or a list method name + parameters In a method the variable :object contains the name of the object recieving the message at run time. The procedure !o (message to current object) is equivalent to ! :object The procedure !s (Message to super object ) is like !o but sends the message to the parent of the object. If you are reading this text from the MSWLOGO editor, ------------ Use of the tutorial. You can hilite the commands with the mouse and execute them using the test button. The procedures have to be copied and pasted in an other editor window. ------------ ; Creating an object poly child of object ! "object [create "poly] ; Creating a variable nsides containing 5 ! "poly [make "nsides 5] ; Creating a variable size containing 100 ! "poly [make "size 100] ; seeing the value of nsides in poly show ! "poly "nsides 5 ; Defining a method to draw a polygon. ; A method is like a procedure but attached to an object. ! "poly [method "draw] ; This command opens the editor to edit the procedure " ; poly.draw The name is made of object's name and method's name ; If the procedure is already defined the editor is opened with ; the text of the procedure. ; copy this text and paste it in the editor. to poly.draw [:ns !o "nsides][:s !o "size ] repeat :ns [fd :s rt 360 / :ns] end ; !o is used inside a method. It sends a message : to the object recieving the message at run time. ; !o "nsides ask the value of nsides to the object ; recieving the message. ! "poly "draw ; Will draw the polygon using the values of nsides and ; size in poly (or inherited by poly). ! "poly [create "square] ; square a child of poly cs ! "square "draw ; Draw a pentagon while square inherits the ; values of nsides and size from poly. ! "square [make "nsides 4] ; Put the correct value for square ; will replace the inherited value. cs ! "square "draw ; draw a square ! "square [create "littlesquare] ! "littlesquare [make "size 20] cs ! "littlesquare "draw ; draw a little square ; nsides inherited size owned ! "object [method "display] ; will display an object at a position to object.display pu setpos !o "position setheading !o "orientation penreverse ; drawing twice will erase !o "draw ; draw the object at position with orientation end ! "object [make "position [0 0]] ; default to center ! "object [make "orientation 0] ; default to north cs ! "littlesquare "display ! "littlesquare [make "position [100 100]] cs ! "littlesquare "display ; draw littlesqare at new position ! "object [method "setposition] to object.setposition :pos !o "display ; erase object at old position !o [make "position :pos] ; change the position value !o "display ; draw object at new position end ! "object [method "setorientation] to object.setorientation :or !o "display ; erase object with old orientation !o [make "orientation :or] ; change the orientation value !o "display ; draw object with new orientation end ! "littlesquare [setposition [-100 0]] ; deplaces the object ! "square "display ;draw square at [0 0] the default postion ! "square [setposition [100 100]] ; deplaces the square ! "object [create "shape] ! "shape [method "draw] to shape.draw pr [Create a descendant with its own method draw] end ! "shape "draw ; Warning each shape should have its own method draw ! "shape [create "house] ! "house [method "draw] to house.draw fd 50 rt 60 fd 20 rt 60 fd 20 rt 60 fd 50 rt 90 fd 40 rt 90 end ! "house "display ! "house [setposition [-100 100]] ; setposition acts on house too ; The same method name in differents objects doing the same thing that's : polymorphism ; I hope you have enjoyed this demo now try by yourself.