CS 3060: Programming Languages

Io

Robert C. Green II, Ph.D.

Day 2

External Things

The Importer proto implements Io's built-in auto importer feature. If you put each of your proto's in their own file, and give the file the same name with and ".io" extension, the Importer will automatically import that file when the proto is first referenced. The Importer's default search path is the current working directory, but can add search paths using its addSearchPath() method.

External Things

						
			doFile("myFancyThings.io")
						
					

File I/O

						
			myFile := File with(fName)
			myFile openForReading

			myFile foreachLine(i, curLine,
			    
			    vals := curLine split(" ")

			    #... Do yo' Thing ...
			)

			myFile close
			    			
					

Cloning Objects

						
			myList := List clone
			myList type
						
					
						
			Vehicle := Object clone
			Vehicle type
						
					
You prototype new objects by cloning existing ones

Objects & Slots

						
		Vehicle description := "Awesome Car"
		Vehicle description
						
					
  • Objects are collections of slots
  • You make objects by cloning other objects
  • You get a slot's value by sending the message

Inheritance

						
		Vehicle := Object clone
		Vehicle description := "Awesome Car"

		Car := Vehicle clone
		Car slotNames
		Car type
		Car description

		ferrari := Car clone
		ferrari slotNames
						
					
What's a Type? An Object? A Prototype?

Inheritance

						
			ferrari := Car clone
			ferrari slotNames

			Ferrari := Car clone
			Ferrari slotNames
						
					

Fundamental Rules

  • Every thing is an object.
  • Every interaction with an object is a message.
  • You don't instantiate classes; you clone other objects called prototypes.
  • Objects remember their prototypes.
  • Objects have slots.
  • Slots contain objects, including method objects.
  • A message returns the value in a slot or invokes the method in a slot.
  • If an object can't respond to a message, it sends that message to its prototype.

Messages

Bruce, there's something you have to understand about Io. Almost everything is a message.
  • Sender: Sends a message
  • Target: Receives and executes a message
  • Arguments: The contents of a message

Messages

						
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)))
)

unless(1 == 2, write("One is not two\n"), write("one is two\n"))
						
					

Reflection

						
slotNames

protos

getSlot("slotName")

code
						
					

Assignment

Assignment #2

Read Day 3