Pocket Scheme

[Screenshot of 1.3 on a WM5 Pocket PC]

Current version: 1.3.2, released 24 September 2006.

Welcome to Pocket Scheme, a standards-compliant implementation of the Scheme programming language for the Microsoft Windows CE (aka Windows Mobile) Pocket PC, Smartphone, and Handheld PC.

Pocket Scheme gives your PDA a standalone programming capability in Scheme, a dialect of Lisp with exceptionally clear and simple semantics. It supports file creation and manipulation, arithmetic operations of unlimited precision, the complete Unicode character set, data sharing via the Windows clipboard, regular expression matching on character strings, simple TCP client and server networking, scripts written in Scheme, and even direct system calls to the Win32 API.

Pocket Scheme also makes an excellent companion to the Friedman/Felleisen tutorial introduction to Scheme programming, The Little Schemer (ISBN 0-26256-099-2), or its sequel, The Seasoned Schemer (ISBN 0-26256-100-X). To quote their Preface:

The book is a dialogue between you and us about interesting examples of Scheme programs. If you can, try the examples while you read.
With Pocket Scheme, you can try the examples on a computer smaller than the book you are reading.

You can use Pocket Scheme for no charge. See the license below, or the FAQ if you're suspicious.

(If this is your first visit to this page, skip past the News bulletins and proceed to the table of contents.)

News bulletins

10 July 2007

I've gathered enough reports of Pocket Scheme successfully running on Smartphones to make me comfortable in claiming Smartphone support. Happy day!

24 September 2006

Released 1.3.2, correcting a couple of bugs in writing non-Unicode output to files and adding routines to access the Win32 registry. (The current system documentation does not include the registry routines. See the development log if you want to use them.)

First-generation Pocket PCs should continue to use version 1.2.2.

1 June 2006

It would seem that, just as 1.2 didn't work on the latest-generation devices, 1.3 now doesn't work on first-generation Pocket PC devices (e.g. Casio Cassiopeia E-125, HP Jornada 547, Compaq Aero 1550) in just the same way, failing to print any output. Until I fix this, antique Pocket PC users should use version 1.2.2, per these legacy binaries: SH3 MIPS ARM

10 April 2006

Released 1.3.1, correcting some memory management problems that I didn't address in 1.3. Pocket Scheme now abides by the specified heap limit, returns memory to the system in more low-memory scenarios, and better handles deep recursions.

When upgrading from 1.3 to 1.3.1, you can delete the temporary file \Temp\Scheme Transcript.htm that the old version created.

The Memory configuration panel now specifies not only the maximum size of the total heap, but also the percent of that heap to dedicate to vector and stack storage. Increase vector storage if your program exhausts storage creating a large number of vectors or strings. Increase stack storage if your program exhausts storage in deeply recursive applications. Generally, try increasing the total heap size before adjusting vector or stack percentages. I hope someday to make this panel simple again.

2 April 2006

Released version 1.3. This version supports the latest Windows Mobile 5.0 Pocket PC devices, as well as all previous Pocket PCs, but does not support the old Handheld PC. Handheld PCs should continue to use 1.2.2.

1.3 contains many user interface changes.

5 March 2006

Introducing the experimental development log. By forking off a separate log, I intend to reduce the chattiness of this page while better tracking and communicating progress towards 1.3 (just to show that something is happening on the pscheme front during these quiet months). I've moved old, chatty news bulletins there as a start.

I'll continue to announce new releases and big bad bugs here.

Table of Contents

Requirements and contraindications

Pocket Scheme requires a Pocket PC (P/PC) running Microsoft Windows CE version 3.0 (aka Windows Mobile) or later, a Smartphone running Windows Mobile 5.0 or later, or an old Handheld PC (H/PC) running CE 2.0 or later. It supports all the processor types that are found in these retail devices: Hitachi SH3 and SH4, MIPS family, and ARM (Intel StrongARM or XScale, Samsung SC32442, etc).

Pocket Scheme will not run on first-generation CE 1.0 clamshell devices such as the Hewlett-Packard 300LX (q.v. the FAQ). The device must run CE 2.0 or later.

As of version 1.1.0, Pocket Scheme no longer supports the old Palm-sized PC (e.g. Casio E-10, E-105; Everex Freestyle). The download page retains a copy of version 1.0.1 (released 10 July 2000) for any Palm-sized PC owners who wish to use Scheme. No future development will take place on this platform.

As of version 1.3, Pocket Scheme no longer supports the old Handheld PC. The download page offers version 1.2.2 (released 5 January 2006) for any Handheld PC owners who wish to use Scheme. Future development on this platform will take place only for special projects.

[Screenshot of 0.4.0 at work on a Japanese H/PC.
(Nihongo o hanashimasen.)]


