From bbfeb8544065c0ee5c7089194431f2eea48bafb7 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Mon, 30 May 2011 07:38:31 -0600 Subject: [PATCH] mak argument to `make-immutable-hash' optional --- collects/scribblings/reference/hashes.scrbl | 6 +++--- collects/tests/racket/basic.rktl | 6 ++++-- src/racket/src/list.c | 12 ++++++------ 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/collects/scribblings/reference/hashes.scrbl b/collects/scribblings/reference/hashes.scrbl index 0d162093cd..c143421cc2 100644 --- a/collects/scribblings/reference/hashes.scrbl +++ b/collects/scribblings/reference/hashes.scrbl @@ -159,11 +159,11 @@ Like @scheme[make-hash], @scheme[make-hasheq], and keys weakly.} @deftogether[( -@defproc[(make-immutable-hash [assocs (listof pair?)]) +@defproc[(make-immutable-hash [assocs (listof pair?) null]) (and/c hash? hash-equal? immutable?)] -@defproc[(make-immutable-hasheqv [assocs (listof pair?)]) +@defproc[(make-immutable-hasheqv [assocs (listof pair?) null]) (and/c hash? hash-eqv? immutable?)] -@defproc[(make-immutable-hasheq [assocs (listof pair?)]) +@defproc[(make-immutable-hasheq [assocs (listof pair?) null]) (and/c hash? hash-eq? immutable?)] )]{ diff --git a/collects/tests/racket/basic.rktl b/collects/tests/racket/basic.rktl index eb42faff82..eb409e2af2 100644 --- a/collects/tests/racket/basic.rktl +++ b/collects/tests/racket/basic.rktl @@ -312,6 +312,7 @@ (test #t immutable? (string->immutable-string "hi")) (test #t immutable? (string->immutable-string (string-copy "hi"))) +(test #t immutable? (make-immutable-hasheq)) (test #t immutable? (make-immutable-hasheq null)) (test #t immutable? (make-immutable-hasheq '((a . b)))) (test #t immutable? (make-immutable-hash '((a . b)))) @@ -2417,8 +2418,9 @@ 3 4) ht)) -(arity-test make-immutable-hash 1 1) -(arity-test make-immutable-hasheq 1 1) +(arity-test make-immutable-hash 0 1) +(arity-test make-immutable-hasheq 0 1) +(arity-test make-immutable-hasheqv 0 1) (arity-test hash-keys 1 1) (arity-test hash-values 1 1) (arity-test hash-count 1 1) diff --git a/src/racket/src/list.c b/src/racket/src/list.c index a463a1e032..b96596b9ee 100644 --- a/src/racket/src/list.c +++ b/src/racket/src/list.c @@ -510,17 +510,17 @@ scheme_init_list (Scheme_Env *env) scheme_add_global_constant("make-immutable-hash", scheme_make_immed_prim(make_immutable_hash, "make-immutable-hash", - 1, 1), + 0, 1), env); scheme_add_global_constant("make-immutable-hasheq", scheme_make_immed_prim(make_immutable_hasheq, "make-immutable-hasheq", - 1, 1), + 0, 1), env); scheme_add_global_constant("make-immutable-hasheqv", scheme_make_immed_prim(make_immutable_hasheqv, "make-immutable-hasheqv", - 1, 1), + 0, 1), env); scheme_add_global_constant("hash", scheme_make_immed_prim(direct_hash, @@ -1848,7 +1848,7 @@ static Scheme_Object *make_weak_hasheqv(int argc, Scheme_Object *argv[]) static Scheme_Object *make_immutable_table(const char *who, int kind, int argc, Scheme_Object *argv[]) { - Scheme_Object *l = argv[0], *a; + Scheme_Object *l = (argc ? argv[0] : scheme_null), *a; Scheme_Hash_Tree *ht; if (scheme_proper_list_length(l) >= 0) { @@ -1860,11 +1860,11 @@ static Scheme_Object *make_immutable_table(const char *who, int kind, int argc, } if (!SCHEME_NULLP(l)) - scheme_wrong_type("make-immutable-hash", "list of pairs", 0, argc, argv); + scheme_wrong_type(who, "list of pairs", 0, argc, argv); ht = scheme_make_hash_tree(kind); - for (l = argv[0]; SCHEME_PAIRP(l); l = SCHEME_CDR(l)) { + for (l = (argc ? argv[0] : scheme_null); SCHEME_PAIRP(l); l = SCHEME_CDR(l)) { a = SCHEME_CAR(l); ht = scheme_hash_tree_set(ht, SCHEME_CAR(a), SCHEME_CDR(a)); }