How to use the online Scheme interpreter
- Write or paste Scheme code into the editor. Reset example restores the starter program, which prints a factorial, the first ten Fibonacci numbers and a sum of squares.
- Press Run or use Ctrl + Enter (⌘ + Enter on a Mac).
- Text written with
display,writeandnewlineappears in the Output panel. When the program finishes, the value of the last expression is printed as=> value, unless that value is unspecified. Errors are reported with BiwaScheme's own message. - Choose a time limit of 5, 15 or 60 seconds. An endless loop is stopped automatically, and Stop ends a run at once.
The interpreter is only about 0.3 MB, so the page is ready almost immediately. Copy and main.scm save your program, and Full screen (Ctrl/⌘ + Shift + F, Esc to leave) gives the editor the whole window.
Your code runs in a Web Worker inside your browser and is never sent to a server. The editor auto-saves your last program in your browser's local storage, separately for each compiler on this site.
About Scheme and BiwaScheme
Scheme is a small dialect of Lisp. Programs are parenthesised expressions, functions are ordinary values, and recursion is the normal way to loop. Its tiny core makes it a popular teaching language for closures, higher-order functions and interpreters.
This page runs BiwaScheme 0.8.3, a Scheme interpreter written in JavaScript. It follows the R6RS and R7RS standards in style and covers the most common Scheme features. It is not a complete implementation of either standard, though.
What's supported
- Core forms:
define,lambda,let,let*,letrec,if,cond,beginandset!. - Lists and higher-order functions:
cons,car,cdr,list,map,applyand quoted data such as'(1 2 3). - Proper tail calls, so loops written as named
letor tail-recursive functions run in constant stack space.
Limitations:
- No input box. Put test data directly in the program.
- Not a full standard implementation. Procedures specific to other Schemes, such as MIT Scheme, Racket or Guile, may be missing.
- Only the code in the editor runs. There are no files to load and no package manager.
Worked example: recursion vs named let
;; Plain recursion: each call waits for the next one to return.
(define (sum-list lst)
(if (null? lst)
0
(+ (car lst) (sum-list (cdr lst)))))
;; Named let: a tail-recursive loop with an accumulator.
(define (sum-to n)
(let loop ((i 1) (acc 0))
(if (> i n)
acc
(loop (+ i 1) (+ acc i)))))
(display (sum-list '(1 2 3 4))) (newline) ; 10
(sum-to 100000) ; => 5000050000
The last expression is not displayed, so its value appears as => 5000050000. sum-list builds up pending additions, while sum-to calls loop in tail position and behaves like a while loop.
Common pitfalls
- Forgetting to quote a list.
(1 2 3)tries to call1as a function and fails. Write'(1 2 3)or(list 1 2 3). The two differ:'(a b)is a list of the symbolsaandb, while(list a b)evaluates the variables. definevslet. A top-leveldefinecreates a global name.letcreates local names that exist only inside its body. Inside a plainlet, one binding cannot refer to another, so uselet*when a later value depends on an earlier one.displayvswrite.displayprints strings without quotes.writekeeps them, which helps when you debug data.- Equality. Use
=for numbers,eq?for symbols, andequal?to compare lists or strings by content.
Frequently asked questions
Is this a Scheme compiler or an interpreter?
An interpreter. BiwaScheme runs your program directly in the browser with no separate compile step.
Which Scheme standard is supported?
BiwaScheme follows R6RS and R7RS in style and covers the most common features. Standard textbook code that uses define, lambda, let, cond, lists and recursion runs as expected. Code that depends on one implementation's libraries may need changes.
Can I use it for SICP or course exercises?
Yes, for exercises built on core Scheme. If an exercise uses a procedure that is not defined, write a small version of it yourself at the top of the program.
Why does my program print nothing?
Only display, write and newline produce output, plus the => line for the value of the last expression. A program that ends with a define shows no value, because that result is unspecified.
What other languages can I run online?
Try the online Clojure compiler for another Lisp, the online Prolog compiler for logic programming, or browse all online compilers.