Lesson 7 Intro

IMPORTANT: Welcome to Scheme

At this point onwards, we will be using the Scheme language. If you're reading this message, that means that we are still working on transitioning to Racket on this section. The following lesson and all lessons afterwards will be from our old curriculum, and is written in Scheme.

See this guide for instructions on setting up your laptop with STk.

For our lessons, the semantics for Scheme are nearly identical, except for these major differences:

  • To run the STk interpreter, type stkw or stk-simply into the terminal. If you have a Windows computer, only stk-simply will work.
  • Instead of require-ing a file, you should load it. For example, typing (load "hw7.scm") into the interpreter will load the file into STk.
  • Multiple definitions are allowed. In your .scm file, Scheme will allow you to define functions twice, and will also allow you to define functions that override built-in functions, e.g., (define (map f lst) 5) will override the map HOF.

Of course, the differences between STk and Racket are not limited to these, but the ones above are the differences that you absolutely need to know.

Thank you for your patience!

Object Oriented Programming (OOP)

One of the main advantages of using generic operators is that new modules can be designed and added to pre-existing modules without modifying the pre- existing code. Object oriented programming is another technique that has this advantage. This is the second major programming paradigm that we are studying, after functional programming.

The Big Idea of object oriented programming is to have data that knows how to perform computations on itself. For example, a number could be represented as an object that knows how to be added to, subtracted from, multiplied with, or divided by another number. This allows programmers to build modules independently. To create a new data representation, a programmer creates a class, which is like a blueprint for objects, that specifies the data to be stored in an object of that class, and what computations can be performed on such objects. The three main ideas that make object-oriented programming possible are message passing, local state and inheritance.

In order to use the OOP language in Sublime, you must first enter the following into the Stk interpreter:

(load "~cs61as/lib/obj.scm")

Afterwards, you will be able to call define-class and ask as necessary.


You need to be done with Unit 2, especially the subsection with "Data Directed" and "Message Passing".


The majority of the content of this lesson is taken from this note.

This is a handy cheatsheet we recommend you use for the homework and quiz.

You should also check out the old lecture notes here.


When we are coding in OOP, we are dealing with objects or "smart data" that know how to do operations internally and how to interact with other objects. For example, we can have an object Fred of type human. He internally knows how to eat other objects, say, dumpling. OOP then allows us to "Ask Fred to eat dumpling".


Programmers who use OOP language have special vocabularies to describe different components of OOP. In the example above, Fred is an instance and the general category of human is a class.

Scheme does not natively support OOP, but we have an extension that provides OOP to Scheme. This lab will focus on "Above the Line" of abstraction for OOP. We will see how to design a class and make objects using the given framework. If you are interested in how OOP is actually implemented in Scheme, don't worry, one of our future lessons will cover exactly that.


In this subsection, you learned the general idea of the following terms:

  • Object Oriented Programming (OOP)
  • Object
  • Instance
  • Class

What's Next?

It's time to learn how to play with OOP and define your own class!