Io_Language

 Object ancestor := method (
     prototype := self proto
     if (prototype != Obejct,
         writeln ("Slots of ",
                  prototype type,
                  "\n------------------"
         )
         prototype slotNames foreach (slotName,
                                      writeln (slotName)
         )
         writeln prototype ancestors
     )
 )

 

 unless := method (
     (
             call sender doMessage (
                     call message argAt(0)
             )
     )
     ifFalse (
             call sender doMessage (
                     call message argAt(1)
             )
     )
     ifTrue (
             call sender doMessage (
                     call message argAt(2)
             )
     )
 )

 Animals.io

    Object ancestors := method (
        prototype := self proto
        if (prototype != Object,
            writeln ("Slots of ", 
                prototype type,
                "\n----------------"
            )
            prototype slotNames foreach (
                slotName, 
                writeln (sloteName)
            )
            writeln prototype ancestors
        )
    )
    
    Animal := Object clone
    Animal speak := method (
        "ambiguous animal noise" println
    )
    Duck := Animal clone
    Duck speak := method (
        "quack" println
    )
    Duck walk := method (
        "waddle" println
    )
    disco := Duck clone
    disco ancestors
            

 

 

posted on 2014-04-26 13:49  thoupin  阅读(332)  评论(1编辑  收藏  举报

导航