guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Pretty Printing values from a hashmap


From: Munyoki Kilyungi
Subject: Re: Pretty Printing values from a hashmap
Date: Thu, 21 Jul 2022 13:14:09 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.1 (gnu/linux)

Munyoki Kilyungi <me@bonfacemunyoki.com>
anaandika:

> Hi!  Say I have a hashmap that has nested hashmaps
> that I want to inspect.  Is there a way to just
> printing it out on my display in a
> straight-forward way without having to loop inside
> the key-value pairs?  Printing a hashmap outputs
> something like this:
>
> #<hash-table 7f56164e9340 2/31>

FWIW, I've come up with something that looks like:

--8<---------------cut here---------------start------------->8---
(use-modules (ice-9 pretty-print))

(define (print-hash-map h)
  (map (lambda (x)
       (newline)
       (display (car x))
       (display ":\n")
       (map (lambda (x)
              (format #t "~a:\n" (car x))
              (pretty-print (hash-map->list cons (cdr x)))
              (newline))
            (hash-map->list cons (cdr x)))
       (newline))
     h))

(print-hash-map (hash-map->list cons (dataset-csv-reader "rand.csv")))
--8<---------------cut here---------------end--------------->8---

I think the above is clanky as I already know the
structure of my hashmap before-hand.
-- 
(Life is like a pencil that will surely run out,
    but will leave the beautiful writing of life.)
(D4F09EB110177E03C28E2FE1F5BBAE1E0392253F
    (hkp://keys.gnupg.net))

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]