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

*To*: srfi-76@xxxxxxxxxxxxxxxxx*Subject*: Re: field initialization: Backward compatible suggestion*From*: Andre van Tonder <andre@xxxxxxxxxxxxxxxxx>*Date*: Fri, 16 Sep 2005 19:41:43 -0400 (EDT)*Delivered-to*: srfi-76@xxxxxxxxxxxxxxxxx

The hash table example looks just like in the draft: (define-type hash-table (pred hasher size) (fields (pred immutable) (hasher immutable) (data mutable (make-vector (nearest-prime size))) (count mutable 0))) (define-type eq-hash-table (pred hasher size) (parent hash-table pred hasher size) (fields (gc-count mutable 0))) For more nontrivial things, there is a |constructor| clause: (define-type rational (x y) (fields (num immutable) (denom immutable)) (constructor (if (= y 0) (fields (num 1) (denom 0)) (let ((common (gcd x y))) (fields (num (/ x common)) (denom (/ y common)))))))

(define-type hash-table (pred hasher size) (fields (pred immutable) (hasher immutable) (data mutable (make-vector (nearest-prime size))) (count mutable 0)) (constructor (if (and (eqv? pred eq?) (< size 10)) ;; assume speed of assq faster for <10 (fields (hasher (lambda (key) 0)) (data (make-vector 1))) (fields))))) Here, e.g., (fields) in the last line will just follow the defaults. Cheers Andre

- Prev by Date:
**Re: Problems with field initialization: Proposal** - Next by Date:
**Re: Why Single Inheritance Restriction?** - Previous by thread:
**Re: Problems with field initialization: Proposal** - Next by thread:
**opaque record types** - Index(es):