Created
January 2, 2011 04:58
-
-
Save tafsiri/762296 to your computer and use it in GitHub Desktop.
making objects and types in io
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#differential inheritance | |
#making types (objects with a type field) | |
Shape := Object clone | |
Shape area := method(width * height) | |
Shape width := 5 | |
Shape height := 9 | |
Rect := Shape clone | |
Square := Shape clone | |
Ellipse := Shape clone | |
#making objects (without a type field, note the lowercase start | |
#to the variable name) | |
box := Rect clone | |
boxyBox := Square clone | |
egg := Ellipse clone | |
# | |
writeln("Differential inheritance") | |
box slotNames println # => list() | |
boxyBox slotNames println # => list() | |
egg slotNames println # => list() | |
Rect slotNames println # => list(type) | |
Square slotNames println # => list(type) | |
Ellipse slotNames println # => list(type) | |
Shape slotNames println # => list(height, type, width, area) | |
#seems like hasSlot will crawl up the inheritance tree | |
box hasSlot("area") println # => true | |
Rect hasSlot("area") println # => true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment