[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: peasant revolt against DrScheme!



> From: Shriram Krishnamurthi <sk@cs.brown.edu>
> 
> Michael,
> 
> > Factorial, no doubt.  
> 
> Thanks.  You, and the others who have replied, have all nicely slipped
> into the trap.  It's interesting, too, how the replies I've received
> don't just say "factorial"; they always add a note of absolutely
> certainty to it.
> 
> First, an incindiary remark (just in case you weren't paying
> attention): Factorial is the worst first example of recursion.  ...
> Except for fibonacci, which is even worse.

Fibonacci, of course, because of the superexponential time complexity.  The
non-tail-recursive factorial causes the stack to grow excessively.  The
tail-recursive one seems OK, though.  What's so bad about it?

> 
> Now: go see how How to Design Programs does it.  If you read it
> carefully enough, you will find that
> 
> (a) we are sympathetic to the student's question about why they
>     shouldn't just use a loop, and
> 
> (b) develop a response to it.
> 
> Indeed, by the fifth week of the course at Rice, these questions are
> definitively quashed.

OK, I'll read on :-)

> (You anticipate the response in your message; for some reason, you
> don't make the connection yourself.)
> 
> > Many students are probably never even taught that there are more
> > conventional iteration constructs in scheme e.g.
> > 
> > (define (factorial n)
> >    (define r 1)
> >    (do ((i 2 (+ i 1)))
> >        ((> i n) r)
> > 	   (set! r (* r i))))
> 
> And thank goodness for that.  Just yesterday I saw a VB teacher
> complaining on the AP computer science mailing list that he simply
> couldn't figure out the syntax of Scheme's conditionals.  If he were
> only to see the syntax of DO ...

:-)  Maybe we should have more sugar:

(if (= a 1)
	(then (display "woo-hoo!"))
	(else (display "too bad!")))

> 
> [I've tried using DO 5-10 times in my life.  Every single time I get
>  the syntax horribly wrong and give up.]

I had to use R5RS to get it right :-)  Which to me just means that macro
forms for iteration that mimic for, while, etc. should be part of the
language, just like mzscheme defines let/cc as syntactic sugar for call/cc.

> > Recursion is important when writing functions to handle recursive data
> > structures (e.g. trees).  It also sometimes, but not always, leads to
> > cleaner and easier-to-understand programs.  It also typically leads to
> > programs that have fewer side-effects, are more functionally pure,
> > etc. etc.  However, very often ordinary iteration is just the most
> > straightforward way to go, and since scheme supports that as well, why not
> > take advantage of it?  
> 
> Because, as you observe, if you simplify the looping construct enough, 
> you are forced to use mutation.  And it is obvious (I hope) that
> beginning students should not be taught mutation.
> 
> Shriram
> 

It's not as clear to me as it is to you (but then, I don't teach
programming).  I see functional and imperative programming as being equally
valid, and that the choice of which to use depends greatly on the
application.  I would like to be able to use both paradigms comfortably,
and in scheme, I can.  What's wrong with that?

There are really two separate issues here:

1) How to teach programming as a way of thinking to students.

2) How to popularize scheme among programmers used to languages that
   only support imperative programming.

Your arguments are aiming at (1), which I'm sympathetic to.  Mine are (in
retrospect) really aiming at (2).  I'd like to be able to tell my
non-scheme-using friends, "hey, you can do all the same stuff you can do in
{perl,python,C} in scheme, and you can also do tons more!", instead of
"you're thinking about programming in the wrong way; you have to totally
unlearn all of your ideas about programming and start over".  The hope is
that if I could say the first, they'd learn the second on their own later.

Mike