Hi Everyone, I'm having trouble getting the value associated with a key in a hash-table and I'm totally confused as to what I'm doing wrong. The code I'm using is shown below:
(use-modules (curl)) (use-modules (json)) ;; use curl to hit the site's api to get results of query as json: (define handle (curl-easy-init)) (curl-easy-setopt handle 'url "http://api.data.gov:80/regulations/v3/documents.json?api_key=mySecKey&countsOnly=0&encoded=1&dktid=EPA-HQ-OAR-2013-0602&dkt=R&cp=C&rpp=25&po=0") (define s (curl-easy-perform handle)) ;; parse the json in the string into guile scheme: (define queryResults (json-string->scm s)) ;; use this to see the keys and values in the resulting hash table: (define print-hash (lambda (my-hash) (hash-for-each (lambda (key value) (format #t "~a => ~a~%" key value)) my-hash))) ;; now let's take a look at the keys and values: (print-hash queryResults) ;; now let's get the value associated with the documents key: (hashq-get-handle queryResults 'documents) It relies on [guile-curl][1] and [guile-json][2] to talk to the webserver and to parse the response. Things seem pretty straight-forward until I run. I can see the response from the server in json (very long and not posted here) and from within Emacs (using geiser to poke around) I can see: scheme@(guile-user)> (hash-table? queryResults) $25 = #t so I know that queryResults is indeed a hash-table. When I take a look at the keys and associated values using print-hash I see that: scheme@(guile-user)> (print-hash queryResults) totalNumRecords => 23318 documents => (#<hash-table 2ad7c60 17/31> #<hash-table 2afdbc0 17/31> #<hash-table 2b0ab60 17/31> #<hash-table 2b0eb00 17/31> #<hash-table 2b10aa0 17/31> #<hash-table 2b13a40 17/31> #<hash-table 2b189e0 17/31> #<hash-table 2b1b980 17/31> #<hash-table 2b1e920 17/31> #<hash-table 2b228c0 17/31> #<hash-table 2b25860 17/31> #<hash-table 2b29800 17/31> #<hash-table 2b2d7a0 17/31> #<hash-table 2b30740 17/31> #<hash-table 2b336e0 17/31> #<hash-table 2b38680 17/31> #<hash-table 2b3b620 17/31> #<hash-table 2b3f5c0 17/31> #<hash-table 2b44560 17/31> #<hash-table 2b48500 17/31> #<hash-table 2b4c4a0 17/31> #<hash-table 2b50440 17/31> #<hash-table 2b533e0 17/31> #<hash-table 2b57380 17/31> #<hash-table 2b5c320 17/31>) so that's good and it's what I expected. But when I try to use hashq-get-handle to get a look at the value for totalNumRecords or documents I get: scheme@(guile-user)> (hashq-get-handle queryResults 'totalNumRecords) $24 = #f scheme@(guile-user)> (hashq-get-handle queryResults 'documents) $24 = #f which seems to indicate the key doesn't exist in the hash-table queryResults. I've tried all night with quotes, w/o quotes, futzing with the SRFI-69 hash-table implementations (during which I discovered the difference between native guile hash-tables and the SRFI-69 hash-tables), and went through the [hash table examples][3] in the guile reference manual (they all worked just fine). I'm out of ideas. If someone could help me understand why my calls to hashq-get-handle aren't working out as expected I'd be most grateful. BTW, this question is also posted at: http://stackoverflow.com/questions/27348357/trouble-using-hashq-get-handle-in-guile Thanks for the help in advance. [1]: http://www.lonelycactus.com/guile-curl.html [2]: https://github.com/aconchillo/guile-json [3]: http://www.gnu.org/software/guile/manual/html_node/Hash-Table-Examples.html#Hash-Table-Examples -j -- ------------------------------------------------------------- Jamil Egdemir uncleja...@gmail.com http://www.power-quant.com (631) 338-3170 (cell) -------------------------------------------------------------