Optional arguments to hash table constructors in ASL
This commit is contained in:
parent
1f830cc2c6
commit
368d711ae2
|
@ -109,12 +109,21 @@
|
||||||
"to determine if a value is a box"))
|
"to determine if a value is a box"))
|
||||||
|
|
||||||
("Hash Tables"
|
("Hash Tables"
|
||||||
((advanced-make-hash make-hash) ((listof (list X Y)) -> (hash X Y))
|
((advanced-make-hash make-hash)
|
||||||
"to construct a hash table from a list of mappings that uses equal? for comparisions")
|
(case->
|
||||||
((advanced-make-hasheq make-hasheq) ((listof (list X Y)) -> (hash X Y))
|
(-> (hash X Y))
|
||||||
"to construct a hash table from a list of mappings that uses eq? for comparisions")
|
((listof (list X Y)) -> (hash X Y)))
|
||||||
((advanced-make-hasheqv make-hasheqv) ((listof (list X Y)) -> (hash X Y))
|
"to construct a hash table from an optional list of mappings that uses equal? for comparisions")
|
||||||
"to construct a hash table from a list of mappings that uses eqv? for comparisions")
|
((advanced-make-hasheq make-hasheq)
|
||||||
|
(case->
|
||||||
|
(-> (hash X Y))
|
||||||
|
((listof (list X Y)) -> (hash X Y)))
|
||||||
|
"to construct a hash table from an optional list of mappings that uses eq? for comparisions")
|
||||||
|
((advanced-make-hasheqv make-hasheqv)
|
||||||
|
(case->
|
||||||
|
(-> (hash X Y))
|
||||||
|
((listof (list X Y)) -> (hash X Y)))
|
||||||
|
"to construct a hash table from an optional list of mappings that uses eqv? for comparisions")
|
||||||
(hash-set! ((hash X Y) X Y -> void)
|
(hash-set! ((hash X Y) X Y -> void)
|
||||||
"to update a hash table with a new mapping")
|
"to update a hash table with a new mapping")
|
||||||
(hash-ref (case->
|
(hash-ref (case->
|
||||||
|
|
|
@ -346,15 +346,15 @@ namespace.
|
||||||
(apply append x)))
|
(apply append x)))
|
||||||
|
|
||||||
(define-teach advanced make-hash
|
(define-teach advanced make-hash
|
||||||
(lambda (a)
|
(lambda ([a empty])
|
||||||
(make-hash (map (lambda (l) (cons (first l) (second l))) a))))
|
(make-hash (map (lambda (l) (cons (first l) (second l))) a))))
|
||||||
|
|
||||||
(define-teach advanced make-hasheq
|
(define-teach advanced make-hasheq
|
||||||
(lambda (a)
|
(lambda ([a empty])
|
||||||
(make-hasheq (map (lambda (l) (cons (first l) (second l))) a))))
|
(make-hasheq (map (lambda (l) (cons (first l) (second l))) a))))
|
||||||
|
|
||||||
(define-teach advanced make-hasheqv
|
(define-teach advanced make-hasheqv
|
||||||
(lambda (a)
|
(lambda ([a empty])
|
||||||
(make-hasheqv (map (lambda (l) (cons (first l) (second l))) a))))
|
(make-hasheqv (map (lambda (l) (cons (first l) (second l))) a))))
|
||||||
|
|
||||||
(provide
|
(provide
|
||||||
|
|
|
@ -258,6 +258,12 @@
|
||||||
(local [(define ht (make-hash (list (list 'a 1))))]
|
(local [(define ht (make-hash (list (list 'a 1))))]
|
||||||
(begin (hash-update! ht 'b add1 (lambda () 1))
|
(begin (hash-update! ht 'b add1 (lambda () 1))
|
||||||
(hash-ref ht 'b))))
|
(hash-ref ht 'b))))
|
||||||
|
(htdp-test #t 'hash?
|
||||||
|
(hash? (make-hash)))
|
||||||
|
(htdp-test #t 'hash?
|
||||||
|
(hash? (make-hasheq)))
|
||||||
|
(htdp-test #t 'hash?
|
||||||
|
(hash? (make-hasheqv)))
|
||||||
(htdp-test #t 'hash?
|
(htdp-test #t 'hash?
|
||||||
(hash? (make-hash (list (list 'a 1)))))
|
(hash? (make-hash (list (list 'a 1)))))
|
||||||
(htdp-test #t 'hash?
|
(htdp-test #t 'hash?
|
||||||
|
|
Loading…
Reference in New Issue
Block a user