Tip:
Highlight text to annotate it
X
We'll require picturing programs,
and we're working in Dr Racket, Intermediate Student with lambda.
Let's work in the interactions pane... so
if you're on my platform, you'll click
Control-D a couple of times until the whole of
Dr Racket is taken up
with interactions.
Now suppose for Some Reason Too Complicated To Explain Just Now
you would like
a back-to-back,
vertically reflected over itself
image of a chameleon... Here's how you might do that, a
a step at a time, by hand. You could flip the chameleon horizontally.
Then, using Alt-P to go back and edit what you've already done,
you could put that image beside...
well the un-flipped version of itself.
Make sure you close parentheses...
Halfway there!
Alt-P again...
and we can go back up
put this
image above....
well put it above
itself, only vertically reflected. So, copy what we've already done.
Flip that thing vertically.
Make sure that
you've got closing right parentheses.
And, it's starting to look pretty cool. Now, suppose we want to do that on images
other than that particular chameleon. Here's the problem. We could cut-and-
paste, but the
value of that chameleon appears in four different places, and we have to go and
fetch a chameleon from somewhere each time.
There's four places in that block of instructions where we've got that
chameleon image. We'd really like to produce a function
that has a place-holder for a chameleon.
And then whenever we
provid it with a value of a chameleon, or something else, it does exactly the
same steps. Here's how we do it. We use define,
pick a name rosette, which it turns out hasn't been used anywhere before
and pic is our place-holder.
After we define that, we tell it what to do with pic.
So, we type basically the same instructions, replacing chameleon by our
placeholder pic each time.
So, we're gonna put pic beside itself, flipped
horizontally, and then put that above...
what'll we put it above?...
Well, gee, we might as well copy what we already have,
because we'll put it above a vertically flipped
copy of itself.
closing
right parens, and as soon as we set enter,
we have our definition.
Now, we need to try out our function on something.
Now, we could go back and get exactly the same image as we had
started with before, and see if it does the same thing.
So, copy that chameleon image
and now we apply, sometimes people say call, rosette on that value.
Get the same rosette.
We could be silly
and we could apply rosette to this newly produced image... see what we get.
My goodness: a rosetted rosette. Now, just to show that
rosette works on values other than just
chameleons,
we can go up and copy an image of a parrot fish.
Apply rosette
to that image...
And, we get a parrot fish back-to-back with itself, and vertically reflected over
that.