guile-user
[Top][All Lists]
Advanced

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

Re: cannot compile: srfi-10 define-reader-ctor 'hash '#,(


From: Jan Nieuwenhuizen
Subject: Re: cannot compile: srfi-10 define-reader-ctor 'hash '#,(
Date: Thu, 31 Jul 2014 08:27:36 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

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 <address@hidden>
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 <address@hidden> | GNU LilyPond http://lilypond.org
Freelance IT http://JoyofSource.com | Avatar®  http://AvatarAcademy.nl  

reply via email to

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