RScheme Overview
What is RScheme?
RScheme is an implementation of the Scheme language, with it's object-orientation approach adapted from the Dylan language.
Implementation Features
Standards Compliance
RScheme implements all of R4RS except transcript-on
and
transcript-off
, and all of R5RS except
define-syntax
(RScheme still employs it's own the
hygienic syntactic extension facility with analagous but not
compatible metasyntax to R5RS's define-syntax
).
Compliance with the revised reports on Scheme is a priority for
RScheme, and we continue to work on trying to support R5RS's
define-syntax
metasyntax while preserving the rich
compile-time dispatch available in RScheme's native syntactic
extension mechanism. And once R6RS is released, compliance in RScheme
is expected to be straightforward.
We also work continually to monitor to status and progress of various SRFIs (Scheme Requests for Implementation). We keep a running chart of RScheme/SRFI compatibility. One focus area for the upcoming 0.7.3.4 release is on improving SRFI coverage breadth and integration with the base system.
Portability
RScheme was designed so that the core system could be built with any ANSI standard-C compiler. It has been known to run on systems as diverse as Linux, NeXTSTEP, MacOS 8, Windows, QNX, and VxWorks.
Of course, some of the extension modules play funky tricks with the operating system and are, relatively speaking, not as portable. For example, the persistent object store installs SEGV handlers to notice when the application is reading or writing memory pages, requiring more than the usual introspection into operating system signal handlers. Most of the extension modules do work on popular variants of Unix.
C Code
Code in RScheme can be compiled to C, and the C can then compiled with a normal C compiler to generate machine code. By default, however, RScheme compiles to bytecodes which are interpreted by a (runtime) virtual machine. This ensures that compilation is fast and keeps code size down. In general, we recommend using the (default) bytecode code generation system, and only compiling your time-critical code to machine code. This allows a nice adjustment of space/time tradeoffs.
On some systems, compiling to C can even be done on-the-fly, with the resulting object code dynamically loaded back into the image for execution.
Extensions
RScheme goes beyond the basic Scheme language as defined in R4RS, adding several powerful extensions including:
- Modules. An ability to control the name space and decompose a large project into smaller components.
-
Object System.
RScheme defines an object system over all values in the system,
including built-in types like small integers (fixnums) and strings.
The object system is based on classes and generic functions, but mostly
employs single-dispatch for method implementations (although a
module that implements multiple-argument dispatch is available,
see
rs.sys.multimethod
) -
Hygienic Macros.
Developed before R5RS was released, RScheme incorporates
hygienic macros based on our research into language extensibility, which allow not only name-safe syntactic extensions but introspection and manipulation of the compile-time environment. Additionally, an R5RS-compatible syntax facility is available for writing portable code. - SRFI Support. The SRFI-enabling, SRFI-0, is built in. There are several SRFIs implemented in the base system, and several more available as RScheme modules.
- Threads. RScheme implements a user-level threads system, leveraging Scheme's continuation architecture as the context capture mechanism. Threads are fast and lightweight.
-
Fast Image Loading. RScheme can save it's heap in a
format which can be
mmap()
'ed back in for very fast startup times despite having everything under the sun loaded into the image. -
System Call Interface. Most common POSIX and Unix
system calls area available in the
syscalls
andunixm
modules. - Separate Compilation. RScheme modules can be compiled separately from a running image, and then linked in later. This allows the distribution of code in the form of binary modules, as well as providing a means for offline compilation of C-generated code.
- Real-time Garbage Collection. An implicit-reclamation garbage collector avoids all GC-related pauses.
- Persistent Object Storage. RScheme includes a persistent object store that is fully integrated with the Scheme heap. The store is based on the work of Wilson and Kakkad's Texas Persistent Store. For usefulness in the Scheme world, this implementation additionally includes features like automatic binding of symbols and other application-definable objects to bridge between the persistent and transient heaps. Underlying the pstore is a log-structured store (LSS), ensuring firm transactional safety and providing an ability to roll back the state of the heap to any commit point that's still live. Also included is a persistent-heap garbage collector that compacts the LSS and does GC over the persistent objects.
- Compilation to C. RScheme code can be compiled to C, and the resulting C code run through the native C compiler to produce native (object) code. The result is all linked together to produce an RScheme executable shell which obtains the performance benefits of native code. (This can also be done using dynamic linking, which brings in a whole other set of benefits.)
-
Native Language (C) Interfacing.
Since RScheme code can be compiled to C, it is a short leap
to interleave C and Scheme code more closely. This is done
with a special form called
define-glue
, and it allows C code to appear as the body of what looks like a Scheme procedure. This can make it easy to quickly interface to fairly complex C libraries, or to hand-craft C code for just the few special places needed by an application. -
Dynamic Compilation to C.
On systems that support it, interactive scheme code
can be compiled to C, or
define-glue
used to write C code from the read-eval-print loop. (See a short demo) We are also experimenting with the libtcc compiler-library to make this even faster and smoother, making the benefits available to even more code. -
Graphics Programming. Library modules to deal with graphic
images (e.g., PNG, TIFF), as well as an device driver
model for rendering to various print streams (PostScript, EPSF,
PDF, X windows). Also, modules to deal with fonts and font
metrics (AFM stuff; no TrueType support except what comes with
libgd
). The RScheme print documentation is rendered using a docbook to PostScript converter written in RScheme (but as yet unreleased) -
Extensive Libraries. More, much more. Hundreds of
modules covering a wide range of features. Text processing, XML
stuff (including a cute
xpath
macro), pattern-based s-expression transformations, context-free grammar processing, internet servers and clients of various flavors, etc., etc., etc.. Some highlights are available here.
Licensing
RScheme is an open-source implementation, meaning that it's source code is readily available and represents contributions from members of a broad community (in reality, it's a broad but somwhat small community). RScheme is freely redistributable and may be used to build commercial applications without any licensing issues.