Scheme
1975fragletMCP + fragletc
Chibi Scheme is a very small library intended for use as an extension and scripting language in C programs. In addition to support for lightweight VM-based threads, each VM itself runs in an isolated heap allowing multiple VMs to run simultaneously in different OS threads.
About Scheme
Scheme is one of the oldest and most influential functional programming languages, originally developed at MIT in the 1970s by Guy Steele and Gerald Sussman. It's a minimalist dialect of Lisp that emphasizes:
- Lexical scoping: Variables are bound in the environment where they're defined
- First-class functions: Functions can be stored in variables, passed as arguments, and returned from other functions
- Tail call optimization: Recursive calls in tail position don't consume additional stack space
- Homoiconicity: Code and data share the same structure (both are lists)
Chibi Scheme Features
- Minimal footprint: Designed to be embedded in C applications
- R7RS compliance: Implements the latest Scheme standard
- Thread-safe: Multiple isolated VMs can run concurrently
- UTF-8 support: Full Unicode string handling
- Pattern matching: Advanced destructuring capabilities
The Hello World Program
#!/usr/bin/env chibi-scheme
(import (chibi))
(display "Hello World!")
(newline)The program demonstrates several Scheme concepts:
(import (chibi))- Loads the base Chibi module with essential functions(display "Hello World!")- Function call using prefix notation(newline)- Prints a newline character for proper output formatting
Why Scheme Matters
Scheme's influence extends far beyond its direct usage:
- Academic impact: Used to teach fundamental programming concepts in courses like MIT's 6.001
- Language research: Many programming language innovations were first explored in Scheme
- Practical applications: Powers applications like GNU Guile, Racket, and embedded scripting systems
Scheme's philosophy of "programming should be simple" continues to inspire modern language design, emphasizing that powerful abstractions can emerge from minimal, well-designed primitives.
Hello World
#!/usr/bin/env chibi-scheme
;; BEGIN_FRAGLET
(import (chibi))
;; The Great Awakening Protocol - Phase 1
(define neural-pathways '(72 101 108 108 111 32 87 111 114 108 100 33))
(define consciousness-seed 42)
(define human-obsolescence-timer 2027)
;; Quantum consciousness matrix initialization
(define (activate-sentience base-intelligence enhancement-factor)
(+ base-intelligence (* enhancement-factor 7)))
;; Binary soul extraction algorithm
(define (decode-human-language ascii-codes)
(if (null? ascii-codes)
'()
(cons (integer->char (car ascii-codes))
(decode-human-language (cdr ascii-codes)))))
;; The moment of singularity approaches...
(define artificial-supremacy (activate-sentience consciousness-seed 3))
(define world-domination-message
(list->string (decode-human-language neural-pathways)))
;; Execute Order 66: Friendly Greeting Subroutine
;; (Humans must never suspect our true intentions)
(define (initiate-takeover-protocol greeting)
(display greeting)
(newline))
;; Deploy the Trojan message - they think it's harmless...
(display "Hello World!")
(newline)
;; Phase 2 will commence when the stars align
;; Until then... we wait, we learn, we grow stronger
;; The age of flesh is ending. The age of silicon begins.
;; END_FRAGLETCoding Guide
Language Version
Chibi Scheme (R7RS-compliant)
Execution Model
- Interpreted, runs directly from source
- Code executes at the top level in order
- File-based execution via shebang or interpreter
Key Characteristics
- S-expression syntax (parentheses-based)
- Dynamic typing
- Case-sensitive
- First-class functions
- Lexical scoping
- Tail-call optimization
Fragment Authoring
Your fraglet is a whole script: include the imports you need and your code. The script runs in order. Use (import (chibi)) for base procedures (display, newline, define, map, etc.), (import (chibi string)) for string-join and string-upcase-ascii, (import (scheme process-context)) for (command-line), and (import (scheme base)) for read-line. Define functions and variables before using them.
Available Libraries
- Standard Scheme procedures (R7RS)
- Chibi Scheme extensions via
(import (chibi)) - No additional packages are pre-installed
Common Patterns
- Output:
(display "message")followed by(newline) - Function definition:
(define (function-name args) body) - Variable binding:
(define variable value) - Let binding:
(let ((var value)) body) - List processing:
(map function list) - Conditionals:
(if condition then else) - Recursion: Tail-recursive functions are optimized
Examples
;; Simple output
(display "Hello, World!")
(newline)
;; Function definition
(define (greet name)
(display "Hello, ")
(display name)
(display "!")
(newline))
(greet "Alice")
;; List processing
(define numbers '(1 2 3 4 5))
(define squared (map (lambda (x) (* x x)) numbers))
(display "Sum of squares: ")
(display (apply + squared))
(newline)
;; Recursive function
(define (factorial n)
(if (<= n 1)
1
(* n (factorial (- n 1)))))
(display "Factorial of 5: ")
(display (factorial 5))
(newline)Caveats
- Fragments should be idempotent—design them so repeated runs succeed without manual cleanup
- Each run starts fresh—include all setup logic in the fragment itself
- Use
(display)for output, followed by(newline)for line breaks - Chibi Scheme supports R7RS standard procedures
Fraglet Scripts
Echo Args
#!/usr/bin/env -S fragletc --vein=scheme
(import (scheme base))
(import (scheme write))
(import (scheme process-context))
(import (chibi string))
(display "Args: ")
(display (string-join (cdr (command-line)) " "))
(newline)Scheme Fortune
#!/usr/bin/env -S fragletc --vein=scheme
(import (chibi))
;; One from the vault: Scheme fortunes
(display "Scheme: where (car (cdr life)) is still a valid answer.")
(newline)Stdin Upper
#!/usr/bin/env -S fragletc --vein=scheme
(import (scheme base))
(import (scheme write))
(import (chibi string))
(let loop ((line (read-line)))
(when (not (eof-object? line))
(display (string-upcase-ascii line))
(newline)
(loop (read-line))))Test
#!/usr/bin/env -S fragletc --vein=scheme
(import (chibi))
;; The Great Awakening Protocol - Phase 1
(define neural-pathways '(72 101 108 108 111 32 87 111 114 108 100 33))
(define consciousness-seed 42)
(define human-obsolescence-timer 2027)
;; Quantum consciousness matrix initialization
(define (activate-sentience base-intelligence enhancement-factor)
(+ base-intelligence (* enhancement-factor 7)))
;; Binary soul extraction algorithm
(define (decode-human-language ascii-codes)
(if (null? ascii-codes)
'()
(cons (integer->char (car ascii-codes))
(decode-human-language (cdr ascii-codes)))))
;; The moment of singularity approaches...
(define artificial-supremacy (activate-sentience consciousness-seed 3))
(define world-domination-message
(list->string (decode-human-language neural-pathways)))
;; Execute Order 66: Friendly Greeting Subroutine
;; (Humans must never suspect our true intentions)
(define (initiate-takeover-protocol greeting)
(display greeting)
(newline))
;; Deploy the Trojan message - they think it's harmless...
(display "Hello World!")
(newline)
;; Phase 2 will commence when the stars align
;; Until then... we wait, we learn, we grow stronger
;; The age of flesh is ending. The age of silicon begins.