.rkt to the filename. That will let the operating system know that it’s a Racket file.Put these lines at the top of your file:
#lang htdp/bsl (require 2htdp/image) (require 2htdp/universe)
There are three kinds of comments:
; &endash; DrRacket ignores everything from the semicolon to the end of the line.#| and end with |# &endash; DrRacket ignores those two pairs of characters and everything between them.#; &endash; DrRacket ignores the #; and the next expression. For example, writing #;"my string" would ignore everything from the hash tag to the second double-quotation mark, since a string is an expression. Similarly, #;(define x (+ 2 (- 3 5))) would comment out all of that, since thing between the first parenthesis and the last one is a single expression.(check-expect your-code expected-value) to check your code. Unless your code is an inexact number (you can tell, because it starts with #i), in which case use (check-within your-code expected-value how-close).
You can download DrRacket from the official Racket website: https://racket-lang.org/download/. Make sure to choose the version that is compatible with your operating system, Windows, Mac, or Linux.
DrRacket needs to know which language you want to use. To make your life easier, ignore the Language menu at the top of the window. If you already chose a language using the menu, you can change it by going to Language→Choose Language and then clicking the top radio button, which says The Racket Language.
Once you’ve done that, make sure you add this line to the top of all your files: #lang htdp/bsl
This stands for “How To Design Programs / Beginning Student Language”.
If you want to use images, you will also need to add this line at the top: (require 2htdp/image)
If you want to do animations or interactive world programs, you will also need to add this line at the top:
(require 2htdp/universe)
If you ever get an error saying that something is not defined, check those three lines and check that the Language is set to The Racket Language. Also, ask a neighbor or me for help.
The top part of the screen is called the Definitions area. This is where you write your code. The bottom part of the screen is called the Interactions area. This is where you can try out stuff to see what happens.
To save the Definitions area, click on the floppy disk icon, or choose File→Save. You can also use the keyboard shortcut Ctrl+S (or ⌘+S on a Mac). You’ll need to type in a file name. Put the extension .rkt after the name to let the operating system know that this is a Racket file. Choose which folder to save your file into (Desktop works well, usually), and click the Save button.
I recommend saving all your files in a folder called apcsp or something like that, maybe with subfolders for files that go together.
To run your code, click on the green Run button at the top of the window. This will execute the code in the Definitions area and show you any output or errors in the Interactions area. It will also erase everything in the Interactions area. Don’t panic, however. Hitting the Esc key, then the P key will pull up the previous thing you typed in the Interactions area, and you can keep hitting