|
Article on other languages:
|
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 RnRS, where n is the number of the revision. The most widely implemented standard is R5RS[1], and on August 28, 2007, R6RS[2], the next major revision of the Scheme language was ratified[3], with about two thirds 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.
OriginScheme 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. R6RSA new language standardization process began at the 2003 Scheme workshop, with the goal of producing an R6RS standard in 2006. This process broke with the earlier RnRS approach of unanimity. R6RS features a standard module system, allowing a split between the core language and libraries. A number of drafts of the R6RS specification were released, the final version being R5.97RS. A successful vote resulted in the ratification of the new standard, announced on August 28, 2007.[2] However, as of October 26, 2007, the developers and maintainers of many of the most active implementations of Scheme have no firm plans to adopt R6RS fully. [5] As of December 2007 two Scheme implementations, Larceny and a newcomer known as Ikarus, support substantial subsets of the R6RS standard. On March 7, 2008 it was announced, that PLT Scheme 4.0 will support R6RS programs and libraries. [6] R6RS introduces numerous significant changes to the language, which include the following: [7]
Distinguishing featuresLike 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 is a minimalist language. The R5RS language standard[1] is only 50 pages, including a denotational semantics for the language core. The latest revision of the standard, R6RS, has been expanded [2] to describe several libraries. In contrast with Common Lisp, Scheme is a "Lisp-1". All data and functions share a common namespace in Scheme, whereas in Common Lisp functions and data have separate namespaces and it is thus possible (in Common Lisp) for a function and a variable to have the same name. Procedures in Scheme are first-class values, as are continuations. Scheme's A simple use of (define (add-if-all-numbers lst) (call/cc (lambda (exit) (let loop ((lst lst) (sum 0)) (if (null? lst) sum (if (not (number? (car lst))) (exit #f) (loop (cdr lst) (+ sum (car lst))))))))) This adds an arbitrary list of numbers, but if a non-numeric value is found in the list the procedure is aborted immediately and the constant value Scheme supports lazy evaluation through the (define a 10) (define eval-aplus2 (delay (+ a 2))) (define a 20) (force eval-aplus2) => 22
Scheme's high level 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. Many implementations also provide a more conventional low level macro system. Tail recursion
Even though looping constructs (such as the In contrast, implementations of many other languages often do not optimize tail calls, making tail recursion impractical due to a limited amount of stack space. Taking the factorial example above: (define (fact n) (if (= n 0) 1 (* n (fact (- n 1))))) This is not tail recursive because factorial n is evaluated recursively by first evaluating factorial n-1 as an intermediate value, then multiplying the result by n. The last operation in the evaluation (the "tail") is the multiplication. A tail recursive version can be written as follows: (define (fact n) (define (fact2 n m) (if (= n 0) m (fact2 (- n 1) (* m n)))) (fact2 n 1)) Although this is written in a recursive form, the recursion is the last operation in evaluating the procedure (a "tail call"), and in effect replaces the procedure invocation by another (for instance, (fact2 10 1) is replaced by (fact2 9 10)). A tail call is sometimes described as "a goto with parameters" because its effect is the same as branching to the start of the procedure and replacing the old parameters with new ones. It is this characteristic that makes it possible for Scheme compilers and interpreters to guarantee that tail recursive procedures will always be evaluated in constant space. Scheme does have a "do" form which can be used for iterations, but tail recursion is used far more frequently. A more idiomatic expression of the above tail recursive factorial procedure, using the "named let" form, would be: (define (fact n) (let loop ((n n) (m 1)) (if (= n 0) m (loop (- n 1) (* m n))))) Language elementsCommentsEach comment is preceded by a semicolon ( VariablesVariables 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 Variables bound in a let are in scope for the body of the let. (let ((var1 value)) ... ; scope of var1 ...)
((lambda (var1) ... ; scope of var1 ...) value) Functions1 (define fun (lambda (arg1 arg2) ...)) 2 (define (fun arg1 arg2) ...) 3 (fun value1 value2) 4 (apply fun (list value1 value2)) Functions (often called procedures) 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 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 (define (+ x y) (- x y)) or simply (define + -) actually redefines the Lists
Scheme uses the singly-linked list data structure, implemented using a primitive data type called the pair, with accessors: getters car and cdr and setters Data typesBesides procedures, continuations, pairs and lists, Scheme provides the following data types: atomic symbols, numbers, booleans, characters, strings, vectors and input/output ports.[1] Association lists are provided by standard procedures, and many Scheme implementations also offer hash tables and such structures.[11] Extensions are standardized through a system of "Scheme Requests for Implementation" (SRFIs).[12] 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 very old implementations of Scheme may predate these standards such that 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. In addition to these traditional properties, Scheme numbers may have the property of "exactness". Integers and rational numbers are exact. An arithmetic operation involving numbers one or more of which is inexact has an inexact result.[1] The boolean type represents true and false by Symbols can be created in at least the following ways: 'hello (string->symbol "hello") Symbols have historically been regarded as case-insensitive ('Aa is the same symbol as 'AA) and this was guaranteed in the standard up to R5RS, but many Scheme implementations have provided case-sensitive symbols, and a major change in R6RS is to switch to case-sensitive symbols as standard. Implementation of case-insensitivity is a relatively trivial matter, usually involving only a conversion of the case of incoming symbols in the reader procedure which serves as the lexical scanner and parser in most Scheme implementations. EqualityScheme has three different types of equality between arbitrary objects denoted by three different relational operators for testing equality,
Type dependent equivalence operations also exist in Scheme: Control structuresConditional evaluation(if test then-expr else-expr) The A form that is more convenient when conditionals are nested is (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 A variant of the cond clause is (cond ... (test => expr) ...) In this case, (case expr0 ... ((datum1) expr1a expr1b...) ((datum2) expr2a expr2b...) ... (else exprna exprnb...)) The expression is evaluated and compared, in sequence, to each datum. If a match is found (using (and expr1 expr2...) (or expr1 expr2...)
Input/outputScheme has the concept of ports to read from or to write to.[1] R5RS defines two default ports, accessible with the functions ImplementationCurrent implementations include: PLT Scheme, MIT/GNU Scheme, Scheme 48, Chicken, Gambit, Guile, Bigloo, Chez Scheme, STk, STklos, Larceny, SCM, Kawa, Stalin, SISC, Pvts, JScheme, Gauche, TinyScheme, Ikarus, Mosh. Almost all implementations provide a traditional Lisp-style read-eval-print loop for development and debugging. Most also compile Scheme programs to executable binary. Support for embedding Scheme code in programs written in other languages is also common, as the relative simplicity of Scheme implementations make Scheme a popular choice for adding scripting capabilities to larger systems developed in languages such as C. Gambit, Chicken and Bigloo work by compiling Scheme to C, which makes embedding particularly easy. In addition, Bigloo's compiler can be configured to generate JVM bytecode, and it also features an experimental bytecode generator for .Net. Some implementations support additional features. For example, Kawa and JScheme provide integration with Java classes, and the Scheme to C compilers often make it easy to use external libraries written in C, up to allowing the embedding of actual C code in the Scheme source. Another example is PVTS which offers a set of visual tools for supporting the learning of Scheme. UsageScheme is widely used by a number[13] of schools; in particular, a number of introductory Computer Science courses use Scheme in conjunction with the textbook Structure and Interpretation of Computer Programs[14]. For the past 12 years, PLT has run the TeachScheme! project, which has exposed close to 600 high school teachers and thousands of high school students to rudimentary Scheme programming. MIT's old introductory programming class 6.001 was taught in Scheme, but that class has been replaced with 6.00, which is taught in Python. The introductory class at UC Berkeley, CS 61A, is taught entirely in Scheme; all course materials, including lecture webcasts, are available online free of charge [15]. There are relatively few examples of Scheme in apparent usage[16] for non-pedagogical purposes. However, the Document Style Semantics and Specification Language (DSSSL), which provides a method of specifying SGML stylesheets, uses a Scheme subset.[17] In addition, the well-known open source raster graphics editor, the GIMP uses Scheme as a scripting language.[18] Guile has been adopted by GNU project as its official scripting language, and that implementation of Scheme is embedded in such applications as GNU LilyPond and GnuCash as a scripting language for extensions. Chez Scheme has been used at Disney World in Florida for controlling virtual rides (Kent Dybvig, invited talk at International Conference on Functional Programming, 2006). See also
References
External links
|
|||||||||||||||||||||||||||||||||||||
This article is from Wikipedia. All text is available under the terms of the GNU Free Documentation License.
Mercedes Car
This site monitored by SitePinger.net