SCHEME (PROGRAMMING LANGUAGE)


'Scheme' is a multi-paradigm programming language. It is one of the two main dialects of Lisp and supports a number of programming paradigms but is best known for its support of functional programming. It was developed by Guy L. Steele and Gerald Jay Sussman in the 1970s. Scheme was introduced to the academic world via a series of papers now referred to as Sussman and Steele's Lambda Papers. There are two standards that define the Scheme language: the official IEEE standard, and a de facto standard called the ''Revisedn Report on the Algorithmic Language Scheme'', nearly always abbreviated R''n''RS, where ''n'' is the number of the revision. The current standard is 'R5RS'[1], and on August 28th, 2007, 'R6RS'[2], the next major revision of the scheme language was ratified[3], with about 2/3rd of the voters in favor of 'R6RS'.
Scheme's philosophy is minimalist. Scheme provides as few primitive notions as possible, and, where practical, lets everything else be provided by programming libraries.
Scheme was the first dialect of Lisp to choose static (a.k.a. lexical) over dynamic variable scope. It was also one of the first programming languages to support first-class continuations.

Contents
Origin
Future
Distinguishing features
Tail recursion
Language elements
Comments
Variables
Functions
Lists
Data types
Equality
Control structures
Conditional evaluation
Input/output
Implementation
Usage
See also
References
External links

Origin


Scheme started as an attempt to understand Carl Hewitt's Actor model.[4] Scheme was originally called "Schemer", in the tradition of other Lisp-derived languages like Planner or Conniver. The current name resulted from the authors' use of the ITS operating system, which limited filenames to two components of at most six characters each. Currently, "Schemer" is commonly used to refer to a Scheme programmer.

Future


A new language standardization process began at the 2003 Scheme workshop, with the goal of producing an R6RS standard in 2006. It breaks with the earlier R''n''RS approach of unanimity. R6RS will feature a standard module system; allowing a split between the core language and libraries. A number of drafts of the R6RS specification have been released, the final version being R5.96RS on June 27th, 2007. A vote will determine whether this draft is accepted, with the announcement taking place on August 25th.2

Distinguishing features


Scheme is a minimalist language. The current language standard is only 50 pages, including a denotational semantics for the language core. The next revision of the standard will be expanded to describe several libraries.
Like all Lisp dialects, Scheme has a very simple syntax. There are no operator precedence rules because fully nested and parenthesized notation is used for ''all'' compound forms. Example (the recursive factorial function):

(define (fact n)
(if (= n 0)
1
(
★ n (fact (- n 1)))))

Scheme's macro system allows the user to add new syntactic constructs to the language. It respects the lexical scoping of the rest of the language, which avoids common programming errors that can occur in the macro systems of other programming languages.
Procedures in Scheme are first-class values.
Scheme's call-with-current-continuation operator allows the user to create non-local control constructs that must be built into other languages, such as iterators, coroutines, and backtracking.

Tail recursion


Even though looping constructs (such as the do loop and named let) are provided in Scheme, and one can use macros to easily define iterating control structures, Scheme programs often use tail recursion to express loops, much more commonly than in other languages. This is in part due to the fact that Scheme implementations are required to optimize tail calls so as to eliminate use of stack space where possible, so that arbitrarily long loops are guaranteed to run in constant space.
In contrast, implementations of other languages often do not optimize tail calls, making tail recursion impractical due to a limited amount of stack.

Language elements


Comments

Each comment is preceded by a semicolon (;) and extends for the rest of the line. Some implementations allow comments to span multiple lines by wrapping them with a #|...|# (possibly nested). Other implementations allow an entire s-expression to be commented out by prepending it with #;.[5] These two comment forms are included in the newly ratified R6RS.
Variables

Variables are dynamically typed. Variables are bound by a ''define'', a ''let'' expression, and a few other Scheme forms. Variables bound at the top level with a define are in ''global scope''.

(define var1 value)

A define expression is equivalent to a let expression whose body is the rest of the current scope.
Variables bound in a let are in scope for the body of the let.

(let ((var1 value))
...
; scope of var1
...)

let is a convenient syntax that is not fundamentally necessary. A let expression can be implemented using procedures directly. For example, the above is equivalent to:

((lambda (var1)
...
; scope of var1
...) value)

Functions


1 (define fun
(lambda (arg1 arg2)
...))
2 (define (fun arg1 arg2)
...)
3 (fun value1 value2)
4 (apply fun (list value1 value2))

Functions are first-class objects in Scheme. They can be arguments to other functions and be returned by them. They can be assigned to variables. Functions are created by lambda forms. For example a function with two arguments arg1 and arg2 is defined in line 1; line 2 is a shorter, equivalent form. line 3 shows how functions are applied. Note that the function being applied is in the first position of the list while the rest of the list contains the arguments. The apply function will take its first argument and apply it to a given list of arguments, so the previous function call can also be written as seen in line 4.
In Scheme, functions are divided into two basic categories: procedures and primitives. All primitives are procedures, but not all procedures are primitives. Primitives are pre-defined functions in the Scheme language. These include +, -,
, /, set!, car, cdr, and other basic procedures. Procedures are user-defined functions. In several variations of Scheme, a user can redefine a primitive. For example, the code

