This is the mail archive of the guile@cygnus.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Bracket heresies. What about subscripting?



> From: Mikael Djurfeldt <mdj@thalamus.nada.kth.se>
> Date: 18 Jul 1999 21:44:50 +0200
> 
> Jim Blandy <jimb@red-bean.com> writes:
> 
> > > There we write
> > > 
> > >   (m i j) ; reference element i,j in m.
> > > 
> > >   (* m m) ; multiply m by itself
> > > 
> > >   (set! (m i j) 17)		 ; assign 17 to element i,j in m
> > >   (set! (a (.. 1 m) (.. 1 n)) b) ; set the m x n block in upper left
> > >                                  ; corner of a to b
> > > 
> > > This is possible since objects of Goops also can be operators.
> > 
> > This is terrible, disgusting chaos, a horrible perversion of the
> > Scheme way
> 
> Well, thank you for your being straight to the point.  :)

I think Jim was kidding to some extent, but I'm not sure...

> But what is the chaos part?  (m i j), the setter style, or objects
> being operators in general?
> 

I haven't programmed that much in scheme/lisp, so as an interested outsider
I can say that I find `vector-ref' etc. pretty distasteful.  One thing you
can do with an OO approach that is not as extreme as what you suggest is
simply to do this:

    (ref m i j)  ; equivalent to your (m i j)

Here, `ref' is a generic function that dispatches on m, so the effect is the
same.  This could be a more schemey alternative without being too verbose.
You could use `index' or some other name instead of `ref', of course.

That said, I think that there is some merit to your proposal, especially
for the specific application you mention.  There's also ample precedent for
it in other languages; in C++ you can overload the function call operator
so that m(i, j, k) is a multidimensional array reference, and in python you
can use the special __call__ action to do the same.  Whether this is the
most elegant solution for *this* problem is a matter of taste, of course.

Mike

--------------------------------------------------------------
Mike Vanier	mvanier@bbb.caltech.edu
Department of Computation and Neural Systems, Caltech 216-76
GNU/Linux: We can't lose; we're on a mission from God.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]