On this page:
1 Setting up your programming environment
2 Comments
3 Numbers
4 Strings
5 Booleans
6 Images

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

A BSL comment is a semi-colon followed by arbitrary text followed by a line break. The first line below is a comment:
; The following BSL expression evaluates to 25:
(* 5 (+ 2 3))
When DrRacket evaluates the code above, it completely ignores the first line. However, a human reading this code may find the first line informative.

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:

\sqrt{(5 - 1)^2 + (6 - 3)^2}

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.

Exercise 10: Another useful operation on strings is substring, which takes a string and two positions and returns the portion of the string which is between the input positions. Try evaluating the following two examples:
(substring "COMP 115" 0 4)
(substring "COMP 115" 5 8)

Now suppose someone gives you the following string
"8 September, 2021"
and you want to extract just the month. Write an expression using substring which does this.

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.

Exercise 12. Booleans often appear as the output of operations on other types of data. For example, when we compute that 1 is less than 3, we apply an operation < to the numbers 1 and 3 and produce true as output:
 (< 1 3) 
Write an example expression that confirms that the number 0 is strictly between -1 and 1. Use and.

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.