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

Re: Problems with field initialization: Proposal



 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