1.7 Graphical Syntax

► |  | Dr Racket: The Racket Programming Environment

1 | Interface Essentials
2 | Languages
3 | Interface Reference
4 | Extending Dr Racket
| Index

▼ | 1 | Interface Essentials

1.1 | Buttons
1.2 | Choosing a Language
1.3 | Editing with Parentheses
1.4 | Searching
1.5 | Tabbed Editing
1.6 | The Interactions Window
1.7 | Graphical Syntax
1.8 | Graphical Debugging Interface
1.9 | The Module Browser
1.10 | Color Schemes
1.11 | Creating Executables
1.12 | Following Log Messages

► | 1.7 | Graphical Syntax

1.7.1 | Images
1.7.2 | XML Boxes and Racket Boxes

On this page:

1.7.1`` Images
1.7.2`` XML Boxes and Racket Boxes

top contents ← prev up next →

#### 1.7`` Graphical Syntax🔗ℹ

In addition to normal textual program, DrRacket supports certain graphical elements as expressions within a program. Plug-in tools can extend the available graphical syntax, but this section describes some of the more commonly used elements.

##### 1.7.1`` Images🔗ℹ

DrRacket’s Insert|Insert Image... menu item lets you select an image file from disk (in various formats such as GIF, PNG, and BMP), and the image is inserted at the current editing caret.

As an expression an image behaves like a number or string constant: it evaluates to itself. DrRacket’s interactions window knows how to draw image-value results or images displayed via print.

A program can manipulate image values in various ways, such as using the htdp/image library or as an image-snip% value.

##### 1.7.2`` XML Boxes and Racket Boxes🔗ℹ

DrRacket has special support for XML concrete syntax. The Special|Insert XML Box menu item inserts an embedded editor into your program. In that embedded editor, you type XML’s concrete syntax. When a program containing an XML box is evaluated, the XML box is translated into an x-expression (or xexpr), which is an s-expression representation of an XML expression. Each xexpr is a list whose first element is a symbol naming the tag, second element is an association list representing attributes and remaining elements are the nested XML expressions.

XML boxes have two modes for handling whitespace. In one mode, all whitespace is left intact in the resulting xexpr. In the other mode, any tag that only contains nested XML expressions and whitespace has the whitespace removed. You can toggle between these modes by right-clicking or Control-clicking (Mac OS) on the top portion of the XML box.

In addition to containing XML text, XML boxes can also contain Racket boxes. Racket boxes contain Racket expressions. These expressions are evaluated and their contents are placed into the containing XML box’s xexpr. There are two varieties of Racket box: the standard Racket box and the splicing Racket box. The standard Racket box inserts its value into the containing xexpr. The contents of the splice box must evaluate to a list and the elements of the list are “flattened” into the containing xexpr. Right-clicking or control-clicking (Mac OS) on the top of a Racket box opens a menu to toggle the box between a Racket box and a Racket splice box.

top contents ← prev up next →