BiwaScheme for LiaScript: Functional Programming with Scheme in the Browser

BiwaScheme for LiaScript: Functional Programming with Scheme in the Browser

Scheme is one of the most influential programming languages ever designed. Its minimal syntax, powerful macro system, and emphasis on functional programming have made it a foundational language in computer science education — from SICP to modern functional programming courses.

The BiwaScheme template brings BiwaScheme 0.8.0, a full Scheme interpreter written in JavaScript, to LiaScript. Students run Scheme programs directly in the browser, with an optional interactive terminal for REPL-style exploration.


Quick Start

<!--
import: https://raw.githubusercontent.com/liaTemplates/BiwaScheme/master/README.md
-->

Two macros: @BiwaScheme.eval for batch execution and @BiwaScheme.evalWithTerminal for interactive REPL sessions.


Macro 1: @BiwaScheme.eval — Execute a Scheme Program

Attach @BiwaScheme.eval to a Scheme code block to run it and display output in the console.

```scheme
(define (factorial n)
  (if (<= n 1)
      1
      (* n (factorial (- n 1)))))

(display (factorial 10))
(newline)
(display (map factorial '(1 2 3 4 5 6 7 8)))
```
@BiwaScheme.eval

Macro 2: @BiwaScheme.evalWithTerminal — Interactive REPL

@BiwaScheme.evalWithTerminal first evaluates the code block, then opens an interactive terminal. Students can continue exploring by typing Scheme expressions directly into the terminal.

```scheme
;; Define a set of functions to explore
(define pi 3.14159265)

(define (circle-area r) (* pi r r))
(define (circle-perimeter r) (* 2 pi r))

(display "Functions defined. Try: (circle-area 5)")
(newline)
```
@BiwaScheme.evalWithTerminal

The terminal is live — students can call (circle-area 5), define new functions, and experiment freely. This is ideal for interactive lectures or exercise sessions where students explore concepts step by step.


Full Template Demo


What BiwaScheme Supports

BiwaScheme implements R7RS Scheme with most standard procedures:

  • define, lambda, let, let*, letrec
  • cond, case, when, unless
  • map, filter, for-each, fold-left, fold-right
  • Tail call optimization (TCO) — deep recursion works without stack overflow
  • call-with-current-continuation (call/cc)
  • define-syntax and syntax-rules for hygienic macros
  • Numeric tower: integers, rationals, reals
  • Lists, vectors, strings, characters

Full reference: biwascheme.org/doc/reference.html


Use Cases

SICP-style courses — Work through the Structure and Interpretation of Computer Programs with live, editable examples. Students evaluate expressions, test substitution models, and build up abstractions incrementally.

Functional programming fundamentals — Introduce map, filter, fold, closures, and higher-order functions with a language specifically designed to make these concepts visible.

Macro systems and metaprogramming — Show how define-syntax and syntax-rules work with live examples. Scheme macros are hygienic and composable — hard to explain, easy to demonstrate.

Interactive lectures — Use @BiwaScheme.evalWithTerminal to open a REPL during a live session. Students type expressions and explore the behavior of functions defined in the lecture code.


Technical Facts

Runs in browserYes — BiwaScheme 0.8.0 (JavaScript)
Server requiredNo
StandardR7RS Scheme
TCOYes — tail calls are optimized
Interactive terminalYes — @BiwaScheme.evalWithTerminal
Based onBiwaScheme by Yutaka Hara
LicenseMIT
MaintainedStable (version 0.0.5)

Try It

Try in LiaScript Open in LiveEditor View on GitHub
  • Tau-Prolog — logic programming with Prolog in the browser
  • Curiosity-Prolog — lightweight Prolog interpreter
  • JSCPP — C++ interpreter for imperative-vs-functional comparisons
  • Pyodide — full Python in the browser via WebAssembly

Related Posts

Algebrite for LiaScript: A Computer Algebra System in the Browser

Use the Algebrite template to add symbolic math computation to your LiaScript courses — evaluate CAS expressions, check student answers algebraically, and verify equations directly in the browser.

Read More

Custom Code Imports for LiaScript: Load External Files Into Executable Blocks

Fetch external source code files from any URL and display or execute them in LiaScript — the Custom-code-imports template demonstrates how to use script blocks, the LIASCRIPT: prefix, and the fetch API to build dynamic, URL-loadable code exercises.

Read More

JSCPP for LiaScript: Run C++ Directly in the Browser Without a Compiler

Use the JSCPP template to make C++ code blocks executable in your LiaScript courses — no compiler, no setup, just write C++ and teach.

Read More