Tip:
Highlight text to annotate it
X
Doctor Racket, intermediate student with lambda, we'll need picturing-programs
for some image tools. And I want to produce a Koch curve.
There's what (koch 0) looks like, (koch 1) is just 4 copies of (koch 0) pushed together.
Here's the definition, let's figure out how it works by looking at smaller examples.
(koch 0), here's how you figure it out.
Look at the body of the definition; replace all the d's by 0's.
It's conditioned with 2 question/answer pairs, look at the first question,
it asks "Is 0 equal to 0?" Of course it is!
So it answers with a line that's 10 dots along and black. Here's that line.
(koch 1) is built up from what you know about (koch 0). Look at the definition
Replace all the d's by 1 and now look at those question/answer pairs.
The first one asks "Is 1 equal to 0?" Of course not! So skip that and move on to the else,
the else says put 4 copies of (koch 0), what does that look like?
That's that short line over there. So 4 short lines, the first one not rotated at all,
the second one rotated 60 degrees counter-clockwise, the third one 60 degrees clockwise,
the forth one not rotated at all. That's what it produces.
(koch 2), well that's built up from what we already Know. Look at the definition of the function,
replace all the d's by 2 now.
The first question says, "Is 2 equal to 0?", Of course not! So we move along to the else,
Which says put 4 copies of Koch... Well Koch of 2-1.. (koch 1), what's that look like?
There's (koch 1) so we are gonna put 4 of those bumpy things beside each other,
The first one not rotated at all, second one rotated backwards, the third one rotated forwards,
And the forth one not rotated at all. Here's what we get... (koch 2)!
(koch 3), what's it going to look like?
Here's how to understand it.
Look at the body of the function, replace all of the d's by 3.
The first question/answer pair asks "Is 3 equal to 0?", No way! So move onto the else.
The else says put beside each other, 4 copies of Koch.. well 3 minus 1 is 2..
(koch 2), that's what It looks like. So we are gonna put Koch 2's first one not rotated,
the second and third rotated in a wiggly way,
and the forth one not rotated at all.. There's (koch 3).
(koch 4), well we need a bit more room, so I hit Control-D
and there's (koch 4) in all its glory. Now there's a problem with this definition,
look at the number of times I had to retype exactly the same thing: (koch (- d 1))
That's a source of both tedium and possible errors, so
next time we will fix that in a new implementation called Koth2!