Email list hosting service & mailing list manager


Re: Comments on LET and constructors Andre van Tonder 20 Oct 2005 19:08 UTC

 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