[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:
 
 > - 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))))
 
 
 Would you perhaps consider a slight variation of this:
 
   (define-type rational (x y)
     (let ((common (gcd x y)))
       (field-values
         (num   (/ x common))
         (denom (/ y common))))
     (fields (num   (rational-num))
             (denom (rational-denom))))
             
 It is only slightly more verbose, but now it can handle this:
 
   (define-type rational (x y)
   
     (if (= y 0)
        (field-values (num   1)
                      (denom 0))
        (let ((common (gcd x y)))
          (field-values
           (num   (/ x common))
           (denom (/ y common)))))
  
     (fields (num   (rational-num))
             (denom (rational-denom))))
             
             
 Andre