Assignment 1 - Scheme Intro 1
Due: Wednesday, April 1, 2026, at 10pm
Starter code: a1_scheme_1.zip
Upload solutions via Gradescope
Goals
This assignment is designed to help you with the following:
- getting started working with Scheme
- trying out functional programming
Collaboration policy
For this first assignment, you may work alone or with a partner, but you must type up all of the code yourself. (It is therefore unexpected for two code submissions to be completely identical.)
You may also discuss the assignment at a high level with other students.
You should list any student with whom you discussed the assignment, and the manner of discussion (high level, partner, etc.) in your readme.txt file.
If you work alone, you should say so instead.
Assessment
Core requirements:
- demonstrate reasonable attempts made towards Part C
- include a
readme.txtfile with your collaboration statement, sources, and reflection
Note that going forward there will be automated tests that you’ll need to pass to satisfy the Core requirements, but for this one it’s just necessary to demonstrate progress.
Advanced requirements:
- satisfy the Core requirements
- successfully complete Part C
Note that in future assignments there will also be style expectations to satisfy Advanced requirements, but those don’t start quite yet.
Getting started
Before you can get started, you have a few tasks:
-
If you haven’t completed the course Development Setup yet, make sure to do that before continuing.
-
Download the starter files.
-
Decide where to put your work – you’ll need a folder (a.k.a. a directory) to keep your code for this course. The best place is probably the
ProgrammingLanguagesdirectory that you created as part of your Docker setup. -
Drag the folder with the starter files into the folder you’ve chosen. I’ll assume it’s named
ProgrammingLanguagesmoving forward. -
Launch Docker in VS Code, then open the
ProgrammingLanguagesfolder (File->Open Folder). You may see a popup in the lower right corner prompting you to reopen the folder in the Docker container. If so, click through to do so. Otherwise, click the><icon in the lower left corner of VS Code and selectReopen in Containerfrom the dropdown menu.
If you run into problems launching Docker, double-check the Development Setup instructions or reach out to me (Tanya) or Mike Tie for help.
Notes when using VS Code and Docker for this course
- It’s important that you open a folder, not a specific file.
- It’s important to make the new terminal after you open the folder, not before. (This way, the terminal starts in the folder where your code and files are.)
If you ever want to check the current directory (a.k.a. folder) in the terminal, type pwd and then hit return. (pwd stands for “print working directory”.)
Running Scheme
Make sure you have the folder for this assignment open in VS Code, and then open a new terminal window in VS Code (Terminal -> New Terminal). We have provided a script to start up the Scheme environment. You can execute the script using the following command (don’t forget the ./):
./schemeIf it works, you should see something like this:
GNU Guile 3.0.9
Copyright (C) 1995-2023 Free Software Foundation, Inc.
Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'.
This program is free software, and you are welcome to redistribute it
under certain conditions; type `,show c' for details.
Enter `,help' for help.
scheme@(guile-user)> The above shows that you are at the Guile interactive prompt. (Guile is the name of the particular Scheme implementation that we’ll be using.) This interactive prompt is much like working with Python interactively. You can type in commands and immediately see what they do.
If the above command didn’t work and you got a “Permission denied” error, it means that the permissions have been changed. It’s easy to fix, though! We want to give executable permissions to that scheme script, so in the terminal, type:
chmod a+x schemeThis says to give executable (x) permissions to all users (a) for the file scheme. If you ever get this error in the future, now you know how to fix it!
Part A: Exploring Guile
At the Guile prompt, type the following:
(+ 3 5)In Scheme, + is a function. To call a function in Scheme, you place the name of the function and its arguments, separated by spaces, inside parentheses. For example, a function in Python that’s called as doStuff(arg1, arg2, arg3) would be called in Scheme like this:
(doStuff arg1 arg2 arg3)So, the code above that you typed should add 3 to 5, and you should see output that looks like:
$1 = 8This means that the resulting value of the above expression is 8, and Guile is assigning it to a history variable called $1. You can ignore these history values; they’re not especially useful for us.
Playing around
Now, go back to the regular Scheme prompt and change the code in some way. For example, re-type it as:
(+ 3 7)The Guile error prompt
If you make a mistake and type in some invalid syntax, Guile Scheme presents a sub-prompt indicating that you’ve had an error. Perhaps this has already happened to you. The error prompt looks like this:
Entering a new prompt. Type `,bt' for a backtrace or `,q' to continue.
scheme@(guile-user) [1]> The key way to notice that you’re there is somewhat subtle: it’s the [1] that appears in the prompt. It means that you’re 1 level deep into the error system. We’ll play with the debugging system more later on, but for now, when you see this, get out of it by typing ,q (don’t miss the comma at the front!).
Let’s try it, just so you can see how it works. At the Guile prompt, just type x and hit enter. you should see an error about an unbound variable, and then you’ll find yourself at the error prompt. Type ,q to return to the main Guile prompt.
Notice that if you type ,q at the main Guile prompt, it will exit Guile and you’ll end up back at the regular bash prompt. If that happens, type ./scheme to start it up again.
Part B: Basic Scheme primitives
You’ve already seen how to perform binary operations on numbers in Scheme. For this assignment, we’ll also look at operations on lists.
Working with lists
At the Guile prompt, enter the following, one line at a time. Try to type it yourself, not just copy+paste. (Note that the last one should cause an error.)
(car '(apple banana canteloupe))
(cdr '(apple banana canteloupe))
(car (apple banana canteloupe))Experiment with the code to try and answer the following questions:
- What do
carandcdrdo? - Why is the single quote necessary? What does it do?
- Why does the third line cause an error?
Again, remember that you can back out of the Guile error prompt using ,q.
More things to try
Enter each of the following lines of Scheme code, one-by-one, into Guile and observe the output. See if you can figure out for yourself what’s going on.
Assemble a list of questions for posting on Slack or discussing in class when this assignment is complete.
;; This is a comment, woo-hoo!
(cons 'x '(1 2))
(cons '(1 5) '(2 3))
(append '(1) '(2 3))
(append '(1 5) '(2 3))
(list '1 '2 '3 '(4 5))
(length '(lulu hobbes cheddar mal))
(reverse '(lulu hobbes cheddar mal))
(member 'mal '(lulu hobbes cheddar mal))
(member 'marshmallow '(lulu hobbes cheddar mal))Part C: Your assignment
Now that you’ve explored Scheme a little bit, write sequences of cars and cdrs that will pick the symbol diamond out of the following expressions:
(coal diamond obsidian bedrock)
(diamond coal)
(((iron) (coal diamond) (gold)))
(oak (copper coal) ((diamond)) (((bedrock))))For example, here is what I might write to pick diamond out of the expression (diamond):
(car '(diamond))Keep in mind that the goal is for you to keep practicing, early and often. I also encourage you to try variants of these as you prepare for quizzes.
Submitting your work
You will submit your work for this assignment in two files.
Scheme code
In the file main.scm, paste in your code to pick out diamond from each expression. You should end up with four lines of code, one below each comment matching the four expressions above.
Readme
For each assignment for this course you will also need to submit a file readme.txt in which you should write:
- Your collaborations with anyone on the assignment
- Your use of any outside sources on the assignment
- Your reflection
You should be specific about your collaborations and sources – they shouldn’t just be empty or lists of names of people. If you worked alone and/or did not use any outside sources, you should say so.
For your reflection, spend a couple of sentences answering the following:
- Were there any particular issues or challenges you dealt with in completing this assignment?
- How long did you spend on this assignment?
Here is an example:
# Collaboration
I worked through a few related examples on the board with Grace Hopper
to better understand car and cdr, and then I wrote the code for the
examples in the assignment on my own.
I also talked with Alan Turing about the assignment to help him
figure out lists in Scheme.
# Sources
I did not refer to any outside sources except the Dybvig book.
# Reflection
I got tripped up by all of the parentheses, but otherwise it wasn't too bad.
I spent one hour on this assignment.Here is another example:
# Collaboration
I did not collaborate with anyone.
# Sources
I only referred to my notes from class.
# Reflection
I probably should have given myself more time to get Docker set up. It was
really tricky, and I spent too long going around in circles trying to make
sense of car and cdr. Maybe I should start earlier next time so I can go
to student hours. I spent four hours on this assignment.Submitting to Gradescope
Once you have your two files, you will combine them into a single file using this command:
./zipitup(make sure you’re in the terminal in the assignment folder). If you get an error about file permissions, first run chmod a+x zipitup.
Submit your .zip file to Gradescope. There is no autograder for this first assignment (graders will just copy-paste your commands from main.scm to test them in a Scheme interpreter).