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

Re: Problems with field initialization



On Wed, 14 Sep 2005, Andre van Tonder wrote:

Alternative Suggestion:

Instead of having a separate <init expression> for each field, one could
simply have an <expression> for the constructor, which should evaluate to a
procedure that returns the computed fields (using VALUES, for example).

This would solve all the above problems.  The overall gain in power and
simplicity would be, in my view, significant.


By the way, it has occurred to me that, if one were to consider the functionality of INIT! to be justified, even INIT! may be dropped if the user-provided constructor procedure is specified abstracted over the "real" constructor.

For example:

(define *the-frob* #f)

(define-type frob (lambda (real-constructor)
                    (lambda (n)
                      (let ((result (real-constructor (make-widget n))))
                        (set! *the-frob* result)
                        result)))
  (fields (widget (getwid setwid!))))


Andre