CSC302 2011S Programming Languages
[Skip to Body]
Admin:
[Front Door]
[Schedule]
[Handouts]
[Honesty]
[Piazzza]
Current:
[Current Outline]
[Current EBoard]
[Current Assignment]
[Current Lab]
[Current Reading]
Groupings:
[Assignments]
[EBoards]
[Examples]
[Exams]
[Handouts]
[Labs]
[Outlines]
[Readings]
[Reference]
Languages:
[Clojure]
[Erlang]
[Haskell]
[Io]
[Prolog (GNU)]
[Ruby]
[Scala]
Misc:
[SamR]
[CSC302 2007S]
[7L7W]
Summary: We begin our exploration of the Io programming language.
Prerequisites: Sections 3.1 and 3.2 of Tate. Experience with Linux.
Contents:
a. Create a directory for the lab.
b. Verify that Io is installed on the workstation you're using. If not, you can ssh to church, where it's installed.
a. Create an Io class
, Person. Include slots
first and last to hold the first and
last name. (Yes, I know, requiring first and last names is not always
appropriate for names.) Make them default values ("FIRST"
for the first name, "LAST" for the last name).
b. Create an object for yourself that extends Person.
Determine what your default first name and last name are. Then,
replace them with your own.
c. Add a method to Person that builds a full name
(first space last). You can reference the current objects
with self. You can concatenate strings with
.. (two periods).
d. Run this method using the Person class.
e. Run this method using your own object.
f. Make a clone of yourself and change the first name. Predict what the full name method will return. Check your answer experimentally.
a. Create an Io class
, Course, that has one slot,
instructor.
b. Create an object for this course (csc302).
c. Make yourself the instructor.
d. What do you expect the result of the following to be?
csc302 instructor fullname
e. Check your answer experimentally.
One of the questions we asked in Ruby was whether Ruby checks the types in the body method when the method is declared or when the method is called. Let's see what Io does.
a. We'll start with an invalid expression. Make sure that the following is invalid.
3 + "hello"
b. Create an object, experiment.
c. Add the following method to experiment and determine
whether it fails at declaration time or evaluation time.
experiment incorrect = method ( 3 + "hello" )
a. Create an objects (a clone of Object), alpha.
and beta.
b. To the basic Object object, add a method of the form
Object doit := method ((self stuff) .. (self stuff) .. (self stuff))
c. What do you expect the result of the following to be?
Object doit alpha doit
d. Check your answer, experimentally.
e. To alpha, add a slot named stuff that contains
a string of your choice.
f. What do you expect the result of the following to be?
Object doit alpha doit
g. Check your answer, experimentally.
Remember the incorrect method from a previous exercise? Let's
see what duck typing suggests about that approach.
a. Verify that experiment incorrect still fails.
b. Override the + method for the object 3.
3 + = method(x,x)
c. What do you expect experiment incorrect to produce now?
d. Check your answer experimentally.
e. What do you expect 3 + 4 to return?
f. Check your answer experimentally.
g. What do you expect 4 + 3 to reutrn?
h. Check your answer experimentally.
As you've no doubt noted, in Io inheritance is done through prototypes,
which you can access with the proto slot.
Write a method, top, that determines if an object
is a top level object
, one whose parent is Object
Io> Course top ==> true Io> csc302 top ==> false Io> Object top ==> false
Write a method that traces an Io hierarchy. (That is, your method should print the name and fields of the current object, check if the class is top level and, if not, recurse on the prototype.
[Skip to Body]
Admin:
[Front Door]
[Schedule]
[Handouts]
[Honesty]
[Piazzza]
Current:
[Current Outline]
[Current EBoard]
[Current Assignment]
[Current Lab]
[Current Reading]
Groupings:
[Assignments]
[EBoards]
[Examples]
[Exams]
[Handouts]
[Labs]
[Outlines]
[Readings]
[Reference]
Languages:
[Clojure]
[Erlang]
[Haskell]
[Io]
[Prolog (GNU)]
[Ruby]
[Scala]
Misc:
[SamR]
[CSC302 2007S]
[7L7W]
Disclaimer:
I usually create these pages on the fly
, which means that I rarely
proofread them and they may contain bad grammar and incorrect details.
It also means that I tend to update them regularly (see the history for
more details). Feel free to contact me with any suggestions for changes.
This document was generated by
Siteweaver on Mon Apr 25 08:06:47 2011.
The source to the document was last modified on Wed Feb 2 20:22:35 2011.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CSC302/2011S/Labs/io-1.html.
A PDF version of this document may be found at
http://www.cs.grinnell.edu/~rebelsky/Courses/CSC302/2011S/Labs/io-1.pdf
You may wish to
validate this document's HTML
;
;