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?


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.  :)

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

Below I'm going to argue a little for this style, but first I want to
stress that this syntax was chosen mainly to get a user interface
which could compete with Matlab in easy of use.  I'm not saying that
this is how subscripting should work in general in Scheme.  It's just
that when you work with numerical algorithms the code becomes so
obscure if formulas consists of things like
(* (vector-ref (vector-ref A i) j) (vector-ref (vector-ref B j) k)).

This was a syntax selected for a special application.  If you have
more Schemey suggestions which are easy to read and easy to type and
can compete with Matlab, I'm grateful to hear them.


You must agree that it is natural to regard a matrix as an operator.
(This is how matrices are regarded in linear algebra.)

  (M V1) --> V2  (where V1 and V2 are vectors)

Right?  

In the context of generic functions it's then not very far-fetched to
assign a meaning to an expression where the matrix is applied to a
couple of integers.

(I don't need to supply code to show that this kind of representation
 for matrices could easily be implemented in standard R5RS Scheme.
 At least apart from the set! syntax which is a different issuel)

> Now, wouldn't it be cool if applying a regexp to a string
> returned a list of the substrings?
> 
> ((make-regexp "(.*)/([^/]*)") "/usr/local/bin/gcc")
> => ("/usr/local/bin" "gcc")
> 
> (define (x-display-hostname display)
>   (car ((make-regexp "([^:]*):.*") display)))

I guess the problem is that with objects being operators you could
easily end up with unreadable code.  Note that our application
specific matrix syntax was intended to enhance readability of code
(* (A i j) (B j k)).

Besides,

(define split-file-name (make-regexp-parser "(.*)/([^/]*)"))

(define (x-display-hostname display)
  (car (split-file-name display)))


Again, I *don't* say that this is how subscripting should look like
in Scheme in general.

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