Computers obviously not harmful (was: Re: [plt-scheme] Computers considered harmful)

From: Joe Marshall (jmarshall at alum.mit.edu)
Date: Mon May 11 13:56:44 EDT 2009

On Mon, May 11, 2009 at 10:10 AM, John Clements
<clements at brinckerhoff.org> wrote:
>
> Yes, I'm imagining it: the solution is still going to look imperative,
> right?
>
> e.g.:
>
> (define (react state)
>  (cond [(empty-sensor? state) (return counter)]
>        [else (set counter (+ counter 1)) (move-to-cdr)]))
>
> It appears to me that applying the "robot model" to introductory programming
> is not going to help you make the crucial bridge to algebraic programming.

The substitution model is going to be a problem in `the real world' because
you can't readily replicate objects.

On the other hand, consider something like this
(map 1+ list-of-numbers)

(define (map f l)
  (cond ((pair? l) (cons (f (car l)) (map f (cdr l))))
           ((null? l) '())
           (else (error))))

You are still applying F one element at a time.  There is a single
sequential locus of execution.  You don't have the side effect problem
though because you have new cons cells all along the way.
So maybe your robot has to do this:

 (define (react state)
  (cond [(empty-sensor? state) (return counter)]
           [else (get-new-counter (+ counter 1)) (move-to-cdr)]))

Where the act of `getting a new counter' doesn't cause a side effect
any more than cons does.

-- 
~jrm


Posted on the users mailing list.