


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Instructions for university students enrolled in cs 173 discrete structures course in the fall 2016 semester on how to install racket, a dialect of scheme, and get started with basic programming constructs. It includes steps for downloading and installing racket, locating useful resources such as the 'getting started' guide, the 'quick: an introduction to racket with pictures' tutorial, and the 'racket cheat sheet'. Students are encouraged to work through the tutorial, try examples, and modify them to get familiar with the syntax. The document also covers basic arithmetic functions, conditionals, and recursive functions.
Typology: Exams
1 / 4
This page cannot be seen from the preview
Don't miss anything!



This term, many (if not all) of our assignments will use a dialect of Scheme called Racket. The goal of this homework is to get started with the basics: install Racket, get used to simple programming constructs.
The main Racket page is at
https://racket-lang.org/
Download and install racket on your computer. Back on the main Racket page, select Documentation at the top. Locate several useful things
2 Getting started
Power up the IDE. Work through sections 1-7 of the Quick tutorial. Try their exam- ples. Try simple modifications of their examples.
Don’t worry if you don’t understand absolutely everything. In particular, some of section 5 might be a bit hard to fully understand. Focus on copy-coding from their examples and getting used to the basic syntax.
On the upper menu, look for FILE and then “save definitions.” This will let you save and load files of code (“definitions”) that you’ve typed into the upper section of the IDE.
3 More basic syntax
For the rest of this assignment, you’ll need a few arithmetic functions. Look in the “primitives” section on the Racket Cheat Sheet to find basic numerical functions. These are similar to the ones in other programming languages, except for having the parentheses outside the whole function call. E.g.
(define x 5) (>= (+ x 3) 10)
should return #f (false). Try playing around with some of the numerical functions.
Also go to the Racket Guide and look at the section on “conditionals.” This has examples of using the if statement, as well as logical connectives like AND. The when statement (see example below) is similar to if, except that it takes only two inputs: the test and what to do if the test succeeds.
4 Recursive functions
All dialects of lisp and scheme use recursive functions more often than languages such as C++ and Java. Here’s a simple recursive implementation of the factorial function in Racket:
Use those two functions to write a function that returns a 2D grid of the input object.
6 Alternating objects
Finally, write a recursive function that makes an alternating sequence of two objects. This function should take an integer and two objects as input. It should return a sequence that contains alternating copies of the two objects.
7 Deliverables
You will need to submit a file containing the following code:
The functions should all be short, so the whole file should not be very long. To submit, find CS 196 (section 73) on moodle. If you aren’t already in that section, hunt it down on the moodle class lists and self-enroll into it. Also make sure to watch the CS 196 piazza for discussion, hints, etc. These use the same access code as the A lecture. Ask Margaret if you don’t know/remember it.
There will be an assignment activity on the moodle site, where you can upload your file of code.