This class will be recorded! Its use is limited to members of the class. Please do not share with others.
Approximate overview
Events
I’m not sure if all of these links are correct. Let me know if any are not.
I’m hoping I help many of you with some Q&A about problem 4.
Trust the magic recursion fairy.
That is, you can assume that any recursive procedure you are writing works on any input closer to the base case (e.g., the car of a list, the cdr of a list, a smaller number, etc.).
Warning!
(define evaluate
(lambda (exp bindings)
(cond
[(symbol? exp)
(simple-evaluate-base exp bindings)]
[(integer? exp)
(simple-evaluate-base exp bindings)]
[else
???])))
What else do we have?
mul or add and has a bunch of
other expressions.Broadly, what are the steps we have to do in that else? (We can assume we have a list.) And yes, I’m using random calling.
mul or add).mul
or add and evaluate them with simple-evaluate-base, at least for
the problem 1)
evaluate does that. <— TRUST THE MAGIC RECURSION FAIRYmul, add for add)Recursion is our friend.
Match is not our friend.
The magic recursion fairy will also help on part 5.
Why are they called “hash tables”?
In the implementation, you chop up the key and then convert it to a simpler implementation.
I’m confused on self-check three. Will you explain it?
Nope. Discuss with your partner.
If we want to keep things, must we put them in the definitions pane?
Yes.
Or rerun them in the interactions page.
I can’t run car or cdr on the empty list.
Don’t attempt to do so until you make sure the list is not empty.
(if (empty? lst)
base-case
(let ([head (car lst)]
[tail (cdr lst)])
whatever-else-you-want-to-do))
I’m trying to write simple-evaluate-list. I’ve used a let to
define mul and add. Why don’t they work as procedures?
Racket isn’t as smart as you think (or doesn’t work like you think).
You probably need to write something more like
(if (equal? (car lst) 'mul)
(apply * whatever)
(apply + whatever))
When you suggest tail recursion, are you saying to use match?
I am not saying that you suggest use
match.
I am suggesting that you write a helper procedure that adds an extra parameter, usually called
so-far.
Fun fun fun!