See the download/installation page.


To launch Pocket Scheme, tap the bright green lambda (l) icon under Programs.

Opening a Scheme source file ("l" document icon) opens that file in the Pocket Scheme editor. Opening a Scheme command file ("l" document icon, with an exclamation point "!") launches Pocket Scheme to execute the file's contents as a script.

For complete usage directions, please consult the contents of the on-line help file or language reference.

Beyond the on-line help, you may find it useful to keep on your PDA for reference a copy of the standard Scheme definition document, readable with Pocket Internet Explorer.

For further discussion of topics such as debugging, performance, and the FFI, see the usage notes page.

[Screenshot of the editor on the H/PC]

Sample code

A collection of code samples and libraries for Pocket Scheme.


See the application notes page.


Here I list some limitations of Pocket Scheme that users should keep in mind, along with my plans to correct them, in some cases.

Standards compliance

Pocket Scheme does not comply completely with the most recent Scheme standard, for want of standard syntax-rules macros, multiple return values, and the second argument to the eval procedure, though it complies fully with the previous standard. The 2.0 release of Pocket Scheme will support standard hygienic macros and the namespace argument to eval. Multiple values, however, are an abomination, which I will support only as a syntactic kludge of some sort, if at all. I have to decide what marketing value would exist in claiming R5RS compliance for Pocket Scheme.

Convergence with the evolving new standard under development is an eventual goal. The 2.0 release will support the new library syntax (cf section 6 of the 5.91 revision).

Regular expression library

While Pocket Scheme works natively in the 16-bit (UCS-2) character representation of Windows CE, its regular expression extension library regex.dll works only on 8-bit data. Regular expressions using this library will not properly match data in Greek, Cyrillic, Kanji, Han, or any character set other than ISO Latin-1. If you need to match non-Latin characters, please instead use this library, written in portable Scheme by Dorai Sitaram. I am investigating a fix for this in the 1.2 1.3 release, which may yield a considerable size increase for regex.dll. Users of devices with little storage memory should adopt Dorai's library.


Transcendental functions are limited to the range representable in a double-precision IEEE floating-point value. Hence given (define (fact x) (if (< x 2) 1 (* x (fact (- x 1)))))), the expression (log (fact 170)) will succeed, while (log (fact 171)) will fail. How important is this? Currently we take the simple approach of coercing any transcendental's argument to a flonum, then calling the C runtime library, an approach that we share with Gambit 3.0 and Scheme48 1.3 (both of which share this limitation). If it's important, we could start with bignum-correct versions of at least SQRT, LOG, and EXP.

Complex numbers in either polar or rectangular notation are not supported. Again, it's only code, but I've never needed this. The biggest hassle will be in extending the reader.

Foreign function interface

The low-level nature of the Pocket Scheme foreign function interface allows the user to create applications as buggy as any C program. Pocket Scheme does guard against illegal memory references, where it can, but is helpless in the face of inter-thread message deadlocks and the like. Careless use of the FFI can conceivably crash Pocket Scheme or even lock the entire mobile device, forcing a soft reset.

The FFI does not accommodate floating-point parameters or return values in functions. (The different CE processor architectures vary greatly in their register usage conventions.) This prevents the FFI from driving DirectX. However, foreign structures may include floating-point fields.

User interface

Parenthesis matching does not work if the current selection is within a string constant.

On old versions of the Pocket PC, changing the text display size in Pocket Internet Explorer will change the size of Pocket Scheme's text output.

Old versions of the Pocket PC become very sluggish with a large amount of data in the transcript pane.

The Pocket PC version of the Pocket Scheme Editor still uses a File menu instead of the standard document list UI.

The Undo function in Pocket Scheme Editor is inconsistent, and hence next to useless. This originates in the manner in which I implement operations such as automatic Lisp code indentation. It will be difficult to correct.

The editor may leave large quantities of whitespace at the end of lines, or on seemingly blank lines. This is a side effect of its attempt to indent Lisp expressions automatically.

Embedded tab characters within a file will confuse the Editor automatic indentation feature. (Note that the Editor itself will not generate tab characters within a file.) To work around this, either disable automatic indentation or else replace the tab characters with a suitable number of spaces, either manually or by the supplied code snippet. I don't know whether this is worth fixing.

