DrRacket is a wonderful editor. It is so feature rich that the first time you begin using it, you may end up missing out on how powerful and pleasant it is to use due to the multitude of options and features. The following is my attempt to share the most useful and interesting features and get a new-user up and running and feeling really good about it as quickly as possible.
Setup
- Download DrRacket, install it, add it to your path, and start it.
- On the bottom-left corner there is a warning about the language, click it, choose “Choose Language”, and choose “Use the language declared in the source” and click “OK”.
- Click the menu Edit -> Preferences and choose colors that you like under Colors -> Background Color and then Racket and REPL.
- Go to Editing -> General and check “Always use the platofrm-specific linefeed convention” and “Show line numbers”.
- Go to General and check “Open files in separate tabs (not separate windows)” then hit OK to save your changes.
- Go to Racket -> Limit Memory and check Unlimited.
- Look just below the menus for “(define …)”. Click it and choose “Sort by name”.
- DrRacket provides code-insight like where symbols are imported form, refactoring of variable names, and click-to-go-to-source via a feature called “online compilation”. It is a neat feature. It will also try to show you code documentation for the symbol that the cursor is on. It shows up in the upper right hand corner of the screen. You can minimize and maximize it by hitting F2. If you mouse over things, some arrows will pop up showing you from where the symbol was imported. Sometimes the arrows and code documentation bother me, and I disable it with a right click on the green expander LED on the bottom-right of the IDE and choose: “Disable online compilation”.
- Go to PLaneT and look for plugins you might want. Install DrSync for nicer default file saving behavior. Subscribe to this feed to be notified of additions to the PLaneT repository.
- Backup your configuration file with a VCS. See here for how to find it.
Must Use Keybindings
- Create a new file and paste the following in and then save it as “atom.rkt”:
-
#lang racket (provide (all-defined-out)) (define atom? (lambda (a) (and (not (null? a)) (not (pair? a)))))
- Hit F5 to evaluate it.
- Hit C:F6 to go back to the definitions window.
- Hit C:e to hide the REPL. Hit again to show it.
- Hit C:d to hide the definitions windows. Hit again to show it.
- Hit C:t to open a new tab. Paste this in and then save it as “atom-test.rkt”.
-
#lang racket (require "atom.rkt") (require rackunit) (check-eq? #f (atom? '())) (check-eq? #f (atom? '(a))) (check-eq? #f (atom? '(a . b))) (check-eq? #t (atom? 'a))
- Hit F5 to run it. No errors should be displayed. Alter one of the tests like this:
-
(check-eq? #t (atom? '(a b c)))
- An error will be reported in the REPL. Click on the x icons to jump to the error. Fix the error.
- Hit C:PgDown to go to the previous tab. Hit C:PgUp to go back and forth.
- Hit C:w to close tab.
- Move the cursor to a symbol like ‘define’ and hit F1 to have the documentation brought up in a web browser.
- Hit C:m and split the editor. Hit C:S:m to collapse the split. Hit C:F6 to move between them all.
- Navigate among s-expressions:
- Move the cursor between s-expressions within a given s-expression
- M:[arrow keys]
- Add shift to make selections eg: M:S:[arrows]
- Navigate among words:
- Move the cursor among words
- C:[arrow keys]
- Add shift to make selections eg: C:S:[arrow keys]
- Insert pairs of operators
- M:S:[char] for: “”, (), [], {}, ||
- ESC:[shift]:l) for lambda template
- Perform after selecting an s-expression to safely wrap s-expressions during refactoring
- For example, select an expression, insert a pair, that pair gets inserted around the selection you just made
- By using these commands, you will never end up with un-balanced parentheses… a major source of pain while working with Lisp.
- Racket code supports Unicode. You can easily insert it by using LaTeX markup like this:
- Enter a backslash
- Enter the macro name
- Enter M:\
- Here are some LaTeX macros to try out:
- rightarrow
- sim
- equiv
- lambda
- pi
- alpha
- omega
Depending on your perspective you might find this sort of long, but it is the shortest I felt like it could take to get a taste of the different features and try them out “for real”. Hope you enjoy reading it. Please post any questions or comments, this is surely far from perfect and I need your help to make it better.
Thanks for these tips. There were a few in there I didn’t know. Happy Thanksgiving!
Geoff:
Thanks, you too.
Just making my way through SICP using Raket and this will make me 10x more productive in DrRacket. Thanks a lot for the writeup!
You are welcome Joe and thank you for the heads up.
Can’t wait to hear about your work with SICP and /your/ personal tips for DrRacket, too!