On this page:
1.7.1 Images
1.7.2 XML Boxes and Scheme Boxes

1.7 Graphical Syntax

In addition to normal textual program, DrScheme 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

DrScheme’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. DrScheme’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 Scheme Boxes

DrScheme 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 X) on the top portion of the XML box.

In addition to containing XML text, XML boxes can also contain Scheme boxes. Scheme boxes contain Scheme expressions. These expressions are evaluated and their contents are placed into the containing XML box’s xexpr. There are two varieties of Scheme box: the standard Scheme box and the splicing Scheme box. The standard Scheme 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 X) on the top of a Scheme box opens a menu to toggle the box between a Scheme box and a Scheme splice box.