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

Re: Problems with field initialization: Proposal

This page is part of the web mail archives of SRFI 76 from before July 7th, 2015. The new archives for SRFI 76 contain all messages, not just those from before July 7th, 2015.

 Andre wrote: 
 > Perhaps another keyword clause
 >    (constructor <expression>)
 > which can be left out for the default constructor.

 As an example, the hash-table example could be expressed:

  (define-type hash-table
    (constructor (k) (lambda (pred hasher size)
                       (k pred
                          (make-vector (nearest-prime size))
    (fields (pred   immutable)
            (hasher immutable)
            (data   mutable)
            (count  mutable))))

  (define-type eq-hash-table
    (parent hash-table)
    (constructor (k) (lambda (pred hasher size)
                       (k pred
    (fields (gc-count mutable)))

 All the initialization information is in a single place, and both 
 the parent clause and the field clauses simplify.  
 A record type with the default constructor ordering would simply
 omit the constructor clause:   
   (define-type point 
     (fields (x mutable)
             (y mutable)))
 which is actually a little more concise than the current specification.
 We don't need the INIT! clause any longer.  The last example from the 
 document becomes:
   (define-type cpoint
     (parent point)
     (constructor (k) (lambda (x y c)
                        (set! *the-cpoint*
                              (k x
                                 (color->rgb c)))
     (fields (rgb mutable)))
 So again, all the initialization information is in a single place.