On this page:
1 Install the Handin plugin
2 Defining constants (variables)
3 Defining functions
8.12

Lecture 2: Definitions🔗

This assignment is due on Tuesday, January 9 at 11:59pm. Submit it using Handin as assignment lecture2. You only need to submit the first 7 exercises. Your submission is only accepted if the message “Handin successful” appears.

1 Install the Handin plugin🔗

All lecture assignments and problem sets will be submitted through the Handin server. To use Handin in DrRacket, you’ll need to install a plugin in your DrRacket:
  1. Open DrRacket. (Don’t open Racket.)

  2. In the File menu, choose “Install .plt file”

  3. In the dialog box, enter the following URL: http://www.cs.indiana.edu/classes/c211/c211-handin.plt

    Make sure you enter this URL exactly.

    Troubleshooting If you try to copy the URL above and paste it into the dialog box, but the text box seems to remain empty, try hitting backspace once or twice.

    Troubleshooting If you try this installation procedure on a lab computer, you might get some red messages like

    open-output-file: error opening file

      path: C:\Program Files\Racket\collects\c211-handin\compiled\tmp16418232271641823366937

      system error: Access is denied.; win_err=5

    But as long as you see “Installation complete.” at the bottom, Handin may well work fine after you restart DrRacket!

  4. Restart DrRacket. When DrRacket starts again, you should have a button with the IU logo.

  5. Create an account, by going to the File menu and choosing Manage C211 Handin Account.

    Important Make sure that your Handin username is the same as your IU login username. However, do not use the same passphrase. Under “full name”, put the full name you’d like us to use in this class.

Troubleshooting If your computer gets stuck for more than a minute at the message “Connecting to server” or “Making secure connection” when you try to use Handin, make sure that your computer is not connected to the Internet through the “IU Guest” wireless network. Instead, use another network such as “IU Secure”, “eduroam”, or tethering to a cell phone. Also, check for any program on your computer (perhaps firewall or protection software) that might be blocking outgoing connections to port 17979.

2 Defining constants (variables)🔗

Exercise 1. Copy an image from the Internet, and use the 2htdp/image library to “frame it inside itself”. For example, if the image you downloaded looks like this:

then make an image that looks like this:

appear in the Interactions Window when you hit the Run button. The inner image should be 70% as wide as and 70% as tall as the original image.

Hint: use scale and overlay.

Introduce a constant definition for the original image you downloaded, so that the Definitions Window contains only a single copy of a single image.

Now is a good time to submit your work so far, using Handin as assignment lecture2 (not ps1 or lab1 or test-handin). Throughout this course, it is a good idea to submit early and submit often, because
  • You can submit any assignment any number of times until the deadline. (We do not accept late submissions.)

  • In case you make a mistake, Handin sometimes provides helpful messages.

  • In case you lose your work, you can retrieve your submission from Handin.

  • We only grade your last successful submission. (Moreover, only your Definitions Window is submitted, so each time you submit, your Definitions Window should include all your work so far on that assignment.)

Your submission is only accepted if the message “Handin successful” appears.

Troubleshooting If you encounter any trouble, one way to get help is to post a screenshot to Discord.

Troubleshooting If Handin says “file to handin is too big”, it means that your submission cannot be accepted because it exceeds the maximum upload size: 7 MB. Be sure that any image that you’ve included in your file is small enough (you may need to rescale it in an image editor).

Exercise 2. Copy a different image from the Internet, and change your constant definition in Exercise 1 to it. Now when you hit the Run button, the new image should be framed in the same way by the same framing formula.

Exercise 3. Show step-by-step calculations for your framing formula. Use the Stepper to confirm that your step-by-step calculations are correct.

Exercise 4. What’s wrong with this program?
(define n (+ 3 2))
(* (n) (n))
And what’s wrong with this program?
(define (n) (+ 3 2))
(* n n)

The code written in the videos above is available for your reference. To download it, don’t use “Save Page As” or “Save As”; use “Save Link As” or “Download Linked File” in your Web browser. If you can’t find the command, try right-clicking or two-finger-tapping or long-pressing.

3 Defining functions🔗

Exercise 5. Let’s keep framing the same image, but make it easier to adjust the size of the inner image. Define a function called framed that takes a number (like 0.7) as input and produces a framed image like the ones we’ve created before. The outer image and the inner image will be from the same picture, and the inner width and height use the given number as the proportion (like 70%) of the original. For example, after you hit the Run button, typing (framed 0.5) and (framed 0.7) and (framed 0.9) in the Interactions Window should produce framed images like the following, except the fruit is different:

Put differently, define a function with the following signature:
; framed : Number -> Image
; frame the image scaled by the given number
(define (framed n)
  FILL-IN-THIS-BLANK)

Exercise 6. Define a second function, called shrink:
; shrink : Number -> Image
; make a smaller version of our image
; (shrink 5) should produce (framed .9509900499)
(define (shrink n)
  (framed (expt 0.99 n)))
This function takes a number n (like 5) as input and produces a framed image whose inner width and height are 0.99n of the original.

Try to use this new function shrink in the Interactions Window.

Pay attention to how this new shrink function uses your existing function framed. In other words, the definition of shrink contains (framed ...). The input to framed is the proportion (expt 0.99 n); this sub-expression uses the built-in function expt for exponentiation.

Optional: Review operators and definitions.

The code written in the videos above is available for your reference. To download it, don’t use “Save Page As” or “Save As”; use “Save Link As” or “Download Linked File” in your Web browser. If you can’t find the command, try right-clicking or two-finger-tapping or long-pressing.

Exercise 7. Use our function shrink to make an animation:
(require 2htdp/universe)
(animate shrink)

Optional: Enjoy more examples of animate.

For the rest of this page, you don’t need to submit anything, but do watch the videos and try the exercises anyway. We’ll work through similar material together in class.

When you do the lectures, make sure you do the whole lecture, not just the required parts. Make sure you understand WHY a function works, not just the code

The code written in the video above is available for your reference. To download it, don’t use “Save Page As” or “Save As”; use “Save Link As” or “Download Linked File” in your Web browser. If you can’t find the command, try right-clicking or two-finger-tapping or long-pressing.

Exercise 8. Show the calculation of (shrink 50) step-by-step. Use the Stepper to confirm that your steps are correct.

Optional: Read Chapter 2 of the textbook.

Optional: Learn a little more about DrRacket.