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:

> it wasn't sarcasm.  I don't think it's so horrible.  Sorry I wasn't
> clearer.

Ah.  OK.  No problem.  :-)

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

Hmm...  Isn't *not* regarding an operator as an object a horrible
perversion of the Scheme way?  Or else, what is meant by procedures
being first class objects?

(define (make-affine-transformation)
  (let ((a 1.0)
	(b 0.0))
    (lambda (x)
      (case x
	((scale)
	 (lambda (x)
	   (set! a (* x a))
	   (set! b (* x b))))
	((translate)
	 (lambda (x)
	   (set! b (+ b x))))
	((add)
	 (lambda (op2)
	   (let* ((b2 (op2 0.0))
		  (a2 (- (op2 1.0) b2)))
	     (set! a (+ a a2))
	     (set! b (+ b b2)))))
	(else
	 (+ (* a x) b))))))

(define (scale! op x) ((op 'scale) x))
(define (translate! op x) ((op 'translate) x))
(define (add! op1 op2) ((op1 'add) op2))

(define f (make-affine-transformation))
(scale! f 2)
(translate! f 3)
(f 1)

> > > 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)).
> 
> I don't find the stringy syntax unreadable, though.  The idea is that
> a regexp is a function which breaks its argument into pieces.  I
> couldn't think of anything more natural for a regexp to do.  I guess
> you didn't like it.  *sigh*

Well, I thought the example was a bit unreadable.  Then I rewrote it
using variables in order to show that the readability problem wasn't
due to the idea of objects being operators but due to the programming
style.

But maybe it isn't that unreadable.  The items of high significance
are `car', the regexp, and `display'.  Maybe it's good that the regexp
and `display' are close together...

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