(define (+ x y)
(- x y))

or simply

(define + -)

actually redefines the + primitive to perform subtraction, rather than addition.
Lists

Scheme uses the singly-linked list data structure with accessors car and cdr.
Data types

Besides procedures and lists, Scheme provides the following data types: atomic symbols, numbers, booleans, characters, strings, vectors and ports. Many Scheme implementations also offer association lists, hash tables and structures.
Since the IEEE Scheme standard and the R4RS Scheme standard, Scheme has asserted that all of the above types are ''disjoint'', that is no value can belong to more than one of these types; however some older implementations of Scheme predate these standards such that #f and '() refer to the same value, as is the case in traditional Lisp including Common Lisp.
The numeric type is further divided into a numerical tower, with subtypes complex, real, rational and integer. (Note that these subtypes are ''not'' disjoint; in fact each type is a subset of the last). While it is not required that a Scheme implementation support the entire numerical tower, most implementations do. Scheme also keeps track of whether a given number is "exact" or "inexact".
The boolean type represents true and false by #t and #f respectively. For historical reasons, however, any value can be used where a boolean is expected - any value other than #f is considered to be true, including the empty list (in traditional Lisp and Common Lisp, the empty list is considered to be false).
Symbols can be created in at least the following ways:

'hello
(string->symbol "hello")

Equality

Scheme has three different types of equality: "eq?" returns #t if its parameters represent the same data object in memory; "eqv?" is generally the same as eq? but treats some objects (eg. characters and numbers) specially so that numbers that are = are eqv? even if they are not eq?; equal? compares data structures such as lists, vectors and strings to determine if they have congruent structure and eqv? contents.
Type dependent equivalence operations also exist in Scheme: string=?; compares two strings; char=? compares characters; = compares numbers.
Control structures

Conditional evaluation


(if test then-expr else-expr)

The test expression is evaluated, and if the evaluation result is true (anything other than #f) then the then-expr is evaluated, otherwise else-expr is evaluated.
A form that is more convenient when conditionals are nested is cond:

(cond (test1 expr1 ...)
(test2 expr2 ...)
...
(else exprn))

The first expression for which the test evaluates to true will be evaluated. If all tests result in #f, the else clause is evaluated.
A variant of the cond clause is

(cond ...
(test => expr)
...)

In this case, expr should evaluate to a function that takes one argument. If test evaluates to true, the function is called with the return value of test.
Input/output

Scheme has the concept of ''ports'' to read from or to write to. R5RS defines two default ports, accessible with the functions current-input-port and current-output-port, which correspond to the Unix notions of stdin and stdout. Most implementations also provide current-error-port.

Implementation


Current implementations include: PLT Scheme, MIT/GNU Scheme, Scheme 48, Chicken, Gambit, Guile, Bigloo, Chez Scheme, STk, STklos, Larceny, SCM, Kawa, Pvts, JScheme.
Some implementations support additional features. For example, Kawa and JScheme provide allow integration with Java. Another example is PVTS which offers a set of visual tools for supporting the learning of Scheme.

Usage


Scheme is widely used by a number[6] of schools; in particular, a number of introductory Computer Science courses use Scheme in conjunction with the textbook Structure and Interpretation of Computer Programs[7]. There are relatively few examples of Scheme in apparent usage[8] for non-pedagogical purposes. However, the Document Style Semantics and Specification Language, which provides a method of specifying SGML stylesheets, uses a Scheme subset.[9] In addition, the well-known open source raster graphics editor, the GIMP uses Scheme as a scripting language.[10]

See also



★ ''Structure and Interpretation of Computer Programs'', a classic computer science textbook.

★ ''How to Design Programs'', which intends to be a more accessible book for introductory Computer Science, and to address perceived incongruities in SICP.

Call-with-current-continuation (call/cc)

Kernel (programming language)

References



1. Revised5 Report on the Algorithmic Language Scheme, Richard Kelsey, William Clinger, Jonathan Rees et al., , , Higher-Order and Symbolic Computation, 1998
2. R6RS.org
3. R6RS ratification-voting results
4. ''"We wanted to better understand Hewitt's actors model but were having trouble relating the actors model and its unusual terminology to familiar programming notions. We decided to construct a toy implementation of an actor language so that we could play with it. Using MacLisp as a working environment, we wrote a tiny Lisp interpreter and then added mechanisms for creating actors and sending messages."''
5. SRFI 62: S-expression comments Taylor Campbell
6. schemers.comlist of Scheme-using schools
7. MIT Press list of SICP-using schools
8. scheme-faq-general; see ''What is Scheme used for?''
9. DSSSL Technology report
10. "''The major scripting language for the GIMP that has been attached to it today is Scheme.''" From The GIMP Basic Scheme Tutorial.


★ Gerald Sussman and Guy Steele. ''SCHEME: An Interpreter for Extended Lambda Calculus'' AI Memo 349, MIT Artificial Intelligence Laboratory, Cambridge, Massachusetts, December 1975.

The Evolution of Lisp Guy L. Steele, Jr., Richard P. Gabriel

The Scheme Programming Language Standardization Experience Christopher T. Haynes

External links



Schemers.org

This article provided by Wikipedia. To edit the contents of this article, click here for original source.

psst.. try this: add to faves