简体   繁体   中英

How to define a hashtable of hashtable in Racket?

I want to define a hash table to represent such a data structure:

(("A" , ("B" ,16)) , ("B" , ("C" , 20)))

and I need to access to the both pairs: ("B" ,16),("C" ,20) and numbers 16,20.

Can I have a hashtable of hashtable in Racket? how should I define it and access to to elements?

I found the answer. Yes, it is possible. One can simply do it like:

(define (fun1) 

 (let ([ht (make-hash (list (cons "A" (make-hash '(("B" "16")("C" "20"))))))])

    ht))

(define v (hash-ref (fun1) "A" ))

(hash-ref v "B")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM