Scheme Language Reference

st-scheme implements a subset of R7RS-small Scheme with four environment modes and a trampoline-based evaluator with proper tail call optimization.

Using the Editor

The main page shows an IDE layout with a tabbed editor panel on the left and a REPL terminal on the right.

Tab / ControlDescription
Editor tabWrite multi-line Scheme programs. Click Run to evaluate the entire buffer in the REPL, or Save & Share to generate a shareable URL.
Prelude tabView and edit the Scheme prelude for the current mode. Click Reload REPL to reinitialize the interpreter with your changes. (Read-only in Full mode.)
RunEvaluate the editor contents. Output and results appear in the REPL terminal.
Save & ShareSave the current editor contents and generate a shareable URL. The link appears next to the button.
Mode selectorChoose the environment mode (Full, Hybrid, Minimal, Bare). Changing the mode reinitializes the interpreter and resets the REPL history.

The REPL terminal accepts one-line expressions at the prompt. For multi-line input, press Shift+Enter to insert a newline — the REPL auto-detects unbalanced parentheses and continues prompting.

Visit the Gallery to try example programs. Clicking "Try it" loads the program into the Editor tab.

Environment Modes

Each mode controls how built-in procedures are provided. Use the mode selector on the REPL page to switch between them.

ModeRust BuiltinsScheme PreludesUse Case
FullAll ~90NoneProduction, maximum performance
HybridPrimitives + derived + 4 extendedprelude_core.scm (17 functions)Demonstrates language expressiveness
Minimal~49 true primitives onlyprelude_core.scm + prelude_extended.scm (46 total)Maximum dogfooding, educational
Bare~37 kernel primitives + type-of + gensymprelude_bare.scm (~42 functions)Chibi-scheme-inspired minimal kernel

Data Types

TypeSyntaxExamples
IntegerDigits, optional sign42, -7, 0
RationalExact fractions1/3, -2/5
FloatDecimal point or exponent3.14, 1e10, 2.5e-3
Boolean#t, #f#t, #f
Character#\<char>#\a, #\space, #\newline
StringDouble-quoted"hello", "world\n"
SymbolUnquoted identifierfoo, +, list?
Pair / ListDotted pair or proper list(1 . 2), (1 2 3), ()
Vector#( ... )#(1 2 3)
Procedurelambda or named(lambda (x) x)
VoidNo valueReturned by display, set!, etc.

Special Forms

FormSyntaxDescription
define(define name expr)Bind a variable
define (fn)(define (f x) body)Define a function (shorthand)
lambda(lambda (params) body)Create a closure
if(if test then else)Conditional expression
cond(cond (test expr) ... (else expr))Multi-branch conditional
let(let ((x 1) (y 2)) body)Parallel local bindings
let*(let* ((x 1) (y x)) body)Sequential local bindings
letrec(letrec ((f (lambda ...))) body)Recursive local bindings
begin(begin expr1 expr2 ...)Sequence expressions
quote(quote datum) or 'datumReturn datum unevaluated
set!(set! name expr)Mutate a binding
and(and expr1 expr2 ...)Short-circuit logical and
or(or expr1 expr2 ...)Short-circuit logical or
when(when test body ...)One-armed conditional (void if false)
unless(unless test body ...)Negated one-armed conditional
do(do ((var init step) ...) (test expr) body)Iteration construct

List Operations

ProcedureSignatureDescription
cons(cons a b)Create a pair
car(car pair)First element of a pair
cdr(cdr pair)Rest of a pair
list(list a b c ...)Create a proper list
append(append lst1 lst2 ...)Concatenate lists
map(map proc lst)Apply proc to each element
filter(filter pred lst)Keep elements satisfying pred
for-each(for-each proc lst)Apply proc for side effects
length(length lst)Number of elements
reverse(reverse lst)Reverse a list
assoc(assoc key alist)Association list lookup
member(member x lst)Find x in list
apply(apply proc args)Apply proc with argument list

Arithmetic

Numbers follow a three-variant tower: exact integers, exact rationals, and inexact floats. Any operation mixing exact + inexact produces inexact.

ProcedureSignatureDescription
+(+ a b ...)Addition
-(- a b ...)Subtraction
*(* a b ...)Multiplication
/(/ a b ...)Division (exact if possible)
modulo(modulo a b)Modulo (sign of divisor)
remainder(remainder a b)Remainder (sign of dividend)
quotient(quotient a b)Integer division
abs(abs n)Absolute value
min(min a b ...)Minimum
max(max a b ...)Maximum
expt(expt base exp)Exponentiation
sqrt(sqrt n)Square root

Comparison

ProcedureSignatureDescription
=(= a b)Numeric equality
<(< a b)Less than
>(> a b)Greater than
<=(<= a b)Less than or equal
>=(>= a b)Greater than or equal
equal?(equal? a b)Deep structural equality
eqv?(eqv? a b)Equivalent values
eq?(eq? a b)Identity (pointer) equality

String Operations

ProcedureSignatureDescription
string-length(string-length s)Length of string
string-ref(string-ref s k)Character at index k
substring(substring s start end)Extract substring
string-append(string-append s1 s2 ...)Concatenate strings
string->number(string->number s)Parse string as number
number->string(number->string n)Convert number to string
string->list(string->list s)String to list of characters
list->string(list->string chars)List of characters to string

Type Predicates

ProcedureDescription
null?Is the empty list?
pair?Is a pair (cons cell)?
list?Is a proper list?
number?Is a number?
string?Is a string?
boolean?Is a boolean?
symbol?Is a symbol?
procedure?Is a procedure?
vector?Is a vector?
char?Is a character?
zero?Is zero?
positive?Is positive?
negative?Is negative?
even?Is even?
odd?Is odd?

Input/Output

ProcedureSignatureDescription
display(display obj)Print human-readable representation
write(write obj)Print machine-readable representation
newline(newline)Print a newline character
read(read)Read an S-expression (limited in WASM)

Syntax Notes

FeatureDescription
Case sensitivityIdentifiers are case-sensitive (R7RS compliant)
Comments; begins a line comment
Block comments#| ... |# for multi-line comments
Quoting'x is shorthand for (quote x)
Quasiquote`(a ,b ,@c) for template expressions
Tail callsProper tail call optimization via trampoline
Multiline inputREPL auto-detects unbalanced parentheses