Scheme Code Editor

Write, validate, and experiment with Scheme programming language code. Perfect for learning functional programming, SICP exercises, and Lisp dialect exploration.

Code is valid
untitled.scm0 lines

Note: Click Check Syntax to validate your code, and Run Code to execute it. The interpreter supports basic Scheme operations including arithmetic, list operations, conditionals, and function definitions.

Understanding Scheme Programming Language

Scheme is a minimalist dialect of Lisp, renowned for its elegance, simplicity, and powerful programming paradigms. Developed at MIT in the 1970s, it has become a cornerstone of computer science education and functional programming research.

Key Characteristics

  • Minimal Syntax: Simple, consistent s-expressions
  • Lexical Scoping: Clear variable scope rules
  • First-class Functions: Functions as values
  • Tail-call Optimization: Efficient recursion
  • Continuations: Advanced control flow
  • Hygienic Macros: Powerful code generation
  • Garbage Collection: Automatic memory management

Scheme Standards

1975: Scheme created at MIT by Guy Steele and Gerald Sussman
1985: First edition of SICP published
1998: R5RS (Revised⁵ Report on Scheme) published
2007: R6RS introduces a more comprehensive standard
2013: R7RS-small published, focusing on core language

Common Use Cases

  • Computer Science Education: Teaching fundamental programming concepts
  • Research Prototypes: Quick implementation of programming language concepts
  • Extension Languages: GNU Guile, Script-fu in GIMP
  • Academic Projects: Compiler design, programming language theory
Did you know? Scheme's influence extends to many modern languages including JavaScript (closures, first-class functions), Python (list comprehensions inspired by Scheme's map/filter), and Ruby (blocks as closures).

Editor Features

  • Syntax validation
  • Parenthesis matching
  • Code examples library
  • Save/load functionality
  • Real-time validation

Quick Reference

Comments; This is a comment
Define variable(define x 5)
Define function(define (square x) (* x x))
Conditional(if (> x 0) 'positive 'negative)
Lambda(lambda (x) (* x x))
List operation(car '(1 2 3)) → 1

Scheme Code Examples

Factorial (Recursive)

(define (factorial n)
  (if (= n 0)
      1
      (* n (factorial (- n 1)))))

Fibonacci Sequence

(define (fib n)
  (cond ((= n 0) 0)
        ((= n 1) 1)
        (else (+ (fib (- n 1))
                 (fib (- n 2))))))

Map Function

(define (my-map proc lst)
  (if (null? lst)
      '()
      (cons (proc (car lst))
            (my-map proc (cdr lst)))))

Quicksort

(define (quicksort lst)
  (if (null? lst)
      '()
      (let ((pivot (car lst)))
        (append (quicksort (filter (lambda (x) (< x pivot)) (cdr lst)))
                (list pivot)
                (quicksort (filter (lambda (x) (>= x pivot)) (cdr lst)))))))

Scheme Syntax Guide

ConstructSyntaxExample
Numbersinteger, float42, 3.14, -7
Booleans#t, #f(if #t 'yes 'no)
Symbols'symbol'hello-world
Lists(1 2 3)(list 1 2 3)
Quoting'(1 2 3)'(a b c)
Lambda(lambda (args) body)(lambda (x) (* x x))
Let binding(let ((var val)) body)(let ((x 5)) (* x x))
Begin(begin expr1 expr2 ...)(begin (display "hi") (newline))

Common Scheme Functions

Arithmetic

  • (+ 1 2 3) → 6
  • (- 10 3) → 7
  • (* 2 3 4) → 24
  • (/ 15 4) → 15/4
  • (quotient 15 4) → 3
  • (remainder 15 4) → 3

List Operations

  • (car '(1 2 3)) → 1
  • (cdr '(1 2 3)) → (2 3)
  • (cons 1 '(2 3)) → (1 2 3)
  • (list 1 2 3) → (1 2 3)
  • (append '(1 2) '(3 4)) → (1 2 3 4)
  • (length '(a b c)) → 3

Predicates

  • (null? '()) → #t
  • (pair? '(1 2)) → #t
  • (number? 42) → #t
  • (symbol? 'x) → #t
  • (eq? 'a 'a) → #t
  • (equal? '(1 2) '(1 2)) → #t

Frequently Asked Questions About Scheme

Scheme is minimalist with a simple, consistent design, while Common Lisp is feature-rich with multiple programming paradigms. Scheme emphasizes functional programming and lexical scoping exclusively; Common Lisp includes both lexical and dynamic scoping. Scheme has a simpler macro system, while Common Lisp's macros are more complex but powerful. Scheme is often used in education and research; Common Lisp in industrial applications.

Scheme's minimal syntax eliminates distractions, letting students focus on concepts like recursion, functional programming, and abstraction. Its simple, regular rules make it easy to understand program evaluation. The language's elegance encourages thinking about computation rather than syntax details. This is why MIT chose Scheme for their legendary SICP course.

Continuations represent the "rest of the computation" at any point. Scheme provides first-class continuations via call/cc (call-with-current-continuation), allowing advanced control structures like non-local exits, coroutines, and backtracking. While powerful, continuations are considered an advanced feature and aren't needed for most everyday programming.

You can run Scheme code using implementations like:
  • MIT/GNU Scheme: Classic implementation from MIT
  • Chez Scheme: Fast, industrial-strength Scheme
  • Racket: Full-featured platform with Scheme roots
  • GNU Guile: Extension language for GNU projects
  • Chicken Scheme: Compiles Scheme to C
Our online editor lets you experiment without installing anything!

SICP (Structure and Interpretation of Computer Programs) is a legendary computer science textbook by Harold Abelson and Gerald Sussman. Used at MIT for decades, it uses Scheme to teach fundamental principles of programming: abstraction, recursion, meta-linguistic abstraction, and more. It's considered one of the most influential CS books ever written, shaping how generations of programmers think about computation.

Related Programming Tools

All code validation is performed client-side in your browser. Your code never leaves your device. No information is stored or transmitted to any server.

Learning Resource: This editor is great for working through SICP exercises and learning functional programming concepts. Start with simple expressions and gradually build up to more complex programs!