whalesong/tests/more-tests/hashes.rkt
2011-11-07 17:53:56 -05:00

95 lines
2.5 KiB
Racket

#lang planet dyoo/whalesong/base
(hash? 1)
(hash? "potatoes")
(hash? (make-hash))
(hash? (make-hash '((1 . one)
(2 . two)
(3 . three)
(4 . four))))
(hash? (make-hasheqv))
(hash? (make-hasheqv '((1 . one)
(2 . two)
(3 . three)
(4 . four))))
(hash? (make-hasheq))
(hash? (make-hasheq '((1 . one)
(2 . two)
(3 . three)
(4 . four))))
(make-hash)
(make-hasheqv)
(make-hasheq)
(make-hash '((1 . one)
(2 . two)
(3 . three)
(4 . four)))
(make-hasheqv '((1 . one)
(2 . two)
(3 . three)
(4 . four)))
(make-hasheq '((1 . one)
(2 . two)
(3 . three)
(4 . four)))
(hash-ref (make-hash '((1 . one)
(2 . two)
(3 . three)))
1)
(hash-ref (make-hash '((1 . one)
(2 . two)
(3 . three)))
4
(lambda () 'not-found))
(define words '("this" "is" "a" "test" "that" "is" "only" "a" "test!"))
(define ht (make-hash))
(for-each (lambda (w)
(hash-set! ht
w
(add1 (hash-ref ht w (lambda () 0)))))
words)
(hash-ref ht "this")
(hash-ref ht "is")
(hash-ref ht "a")
(hash-ref ht "test")
(hash-ref ht "that")
(hash-ref ht "only")
(hash-ref ht "test!")
(make-immutable-hash '((1 . one)
(2 . two)
(3 . three)
(4 . four)))
(make-immutable-hasheqv '((1 . one)
(2 . two)
(3 . three)
(4 . four)))
(make-immutable-hasheq '((1 . one)
(2 . two)
(3 . three)
(4 . four)))
(hash? (make-immutable-hash))
(hash? (make-immutable-hasheq))
(hash? (make-immutable-hasheqv))
(hash-eq? (make-immutable-hash))
(hash-eq? (make-immutable-hasheq))
(hash-eq? (make-immutable-hasheqv))
(hash-eqv? (make-immutable-hash))
(hash-eqv? (make-immutable-hasheq))
(hash-eqv? (make-immutable-hasheqv))
(let* ([ht (make-immutable-hash)]
[ht (hash-set ht 'name "danny")]
[ht (hash-set ht 'email "dyoo@hashcollision.org")])
(displayln (hash-ref ht 'name "unknown"))
(displayln (hash-ref ht 'email "unknown"))
(displayln (hash-ref ht 'phone "unknown")))