Lab 1 BSL in DrRacket
Purpose The purpose of this lab is to give you some hands-on experience with the BSL programming language and with the DrRacket programming environment for BSL.
BSL programming is basically prefix syntax for pre-algebra plus a range of pre-defined functions. In contrast to your pre-algebra courses, your BSL expressions and functions definitions are mechanically checked and, if they are found to be ill-formed, you get an error message. Getting an error message is good. All novice programmers make mistakes. The key is that by the time you walk out of this lab, you must have seen error messages, you must know how to read them and how to react to them.
the Definitions area, where you define functions, state tests, and write down expressions your program must evaluate;
The Interactions area, where you ask DrRacket to evaluate expressions and to experiment with ideas;
The Stepper, which helps you step through the evaluation of function definitions and expressions from the Definitions area.
Welcome to Lab
Collect contracts from all students who enter the room. Hand contracts to co-pilot TA who matches up pairs on a random basis. Co-pilot: this is your job.
How Pairs Work
3 min
You will be working in pairs during labs. Pairs consist of a pilot and a co-pilot. The pilot types at the keyboard while the co-pilot looks over the pilot’s shoulder. Like in real airplanes, pilots and co-pilots switch back and forth during the lab.
Launching DrRacket
Launch DrRacket. It is a interactive development environment aka an IDE. You can use it for many different programming language: Algol 60, Beginning Student Language aka BSL, Datalog, Racket, R6RS Scheme, and a few more. Choose the Beginning Student Language from the {Language | Teaching Languages} drop-down menu.
Interacting with DrRacket
45 min
Use DrRacket’s interactions area as a calculator. Show a range of operations on numbers, booleans, strings. Use big numbers, use complex numbers. In the future, you don’t need a calculator; use the interactions area. It is your time to play. Re-arrange room so partners get to work with each other. Co-pilot TA must have finished pair assignment now.
Use DrRacket’s definitions area to write down expressions. Nothing happens. Show run. Show the stepper. Time to play again.
Sample Problem The function how-far consumes the number of minutes you drive at 55mph and produces how far you get in the given time.
Define a function that accepts a number of minutes and computes how many whole hours these minutes represent. 15min
You’ve Got Errors
syntax errors, meaning what you wrote is not a BSL “sentence;”
run-time errors, that is, you wrote a BSL sentence but when you interact with it, it signals an error because a function is applied to too many or too few arguments or the wrong kinds of arguments and so on;
logical errors, which does not manifest itself as some red text in the interactions area. Instead, you apply a function and it gives you a response that is wrong.
Switch partners
Conditions
Sample Problem The function how-hot consumes a temperature (number) and produces one of three strings: "cold" for temperatures below 45 (inclusive), "comfortable" for temperatures between 45 (exclusive) and 75 (inclusive), and "hot" for temperatures above 75.
15 min
Sample Problem Define the function letter-grade. It consumes a score (number) between 0 and 100 and produces a letter grade ("A", "B", "C", "D", or "F"). You may choose your own scale.
Programming with Images
30 min
Use (require 2htdp/image). Show circles, squares, text. Show “addition” of images.
Find an image of a car on the web. Copy and paste it into DrRacket’s definitions area and give it a name. Interactively determine its width, height, area. Compose car imagine with squares, circles, triangles. Draw red frame around it.
Sample Problem Define the function frame, which consumes an image and draws a red frame around it.
Switch partners; 15 min
Sample Problem Define the function sale. It accepts a wish in the form of a string and, if it recognizes the string, it returns an image of this object; otherwise it produces "sorry" as a large text.
Working on Problem Sets
10 min
Work out the solution to an individual problem in a tab by itself, then copy and paste the solution into a solution file for the problem set. Make sure the latter still runs.
Sample Problem Define a program that consumes a string and judges how long it is. If the string is shorter than 3 characters, we call it stubby. If it is a bit longer, say up to 10, it’s dubbed a shorty. For strings, up to 25 characters, we go with middling. And for a string that’s even longer, the function says it is "too wordy".