Top Document: FAQ: Lisp Frequently Asked Questions 1/7 [Monthly posting] Previous Document: [1-0] What is the purpose of this newsgroup? Next Document: [1-2] Lisp books, introductions, documentation, periodicals, journals, and conference proceedings. See reader questions & answers on this topic! - Help others by sharing your knowledge Scheme is a dialect of Lisp that stresses conceptual elegance and simplicity. It is specified in R4RS and IEEE standard P1178. (See the Scheme FAQ for details on standards for Scheme.) Scheme is much smaller than Common Lisp; the specification is about 50 pages, compared to Common Lisp's 1300 page draft standard. (See question [4-10] for details on standards for Common Lisp.) Advocates of Scheme often find it amusing that the Scheme standard is shorter than the index to CLtL2. Scheme is often used in computer science curricula and programming language research, due to its ability to represent many programming abstractions with its simple primitives. Common Lisp is often used for real world programming because of its large library of utility functions, a standard object-oriented programming facility (CLOS), and a sophisticated condition handling system. See the Scheme FAQ for information about object-oriented programming in Scheme. In Common Lisp, a simple program would look something like the following: (defun fact (n) (if (< n 2) 1 (* n (fact (1- n))))) In Scheme, the equivalent program would like like this: (define fact (lambda (n) (if (< n 2) 1 (* n (fact (- n 1)))))) Experienced Lisp programmers might write this program as follows in order to allow it to run in constant space: (defun fact (n) (labels ((tail-recursive-fact (counter accumulator) (if (> counter n) accumulator (tail-recursive-fact (1+ counter) (* counter accumulator))))) (tail-recursive-fact 1 1))) Whereas in Scheme the same computation could be written as follows: (define fact (lambda (n) (letrec ((tail-recursive-fact (lambda (counter accumulator) (if (> counter n) accumulator (tail-recursive-fact (+ counter 1) (* counter accumulator)))))) (tail-recursive-fact 1 1)))) or perhaps (using IEEE named LETs): (define fact (lambda (n) (let loop ((counter n) (accumulator 1)) (if (< counter 2) accumulator (loop (- counter 1) (* accumulator counter)))))) Some Schemes allow one to use the syntax (define (fact n) ...) instead of (define fact (lambda (n) ...)). User Contributions:Top Document: FAQ: Lisp Frequently Asked Questions 1/7 [Monthly posting] Previous Document: [1-0] What is the purpose of this newsgroup? Next Document: [1-2] Lisp books, introductions, documentation, periodicals, journals, and conference proceedings. Part1 - Part2 - Part3 - Part4 - Part5 - Part6 - Part7 - Single Page [ Usenet FAQs | Web FAQs | Documents | RFC Index ] Send corrections/additions to the FAQ Maintainer: ai+lisp-faq@cs.cmu.edu
Last Update March 27 2014 @ 02:11 PM
|
Comment about this article, ask questions, or add new information about this topic: