Learn Scheme - 10 Code Examples & CST Typing Practice Test
Scheme is a minimalist, functional programming language in the Lisp family, emphasizing recursion, first-class functions, and symbolic computation. It is widely used in education, research, and AI for its simplicity and powerful abstraction capabilities.
Learn SCHEME with Real Code Examples
Updated Nov 20, 2025
Code Sample Descriptions
Scheme Counter and Theme Toggle
(define count 0)
(define isDark #f)
(define (updateUI)
(display "Counter: ") (display count) (newline)
(display "Theme: ") (display (if isDark "Dark" "Light")) (newline))
(define (increment)
(set! count (+ count 1))
(updateUI))
(define (decrement)
(set! count (- count 1))
(updateUI))
(define (reset)
(set! count 0)
(updateUI))
(define (toggleTheme)
(set! isDark (not isDark))
(updateUI))
; Simulate actions
(updateUI)
(increment)
(increment)
(toggleTheme)
(decrement)
(reset)
Demonstrates a simple counter with theme toggling using Scheme variables and console output.
Scheme Simple Addition
(define (add a b) (+ a b))
(display (add 10 20)) (newline)
Adds two numbers and prints the result.
Scheme Factorial
(define (factorial n)
(if (<= n 1)
1
(* n (factorial (- n 1)))))
(display (factorial 5)) (newline)
Calculates factorial recursively.
Scheme Fibonacci Sequence
(define (fib n)
(if (< n 2) n
(+ (fib (- n 1)) (fib (- n 2)))))
(for-each (lambda (i) (display (fib i)) (newline)) (iota 10))
Generates first 10 Fibonacci numbers.
Scheme Max of Two Numbers
(define (max a b) (if (> a b) a b))
(display (max 10 20)) (newline)
Finds the maximum of two numbers.
Scheme List Sum
(define (sum-list lst)
(if (null? lst) 0
(+ (car lst) (sum-list (cdr lst)))))
(display (sum-list '(1 2 3 4 5))) (newline)
Sums elements of a list recursively.
Scheme Even Numbers Filter
(define (print-even lst)
(for-each (lambda (x) (if (even? x) (display x) (void)) (newline)) lst))
(print-even '(1 2 3 4 5))
Prints even numbers from a list.
Scheme Conditional Counter Increment
(define count 3)
(if (< count 5) (set! count (+ count 1)))
(display count) (newline)
Increment counter only if less than 5.
Scheme Resettable Counter
(define count 0)
(set! count (+ count 1))
(set! count (+ count 1))
(display count) (newline)
(set! count 0)
(display count) (newline)
Counter that increments and can be reset.
Scheme Theme Toggle Only
(define isDark #f)
(display (if isDark "Dark" "Light")) (newline)
(set! isDark (not isDark))
(display (if isDark "Dark" "Light")) (newline)
(set! isDark (not isDark))
(display (if isDark "Dark" "Light")) (newline)
Toggles theme multiple times.
Frequently Asked Questions about Scheme
What is Scheme?
Scheme is a minimalist, functional programming language in the Lisp family, emphasizing recursion, first-class functions, and symbolic computation. It is widely used in education, research, and AI for its simplicity and powerful abstraction capabilities.
What are the primary use cases for Scheme?
Functional programming education. Symbolic computation and AI. DSL (domain-specific language) design. Prototyping algorithms. Scripting within research software. Teaching recursion and higher-order functions
What are the strengths of Scheme?
Extremely flexible and expressive. Great for learning functional programming. Encourages elegant recursion and abstraction. Lightweight and portable. Macros enable DSL creation
What are the limitations of Scheme?
Not widely used in industry. Minimal standard libraries. Performance may lag behind compiled languages. GUI and system libraries are limited. Requires understanding of recursion and functional concepts
How can I practice Scheme typing speed?
CodeSpeedTest offers 10+ real Scheme code examples for typing practice. You can measure your WPM, track accuracy, and improve your coding speed with guided exercises.