Newsgroups: comp.lang.scheme
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!news2.near.net!news.mathworks.com!news.duke.edu!convex!cs.utexas.edu!rutgers!njitgw.njit.edu!funcity!aaron
From: aaron@funcity.njit.edu (Aaron Watters)
Subject: Re: Scheme Digest V6 #314
Message-ID: <1994Oct25.152130.4482@njitgw.njit.edu>
Sender: news@njit.edu
Nntp-Posting-Host: funcity.njit.edu
Organization: New Jersey Institute of Technology
References: <dig-Scheme-6.314@mc.lcs.mit.edu> <9410250041.aa15731@mc.lcs.mit.edu>
Date: Tue, 25 Oct 1994 15:21:30 GMT
Lines: 89

In article <9410250041.aa15731@mc.lcs.mit.edu> hal@mit.edu writes:
>The real reason people get so confused about arrays being the "single
>most useful structures in real programming" is that they think in
>terms of impoverished languages that do not permit people to
>manipulate compound data structures as first-class objects.  Thus they
>are forced to build almost all data structures by using explicit
>arrays to simulate the memory cubbyholes that hold pointers, and they
>believe that everyone else should do likewise.  Hence their
>irritation.

Well I hope you're not referring to me.  This is not the source of
my irritation.

>Arrays can often be quite handy, expecially in numerical programming,
>and one can "'do' arrays in functional programming" quite well, thank
>you, as in the following procedure to multiply matrices:
>
>(define (matrix*matrix m1 m2)
>  (if (not (=  (num-cols m1) (num-rows m2)))
>      (error "Matrix sizes do not match -- MATRIX*MATRIX" m1 m2)
>      (let ((m1cm1 (- (num-cols m1) 1)))
>	(generate-matrix (num-rows m1) (num-cols m2)
>	 (lambda (i j)
>	   (let ((r1i (vector-ref m1 i)))
>	     (sigma (lambda (k)
>		      (* (vector-ref r1i k) (matrix-ref m2 k j)))
>		    0
>		    m1cm1)))))))

Great.  Write once arrays.  What about all the many many beautiful
algorithms that use write-many arrays -- hash tables, radix methods,
B-trees and variants, just about any numerical computation that isn't
trivial, graph algorithms, statistical computations.  These are all
more than "memory cubbyhole" replacements.  I suspect their is some
hack to make these look "functional" as well (I remember reading some
stuff along these lines) -- but this approach simply offers NO REAL
ADVANTAGE over conventional methods for MOST applications
[flame bait clause deleted].

But lets talk python:

   def mmult(m1,m2):
       m2rows,m2cols = len(m2),len(m2[0])
       m1rows,m1cols = len(m1),len(m1[0])
       if m1cols != m2rows: raise IndexError, "matrices don't match"
       result = [ None ] * m1rows
       for i in range( m1rows ):
           result[ i ] = [0] * m2cols
           for j in range( m2cols ):
              for k in range( m1cols ):
                 result[i][j] = result[i][j] + m1[i][k]*m2[k][j]
       return result
usage:
   >>> x = [ [1, -1],
   ...       [-1, 2] ]
   >>> y = [ [4, 3, -3],
   ...       [9, 0,  1]]
   >>> mmult(x,y)
   [[-5, 3, -4], [14, -3, 5]]

I suspect some fp purists are having fits, but I also suspect most
physicists and chemists would have little trouble with the python
without looking at the manual, whereas the scheme is greek (but you
could transliterate it to python if you *really* insist).  If you think
it's too slow in python, translate to C (after debugging in python
-- far easier) and interface the result to python.  Actually, don't
(somebody already did!).

Now I know that you folks prefer to focus on a set of problems
of measure zero where the fp approach is the way to go, but I
still think it's cruel to inflict it on your students when they
are missing other stuff.  I'm not worried about the MIT students
-- they are so smart that you could lock them in a closet for
4 years with a selection of good books and they'd come out self-educated.
I have seen students from other places, however, that have
missed a lot.  The industrial world of course will take care of
itself, as it has done.

Go ahead, beat me up.  I'll try to sit helpless and quiet from now
on until I die.
        Aaron Watters
        Department of Computer and Information Sciences
        New Jersey Institute of Technology
        University Heights
        Newark, NJ 07102
                phone (201)596-2666
		fax (201)596-5777
		home phone (908)545-3367
		email: aaron@vienna.njit.edu
