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 / Control | Description |
|---|
| Editor tab | Write multi-line Scheme programs. Click Run to evaluate the entire buffer in the REPL, or Save & Share to generate a shareable URL. |
| Prelude tab | View and edit the Scheme prelude for the current mode. Click Reload REPL to reinitialize the interpreter with your changes. (Read-only in Full mode.) |
| Run | Evaluate the editor contents. Output and results appear in the REPL terminal. |
| Save & Share | Save the current editor contents and generate a shareable URL. The link appears next to the button. |
| Mode selector | Choose 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.
| Mode | Rust Builtins | Scheme Preludes | Use Case |
|---|
| Full | All ~90 | None | Production, maximum performance |
| Hybrid | Primitives + derived + 4 extended | prelude_core.scm (17 functions) | Demonstrates language expressiveness |
| Minimal | ~49 true primitives only | prelude_core.scm + prelude_extended.scm (46 total) | Maximum dogfooding, educational |
| Bare | ~37 kernel primitives + type-of + gensym | prelude_bare.scm (~42 functions) | Chibi-scheme-inspired minimal kernel |
Data Types
| Type | Syntax | Examples |
|---|
| Integer | Digits, optional sign | 42, -7, 0 |
| Rational | Exact fractions | 1/3, -2/5 |
| Float | Decimal point or exponent | 3.14, 1e10, 2.5e-3 |
| Boolean | #t, #f | #t, #f |
| Character | #\<char> | #\a, #\space, #\newline |
| String | Double-quoted | "hello", "world\n" |
| Symbol | Unquoted identifier | foo, +, list? |
| Pair / List | Dotted pair or proper list | (1 . 2), (1 2 3), () |
| Vector | #( ... ) | #(1 2 3) |
| Procedure | lambda or named | (lambda (x) x) |
| Void | No value | Returned by display, set!, etc. |
List Operations
| Procedure | Signature | Description |
|---|
| 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.
| Procedure | Signature | Description |
|---|
| + | (+ 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
| Procedure | Signature | Description |
|---|
| = | (= 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
| Procedure | Signature | Description |
|---|
| 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
| Procedure | Description |
|---|
| 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
| Procedure | Signature | Description |
|---|
| 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
| Feature | Description |
|---|
| Case sensitivity | Identifiers 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 calls | Proper tail call optimization via trampoline |
| Multiline input | REPL auto-detects unbalanced parentheses |