(define (detab tabwidth in out)
  (let loop ((i 0))
    (let ((ch (read-char in)))
        ((eof-object? ch) 'done)
        ((eq? ch #\newline) 
         (write-char ch out) 
         (loop 0))
        ((eq? ch #\x09)
         (let ((n (- tabwidth (modulo i tabwidth))))
           (do ((j n (- j 1))) ((zero? j)) (write-char #\space out))
           (loop (+ i n))))
          (write-char ch out)
          (loop (+ i 1)))))))


The desktop computer setup program does not allow the user to select a particular destination directory on the desktop computer; instead, it always installs into the directory Pocket Scheme within the Microsoft ActiveSync directory. The final destination on the mobile device, however, is properly user-configurable.

Known shortcomings and bugs in this release

Please report any problems that you encounter. If you don't report bugs, I can't fix them.

When reporting a problem, please include all of the following information. I will need this information when attempting to reproduce your problem. Furthermore, you may well find the solution to your problem yourself while gathering this information. It's happened before.

(Simon Tatham has written a very nice essay on reporting bugs effectively, which you may find enlightening, especially if you don't either report bugs or respond to bug reports for a living.)

Outstanding bugs

Certain macro expansions can confuse the variable binding mechanism. The program

(define-macro (bug . clauses) (car clauses))
(let ()
    (define (g x) (+ x 2))
    (display (bug (g 1) (k 2)))

does not bind g to the local definition. Changing the macro to read (define-macro (bug . clauses) `(begin ,(car clauses))) works around the bug. I will correct this in the 2.0 release.

The Tools - Load command confuses the Soft Input Panel state.

When the transcript window reappears, it shows the first elements in the window before scrolling down to show the most recent. This creates a distracting flashing effect.

Coming Attractions

Note that Pocket Scheme development is currently on hiatus.

The next planned release of Pocket Scheme is 1.4. 1.4 provides a simple thread-safe interface for modal dialog input and persistent graphical output.

A major rewrite of the core Pocket Scheme engine is also under development. 2.0 replaces the existing one-pass memoizing evaluator with a new two-pass eval that cleanly separates program translation and execution. The new separate compiling pass allows more efficient use of program memory. We retain the existing SIOD-derived conservative mark/sweep storage manager, as well as its use of the machine runtime stack to store intermediate computations.

The 2.0 release will contain the following features:

The following features remain under consideration for 1.4.

I am trying to decide what to do with the Pocket Scheme Editor. I originally threw this editor together as a quick hack, essentially a Windows Notepad clone that could perform block-indent and balance-parenthesis functions, with the hope that something better would come along to supplant it; now, years later, Pocket Scheme still depends on it. In particular, its lack of a functional Undo annoys and embarrasses me.

Frequently asked questions

See the FAQ page.

Release history

See the release history page.

Copyrights, License, and Acknowledgements

Pocket Scheme is Copyright 1998-2006 Ben Goetter, and distributed under the Artistic License.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the License for more details.

Portions of this software are based in part on the http://people.delphiforums.com/gjc/siod.html work of George J. Carrette.

The regular expression matching code is Copyright 1992, 1993, 1994 Henry Spencer. All rights reserved.

This work uses the BigNum package developed jointly by INRIA and Digital PRL, Copyright 1988, 1989 Digital Equipment Corporation & INRIA.

Thank You

I gratefully acknowledge George J. Carrette's magnificently minute Scheme In One Day as the starting point for the Pocket Scheme project. SIOD 3.5 is Copyright 1988-1997, Paradigm Associates Inc., Cambridge MA, all rights reserved.

Kurt Nørmark's LAML generated much of the online language reference.

Other destinations

A more recent Scheme project.
Pocket Scheme Language Reference
The on-line help file for Pocket Scheme language extensions.
Revised(4) Report on The Algorithmic Language Scheme
R4RS, the official specification of the Scheme language
Revised(5) Report on The Algorithmic Language Scheme
R5RS, the most recent revision of the Scheme language specification, which Pocket Scheme does not honor for want of standard-compliant macros and multiple return values
Exception Handling Proposal
A proposed standard set of exception handling primitives for Scheme. Pocket Scheme implements raise, current-exception-handler, and the with-handlers form. See also these workshop minutes. and this Scheme Request for Implementation (SRFI), both discussing exception handling standardization.
A collection of resources for the Scheme programming language, home to textbook recommendations and tutorials
Scheme In One Day
SIOD: the illustrious ancestor of Pocket Scheme, STk, and SCM (and hence, Guile)
An exceptionally compact Scheme implementation for the Palm Pilot
SCM for Windows CE
The competition! Rainer's port of Aubrey's interpreter, which can run either within Emacs or in its own console process.
SCM for PocketPC
Another port of the same interpreter, running under PocketConsole.
A possible replacement for my tiny Pocket Scheme editor. Supposedly supports Japanese-language files.
GNU Emacs 20.7
Another potential replacement for the Pocket Scheme editor
Go to Ben Goetter's personal page
Site Map
Find your way around this site

Last modified: Tue Feb 05 03:03:04 Pacific Standard Time 2008

Ben Goetter (contact information)

Copyright 1998-2008, Ben Goetter. All rights reserved.