Lisp Programming Question:
Download Job Interview Questions and Answers PDF
What is the difference between Scheme and Common Lisp?
Answer:
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) ...)).
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) ...)).
Download Lisp Programming Interview Questions And Answers
PDF
Previous Question | Next Question |
How to save an executable image of my loaded Lisp system? How to run a Unix command in Lisp? How to exit Lisp? Access environment variables? | How to pass commands to LG3? |