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

Re: peasant revolt against DrScheme!




> From: Shriram Krishnamurthi <sk@cs.brown.edu>
> 
> Even 10-year-olds have no trouble (with perhaps some hand-holding)
> describing recursively-defined data.  When the control follows from
> the data in a mechanical fashion, they have no real difficulty
> describing the control also.  We've seen this with actual kids.
> 
[snip]
> 
> Both factorial and fibonacci suffer another problem.  Factorial
> rapidly produces numbers beyond the expressive capability of the
> implementations of most other languages (and a few Schemes).
> Fibonacci rapidly becomes too expensive to compute.  Students are
> notorious for imputing properties resulting from X to Y (for Y =/= X).
> The fibonacci case is especially insidious because, if you write the
> standard iterative version, you *don't* suffer from the blow-up.  You
> can only imagine what *that* does to students' understanding.
> 
> Shriram
>

Shriram,

That's is a very good point that I hadn't thought about.

However...

Let's say I agree 100% with everything you've said so far.  Recursive
functions are extremely effective for dealing with many data structures,
lists among them.  What if you want to iterate down a vector and pick out
the largest element?  You can certainly do it recursively:

(let loop ((v #(1 10 3 22 4))
           (i 0) ; index
           (max -1)) ; assume all elements of v are positive
    (if (>= i (vector-length v))
        (begin (display "maximum = ") (display max) (newline))
        (let ((v_i (vector-ref v i)))
          (if (> v_i max)
              (loop v (+ i 1) v_i)
			  (loop v (+ i 1) max)))))

But this seems rather excessive compared to a straight iteration construct
(and no mutation is going on either).  Vectors are very important data
structures in (for instance) numeric programming, so this issue is not
trivial.

Mike