[Edu-sig] Re: Teaching Middle-School Math with Python

Kirby Urner pdx4d@teleport.com
Tue, 10 Oct 2000 15:50:01 -0700


>  Also, I'd think you'd _want_ to cover car and cdr when approaching 
>  programming in Scheme
>
>Why? That would be silly. Teaching in middle school and even high school
>our objectives are to produce thinking kids who can use some programming 
>tool not finished Python/Scheme programmers. 

I'll have to look at those docs again.  Seems to me that using recursion
as your primary means of looping means you're very often writing stuff 
like:

 (define (Reduce procedure mylist)
    (cond
       [(= (length mylist) 1)(car mylist)]
       [(procedure (car mylist)(Reduce procedure (cdr mylist)))]
       ))

 Usage:

 > (Reduce + '(1 2 3 4))
 10
 > (Reduce * '(1 2 3 4))
 24

In Python:

 def Reduce(proc, mylist):
     if len(mylist)==1: return mylist[0]
     else: return apply(proc, (mylist[0], Reduce(proc, mylist[1:])))


 Usage:

 >>> import operator	
 >>> Reduce(operator.add,(1,2,3,4))
 10
 >>> Reduce(operator.mul,(1,2,3,4))
 24

(Note:  for illustration purposes only -- Python has a built-in 
reduce function that already does the above).

... just back from the docs.  Looks like you're using 'first' and 'rest'
in place of 'car' and 'cdr'.  That's good.  'car' and 'crd' are silly 
names.  But I'm not finding where 'first' and 'rest' get defined.
They're not MzScheme primitives i.e. I get an error message when I 
try using either one.

Anyway, not to worry, I'll find this missing puzzle piece eventually.

>Absolutely. Model and view is for us who know that Model is about
>functions, relations, compositions, domain, range, sets, ... (see TLL).
>View is about the stupid i/o crap that most languages impose on kids. 
>
>-- Matthias

Yeah, we don't want to start off on the wrong foot with a lot of
stupid i/o crap, I agree.

Thanks for the dialog.  Sounds like we're not in any serious disagreement
at this point.

Kirby