CSC151 2010S, Class 21: Naming Local Values
Overview:
* Questions on assignment 5.
* Questions on the reading.
* Lab.
Admin:
* Don't forget to email me if you can't make it to class.
* I'm way behind on grading, as you can tell. Hopefully, I'll have time soon.
* What questions are there on Assignment 5?
Questions on Assignment 5
* Is it important that we use the same procedure names as you gave us? Yes.
* Why?
* So that I can do some automated testing. (If, for some reason, I decided to grade your assignment.)
* Why are some parts of this so hard? It it inherent in the language?
* Your knowledge is limited. We'll learn some easier ways to do some of these things later.
* It's purposefully hard because the hard approach can help you learn some important concepts.
* How much should I turn the turtle in the centered polygon?
* Draw a diagram.
* Sam is an idiot. sin and cos work in radians, but turtles work in degrees.
* To convert from radians to degrees: multiply by 180/pi. To convert from degrees to radians, multiply by pi/180.
* Can you explain the use of repeat, particularly with parameters from the main procedure?
(define turtle-stuff!
(lambda (turtle distance angle)
(repeat 5
(lambda (t)
(turtle-forward! t distance)
(turtle-turn! t angle))
turtle)))
(define turtle-stuff2!
(lambda (turtle distance angle)
(repeat 5
(lambda ()
(turtle-forward! turtle distance)
(turtle-turn! turtle angle)))))
* Can we nest repeats? Certainly. Here's an indirect nesting.
(define repeat-turtle-stuff2!
(lambda (turtle times distance angle)
(repeat times
(lambda ()
(turtle-stuff2! turtle distance angle)))))
* Why the lambda?
* Repeat HAS TO TAKE A PROCEDURE as its second parameter. (turtle-stuff2! turtle distance angle) is a value.
(define repeat-turtle-stuff2!
(lambda (turtle times distance angle)
(repeat times
turtle-stuff2!
turtle
distance
angle)))))
* What do you mean by "reset the turtle every time"?
* When your procedure is done, the procedure should be back in its original position and orientation?
---
(define turtle-square!
(lambda (turtle edge)
(repeat 4
(lambda ()
(turtle-forward! turtle edge)
(turtle-turn! turtle 90)))))
(for-each (lambda (n)
(turtle-forward! tommy n)
(turtle-turn! tommy n)
(turtle-square! tommy n))
(list-drop (iota 20) 1))