Scheme Playground - Online IDE

Coding Tools

Type your Scheme code and click Run to see the output instantly.

Result:

Scheme Programming Guide

Basic Syntax

Scheme uses prefix notation (also called Polish notation) where the operator comes before the operands, all wrapped in parentheses.

Code Examples

Try these examples in the playground above. Click Run to see the results.

Arithmetic

Basic math operations. Operators can take multiple arguments.

(+ 1 2 3)        ; => 6
(* 4 5)          ; => 20
(- 10 3)         ; => 7
(/ 15 3)         ; => 5

Variables

Use define to bind values to names.

(define x 42)
(define name "hello")
x                ; => 42

Functions

Define functions with (define (name args...) body).

(define (square x)
  (* x x))
(square 5)       ; => 25

Conditionals

Use if for simple conditions, cond for multiple branches.

(if (> 3 2)
    "yes"
    "no")          ; => "yes"

(cond
  ((< x 0) "negative")
  ((= x 0) "zero")
  (else "positive"))

Lists

Lists are the fundamental data structure. car returns the first element, cdr returns the rest.

(list 1 2 3)     ; => (1 2 3)
(car '(1 2 3))   ; => 1
(cdr '(1 2 3))   ; => (2 3)
(cons 0 '(1 2))  ; => (0 1 2)

Lambda (Anonymous Functions)

Lambda creates unnamed functions. Essential for functional programming patterns like map and filter.

; Anonymous function
((lambda (x) (* x x)) 5)  ; => 25

; Assign lambda to variable
(define double
  (lambda (x) (* x 2)))
(double 7)               ; => 14

; Higher-order function
(map (lambda (x) (+ x 1))
     '(1 2 3))           ; => (2 3 4)

Recursion

Scheme relies heavily on recursion instead of loops.

(define (fibonacci n)
  (if (<= n 1)
      n
      (+ (fibonacci (- n 1))
         (fibonacci (- n 2)))))
(fibonacci 10)   ; => 55

Key Concepts

  • Everything is an expression — Every piece of Scheme code returns a value, including if statements and definitions.
  • First-class functions — Functions can be passed as arguments, returned from other functions, and stored in variables.
  • Tail call optimization — Scheme guarantees that tail-recursive functions run in constant stack space, making recursion as efficient as loops.
  • Lexical scoping — Variables are resolved in the environment where they are defined, not where they are called.
  • Minimalist design — Scheme has very few special forms. Most functionality is built from a small set of primitives.

Glossary

Scheme
Scheme is a classic programming language in the Lisp family, created in 1975 by Guy L. Steele and Gerald Jay Sussman at MIT. It is known for its clean, minimalist design and is widely used in computer science education.
S-expression
An S-expression (symbolic expression) is the basic syntax unit in Lisp languages. It is either an atom (like a number or symbol) or a list of S-expressions enclosed in parentheses, such as (+ 1 2).
Lambda
Lambda creates an anonymous (unnamed) function. For example, (lambda (x) (* x x)) creates a function that squares its argument. The name comes from lambda calculus, the mathematical foundation of functional programming.
Tail Call Optimization
Tail call optimization (TCO) is a technique where the compiler/interpreter reuses the current stack frame for a function call in tail position. This allows recursive functions to run without growing the call stack, preventing stack overflow errors.
SICP
Structure and Interpretation of Computer Programs is a legendary textbook by Harold Abelson and Gerald Jay Sussman. Originally used at MIT, it teaches fundamental programming concepts using Scheme and is freely available online.
LIPS Interpreter
This playground uses LIPS (Lisp In Parentheses Syntax), a Scheme interpreter written in JavaScript. It supports most R7RS Scheme features and runs entirely in the browser.

Frequently Asked Questions

Q: What is the difference between Scheme and Common Lisp?
A: Scheme is minimalist with a single namespace and guaranteed tail call optimization. Common Lisp is larger with separate namespaces for functions and variables, and a more extensive standard library. Scheme emphasizes elegance and simplicity.
Q: Why are there so many parentheses?
A: Parentheses in Scheme define the structure of the code (S-expressions). This uniform syntax makes the language easy to parse and enables powerful metaprogramming with macros. Most editors provide auto-matching to make them manageable.
Q: Is Scheme still used today?
A: Yes. Scheme is widely used in computer science education (e.g., the classic textbook SICP). Languages like Racket (a Scheme descendant) are actively developed. Guile Scheme is used as an extension language in GNU software.
Q: Does the code run on a server?
A: No. All code runs entirely in your browser using the LIPS Scheme interpreter (JavaScript-based). Nothing is sent to any server.

Related Tools & Games