Lab 1: Getting started
This lab introduces DrRacket and Beginning Student.
1 Sign up for Discord
We will use Discord to ask and answer questions, make announcements, and hang out. Sign up with the link we announced on Canvas when the course started. Change your nickname on Discord to the full name you’d like us to use in this class. Then, introduce yourself in the #introductions channel.
If you would like to talk to only instructors on Discord, type /breakout (with a forward slash at the beginning of the message) then hit Enter. This should create a “breakout channel” that only you and the staff can see.
Two safety tips on Discord (actually, on any network): First, enable two-factor authentication (next to your password setting). Second, don’t open any download you receive through a private message.
2 Pay attention to announcements
; Exercise 1 ; Answer:
Exercise 1. Alex started early on problem set 1 and submitted their work already on Wednesday. Unfortunately, they made a critical mistake and only got 5 out of 10 points. Where can they get personal feedback about their homework? How can they raise their grade on this assignment? When? By how much?
Exercise 2. Bri plans to work on problem set 1 this weekend and submit their work by Monday morning. According to this plan, what grade will they receive? Will they be able to raise it?
Exercise 3. When is problem set 2 due? When is midterm 1 scheduled?
Exercise 4. Describe one way you should work with other students in this course, and one way you should not work with other students in this course.
Exercise 5. Name three ways to get help in this course if you get stuck.
Decide when you are going to work on this course every week.
Put at least 2 hours as a weekly appointment on your calendar. If you have never used a calendar, start using one, such as the one on your phone.
Then, enter the time you chose at When2meet. This way, y’all can find study buddies.
3 Arithmetic and constants
Make sure that the language level in DrRacket is set to “Beginning Student”. (Note: if you change the language level, it will not take effect until you hit the “Run” button.)
Exercise 7. Experiment using DrRacket’s Interactions Window as a calculator. See what operations you can use to calculate. Make sure to try fractions.
Exercise 8. Define a variable big-number to be a big number. (If you’re not sure how to define a variable, review Lecture 2: Definitions Exercise 1.) Then, define another variable bigger-number to be the result of multiplying big-number by itself. Finally, define a number that is bigger than bigger-number.
Hint: DrRacket comes with a help system called Help Desk, under the Help menu. Open the Help Desk and click “How to Design Programs Languages”, then click “Beginning Student”. You will get a reference for the Beginning Student language. You can also search in the Help Desk for documentation about a particular function, such as expt.
4 Images
Exercise 9. Download a tiny image off the Web and insert it into your Definitions Window. Use define to give it a descriptive name. Examples: vehicles, plants, foods, etc.
Exercise 10. Use place-image and empty-scene to create scenes with your image. (If you’re not sure how to use a function, review Lecture 1: DrRacket and arithmetic Exercise 12.) Andy Warhol used this rubber stamping technique to create art such as Stars and Half Moons, 1960, to the right.
Hint: DrRacket comes with a help system called Help Desk, under the Help menu. Open the Help Desk and click “How to Design Programs Teachpacks”, scroll down to “HtDP/2e Teachpacks”, then click “Basic Images”. You will get a reference for the 2htdp/image library. You can also search in the Help Desk for documentation about a particular function, such as rectangle.
a rectangle that is tall and narrow,
a rectangle that is short and wide, and
a square.
5 Functions
Exercise 14. Define a function that, when given a diameter and a height, will produce an image that can be printed, folded up, and taped together to make the cylinder of the given diameter and height. Name your function can. For example, the images you just created should be just as well produced by (can 75 105) and (can 85 40).
Exercise 15. Define a function that, when given a diameter and a height, will compute the surface area of the cylinder of the given diameter and height.
syntax error, when you write something that DrRacket doesn’t recognize as a program
run-time error, such as when you provide the wrong kinds of inputs to an operation
logical error, when your program produces an answer, but it’s the wrong answer
6 Food
(overlay (triangle 30 "solid" (make-color 190 70 10)) (triangle 60 "solid" (make-color 250 230 190)))
Exercise 18. What happens if you feed the number -1234567/89 to the function you just defined? What range or kind of numbers can your function actually handle correctly? Write down your answer clearly.
7 Animation
Exercise 19. Define a function which produces an image when given a number. The image produced must have the same size no matter what number is given. For instance, you could define a function that places a circle with the given radius in the middle of a large empty scene.
Exercise 20. Use the function you just created, along with animate, to produce an animation. Remember that using something means putting its name in your code.
That’s it for this lab! Your lab instructors will grade your work and give you friendly feedback. For later reference, you should also save your work using the Handin server, as assignment lab1.