[plt-scheme] Doubt about hashes

From: ebellani at gmail.com (ebellani at gmail.com)
Date: Tue Nov 10 13:39:58 EST 2009

Hey Plt folk

I'm having a bit of a equality problem here, if someone
could help I would very much appreciate it:

;; build-lexical-analysis : string -> hash
;; calculates the letter frequency for a given word
;; uses the letter as key and the frequency as value for
;; a hash
(define (build-lexical-analysis word0)
  (local [(define (build-it word the-analysis)
            (cond
              [(empty? word) the-analysis]
              [(hash-has-key? the-analysis
                              (first word))
               (build-it (rest word)
                         the-analysis)]
              [else
               (build-it
                (rest word)
                (hash-set the-analysis
                          (first word)
                          (count (λ (the-char)
                                   (equal? (first word)
                                           the-char))
                                 word)))]))]
    (build-it (string->list word0) #hash())))

(check-expect (build-lexical-analysis "hellol")
              #hash(("e" . 1)
                        ("h" . 1)
                        ("l" . 3)
                        ("o" . 1)))


Now, why is this check-expect failing? 

-- 
Eduardo Bellani

www.cnxs.com.br

I object to doing things that computers can do.
- Olin Shivers

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: OpenPGP digital signature
URL: <http://lists.racket-lang.org/users/archive/attachments/20091110/640a420c/attachment.sig>

Posted on the users mailing list.