Scheme (programming Language) Article Index for
Scheme
Shopping
Scheme
Website Links For
Scheme
 

Information About

Scheme (programming Language)




  paradigm Multi-paradigm
  year 1970s
  designer Guy L Steele and Gerald Jay Sussman
  typing strong, dynamic
  dialects T
  implementations PLT Scheme , MIT/GNU Scheme , Scheme 48 , Chicken , Gambit , Guile , Bigloo , Chez Scheme , STk , STklos , Larceny , SCM , Kawa
  influenced By Lisp , ALGOL
  influenced Common Lisp , JavaScript , Ruby



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 Continuation s.


ORIGIN



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 .


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 Iterator s, Coroutine s, 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



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.

  • , /, 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 , Number s, Booleans , Characters , Strings , Vector s and ports. Many Scheme implementations also offer Association List s, Hash Table s and Structure s.

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 schemers.com list of Scheme-using schools of schools; in particular, a number of introductory Raster Graphics Editor , the GIMP uses Scheme as a Scripting Language ."''The major scripting language for the GIMP that has been attached to it today is Scheme.''" From The GIMP Basic Scheme Tutorial .


SEE ALSO




REFERENCES




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




EXTERNAL LINKS