1#lang scribble/doc
2@(require "common.rkt"
3          scribble/decode scribble/eval scribble/struct scribble/racket
4          (for-label racket/gui/base framework compiler/embed)
5          setup/getinfo racket/pretty string-constants)
6
7@(define (ioinputfont . s)
8   (apply tt s))
9@(define (iooutputfont . s)
10   (make-element output-color (decode-content s)))
11
12@title[#:tag "interface-essentials" #:style 'toc]{Interface Essentials}
13
14The DrRacket window has three parts: a row of buttons at the top, two
15editing panels in the middle, and a status line at the bottom.
16
17@centerline{@image[#:scale 0.7 "example.png"]}
18
19The top editing panel, called the @deftech{definitions window}, is for
20defining programs. The above figure shows a program that defines the
21function @racket[square].
22
23The bottom panel, called the @deftech{interactions window}, is for
24evaluating Racket expressions interactively. The @onscreen{Language} line
25in the interactions window indicates which primitives are available in
26the definitions and interactions windows.  In the above figure, the
27language is determined from the program source's @hash-lang[] line.
28
29@margin-note{The interactions window is described further in
30@secref["interactions-window"], later in this manual.}
31
32Clicking the @onscreen{Run} button evaluates the program in the
33definitions window, making the program's definitions available in the
34interactions window. Given the definition of @racket[square] as in the
35figure above, typing @racket[(square 2)] in the interactions window
36produces the result @racket[4]. Clicking the @onscreen{Run} button
37again resets the interactions window and re-evaluates the definitions
38window.
39
40The signature boxes (available via the blue quarter circle in the upper right corner) provide access
41to the summary information from the documentation.
42The @deftech{status line} at the bottom of DrRacket's window provides
43information about the current line and position of the editing caret,
44whether the current file can be modified, and whether DrRacket is
45currently evaluating any expression. The @as-index{recycling icon}
46flashes while DrRacket is ``recycling'' internal resources, such as
47memory.
48
49@local-table-of-contents[]
50
51@; ----------------------------------------------------------------------
52
53@section[#:tag "buttons"]{Buttons}
54
55The left end of the row of buttons in DrRacket contains a miniature
56button with the @index['("filename button")]{current file's
57name}. Clicking the button opens a menu that shows the file's full
58pathname. Selecting one of the menu entries produces an open-file
59dialog starting in the corresponding directory.
60
61Beside the filename button is a @as-index{@onscreen{(define ...)}
62button} for a pop-up menu of names that are defined in the definitions
63window. Selecting an item from the menu moves the insertion point (blinking
64caret) to the corresponding definition.
65
66The @as-index{@onscreen{Save} button} appears whenever the definitions
67window is modified. Clicking the button saves the contents of the
68definitions window to a file. The current name of the file appears to
69the left of the @onscreen{Save} button, but a file-selection dialog
70appears if the file has never been saved before.
71
72The @as-index{@onscreen{Step} button}---which appears only for the
73@|HtDP| teaching languages @drlang{Beginning Student} through
74@drlang{Intermediate Student with Lambda}---starts the
75@as-index{Stepper}, which shows the evaluation of a program as a
76series of small steps. Each evaluation step replaces an expression in
77the program with an equivalent one using the evaluation rules of
78DrRacket. For example, a step might replace @racket[(+ 1 2)] with
79@racket[3]. These are the same rules used by DrRacket to evaluate a
80program.  Clicking @onscreen{Step} opens a new window that contains
81the program from the definitions window, plus several new buttons:
82these buttons allow navigation of the evaluation as a series of steps.
83
84@margin-note{The debugging interface is described further in
85@secref["debugger"], later in this manual.}
86
87The @as-index{@onscreen{Debug} button}---which does @emph{not} appear
88for the @|HtDP| teaching languages---starts a more conventional
89stepping @as-index{debugger}.  It runs the program in the definitions
90window like the @onscreen{Run} button, but also opens a debugging
91panel with several other buttons that provide control over the
92program's execution.
93
94Clicking the @as-index{@onscreen{Check Syntax} button} annotates the
95program text in the definitions window.  It adds the following
96annotations:
97
98@itemize[
99
100 @item{@bold{Syntactic Highlighting:} Imported variables and locally
101        defined variables are highlighted with color
102        changes. Documented identifiers are hyperlinked (via a
103        right-click) to the documentation page.}
104
105 @item{@bold{Lexical Structure:} The lexical structure is shown with
106       arrows overlaid on the program text.  When the mouse cursor
107       passes over a variable, DrRacket draws an arrow from the
108       binding location to the variable, or from the binding location
109       to every bound occurrence of the variable.
110
111       @index['("Check syntax" "purple arrows")]{@index['("Check
112       syntax" "question-mark arrows")]{In}} addition to indicating
113       definite references with blue arrows, DrRacket also draws
114       arrows to indicate potential references within macro
115       definitions. Potential arrows are drawn in purple and annotated
116       with a question mark to indicate uncertainty, because DrRacket
117       cannot predict how such identifiers will eventually be
118       used. Their roles may depend on the arguments to the macro and
119       the context the macro is used in.
120
121       @index['("alpha renaming")]{Additionally}, right-clicking (or
122       Control-clicking on Mac OS) on a variable activates a
123       pop-up menu that lets you jump from binding location to bound
124       location and vice versa, @as-index{@"\u03B1"-rename} the
125       variable, or tack the arrows so they do not disappear.}
126
127 @item{@index['("tail calls")]{@bold{Tail Calls:}} Any
128       sub-expression that is (syntactically) in tail-position with
129       respect to its enclosing context is annotated by drawing a
130       light purple arrow from the tail expression to its surrounding
131       expression.}
132
133  @item{@bold{Require Annotations:} Right-clicking (or
134        Control-clicking on Mac OS) on the argument to
135        @racket[require] activates a pop-up menu that lets you open the
136        file that contains the @racket[require]d module.
137
138        Passing the mouse cursor over a @racket[require] expression
139        inside a module shows all of the variables that are used from
140        that @racket[require] expression. Additionally, if no
141        variables are used from that require expression, it is colored
142        like an unbound variable.
143
144         Finally, passing the mouse cursor over a variable that is
145         imported from a module shows the module that it is imported
146         from in a status line at the bottom of the frame.}
147
148]
149
150Check Syntax also runs automatically as you edit your program,
151and the bottom, rightmost corner of the DrRacket window
152shows its status. A red dot means that something has gone wrong;
153move your mouse over the dot to find out what is wrong.
154
155When nothing goes wrong, the colors indicate the stages processing of the program:
156blue (expanding), purple (computing check syntax information), orchid (updating the
157editor with the check syntax information), and green (finished).
158
159Also, right-clicking (or control clicking) in that area
160yields a menu that lets you disable (or re-enable) automatic
161Check Syntax.
162
163The @as-index{@onscreen{Run} button} evaluates the program in the
164@tech{definitions window} and resets the @tech{interactions window}.
165
166The @as-index{@onscreen{Break} button} interrupts an evaluation, or
167beeps if DrRacket is not evaluating anything. For example, after
168clicking @onscreen{Run} or entering an expression into the
169interactions window, click @onscreen{Break} to cancel the
170evaluation. Click the @onscreen{Break} button once to try to interrupt
171the evaluation gracefully; click the button twice to kill the
172evaluation immediately.
173
174@; ----------------------------------------------------------------------
175
176@section[#:tag "choose-language"]{Choosing a Language}
177
178@section-index["language levels"]
179
180DrRacket supports multiple dialects of Racket, as well as some
181non-Racket languages. You specify a language in one of two ways:
182
183@itemize[
184
185 @item{Select the @drlang{Use the language declared in the source}
186       option (via the @menuitem["Language" "Choose Language..."] menu
187       item), and then specify a specific language as part of the
188       program usually by starting the definitions-window content with
189       @hash-lang[].}
190
191  @item{Select the @menuitem["Language" "Choose Language..."] menu
192       item, and choose a specific language. After changing the
193       language, click @onscreen{Run} to reset the language in the
194       interactions window. The bottom-left corner of DrRacket's main
195       window also has a shortcut menu item for selecting previously
196       selected languages.}
197
198]
199
200Using a language declared in a program's source is the recommend mode,
201and it is described further in @secref["module"].
202
203The @menuitem["Language" "Choose Language..."] dialog contains a
204@onscreen{Show Details} button for configuring certain details of the
205chosen language. Whenever the selected options do not match the
206default language specification, a @onscreen{Custom} indicator appears
207next to the language-selection control at the top of the dialog.
208
209See @secref["languages"] (later in this manual) for more information
210on the languages that DrRacket supports.
211
212@; ----------------------------------------------------------------------
213
214@section[#:tag "editor"]{Editing with Parentheses}
215
216@index['("flashing parenthesis matches")]{@index['("gray highlight
217regions")]{In}} Racket mode, especially, DrRacket's editor provides
218special support for managing parentheses in a program. When the
219blinking caret is next to a parenthesis, DrRacket shades the region
220between the parenthesis and its matching parenthesis. This feature is
221especially helpful when balancing parentheses to complete an
222expression.
223
224@index['("formatting Racket code")]{@index['("indenting Racket
225code")]{Although}} whitespace is not significant in Racket, DrRacket
226encourages a particular format for Racket code. When you type Enter or
227Return, the editor inserts a new line and automatically indents it. To
228make DrRacket re-indent an existing line, move the blinking caret to
229the line and hit the Tab key. (The caret can be anywhere in the line.)
230You can re-indent an entire region by selecting the region and typing
231Tab.
232
233@index['("changing a parenthesis as you type")]{@index['("automatic
234parenthesis")]{DrRacket}} also rewrites parenthesis as you type them,
235in order to make them match better. If you type a closing parenthesis
236@litchar{)}, a closing square bracket @litchar{]}, or a closing curly brace
237@litchar["}"], and if DrRacket can match it back to some earlier opening
238parenthesis, bracket, or brace, then DrRacket changes what you type to
239match.  DrRacket also rewrites open square brackets, usually to an
240open parenthesis. There are some exceptions where opening square
241brackets are not automatically changed to parentheses:
242
243@itemize[
244
245 @item{If the square bracket is after @racket[cond]-like keyword,
246       potentially skipping some of the sub-expressions in the
247       @racket[cond]-like expression (for example, in a @racket[case]
248       expression, the square brackets start in the second
249       sub-expression).}
250
251 @item{If the square bracket begins a new expression immediately after
252       a @racket[local]-like keyword. Note that the second expression
253       after a @racket[local]-like keyword will automatically become
254       an ordinary parenthesis.}
255
256 @item{If the square bracket is after a parenthesis that is after a
257       @racket[letrec]-like keyword,}
258
259 @item{If the square bracket is in a sequence and the s-expression
260      before in the sequence is a compound expression, DrRacket uses
261      the same kind parenthesis, brace, or bracket as before, or}
262
263 @item{If the square bracket is in the middle of string,
264       comment, character, or symbol.}
265]
266
267The upshot of DrRacket's help is that you can always use the
268(presumably unshifted) square brackets on your keyboard to type
269parenthesis. For example, when typing
270
271@racketblock[
272(define (length l)
273  (cond
274   [(empty? l) 0]
275   [else (+ 1 (length (rest l)))]))
276]
277
278If you always type @litchar{[} and @litchar{]} where any of the square
279brackets or parentheses appear, DrRacket will change the square
280brackets to match the code above.
281
282Of course, these features can be disabled and customized in the
283preferences dialog; see @secref["prefs-explanation"].  Also, in case
284DrRacket does not produce the character you want, holding down the
285control key while typing disables DrRacket's parenthesis, brace, and
286bracket converter.
287
288@; -------------------------------
289
290@section{Searching}
291
292DrRacket's search and replace feature is interactive,
293similar to those in Safari, Firefox, and Emacs, but with a
294few differences.
295
296To start a search, first select the @onscreen{Find} menu
297item from the @onscreen{Edit} menu. This will open a small
298editor at the bottom of the DrRacket window. Start typing in
299there and, as you type, all occurrences of the string you're
300searching for will be circled in the editor window. Watch
301the space right next to the search window to see how many
302occurrences of the search string there are in your
303file. When you're ready, you use the @onscreen{Find Again}
304menu item to jump to the first occurrence of the search
305string. This will color in one of the circles. Use
306@onscreen{Find Again} a second time to jump to the next
307occurrence.
308
309If you click back into the definitions window, the
310@onscreen{Find Again} menu item, DrRacket will move the
311selection to the next occurrence of the search string.
312
313DrRacket also supports a mode where typing in the search
314editor takes you directly to the next occurrence of the
315search string, without selecting the @onscreen{Find Again}
316menu item. In the preference dialog, in the
317@onscreen{Editing} section and then in the
318@onscreen{General Editing} section is a checkbox labeled
319@onscreen{Search using anchors}. When it is checked,
320DrRacket shows a little red dot and a red line indicating
321where the @deftech{search anchor} is. When the search anchor
322is enabled, typing in the search window jumps to the first
323occurrence of the search string after the anchor.
324
325@; -------------------------------
326
327@section{Tabbed Editing}
328
329DrRacket's allows you to edit multiple files in a single window via
330tabs. The @menuitem["File" "New Tab"] menu item creates a new tab to
331show a new file. Each tab has its own interactions window.
332
333In the @onscreen{General} pane of the
334the preferences window, a checkbox labeled @onscreen{Open files in
335separate tabs} causes DrRacket to open files in new tabs in the
336frontmost window, rather than opening a new window for the file.
337
338The key bindings Control-Pageup and Control-Pagedown move between
339tabs. On Mac OS, Command-Left-Square-Bracket and Command-Right-Square-Bracket also
340move between tabs.
341
342@; ----------------------------------------------------------------------
343
344@section[#:tag "interactions-window"]{The Interactions Window}
345
346@index['("> prompt")]{@index['("evaluating expressions")]{The}}
347interactions window lets you type an expression after the @tt{>}
348prompt for immediate evaluation. You cannot modify any text before the
349last @tt{>} prompt. To enter an expression, the blinking caret must
350appear after the last prompt, and also after the space following the
351prompt.
352
353When you type a complete expression and hit Enter or Return, DrRacket
354evaluates the expression and prints the result. After printing the
355result, DrRacket creates a new prompt for another expression. Some
356expressions return a special ``void'' value; DrRacket never prints
357void, but instead produces a new prompt immediately.
358
359If the expression following the current prompt is incomplete, then
360DrRacket will not try to evaluate it. In that case, hitting Enter or
361Return produces a new, auto-indented line. You can force DrRacket to
362evaluate the expression by typing Alt-Return or Command-Return
363(depending on your platform).
364
365To copy the @as-index{previous expression} to the current prompt, type
366ESC-p (i.e., type Escape and then type p). Type ESC-p multiple times
367to @as-index{cycle back through old expressions}. Type ESC-n to cycle
368forward through old expressions. There are other keys that have these
369same functions; see @seclink["Keyboard Shortcuts"] and the menu
370item @onscreen{Show Active Keybindings} menu item in the @onscreen{Edit} menu.
371
372Clicking the @onscreen{Run} button evaluates the program in the
373@tech{definitions window} and makes the program's definitions
374available in the interactions window. Clicking @onscreen{Run} also
375resets the interactions window, erasing all old interactions and
376removing old definitions from the interaction environment. Although
377@onscreen{Run} erases old @tt{>} prompts, ESC-p and ESC-n can still
378retrieve old expressions.
379
380@; ----------------------------------------
381
382@subsection{Errors}
383
384@index['("error highlighting")]{Whenever} DrRacket encounters an error
385while evaluating an expression, it prints an error message in the
386interactions window and highlights the expression that triggered the
387error. The highlighted expression might be in the definitions window,
388or it might be after an old prompt in the interactions window.
389
390For certain kinds of errors, DrRacket turns a portion of the error
391message into a hyperlink. Click the hyperlink to get help regarding a
392function or keyword related to the error.
393
394For some run-time errors, DrRacket shows a bug icon next to the error
395message. Click the bug icon to open a window that shows a ``stack'' of
396expressions that were being evaluated at the time of the error. In
397addition, if the expressions in the stack appear in the
398@tech{definitions window}, a red arrow is drawn to each expression
399from the next deeper one in the stack.
400
401@; ----------------------------------------
402
403@subsection{Input and Output}
404
405@section-index["I/O"]
406
407Many Racket programs avoid explicit input and output operations,
408obtaining input via direct function calls in the @tech{interactions
409window}, and producing output by returning values. Other Racket
410programs explicitly print output for the user during evaluation using
411@as-index{@racket[write]} or @as-index{@racket[display]}, or
412explicitly request input from the user using @as-index{@racket[read]}
413or @as-index{@racket[read-char]}.
414
415Explicit input and output appear in the @tech{interactions window},
416but within special boxes that separate explicit I/O from normal
417expressions and results. For example, evaluating
418
419@racketblock[
420@#,tt{>} (read)
421]
422
423in the interactions window produces a special box for entering input:
424
425@centerline{@image[#:scale 0.7 "io.png"]}
426
427Type a number into the box and hit Enter, and that number becomes the
428result of the @racket[(read)] expression. Once text is submitted for
429an input box, it is moved outside the input box, and when DrRacket
430shows a new prompt, it hides the interaction box. Thus, if you type
431@racket[5] in the above input box and hit Return, the result appears
432as follows:
433
434@racketblock[
435@#,tt{>} (read)
436@#,ioinputfont{5}
437@#,racketresult[5]
438@#,tt{>} @#,tt{_}
439]
440
441In this case, the first @ioinputfont{5} is the input, and the second
442@racketresult[5] is the result of the @racket[(read)] expression. The
443second @racketresult[5] is colored blue, as usual for a result printed
444by DrRacket. (The underscore indicates the location of the blinking
445caret.)
446
447Output goes into the @tech{interactions window} directly. If you run
448the program
449
450@racketmod[
451racket
452(define v (read))
453(display v) (newline)
454v
455]
456
457and provide the input S-expression @racket[(1 2)], the interactions
458window ultimately appears as follows:
459
460@racketblock[
461@#,ioinputfont{(1 2)}
462@#,iooutputfont{(1 2)}
463@#,racketresult['(1 2)]
464@#,tt{>} @#,tt{_}
465]
466
467In this example, @racket[display] produces output immediately beneath
468the input you typed, and the final result is printed last. The
469displayed output is drawn in purple. (The above example assumes
470default printing. With constructor-style value printing, the final
471before the prompt would be @racket[(list 1 2)].)
472
473Entering the same program line-by-line in the interactions window
474produces a different-looking result:
475
476@racketblock[
477@#,tt{>} (define v (read))
478@#,ioinputfont{(1 2)}
479@#,tt{>} (display v)
480@#,iooutputfont{(1 2)}
481@#,tt{>} v
482@#,racketresult['(1 2)]
483@#,tt{>} @#,tt{_}
484]
485
486Depending on the input operation, you may enter more text into an
487input box than is consumed. In that case, the leftover text remains in
488the input stream for later reads. For example, in the following
489interaction, two values are provided in response to the first
490@racket[(read)], so the second value is returned immediately for the
491second @racket[(read)]:
492
493@racketblock[
494@#,tt{>} (read)
495@#,ioinputfont{5 6}
496@#,racketresult[5]
497@#,tt{>} (read)
498@#,racketresult[6]
499@#,tt{>} @#,tt{_}
500]
501
502The following example illustrates that submitting input with Return
503inserts a newline character into the input stream:
504
505@racketblock[
506@#,tt{>} (read)
507@#,ioinputfont{5}
508@#,racketresult[5]
509@#,tt{>} (read-char)
510@#,racketresult[#\newline]
511@#,tt{>} @#,tt{_}
512]
513
514The @onscreen{eof} button that appears beside an input box inserts
515a single @racket[eof-object] into the input stream, but more IO may
516follow in a later sequence. For example, in the following interaction,
517the user typed @litchar{1} and then clicked the @onscreen{eof} button:
518
519@racketblock[
520@#,tt{>} (read-char)
521@#,ioinputfont{1}@#,racketresult[#\1]
522@#,tt{>} (read-char)
523@#,racketresultfont{#<eof>}
524]
525
526At this point, however, future interactions can still take place:
527new calls to input functions with open a new input box and new
528characters will come from the same port.
529
530Within a @racket[@#,hash-lang[] @#,racketmodname[racket]] module,
531the results of top-level expression print the same as the results of
532an expression entered in the @tech{interactions window}. The reason is
533that @racket[@#,hash-lang[] @#,racketmodname[racket]] explicitly
534prints the results of top-level expressions using
535@racket[(current-print)], and DrRacket sets @racket[(current-print)]
536to print values in the same way as for interactions.
537
538@; ----------------------------------------------------------------------
539
540@section{Graphical Syntax}
541
542In addition to normal textual program, DrRacket supports certain
543graphical elements as expressions within a program. Plug-in tools can
544extend the available graphical syntax, but this section describes some
545of the more commonly used elements.
546
547@subsection[#:tag "images"]{Images}
548
549DrRacket's @menuitem["Insert" "Insert Image..."] menu item lets you
550select an image file from disk (in various formats such as GIF, PNG,
551and BMP), and the image is inserted at the current editing caret.
552
553As an expression an image behaves like a number or string constant: it
554evaluates to itself. DrRacket's @tech{interactions window} knows how
555to draw image-value results or images displayed via @racket[print].
556
557A program can manipulate image values in various ways, such as using
558the @racket[htdp/image] library or as an
559@racket[image-snip%] value.
560
561@subsection[#:tag "xml-boxes"]{XML Boxes and Racket Boxes}
562
563DrRacket has special support for XML concrete syntax. The
564@menuitem["Special" "Insert XML Box"] menu item inserts an embedded
565editor into your program. In that embedded editor, you type XML's
566concrete syntax. When a program containing an XML box is evaluated,
567the XML box is translated into an @deftech{x-expression} (or
568@deftech{xexpr}), which is an s-expression representation of an XML
569expression. Each xexpr is a list whose first element is a symbol
570naming the tag, second element is an association list representing
571attributes and remaining elements are the nested XML expressions.
572
573XML boxes have two modes for handling whitespace. In one mode, all
574whitespace is left intact in the resulting xexpr.  In the other mode,
575any tag that only contains nested XML expressions and whitespace has
576the whitespace removed. You can toggle between these modes by
577right-clicking or Control-clicking (Mac OS) on the top portion of
578the XML box.
579
580In addition to containing XML text, XML boxes can also
581contain Racket boxes. Racket boxes contain Racket
582expressions. These expressions are evaluated and their
583contents are placed into the containing XML box's xexpr.
584There are two varieties of Racket box: the standard Racket
585box and the splicing Racket box. The standard Racket box
586inserts its value into the containing xexpr. The contents of
587the splice box must evaluate to a list and the elements of
588the list are ``flattened'' into the containing xexpr.
589Right-clicking or control-clicking (Mac OS) on the top of a Racket
590box opens a menu to toggle the box between a Racket box and
591a Racket splice box.
592
593@; ----------------------------------------------------------------------
594
595@section[#:tag "debugger"]{Graphical Debugging Interface}
596
597@margin-note{@bold{Tip:} Changing the name of a file in the middle of
598a debugging session will prevent the debugger from working properly on
599that file.}
600
601Like the @onscreen{Run} button, the @as-index{@onscreen{Debug} button}
602runs the program in the definitions window.  However, instead of
603simply running it from start to finish, it lets users control and
604observe the program as it executes.  The interface includes a panel of
605buttons above the definitions window, as well as extensions to the
606definitions window itself.
607
608The program starts out paused just before the first expression is
609executed.  This is indicated in the definitions window by the presence
610of a green triangle over this expression's left parenthesis.
611
612@subsection{Debugger Buttons}
613
614While execution is paused, several buttons are available:
615
616@itemize[
617
618    @item{The @as-index{@onscreen{Go} button} is enabled
619whenever the program is paused.  It causes the program to resume
620until it either completes, reaches a breakpoint, or raises an
621unhandled exception.}
622
623    @item{The @as-index{@onscreen{Step} button} is enabled whenever
624the program is paused.  It causes the program to make a single step
625and then pause again.}
626
627    @item{The @as-index{@onscreen{Over} button} is only enabled when
628execution is paused at the start of an expression that is not in tail
629position.  It sets a one-time breakpoint at the end of the
630expression (represented by a yellow circle) and causes the program to
631proceed.  When execution reaches the one-time breakpoint, it pauses
632and removes that breakpoint.}
633
634    @item{The @as-index{@onscreen{Out} button} is only enabled when
635execution is paused within the context of another expression.  Like
636the @onscreen{Over} button, it sets a one-time breakpoint and
637continues execution.  In this case, the program stops upon returning
638to the context or raising an unhandled exception.}
639
640]
641
642If the program is running (not paused), then only the @as-index{Pause}
643button will be enabled.  Clicking it will interrupt execution and
644pause it.  In this case, the current expression may only be known
645approximately, and it will be represented as a gray triangle.  The
646other features described above will still be available.
647
648At any time, execution may be interrupted by clicking the
649@onscreen{Stop} button.  However, unlike with the @onscreen{Pause}
650button, stopped execution cannot be continued.
651
652@subsection{Definitions Window Actions}
653
654When execution is paused, the definitions window supports several
655additional actions:
656
657@itemize[
658
659    @item{Hovering the mouse cursor over a parenthesis may reveal a
660pink circle.  If so, right-clicking or control-clicking (Mac OS)
661will open a menu with options to @onscreen{Pause at this point} or
662@onscreen{Continue to this point}.  The former sets an ordinary
663breakpoint at that location; the latter sets a one-time breakpoint and
664resumes execution.  An ordinary breakpoint appears as a red circle,
665and a one-time breakpoint appears as a yellow circle.
666
667@bold{Tip:} If the debugged program is not a module, then the
668@italic{first time} it is debugged, breakpoints will only become
669available in expressions as they are evaluated.  However, the next
670time the program is debugged, the debugger will remember the set of
671breakable locations from the previous session.
672
673@bold{Tip:} Clicking the @onscreen{Run} button after a debugging
674session will cause all breakpoints to disappear from the definitions
675window.  These breakpoints are not forgotten, and clicking
676@onscreen{Debug} again will restore them.  However, breakpoints do
677@italic{not} persist across restarts of DrRacket.}
678
679    @item{If execution is paused at the start of an expression, then
680right-clicking or control-clicking (Mac OS) on the green triangle
681opens a menu with the option to @onscreen{Skip expression...}.
682Selecting this opens a text box in which to enter a value for the
683expression.  The expression is skipped, with the entered value
684substituted for it.}
685
686    @item{If execution is paused at the end of an expression, then the
687expression and its value are displayed to the left of the button bar.
688Right-clicking or control-clicking (Mac OS) on the green triangle
689opens a menu with options to @onscreen{Print return value to console}
690and @onscreen{Change return value...}.  The former displays the return
691value in the interactions window; the latter opens a text box in which
692to enter a substitute value.}
693
694    @item{Hovering the mouse cursor over a bound variable displays the
695variable's name and value to the right of the button bar.
696Right-clicking or control-clicking (Mac OS) opens a menu with
697options to @onscreen{Print value of <var> to console} or
698@onscreen{(set! <var> ...)}.  The former displays the variable's value
699in the interactions window; the latter opens a text box in which to
700enter a new value for the variable.}
701
702]
703
704@subsection{Stack View Pane}
705
706In addition, while execution is paused, the stack view pane at the
707right of the DrRacket frame is active.  The top of the pane shows a
708list of active stack frames.  Mousing over a frame produces a faint
709green highlighting of the corresponding expression.  Clicking on the
710frame selects that frame, which makes its lexical variables visible.
711The selected frame is indicated by a bold font.
712
713The bottom of the pane shows the lexical variables in the selected
714stack frame.
715
716The following screenshot illustrates several aspects of the debugger
717interface.  The red circle in the body of @racket[for/sum] is a breakpoint,
718and the green triangle at the end of the @racket[(+ i n)] is where
719execution is currently paused.  The expression's return value is
720displayed at the left of the button bar, and the value of @racket[i]
721and other variables are displayed in the stack view pane.
722
723@centerline{@image[#:scale 0.7 "debugger1.png"]}
724
725@subsection{Debugging Multiple Files}
726
727To debug a program that spans several files, make sure that all of the
728files are open in DrRacket.  Click the @onscreen{Debug} button in the
729window containing the main program.  As this program loads additional
730files that are present in other windows or tabs, message boxes will
731pop up asking whether or not to include the file in the debugging
732session.  Including the file means that it will be possible to set
733breakpoints, inspect variables, and single-step in that file.
734
735@bold{Tip:} A file may only be involved in one debugging session at a
736time.  If you try to debug a file that loads another file that is
737already being debugged, a message box will pop up explaining that the
738file cannot be included in another debugging session.
739
740@; ----------------------------------------------------------------------
741
742@section[#:tag "module-browser"]{The Module Browser}
743
744The module browser shows you the structure of all of the files in your program.
745It can be opened via the @onscreen{Show} menu, or via the
746@onscreen{Module Browser}
747menu items in the @onscreen{Racket} menu.
748
749A module browser window contains a square for each
750  module. The squares are colored based on the number of
751  lines of code in the module. If a module has more lines of
752  code, it gets a darker color. If a module is red, it means
753  that DrRacket did not find a source file for it.
754
755  In addition, for each normal import, a blue line drawn is
756  from the module to the importing module. Similarly, purple
757  lines are drawn for each for-syntax, for-template or for-meta import. In the initial
758  module layout, modules to the left import modules to the
759  right, but since modules can be moved around
760  interactively, that property might not be preserved.
761
762  To open the file corresponding to the module, double click
763  on the box for that module.
764
765  The module browser will also show you the phases that each
766  module is loaded in; choose the ``Long, with phases'' menu item
767  in the ``Names'' pop-up menu. The integers indicate the phases and
768  if @racket[#f] is present, it means the module is loaded @racket[for-label].
769
770  The bar along the bottom helps you find your way in a module graph. Specifically,
771  if you type something there, then all of the modules whose filenames match
772  what you type will turn green in the module window. This bar is only visible
773  in the stand alone module browser window (via the @onscreen{Racket} menu)
774
775@section[#:tag "color-scheme"]{Color Schemes}
776
777DrRacket comes with a selection of color schemes, available in the preferences dialog's
778@onscreen{color} panel.
779
780You can add your own color schemes to DrRacket, too. The first step is to
781create a package (see @secref["how-to-create" #:doc '(lib "pkg/scribblings/pkg.scrbl")])
782and add an @filepath{info.rkt} file to it. The file should define
783@racket[framework:color-schemes] as a list of hashes that describe the color schemes.
784
785@(define example-key #f)
786
787As an example, this is the specification of the @racket["Modern"] style:
788@(let ()
789   (define key 'framework:color-schemes)
790   (define pths (find-relevant-directories (list key) 'all-available))
791   (define datum
792     (apply
793      append
794      (for/list ([pth (in-list pths)])
795        (define info (get-info/full pth))
796        (if info
797            (info key)
798            '()))))
799   (define name-as-string-datum
800     (filter
801      (λ (x) (equal? (hash-ref x 'name)
802                     (string-constant modern-color-scheme)))
803      (let loop ([datum datum])
804        (cond
805          [(list? datum)
806           (for/list ([datum (in-list datum)])
807             (loop datum))]
808          [(hash? datum)
809           (for/hash ([(k v) (in-hash datum)])
810             (if (and (equal? k 'name) (string-constant? v))
811                 (values k (dynamic-string-constant v))
812                 (values k (loop v))))]
813          [(and (symbol? datum)
814                (regexp-match #rx"framework:" (symbol->string datum)))
815           (unless example-key (set! example-key datum))
816           datum]
817          [else datum]))))
818   (when (null? name-as-string-datum)
819     (error 'interface-essentials.scrbl "could not find \"Modern\" style"))
820   (define sp (open-output-string))
821   (parameterize ([pretty-print-columns 60]
822                  [current-output-port sp])
823     (pretty-write
824      `(define ,key
825         ',name-as-string-datum)))
826   (codeblock
827    (string-append "#lang info\n"
828                   (get-output-string sp))))
829
830Each of the keys, e.g., @racketvalfont[(format "'~s" example-key)], maps to a color and possibly to
831some style information. All keys accept colors (the vectors shown
832above represent colors in red--green--blue format), but only some accept style information. To
833find out which are which and to get a complete list of the possible keys, click the button
834labeled @onscreen[(regexp-replace #rx"&&" (string-constant style-and-color-names) "\\&")]
835at the bottom of the
836@onscreen[(string-constant color-schemes)] tab of the
837@onscreen[(string-constant preferences-colors)] tab in the preferences dialog.
838If one can accept style information, then you may include any of @racket['bold],
839@racket['underline], @racket['italic] or @racket[`#s(background ,_color)] in the list with the color.
840
841Full details on the specification of the info files can be found in the documentation
842for the function @racket[color-prefs:register-info-based-color-schemes].
843
844You may have to restart DrRacket (and, at least the first time after you add the @filepath{info.rkt}
845file, re-run @tt{raco setup}) to see changes to your color scheme.
846
847Color schemes are not limited only to the colors that DrRacket already knows about.
848If you are adding your own plugin to DrRacket, you can add new names that can be
849mapped in the color scheme. See @racket[color-prefs:register-color-preference] for
850more information.
851
852@section[#:tag "create-exe"]{Creating Executables}
853
854DrRacket's @onscreen{Create Executable...} menu item lets you create
855an executable for your program that you can start without first
856starting DrRacket. To create an executable, first save your program to
857a file and set the language and teachpacks.  Click @onscreen{Run},
858just to make sure that the program is working as you expect. The
859executable you create will not have a read-eval-print-loop, so be sure
860to have an expression that starts your program running in the
861definitions window before creating the executable.
862
863Once you are satisfied with your program, choose the @onscreen{Create
864Executable...}  menu item from the @onscreen{Racket} menu. You will be
865asked to choose an executable file name or an archive file name. In
866the latter case, unpack the generated archive (on this machine or
867another one) to access the executable. In either case, you will be
868able to start the executable in the same way that you start any other
869program on your computer.
870
871The result of @onscreen{Create Executable...} is either a
872@defterm{launcher executable}, a @defterm{stand-alone executable}, or
873a @defterm{distribution archive}, and it uses either a
874@defterm{Racket} (textual) or @defterm{GRacket} (graphical) engine.
875For programs implemented with certain languages, @onscreen{Create
876Executable...}  will prompt you to choose the executable type and
877engine, while other languages support only one type or engine.
878
879Each type has advantages and disadvantages:
880
881@itemize[
882
883  @item{A @deftech{launcher executable} uses the latest version of
884  your program source file when it starts. It also accesses library
885  files from your DrRacket installation when it runs. Since a launcher
886  executable contains specific paths to access those files, launchers
887  usually cannot be moved from one machine to another.}
888
889 @item{A @deftech{stand-alone executable} embeds a compiled copy of
890 your program and any Racket libraries that your program uses. When
891 the executable is started, it uses the embedded copies and does not
892 need your original source file. It may, however, access your DrRacket
893 installation for DLLs, frameworks, shared libraries, or helper
894 executables. Consequently, a stand-alone executable usually cannot be
895 moved from one machine to another.}
896
897 @item{A @deftech{distribution archive} packages a stand-alone
898 executable together with any needed DLLs, frameworks, shared
899 libraries, and helper executables. A distribution archive can be
900 unpacked and run on any machine with the same operating system as
901 yours.}
902
903]
904
905DrRacket's gives you the most options when it infers a
906language from a program's source. Most other languages only allow one
907type of executable. The teaching languages, for example, create
908stand-alone executables in distributions. The legacy languages create
909only launchers.
910
911@bold{Tip:} Disable debugging in the language dialog before creating
912your executable. With debugging enabled, you will see a stack trace
913with error messages, but your program will run more slowly.  To
914disable debugging, open the language dialog, click the @onscreen{Show
915Details} button, and select @onscreen{No debugging or profiling}, if
916it is available.
917
918When you create an executable in some languages, you can supply
919additional files to determine the executable's icon and similar
920properties, depending on the platform. The file's purpose is
921determined by its suffix:
922
923@itemlist[
924
925 @item{On Windows, supply an @filepath{.ico} file for an icon. Only
926       16x16, 32x32, or 48x48 images from the @filepath{.ico} file are
927       used.}
928
929 @item{On Mac OS, supply an @filepath{.icns} file for an icon.  You
930       can set the application's creator with an @filepath{.creator}
931       file (whose first four bytes are used), and you can set
932       documents for the application through a @filepath{.utiexports}
933       file (see @racket['uti-exports] in
934       @racket[create-embedding-executable] for more information).}
935
936 @item{On Unix, supply a @filepath{.png} or @filepath{.ico} file for
937       an icon.}
938
939]
940
941@section[#:tag "follow-log"]{Following Log Messages}
942
943The @onscreen{Show Log} menu item in the @onscreen{View} menu opens
944a pane in the DrRacket window showing log messages.
945
946Along the top of the window is a text field that should be filled with
947a description of which log messages are interesting, as described in
948the @secref[#:doc '(lib "scribblings/reference/reference.scrbl") "logging"]
949section of @other-doc['(lib "scribblings/reference/reference.scrbl")].
950
951