For this lab we're going to use a language developed by two former cs019 students (including current cs019 TA jmiranda) that allows you to trace the evaluation of your program, or look at the big-step operational semantics of your program. To begin, change the language of your file to #lang planet tracer/tracer
. Then, add (trace-all)
as the next line of your file.
When you run your program, a browser will automatically open up and show you a pretty graphical representation of the evaluation of your code. The only difference between #lang planet cs019/cs019
and this language is that you get to see a trace of your program — the rest of the semantics will still be the same. This will become an invaluable debugging tool, so be sure to check out the documentation.
To set what browser DrRacket opens Bigfoot in, go to Edit, Preferences. Select the Browser tab, and choose Google Chrome.
What happened when you traced a check-expect
that failed? One that passed?
What happened when you traced code that generated an error?
How can you find out where a function was defined? Or where it was used?
Solve the following exercises. Don't forget to write check-expect
s.
sum-coins
. It consumes five numbers: the number of pennies,
nickels, dimes, quarters, and those annoying gold-dollar things that the MBTA gives you as change; it produces the amount of money in the bag.
total-profit
.
It consumes the number of attendees (of a show) and produces how much income the attendees produce. (But really concerts are free and you should come!)
steal-cards
, which takes the number of cards that a player has and returns the number of cards that are stolen from him
when the new robber is moved.
discount
, which takes the name of a course that someone belongs to
and produces the discount (a percentage) that the person should receive on a purchase.
Members of CS19 get 20%, members of CS15 or CS17 get 10%, and members of CS2 get 5%. All other CS courses get 15%. Sometimes a non-CS student
will try to get a discount, but these students get 0% discount.
purchase
, which takes the price of an item and the name of a course that the student is in
and produces the amount owed after the discount is applied.
assign-grade
that takes a grade record and produces a grade record. The produced grade record has the same exam grades as the original, but has computed the course grade from the exam grades. The course grade is A for an average above 85, B for an average between 70 and 84, C for an average between 55 and 69, and NC otherwise.
new-student
which consumes a student name and class year and produces a student record with the given name and class year, both exam grades initialized to 0 and the course grade initialized to false.
average
that consumes a list of numbers and produces its average. Return an error message if the list is empty.
suffixes
that consumes a list L (containing anything) and produces a list of all the suffixes of L. For example, (suffixes (list a b c d))
should produce (list (list a b c d) (list b c d) (list c d) (list d) empty)
.
Call a TA over to get yourself checked off. Once you have been checked off you are free to go.