Email list hosting service & mailing list manager


Re: Problems with field initialization: Proposal Andre van Tonder 16 Sep 2005 18:16 UTC

 Mike Sperber wrote:

 > the association between construction
 > procedure arguments and fields is by name rather than by position.

 This is indeed a weakness of my suggestion.  I think it can be fixed
 but let me think about it.

 > - Add a LET clause that introduces a binding into the constructor like
 >   so:
 >
 > (define-type rational (x y)
 >   (let ((common (gcd x y))))
 >   (fields
 >     (num   (rational-num)    (/ x common))
 >     (denom (rational-denom)  (/ y common))))

 Hmm.  This is interesting.  The body of the type definition is starting
 to look like a lambda body, which is actually not too far from my suggestion.

 But how would you express this?

  (define-type rational
    (constructor (lambda (x y)
                   (if (= y 0)
                       (values 1 0)  ; my representation of infinity
                       (let ((common (gcd x y)))
                         (values (/ x common)
                                 (/ y common))))))
    (fields num denom))

 Cheers
 Andre

------------- End Forwarded Message -------------