Skip to content

Instantly share code, notes, and snippets.

@tafsiri
Created January 2, 2011 04:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tafsiri/762296 to your computer and use it in GitHub Desktop.
Save tafsiri/762296 to your computer and use it in GitHub Desktop.
making objects and types in io
#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