Why is Python popular, while Lisp and Scheme aren't?
Jens Axel Søgaard
usenet at soegaard.net
Wed Nov 13 15:48:54 EST 2002
Terry Reedy wrote:
> "Jens Axel Søgaard" <usenet at soegaard.net> wrote in message
> news:3dd1ffd7$0$63936$edfadb0f at dread15.news.tele.dk...
>
>> Beating
>>
>> http://www.htdp.org
>
> Thanks. I'll learn a few things from this. However, apropos to the
> thread topic, I am somewhat flabbergasted that anyone could think that
> Scheme's
>
> (sort (cons 1297.04 (cons 20000.00 (cons -505.25 empty))))
> ;; expected value:
> (cons 20000.00 (cons 1297.04 (cons -505.25 empty)))
>
> (section 12.2) is a sensible list notation to inflict on anyone, let
> alone newcomers,
This is in the beginning of the book. Later you will learn to write
(list 1 2 3) or '(1 2 3).
There is a *very* good explanation. Read on.
[For the Pythonians that does not know Scheme.
Note that the Scheme-list called a linked list in som other
languages. A python list is called a vector in stead.]
But why? HTDP uses DrScheme. In DrScheme there are several teaching
language levels. Ranging from beginner, intermediary, advanced. Then
one is ready to use Pretty Big Scheme.
The language levels enables DrScheme to provide the user with error
messages that the student understands. In most languages a simple
syntax error can provoke an error message using concepts the beginner
does not yet understand. DrScheme has the most beginner-friendly error
messages I have ever seen.
Back to the issue, whether to write (cons 1 (cons 2 empty)) or (list 1 2).
This choice is made to learn the beginner the representation of a list.
What is a list of numbers? A list of numbers is either empty, or constructed
by the first number of the list followed by the rest of the list.
Thus a list-of-numbers is either
empty
or
(cons a-number a-list).
Examples of lists:
empty
(cons 1 empty)
(cons 2 (cons 1 empty))
Examples of first and rest:
(first (cons 2 (cons 1 empty))) = 2
(rest (cons 2 (cons 1 empty))) = (cons 1 empty))
This is important! If you know this we kan write follow the design recipe
for developing list processing function to make functions that handle list
automatically (i.e. without thinking too much).
Let make a function that counts the number of elements in a list
(don't worry it's already in Scheme - it's just an example)
(define (length a-list)
(cond
[(empty? a-list) 0]
[(cons? a-list) (+ 1 (length (rest a-list)))]))
In prose this says,
if a-list is empty, then the length of the list is 0,
if the list is cons-tructed then the length is 1 (there is a first
element) plus the length of the rest of the list.
If in constrast you learned to make lists like
'(1 2 3) which gets printed as (1 2 3),
then you wouldn't know how to make list processing functions.
When you master how to make the functions, it is ok to learn
the notational short cuts.
In more general terms: in the teaching languages values
are printed in the same notation that are used to construct them.
For example: "Hello world" gets printed as "Hello world". This a good
thing for beginners - they are less likely to get confused by the internal
and the printed representation of the various datatypes.
If you haven't looked at the tour, then take a look at
which shows that bitmaps are a builtin datatype, which can be
put directly in the editor:
http://www.drscheme.org/tour/202/tour-Z-H-5.html
Another beginner friendly thing is the Stepper, which alows you
to execute your programs in small steps also backwards!
http://www.drscheme.org/tour/202/tour-Z-H-8.html
Finally there are builtin support for XML for making homepages:
http://www.drscheme.org/tour/202/tour-Z-H-11.html
Have fun,
--
Jens Axel Søgaard
More information about the Python-list
mailing list