A student-friendly Gleam environment with an interactive REPL, image support, and interactive programs, designed for teaching functional programming.
sgleam is built on Gleam for compilation and QuickJS (via rquickjs) for execution. A similar project for Python is spython.
- Gleam stdlib included — 18 standard library modules available out-of-the-box, no project setup required
- Scripting — run single
.gleamfiles directly, without creating a Gleam project. Usesmainto read from stdin, making sgleam suitable for solving Advent of Code challenges and other scripting tasks - Interactive REPL — auto-indent, tab completion, multiline editing
- BigInt / Number modes — BigInt (default) for arbitrary-precision
integers, or Number mode (
-n) for better performance - Image library — built-in SVG-based graphics library for teaching, inspired by HtDP image teachpacks
- Interactive programs —
worldlibrary for animations and keyboard-driven programs - Testing —
checklibrary for example-based testing - WASM support — runs in the browser via a WASM build
Requires Rust (stable). Dependencies are fetched automatically.
cargo build # debug build
cargo build --release # optimized build# Start the REPL
sgleam
# Run a script
sgleam file.gleam
# Run with Number mode (instead of BigInt)
sgleam -n file.gleamsgleam can run single .gleam files without a project. Define a smain
function to read input from stdin:
import gleam/io
import gleam/list
import gleam/string
/// Reads lines from stdin and prints them reversed
pub fn smain(lines: List(String)) {
lines
|> list.map(string.reverse)
|> list.each(io.println)
}echo -e "hello\nworld" | sgleam file.gleam
# olleh
# dlrowThe smain function accepts three signatures:
fn smain() -> a— no inputfn smain(input: String) -> a— all stdin as a single stringfn smain(lines: List(String)) -> a— stdin split into lines
sgleam includes a built-in image library for teaching graphics programming, inspired by the HtDP image teachpacks. Images are rendered as SVG.
import sgleam/image.{circle, overlay, rectangle, to_svg}
import sgleam/fill
import sgleam/stroke
let img = overlay(circle(30, stroke.red), rectangle(80, 50, fill.blue))The library provides:
- Shapes — rectangles, circles, ellipses, triangles (7 constructors), polygons, stars, lines, wedges, bezier curves
- Transformations — rotate, scale, flip, crop
- Composition — overlay, underlay, beside, above (with alignment options)
- Scenes — place images at coordinates, draw lines/polygons/curves
- Text and fonts — text rendering with customizable fonts
- Styles — fill and stroke with color, opacity, width, dash patterns
- Colors — 140+ CSS named colors,
rgb(),rgba() - Animation —
worldlibrary for interactive programs with keyboard input
The workspace has three crates:
engine— shared library (REPL engine, Gleam compiler integration, QuickJS runtime)cli— CLI binary with REPLwasm— WASM target for browser use
make check # clippy + fmt + deno fmt
make test # cargo test + deno test (WASM)
make test-rs # cargo test only (faster)
make wasm # build WASM binaryApache 2.0 — see LICENSE.