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

Re: Comments on LET and constructors



 
 A small question:  Are the parent constructor arguments also in the 
 scope of the LET?  
 
 I think they should be.  If they are, then we can at least express one 
 of the "inexpressible" examples I listed:
    
 >    ;; Conditionally instantiating the parent with different arguments:
 >    ;; (actually this specific example can be expressed but would 
 >    ;;  require the test for (= y 0) to be duplicated):
 >                   
 >    (define-type rational 
 >      (parent finite-rational)
 >      (constructor (lambda (x y)
 >                     (if (= y 0)
 >                         (instantiate (parent 1 0))   
 >                         (instantiate (parent x y))))))    
  
 as follows:
 
   (define-type rational (x y)
     (let ((parent-args (if (= y 0)
                            (cons 1 0)   
                            (cons x y)))))
     (parent finite-rational (car parent-args)
                             (cdr parent-args)))
                                                                                                          
 Cheers
 Andre