"Jens Axel S?gaard" <usenet at soegaard.net> wrote in message
Thanks. I'll learn a few things from this. However, apropos to the
thread topic, I am somewhat flabbergasted that anyone could think that
(sort (cons 1297.04 (cons 20000.00 (cons -505.25 empty))))
(cons 20000.00 (cons 1297.04 (cons -505.25 empty)))
(section 12.2) is a sensible list notation to inflict on anyone, let
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
(cons a-number a-list).
Examples of lists:
(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)
[(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:
Another beginner friendly thing is the Stepper, which alows you
to execute your programs in small steps also backwards!
Finally there are builtin support for XML for making homepages:
Jens Axel S?gaard