CS 173 Discrete Structures Homework 1: Getting Started with Racket, Exams of Programming Languages

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

2021/2022

Uploaded on 08/05/2022

dirk88
dirk88 🇧🇪

4.4

(222)

3.1K documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Honors Homework 1
Discrete Structures, CS 173, Fall 2016
Due Friday, September 30
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.
1 Installation, finding the manuals
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
“Getting Started” explains how to power up the IDE
“Quick: An Introduction to Racket with Pictures” the tutorial we’ll be using
“Racket Guide” language manual, useful later
“Racket Cheat Sheet” list of functions, some mysterious but some that you can
figure out soon
1
pf3
pf4

Partial preview of the text

Download CS 173 Discrete Structures Homework 1: Getting Started with Racket and more Exams Programming Languages in PDF only on Docsity!

Honors Homework 1

Discrete Structures, CS 173, Fall 2016

Due Friday, September 30

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.

1 Installation, finding the manuals

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

  • “Getting Started” explains how to power up the IDE
  • “Quick: An Introduction to Racket with Pictures” the tutorial we’ll be using
  • “Racket Guide” language manual, useful later
  • “Racket Cheat Sheet” list of functions, some mysterious but some that you can figure out soon

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:

  • Your implementation of remainder
  • Your recursive horizontal and vertical sequence functions, also your function for making a 2D grid.
  • Your function for the alternating sequence of objects.

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.