Recent Articles



































Scheme (programming language)



         


The Scheme programming language is a functional programming language and a dialect of Lisp. It was developed by Guy L. Steele and Gerald Jay Sussman in the 1970s and introduced to the academic world via a series of papers now referred to as Sussman and Steele's Lambda Papers.

Scheme's philosophy is unashamedly minimalist. Its goal is not to pile feature upon feature, but to remove weaknesses and restrictions that make new features appear necessary. Therefore, Scheme provides as few primitive notions as possible, and lets everything else be implemented on top of them. For example, the main mechanism for governing control flow is tail recursion.

Scheme was the first variety of Lisp to use lexical variable scoping (as opposed to dynamic variable scoping) exclusively. It was also one of the first programming languages to support explicit continuations. Scheme supports garbage collection of unreferenced data.

It uses lists as the primary data structure, but also has good support for arrays. Owing to the minimalist specification, there is no standard syntax for creating structures with named fields, or for doing object oriented programming, but many individual implementations have such features.

Scheme was originally called "Schemer", in the tradition of the languages Planner and Conniver. The current name resulted from the authors' use of the ITS operating system, which limited filenames to 6 characters.

[Top]

Advantages of Scheme

Scheme, as all Lisp dialects, has very little syntax compared to many other programming languages. It has no operator precedence rules because there are essentially no operators—prefix notation is used for all function calls.

Scheme's macro facilities allow it to be adapted to any problem domain. They can be used to add support for object-oriented programming. Scheme provides a hygienic macro system which, while not quite as powerful as Common Lisp's macro system, is much safer and often easier to work with. The advantage of a hygienic macro system (as found in Scheme and other languages such as Dylan) is that any name clashes in the macro and surrounding code will be automatically avoided. The disadvantage is that the macro may not introduce any new symbols.

Scheme encourages functional programming. Purely functional programs need no global variables and don't have side-effects, and are therefore automatically thread-safe and automatically verifiable.

In Scheme, functions are first-class objects. This allows for higher-order functions which can further abstract program logic. Functions can also be created anonymously.

Scheme has a minimalistic standard. While this can be seen as a disadvantage, it can also be valuable. For example, writing a conforming Scheme compiler is easier (since there are fewer features to implement) than a Common Lisp one; embedding Lisp in low-memory hardware may also be more feasible with Scheme than Common Lisp. Schemers find it amusing to note that the Scheme standard is smaller than the index to Guy Steele's IEEE standard, and a de facto standard called the Revisedn-th Report on the Algorithmic Language Scheme, nearly always abbreviated RnRS, where n is the number of the revision. The latest RnRS version is R5RS, also available .

[Top]

Language elements

[Top]

Comments

Comments are preceded by a semicolon (;) and continue for the rest of the line.

[Top]

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)

Variables bound in a let are in scope for the body of the let.

(let ((var1 value)) ... scope of var1 ...)
[Top]

Functions

Functions are first-class objects in Scheme. They can be assigned to variables. For example a function with two arguments arg1 and arg2 can be defined as

(define fun (lambda (arg1 arg2) ...))

which can be abbreviated as follows:

(define (fun arg1 arg2) ...)

Functions can be called with the following syntax:

(fun value1 value2)

Note that the function being called is in the first position of the list while the rest of the list contain the arguments. The apply function will take the first argument and apply the rest of the arguments to the first argument, so the previous function call can also be written as

(apply fun (list value1 value2))

In Scheme, functions are divided into two basic categories: the procedures and the 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 + (lambda (x y) (- x y)))

actually redefines the + primitive to subtract, rather than add. This code turns the + primitive into a + procedure.

[Top]

Lists

Scheme uses the linked list data structure in the same form as it exists in Lisp.

[Top]

Data types

Other common data types in Scheme besides functions and lists are: integer, rational, real, complex numbers, symbols, strings, ports. Most Scheme implementations also offer association lists, hash tables, vectors, arrays and structures.

Most Scheme implementations offer a full numerical tower as well as exact and Arithmetic-geometric mean

[Top]

Implementations

[Top]

Additional resources










  View Live Article   This article is from Wikipedia. All text is available under the terms of the GNU Free Documentation License