Lab 1: Getting started
You may submit this lab to lab1 on Handin (this is optional).
In this lab, we will install DrRacket and the Handin plugin and start using the Beginning Student Language.
1 Setting up your programming environment
Exercise 1: Download DrRacket and install it on your laptop.
Exercise 2: Install the Handin plugin in DrRacket and create an account on the Handin server. The instructions are here.
Exercise 3: In DrRacket, click "Choose language" under the "Language" menu. Then select "Beginning Student" and click "OK". Finally, click "Run". You should see "Language: Beginning Student" in the Interactions Window.
Exercise 4: Test your setup. Type something into the Definitions Window. Then click "COMP 115 Handin" and submit the contents of the Definitions Window to lab1. You should see "Handin successful."
Exercise 5: Try to retrieve the file which you just uploaded to the Handin server by clicking "COMP 115 Handin" and selecting "Retrieve".
Important: You should also always save your definitions locally (on your own computer).
2 Comments
We will use comments extensively in this class to make our programs more readable to other humans.
Exercise 6: In other classes, when you prepare homework to hand in on paper, you usually write some kind of header at the top (for example, you would typically include your name). Add a header as a comment to the top of the Definitions Window and try running it.
3 Numbers
Exercise 7: Type (or paste) the following expression into the Definitions Window:
(+ 1 (+ 2 (+ 3 (+ 4 (+ 5 (+ 6 (+ 7 (+ 8 9))))))))
Predict what you will see when you click "Run"; and then click "Run". Next, instead of clicking run, click "Step". Use the "Next" button to watch DrRacket evaluate that expression step-by-step.
Exercise 8: Suppose that we want to compute the distance from the point (1,3) to the point (5,6). Plugging these numbers into the distance formula, we get the following expression:
Let’s use DrRacket to perform this calculation. Translate this mathematical expression into a BSL expression. Use sqr and sqrt.
4 Strings
Exercise 9: Write an expression which combines several words into a sentence (with spaces) using string-append.
"8 September, 2021"
5 Booleans
Unlike numbers, of which there are many examples, there are only two booleans, true and false.
Exercise 11. Some basic operations on booleans are not, and and or. Write example expressions of each of these operations applied to boolean data.
(< 1 3)
Exercise 13. Write an example expression that confirms that the number 1/2 is between 1/2 and 1 (use and and <=). Come up with two other example expressions using > and >=.
6 Images
Beginning Student Language offers few operations on images. To get access to a good collection of operations involving images, add the following line to the Definitions Window:
(require 2htdp/image)
Exercise 14. Some operations take information in the form of numbers and strings and produce an image. For example, try evaluating
(triangle 50 "solid" "red")
Now, using triangle, beside and above, write an expression which produces the following image:
Feel free to pick another color or size.