(record-predicate type))
(define (alist->bundle type alist)
- (guarantee bundle-type? type 'alist->bundle)
(guarantee %bundle-alist? alist 'alist->bundle)
((record-constructor type) (alist-copy alist)))
+(defer-boot-action 'predicate-relations
+ (lambda ()
+ (set! alist->bundle
+ (named-lambda (alist->bundle type alist)
+ (guarantee bundle-type? type 'alist->bundle)
+ (guarantee %bundle-alist? alist 'alist->bundle)
+ ((record-constructor type) (alist-copy alist))))
+ unspecific))
+
(define (%bundle-alist? object)
(and (alist? object)
(every (lambda (p)
(symbol? (car p)))
object)))
-
+\f
(define-record-type <bundle>
(%unused% alist) ;change to #f after 9.3 release
bundle?
(add-boot-init!
(lambda ()
(let ((table (make-alist-metadata-table)))
- (set! get-char-codec (table 'get))
- (set! set-char-codec! (table 'put!))
+ (set! get-char-codec (bundle-ref table 'get))
+ (set! set-char-codec! (bundle-ref table 'put!))
unspecific)))
(define (define-char-codec name codec)
(add-boot-init!
(lambda ()
(let ((table (make-alist-metadata-table)))
- (set! compound-operator-builder (table 'get))
- (set! define-compound-operator (table 'put!))
+ (set! compound-operator-builder (bundle-ref table 'get))
+ (set! define-compound-operator (bundle-ref table 'put!))
unspecific)))
(add-boot-init!
(define get-metadata-alist)
(define (use-metadata-implementation! implementation)
- (set! parameter? (implementation 'has?))
- (set! parameter-metadata (implementation 'get))
- (set! set-parameter-metadata! (implementation 'put!))
- (set! get-metadata-alist (implementation 'get-alist))
+ (set! parameter? (bundle-ref implementation 'has?))
+ (set! parameter-metadata (bundle-ref implementation 'get))
+ (set! set-parameter-metadata! (bundle-ref implementation 'put!))
+ (set! get-metadata-alist (bundle-ref implementation 'get-alist))
unspecific)
;; Use alist for cold-load.
(use-metadata-implementation! (make-alist-metadata-table))
;; Later move metadata to hash table.
-(define (initialize-package!)
- (let ((implementation (make-hashed-metadata-table)))
- ((implementation 'put-alist!) (get-metadata-alist))
- (use-metadata-implementation! implementation)))
+(add-boot-init!
+ (lambda ()
+ (let ((implementation (make-hashed-metadata-table)))
+ (implementation 'put-alist! (get-metadata-alist))
+ (use-metadata-implementation! implementation))))
(define-guarantee parameter "parameter")
\f
;;;; Metadata tables
+(define <metadata-table>
+ (make-bundle-type 'metadata-table))
+
(define (make-alist-metadata-table)
(let ((alist '()))
(put! (car p) (cdr p)))
alist*))
- (lambda (operator)
- (case operator
- ((has?) has?)
- ((get) get)
- ((put!) put!)
- ((intern!) intern!)
- ((delete!) delete!)
- ((get-alist) get-alist)
- ((put-alist!) put-alist!)
- ((get-if-available) get)
- (else (error "Unknown operator:" operator))))))
+ (bundle <metadata-table>
+ has? get put! intern! delete! get-alist put-alist!)))
\f
(define (make-hashed-metadata-table)
(let ((table (make-key-weak-eqv-hash-table)))
(put! (car p) (cdr p)))
alist*))
- (lambda (operator)
- (case operator
- ((has?) has?)
- ((get) get)
- ((put!) put!)
- ((intern!) intern!)
- ((delete!) delete!)
- ((get-alist) get-alist)
- ((put-alist!) put-alist!)
- ((get-if-available) get)
- (else (error "Unknown operator:" operator))))))
+ (bundle <metadata-table>
+ has? get put! intern! delete! get-alist put-alist!)))
\f
;;;; Builder for vector-like sequences
(add-boot-init!
(lambda ()
(let ((table (make-hashed-metadata-table)))
- (set! equality-predicate? (table 'has?))
- (set! %equality-predicate-properties (table 'get))
- (set! %set-equality-predicate-properties! (table 'put!)))
+ (set! equality-predicate? (bundle-ref table 'has?))
+ (set! %equality-predicate-properties (bundle-ref table 'get))
+ (set! %set-equality-predicate-properties! (bundle-ref table 'put!)))
(set-equality-predicate-properties! eq? hash-by-identity #t)
(set-equality-predicate-properties! eqv? hash-by-eqv #t)
(set-equality-predicate-properties! equal? hash-by-equal #t)
(->environment '(runtime hash-table))
'hash-table-constructor))
+ (if (unbound? env 'bundle)
+ (eval '(define-syntax bundle
+ (syntax-rules ()
+ ((_ predicate name ...)
+ (alist->bundle predicate
+ (list (cons 'name name) ...)))))
+ env))
+
(for-each (lambda (old-name)
(provide-rename env old-name (symbol 'scode- old-name)))
'(access-environment
(add-boot-init!
(lambda ()
(let ((table (make-hashed-metadata-table)))
- (set! predicate? (table 'has?))
- (set! get-predicate-tag (table 'get))
- (set! set-predicate-tag! (table 'put!)))
+ (set! predicate? (bundle-ref table 'has?))
+ (set! get-predicate-tag (bundle-ref table 'get))
+ (set! set-predicate-tag! (bundle-ref table 'put!)))
(set! predicate->dispatch-tag
(named-lambda (predicate->dispatch-tag predicate)
(let ((tag (get-predicate-tag predicate #f)))
make-general-parameter
make-settable-parameter
make-unsettable-parameter
- parameterize*)
- (initialization (initialize-package!)))
+ parameterize*))
(define-package (runtime stream)
(files "stream")
(define (port-property port name #!optional default-value)
(guarantee symbol? name 'port-property)
- (((port-metadata port) 'get) name default-value))
+ ((port-metadata port) 'get name default-value))
(define (set-port-property! port name value)
(guarantee symbol? name 'set-port-property!)
- (((port-metadata port) 'put!) name value))
+ ((port-metadata port) 'put! name value))
(define (intern-port-property! port name get-value)
(guarantee symbol? name 'intern-port-property!)
- (((port-metadata port) 'intern!) name get-value))
+ ((port-metadata port) 'intern! name get-value))
(define (remove-port-property! port name)
(guarantee symbol? name 'remove-port-property!)
- (((port-metadata port) 'delete!) name))
+ ((port-metadata port) 'delete! name))
(define (port-properties port)
- (alist-copy (((port-metadata port) 'get-alist))))
+ (alist-copy ((port-metadata port) 'get-alist)))
(define (transcribe-char char port)
(let ((tport (textual-port-transcript port)))
(define comparator-metadata)
(define set-comparator-metadata!)
(let ((table (make-hashed-metadata-table)))
- (set! comparator? (table 'has?))
- (set! comparator-metadata (table 'get))
- (set! set-comparator-metadata! (table 'put!))
+ (set! comparator? (bundle-ref table 'has?))
+ (set! comparator-metadata (bundle-ref table 'get))
+ (set! set-comparator-metadata! (bundle-ref table 'put!))
unspecific)
(define-for-tests (define-comparator comparator name)