From 120f12b197d3a2b9ae0fda4583e5d54b3001ecd7 Mon Sep 17 00:00:00 2001 From: elioat Date: Tue, 6 Dec 2022 07:20:41 -0500 Subject: back to data diving -- sorting out how to use cond expressions correctly --- src/tmp.rkt | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/tmp.rkt b/src/tmp.rkt index ffb0edb..321226d 100644 --- a/src/tmp.rkt +++ b/src/tmp.rkt @@ -41,28 +41,20 @@ ;; "stats" and "types" AREN'T exactly nested hash tables! They're lists, with hash tables embedded in them! ;; SO! I need a way to test for if something is a LIST, and then if it is a LIST I think then I hash map through that! - -(define (inspector h) - (hash-map h - (lambda (k v) - (if (list? v) (display (~a "HARK! THE VALUE FOR THE KEY ~"k"~ IS A LIST \n====\n")) - (display (~a " key: " k "\nvalue: " v "\n=====\n"))))) - h) - -;;(inspector test-data) - ;; NEXT STEPS -> https://stackoverflow.com/questions/13504302/racket-scheme-filtering ; (hash-ref test-data "stats") ; all stats ; (hash-ref (car (hash-ref test-data "stats")) 'base_stat) ; value for a given stat ; (hash-ref (hash-ref (car (hash-ref test-data "stats")) 'stat) 'name) ; name for a given stat -(define (inspector2 h) + +(define (inspector h) + "display the contents of a hash table for human eyeballs and let the hash table fall back out" (hash-map h (lambda (k v) - (if (list? v) (map - (lambda (x) (inspector2 x)) v) - (display (~a " key: " k "\nvalue: " v "\n=====\n"))))) + (cond [(list? v) (map (lambda (x) (inspector x)) v)] + [(hash? (car (hash-ref v k)) (map (lambda (x) (inspector x)) v))] + [(display (~a " key: " k "\nvalue: " v "\n=====\n"))]))) h) -(inspector2 test-data) +(inspector test-data) -- cgit 1.4.1-2-gfad0