On this page:
1 Install Dr  Racket
2 Start
3 Boring Arithmetic
4 From Syntax to Semantics
5 Submit
6.12

Exercise 1

Due: Monday, July 8, 11:59:59 PM EST.

1 Install DrRacket

If you haven’t already, download and install DrRacket, part of the Racket platform, available for download from https://download.racket-lang.org/.

The installation process is pretty easy and should work just like installing any other software on your computer. Here’s a short video demonstrating the process.

2 Start

Open DrRacket. Make sure your language is set to Beginning Student. At the top of the file, write the following, except use your actual name in place of ... your name here...:

;; Exercise 1
;; Name: ...your name here...

Save the file on your computer with the name ex1.rkt.

Log in to ELMS and upload your file as a solution to Exercise 1.

Continue to do the rest of this exercise. Save and upload ex1.rkt as you make progress. Getting in the habit of submitting early and often will pay off in saving you hours or weeks of lost work in the future.

3 Boring Arithmetic

One of the first things you will have to do when learning a programming language for the first time is get comfortable translating from concepts you’re comfortable with into the notation (or syntax) of the langauge you’re learning.

Translate the following arithmetic expressions into BSL notation. For each translation, write an expression in ex1.rkt. Based on the arithmetic, calculate what the expression should produce when you run the program. Run the program and confirm (or refute) your prediction.

This arithmetic stuff is boring. We get it. More interesting stuff is coming, we promise, but first you have to master the syntax of BSL. It’s like learning the grammar of a foreign language. It takes time and practice, but eventually it will become second nature.

If your BSL expressions don’t produce the right answer, it could be that you’ve translated incorrectly or you calculated the arithmetic wrong. Reflect on which has occurred and revise your program if needed until your predictions and observed outcomes match up.

Note that you may need to recall the precedence of arithmetic operations in order to make sense of some of these.

Problem 1: Translate expressions to BSL

  • 25 · 3

  • 25 + 3

  • 25 / 3

  • 25 · 2 + 4

  • 15 - 4 · 2

  • 2 / 3

  • 6 / 3 · 2

  • 2 · 6 / 3

These examples involve using more operations. Skim the documentation on numeric operations to see what BSL operations correspond to these arithmetic operations.

Problem 2: Translate expressions to BSL with more operations

  • 25

  • √-1

  • 52

  • 25

  • |4|

  • |-4|

Leveling-up from arithmetic to algebra, consider the following function definitions and translate each into equivalent BSL definitions.

Problem 3: Translate functions to BSL

  • f(x) = 2 · x

  • g(x) = 2x+x3+4

  • h(x) = 7 / x

  • q(v) = 1 / 2 · v2

  • r(s) = f(s) + 4 · g(3 · s)

  • m(x) = x + h(2)

  • z(a,b,c) = 2a+b2+c

Now write expressions for each of these uses of the functions you defined. Make hypotheses about what should happen and compare them to what does happen.

Problem 4: Using functions in BSL

  • f(3)

  • f(5)

  • g(4)

  • h(-7)

  • q(8)

  • r(3)

  • r(4)

  • z(5,9,1)

You should now have a sense of how to translate a language you know (math) into a language you’re learning (BSL). From this, you can build a fluency in understanding BSL in particular, and computation in general.

4 From Syntax to Semantics

Being able to translate from math notation into BSL notation is all about understanding the rules for how expressions are formed. In other words, it’s all about grammar (a.k.a. syntax). Understanding what expressions mean requires an understanding of BSL semantics.

You already have a sense of what BSL programs should mean because you know it should match the meaning of the original mathematical expressions. But how do you determine the meaning of a mathematical expression like 2 · 6 / 3? You calculate. You start by simplifying 2 · 6, which you know from the rules of multiplication is 12. So the meaning of 2 · 6 / 3 is the same as 12 / 3, which by the rules of division, is the same as 4.

The same process is how BSL compute and there’s a tool to help you explore this process called "the stepper."

Using the program you wrote above, use the Step button (rather than Run) to explore the peice by peice calculation that happens when you run a BSL program.

Step through several examples and try to build a mental model of how computation in BSL works. (Formulate hypotheses about what will happen next, observe, and revise if needed.)

(This part of the exercise is all about building understanding, but doesn’t require you to write or submit anything new.)

5 Submit

Save your work as ex1.rkt and submit the file on ELMS. The latest submission before the deadline will be graded, so submit the entirety of your work every time. Do not email submissions to course staff.