[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problems with field initialization: Proposal

This page is part of the web mail archives of SRFI 76 from before July 7th, 2015. The new archives for SRFI 76 contain all messages, not just those from before July 7th, 2015.



 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 -------------