Ludovic Courtès writes: Hi,
> In this example, you want the reader extension to be available at > compile time, and not necessarily at run time. However, by writing the > code as is, the reader extension is available only at run time, hence > the error. Alright, that makes sense when you think about it... > To require evaluation of the ‘define-reader-ctor’ form at compile time, > change the code to (info "(guile) Eval When"): Wow, many thanks! This works for me; would it be nice to have some of this more explicitly in the srfi-10 manual? This is great, I am using this now for easy communication with json and therefore I also want to pretty-print hash tables this way. For now, I copied (ice-9 pretty-print) and applied the patch below, I did not find a way to hook into, or just override, the inner (wr) procedure. How do I get pretty-print to produce non-opaque hash tables using this #, hash read syntax than to copy all of (ice-9 pretty-print) or carry this diff? Greetings, Jan
>From 16768de55f4f2c79bf38af93ca907772c71a603a Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen <[email protected]> Date: Thu, 31 Jul 2014 08:19:17 +0200 Subject: [PATCH] Have pretty-print write non-opaque srfi-10 #,(hash hash tables. * module/ice-9/pretty-print.scm (generic-write): write hash tables in srfi-10 hash-comma read syntax. --- module/ice-9/pretty-print.scm | 2 ++ 1 file changed, 2 insertions(+) diff --git a/module/ice-9/pretty-print.scm b/module/ice-9/pretty-print.scm index 007061f..a5a590d 100644 --- a/module/ice-9/pretty-print.scm +++ b/module/ice-9/pretty-print.scm @@ -64,6 +64,8 @@ (match obj (((or 'quote 'quasiquote 'unquote 'unquote-splicing) body) (wr body (out (read-macro-prefix obj) col))) + ((? hash-table?) (wr (cons 'hash (hash-map->list list obj)) + (out "#," col))) ((head . (rest ...)) ;; A proper list: do our own list printing so as to catch read ;; macros that appear in the middle of the list. -- 1.9.1
-- Jan Nieuwenhuizen <[email protected]> | GNU LilyPond http://lilypond.org Freelance IT http://JoyofSource.com | Avatar® http://AvatarAcademy.nl
