diff --git a/collects/syntax/id-table.rkt b/collects/syntax/id-table.rkt index 02ca90f425..452557275d 100644 --- a/collects/syntax/id-table.rkt +++ b/collects/syntax/id-table.rkt @@ -69,7 +69,8 @@ [idtbl-map (s '-map)] [idtbl-for-each (s '-for-each)] [idtbl-mutable-methods (s '-mutable-methods)] - [idtbl-immutable-methods (s '-immutable-methods)]) + [idtbl-immutable-methods (s '-immutable-methods)] + [idtbl/c (s '/c)]) #'(begin ;; Struct defs at end, so that dict methods can refer to earlier procs @@ -119,6 +120,29 @@ (list idtbl-immutable-methods dict-contract-methods)) + (define (mutable-idtbl/c value/c) + (struct/c mutable-idtbl + (hash/c any/c + (listof (cons/c any/c value/c)) + #:immutable #f) + any/c)) + + (define (immutable-idtbl/c value/c) + (struct/c immutable-idtbl + (hash/c any/c + (listof (cons/c any/c value/c)) + #:immutable #t) + any/c)) + + + (define (idtbl/c value/c #:immutable (immutable 'dont-care)) + (case immutable + ((dont-care) (or/c (mutable-idtbl/c value/c) + (immutable-idtbl/c value/c))) + ((#t) (immutable-idtbl/c value/c)) + ((#f) (mutable-idtbl/c value/c)))) + + (provide/contract [make-idtbl (->* () (dict? #:phase (or/c #f exact-integer?)) mutable-idtbl?)] @@ -153,7 +177,11 @@ [idtbl-map (-> idtbl? (-> identifier? any/c any) list?)] [idtbl-for-each - (-> idtbl? (-> identifier? any/c any) any)]))))])) + (-> idtbl? (-> identifier? any/c any) any)] + [idtbl/c + (->* (contract?) + (#:immutable (or/c 'dont-care #t #f)) + contract?)]))))])) (make-code bound-id-table) (make-code free-id-table) diff --git a/collects/syntax/scribblings/id-table.scrbl b/collects/syntax/scribblings/id-table.scrbl index 95b2741371..b28fc6b10f 100644 --- a/collects/syntax/scribblings/id-table.scrbl +++ b/collects/syntax/scribblings/id-table.scrbl @@ -154,6 +154,12 @@ identifier table (free or bound, mutable or immutable), @racket[#f] otherwise. } +@defproc[(free-id-table/c [val contract?] + [#:immutable immutable (or/c #t #f 'dont-care) 'dont-care]) + contract?]{ + +Like @racket[hash/c], but more limited. It only supports contracts on the values in the identifier table. +} @;{----------} @section{Dictionaries for @racket[bound-identifier=?]} @@ -204,6 +210,9 @@ etc) can be used on bound-identifier tables. void?] @defproc[(bound-id-table-count [table bound-id-table?]) exact-nonnegative-integer?] +@defproc[(bound-id-table/c [val contract?] + [#:immutable immutable (or/c #t #f 'dont-care) 'dont-care]) + contract?] @;{ @defproc[(bound-id-table-iterate-first [table bound-id-table?]) id-table-position?]