4.2 KiB
Scheme
Scheme is a Lisp dialect created in 1975 by Guy Steele and Gerald Sussman at the MIT. Scheme is minimalistic and elegant leaning towards a functional programming paradigm, being the language used in the famous SICP book (using the MIT/GNU Scheme implementation).
Scheme is standardized in a series of documents called Revised^n Report on the Algorithmic Language Scheme (RnRS) (where the n
stands for
the version), being the most popular the R5RS revision released in 1998.
Controversy around the R6RS revision (The Great Bloatening)
In 2003 work in a new revision of Scheme began, R6RS, finished in 2007. This new revision was controversial since it added additional features that Scheme hackers deemed as a departure from Scheme's minimalism. In a attempt to amend this, work on R7RS began, splitting Scheme into two different (but still similar) languages, differing in the amount of features; a big language for practical use and a small, minimalistic version. Of course R7RS is still less bloated than Common Lisp and other mainstream languages.
Scheme Requests for Implementation (SRFI)
Aside from the RnRS, Scheme is also informally standarized by the SRFI, in which extensions to Scheme are discussed, mainly libraries. Some SRFIs are:
- SRFI-13: adds string manipulation procedures
- SRFI-43 and SRFI-133: both adding vector manipulation procedures
- SRFI-1: list library
- SRFI-125: hash tables
- SRFI-48: Common Lisp-like
format
procedure
Unlike the revisions, these aren't hard requirements to implement, so Scheme implementations are free to implement them or not.
Implementations
Since Scheme (specially the R5RS standard) is simple, there are multiple implementations:
- CHICKEN Scheme: compiler and interpreter, supports extensions in a modular way, called "eggs".
- MIT/GNU Scheme: compiler, one of the "original" implementations, also includes a debugger.
- Chez Scheme: another classic compiler, freed in 2016.
- GNU Guile: main Scheme implementation of the GNU project, used as a scripting language in some GNU projects.
- Gambit Scheme
- Chibi Scheme: small implementation with a focus in being embeddable.
- Cyclone Scheme: compiler, aims to support the R7RS standard.
- Gerbil Scheme
- Gauche Scheme
- ...
Examples
Hello World
(display "Hello, Scheme!")
Factorial
(define (fact n acc)
(if (zero? n)
acc
(fact (- n 1) (* acc n))))
(let ((ns '(4 0 5 10 1)))
(for-each (lambda (n)
(display n)
(display "! = ")
(display (fact n 1))
(newline))
ns))
Resources
- CHICKEN Scheme tutorials (of course most also applies to other implementations): https://wiki.call-cc.org/tutorials
- https://docs.scheme.org/
- R5RS document
- Official Scheme site
- Teach Yourself Scheme in Fixnum Days
- A Scheme Primer
- Practical Scheme
- R7RS site
- https://try.scheme.org/: Scheme in a web browser, seems to be Gambit Scheme.
- https://try.gambitscheme.org/: ditto
- A incomplete tutorial in wikibooks: https://en.wikibooks.org/wiki/Scheme_Programming
- List of SRFIs and which implementations implement each: https://practical-scheme.net/wiliki/schemexref.cgi?SRFI
- The CONS Should Not CONS Its Arguments, Part II: Cheney on the M.T.A. paper, describes how to compile Scheme to C efficiently by using CPS.