Why should I care about Lisp and Scheme?



I've shamelessly "borrowed" material from these sources.
(http://www.catb.org/~esr/faqs/hacker-howto.html)
(http://www.paulgraham.com/icad.html)
(http://www.paulgraham.com/rootsoflisp.html)
(http://groups.google.com/group/comp.lang.scheme/browse_frm/thread/3ae4ac3836bbde34/8add0f479c70ad73#8add0f479c70ad73)
(http://groups.google.com/group/comp.lang.scheme/browse_frm/thread/1c62fe94aee4dcab/7b657644f6d6638e#7b657644f6d6638e)
Foreword to the book "Essentials of Programming Languages".
Special thanks to Brian Harvey, Pascal Bourguignon, Anton van Straaten
and others at comp.lang.scheme, whose advice and statements I've used
heavily.

I see this document as a first draft that needs to be worked on. Hence
any comments are appreciated.

It's an imaginary conversation between a newbie and a hacker.

---
Newbie: Why should I care about Lisp and Scheme?

Hacker: If your happy with what you've got so far you don't need to
care about Lisp or Scheme. But if you want to get more perspective
about what programming is all about, then Lisp or Scheme could be worth
trying. They are worth learning for the profound enlightenment
experience you will have when you finally get it. That experience will
make you a better programmer for the rest of your days, even if you
never actually use Lisp (or Scheme) itself a lot.

Newbie: Lisp is one of the oldest languages around. How come it
survived? What's the story behind Lisp?

Hacker: Lisp differs from other programming languages, because it was
not written as a language. It came as a byproduct of McCarthy trying to
axiomatize computation. He invented a notation representing Lisp
functions as Lisp data, and such a notation was devised as a pure
abstract concept. One of the functions McCarthy devised was eval and
when Steve Russell, one of McCarthy's grad students, looked at the
definition of eval and realized that if he translated it into machine
language, the result would be a Lisp interpreter. Here is what McCarthy
said about it later in an interview:

"Steve Russell said, look, why don't I program this eval..., and I said
to him, ho, ho, you're confusing theory with practice, this eval is
intended for reading, not for computing. But he went ahead and did it.
That is, he compiled the eval in my paper into [IBM] 704 machine code,
fixing bugs, and then advertised this as a Lisp interpreter, which it
certainly was. So at that point Lisp had essentially the form that it
has today.... "
So the reason why Lisp is different from many other programming
languages is that it is math, and math doesn't become old so fast as
technology does.

Newbie: What would you say is special about Lisp, in practice?

Hacker: One thing is that symbolic data (words, sentences, etc.) are
easy to manipulate. Another thing is that procedures are first class
objects. A third thing is that variables are not typed.

Newbie: Can you illustrate with a simple example that symbolic data is
easy to manipulate.

Hacker: Here's a simple example
> (car '(define (f x) (* x x)))
define

Now you know that the expression defines something ad so on.

Newbie: What do you mean by procedures being first class objects?

Hacker: I mean that functions can be used in programs without
restriction, just as if they were simple data. For example a function
can:
* be constructed at runtime.
* be stored in variable.
* be passed as a parameter to a procedure.
* be returned as the result of a procedure call.

Newbie: Can you give a simple example?

Hacker: Here's a simple procedure that takes a function as a parameter.
> (define (add x y) (+ x y))
> (define (sub x y) (- x y))
> (define (func g) (g 8 4))
> (func add)
12
> (func sub)
4

As you can see the parameter of the procedure func is a procedure
called g. If we pass the procedure add to func we get 12, and if we
pass the procedure sub to func we get 4.

Newbie: You also mentioned that in Lisp variables are not typed. What
does that mean?

Hacker: In Lisp data (and procedures) are stored in the heap and
variables hold pointers pointing at the data. In this way variables do
not need to have any special type.

Newbie: What's so cool with that?

Hacker: Since the variables are not typed, there are no restrictions on
which values may be associated with names. Therefore the same procedure
can be used with values of various types. Here's one example

(define (third seq)
(element seq 2))

(define (element seq index)
(cond ((vector? seq) (vector-ref seq index))
((list? seq) (list-ref seq index))
((string? seq) (string-ref seq index))
(else (errorstring "First argument must be a sequence"))))

; Test
(define L '(1 2 3 4 5))
(third L)
; ==> 3
(define V '#(1 2 3 4 5))
(third V)
; ==>
(define S '"12345")
(third S)
; ==> #\3

As you can see the function third accepts any kind of sequence. You can
feed it with a list, a vector or a string. It does it's job without
complaining.

Newbie: What you're saying reminds me of Python, which is also
dynamically typed. The other two features of Lisp that you mentioned,
the symbolic data and procedures being first class, also apply to
Python I think? Python doesn't have the simple structure that Lisp has,
but it has lists, dictionaries and tuples as primitive elements so in
principle those two features apply to Python as well.

Hacker: Python has no easy data=code. The point of symbols and lists in
Lisp is that they are used both to represent data and code, and you can
convert between data and code at run-time. You can't beat the ease of
Lisp to treat code as data. Even though some programming language has
some part that Lisp has, it's the whole philosophy behind Lisp, which
is more than the sum of the parts.

Newbie: The reason I started to look at Scheme was this concept of not
distinguishing between the data and code. I mean both of them are zeros
and ones inside a computer so why should you make difference between
them. That many programming languages do so, feels like blocking a
world of opportunities.

Hacker: Interpreters and compilers are the prime examples of programs
that utilizes that code is data. If you don't understand interpreters,
you can still write programs; you can even be a competent programmer.
But you can't be a master.

Newbie: Why is understanding interpreters so important.

Hacker: One reason is that understanding interpreters allows you to
create special-purpose "little languages" that are custom made for your
problem. Another reason is that in order to understand computers and
programming, you need to understand the link between the code you write
and what happens inside the computer when it runs your code. In other
words you have to understand the link between syntax and semantics. An
the interpreter is that link. Even programmers who haven't studied
interpreters develop an intuitive understanding of the link between
syntax and semantics. They do this in two main ways: by reasoning about
programs, i.e. interpreting them in their head; and by using a computer
as a "black box", watching what the output that the computer generates
when fed with a certain syntax. But this still leaves something to be
desired. Our "mental" interpretation tends to be full of gaps and the
"black box" can't give the whole picture. So, the only way to really
fill in our knowledge of that important link is to study interpreters
themselves.

Newbie: What goes on in my head is that I visualize a memory space
containing a stack, a heap, registers and so on.

Hacker: Right, so you're simulating the hardware in your mind. This is
quite common, but not necessarily the most effective approach. It might
be more effective to translate into one or more "intermediary
languages". Translating to the machine level too early tends to create
a trees vs. forest problem, and doesn't help you deal with the
complexity in the most efficient way. Understanding abstraction layers
and the languages within each abstraction layer might help you control
complexity.

Newbie: Can you explain little more about these "intermediary
languages".

Hacker: It's easier to appreciate what's special in Lisp and Scheme by
shifting your viewpoint from a language user to a language designer -
the former is to accept the language features as given and
unchangeable, and tries to write all the solutions in it; while the
latter first look at the problem, think about what language is suitable
to describe the problem, then write the language using the base
language. In Lisp and Scheme programmers can become "language
designers" inventing the "language" for their specific problem. In that
way they get a very flexible program that can adapt easily when the
original problem changes.

Newbie: Is there other reasons that make Lisp and Scheme cool?

Hacker: I like the free SICP video lectures and the corresponding SICP
book. There's a very rich and exciting literature! For instance EoPL,
PLAI, On Lisp, and so on. I also like the intelligent conversations in
comp.lang.scheme and comp.lang.lisp.

Bob

.



Relevant Pages

  • Re: Computer Algebra Algorithms
    ... If you want to learn CAS, learn lisp because that is what the ... The parser could be written in C or any other language. ... I would consider that such a minor aspect of a programming ... generally prefer righting there numeric algorithms in Maple and MATLAB ...
    (sci.math.symbolic)
  • Re: F#
    ... Why did they take Lisp? ... properties of the language are only a part of the picture. ... If the favored programming style of a certain language ... Knowing a success story only tells me that other people ...
    (comp.lang.functional)
  • Re: Opinions on intro lisp books
    ... But Lisp is a little different, ... Some languages support one style of programming better than they ... Even if that weren't the case, I'm not sure that a language being a ... I don't believe that learning to program in CL requires more theory ...
    (comp.lang.lisp)
  • [ANN] 2nd European Lisp & Scheme Workshop
    ... Pascal Costanza, Programming Technology Lab, Vrije Universiteit Brussel ... Lisp has a tradition of providing a fruitful basis for language design ... and suggestions for breakout groups that discuss the opportunities Lisp ...
    (comp.lang.lisp)
  • Re: Why should I care about Lisp and Scheme?
    ... Newbie: What would you say is special about Lisp? ... Hacker: In Lisp programs are represented as lists which means that you ... viewpoint from a language user to a language designer - the former is ...
    (comp.lang.scheme)