From 32a3bfef3e4307a80e83aa8be825f9e9240124f5 Mon Sep 17 00:00:00 2001 From: elioat Date: Fri, 2 Dec 2022 14:24:14 -0500 Subject: Exploring nested-hashtables --- log.txt | 3 ++- src/pokedex.rkt | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/log.txt b/log.txt index 10d00cb..39a7d57 100644 --- a/log.txt +++ b/log.txt @@ -1,2 +1,3 @@ 30 NOV: Came up with the idea to do December Adventure, bootstrapped this repo -01 DEC: Played with vector sorting and summing in APL. Wrote function to fetch data from pokeapi, and return data as s-expression. Explored racket fmt utility \ No newline at end of file +01 DEC: Played with vector sorting and summing in APL. Wrote function to fetch data from pokeapi, and return data as s-expression. Explored racket fmt utility +02 DEC: \ No newline at end of file diff --git a/src/pokedex.rkt b/src/pokedex.rkt index d710758..16f59c0 100644 --- a/src/pokedex.rkt +++ b/src/pokedex.rkt @@ -14,6 +14,7 @@ ;; basic GET request (require net/url) (require json) +(require nested-hash) ;; package that makes traversing nested hash tables a wee bit easier ;; API URL (define *POKE-API* "https://pokeapi.co/api/v2/pokemon/") @@ -30,3 +31,8 @@ ;; (get-pokemon "ditto") ;; (get-pokemon 123) + +(define poke-data (get-pokemon 123)) + +(nested-hash-ref poke-data 'name) ;; this will return "scyther" +(nested-hash-ref poke-data 'id) ;; this will return 123 \ No newline at end of file -- cgit 1.4.1-2-gfad0