[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Problems with field initialization: Proposal
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
> (define-type rational (x y)
> (let ((common (gcd x y))))
> (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?
(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))
------------- End Forwarded Message -------------