Scheme Windows
Volume Number: 3
Issue Number: 1
Column Tag: Lisp Listener
Scheme Does Windows!
By Anne Hartheimer, President
Programming a Text Editor in MacScheme+Toolsmith™
The purpose of this article is to give an example of an application written in
MacScheme+Toolsmith™. The application is a simple text editor, similar to the text
editor written in Pascal that appears elsewhere in this issue of MacTutor. This editor
is incomplete in many ways. It does not support the Clipboard, for example, nor does
it check to make sure that the edited text does not exceed the limits of a single text edit
record. It does, however, convey a sense of what it is like to program using
MacScheme+Toolsmith. The code for this editor is a pre-release version of an example
included with MacScheme+Toolsmith. A screen shot of the program is shown in figure
1. The program loads and saves files (which the Pascal version in this issue doesn't),
and includes a find and change function.
Figure 1: Our Lisp version Text Editor
About MacScheme, MacScheme+Toolsmith
MacScheme™ is a Lisp system from Semantic Micro systems that runs on 512K
and larger Macintoshes and includes an editor, incremental byte code compiler,
debugger, and tracer. MacScheme implements the Scheme dialect of Lisp, a dialect
known for its simplicity, regularity, and power. Aside from simple quickdraw
graphics routines, however, the only way to access the Toolbox from MacScheme was
by using machine code. This was one of the motivations behind a new product called
MacScheme+Toolsmith.
MacScheme+Toolsmith lets you program the Macintosh Toolbox interactively in
Lisp. It provides Lisp access to the complete set of Toolbox traps and high level
routines for creating window and menu objects. (You can bring up a text edit window
with a single line of code, interactively.) Source code for the object-oriented window
and menu routines is included so you can modify them if you want.
MacScheme+Toolsmith supports multitasking and provides an interrupt system for
handling events.
MacScheme+Toolsmith is being released in December 1986. To use the high
level window and menu routines, 1 M RAM is needed. You can use the rest of
MacScheme+Toolsmith with only 512K.
The Text Editor Program
Scheme programs consist of definitions mixed with expressions. These
definitions and expressions are executed in order, just as if they were typed
interactively. The first expression that appears in the editor program sets some
variables that tell the compiler not to include documentation for source code and
arguments. The second expression loads a number of files from the
MacScheme+Toolsmith disks containing definitions of procedures and data used by the
program.
Figure 2: The Scheme Trap Docs
Figure 2 shows the files in the "Chapters" folder which correspond to chapters
in Inside Macintosh. Thus "chap20.data" contains the type declarations for the
standard file package described in chapter 20 of Inside Macintosh, while
"v2.chap4.traps" contains the low level file manager traps described in chapter 4 of
volume II of Inside Macintosh. By this neat packaging trick, you can easily find the
Scheme definition for trap calls as you study the toolbox documentation in Inside
Macintosh.
The files in the "Examples" folder shown in figure 3 are examples included with
MacScheme+Toolsmith. The file "fs.sch" contains high level file system calls
analogous to the Pascal calls documented in Inside Macintosh, and the file " files.sch
contains even higher level calls for prompting for, reading, and writing entire files.
The file "fonts.sch" defines some general purpose procedures for setting fonts in a
window. This file is reproduced in this article to show you some low level Toolbox
hacking. The file " search.sch" defines a procedure for creating a Search menu that is
used in this text editor. It's about five pages long, and we thought we could safely omit
it from this article.