Pretty-printing records
Duncan Mak
duncanmak@gmail.com
Tue Jan 1 20:42:00 GMT 2019
Ahh, I just tested out the change. Very cool.
The old output:
#|kawa:2|# (import (mit-scheme pathname))
#|kawa:3|# (define path2 (->pathname "/usr/morris"))
#|kawa:4|# path2
mit-scheme.pathname$pathname@7b53b1ad
The new output
#|kawa:4|# path2
#<<pathname> device: unspecific directory: (absolute usr) name:
morris type: false version: unspecific>
Like you wrote, it's not exactly pretty-printing, but at least the
fields of the record are visible in the REPL now.
I know that in Scheme48, they have a DEFINE-RECORD-DISCLOSER form, it
looks like this:
http://s48.org/1.9.2/manual/manual-Z-H-6.html#node_sec_5.9
In MIT Scheme, their DEFINE-STRUCTURE form is more complicated, and
includes a PRINT-PROCEDURE option.
SRFI 9 records are very close to S48 records, maybe
DEFINE-RECORD-DISCLOSER is the way to go?
Thanks and happy new year!
Duncan.
On Tue, Jan 1, 2019 at 3:05 PM Per Bothner <per@bothner.com> wrote:
>
> On 12/31/18 7:32 PM, Per Bothner wrote:
> > Something similar could be done for SRFI-9 records, but it might take some changes
> > in how they are implemented, to better support introspection. Using Java
> > reflection is possible, though maybe expensive.
>
> It turned out to be relatively simple to change SRFI-9 records so they
> extend kawa.lang.Record. This fixes printing of the resulting records.
>
> This doesn't accomplish pretty-printing, but that should also be fairly simple.
> Probably best by having kawa.lang.Record implement gnu.kawa.format.Printable.
> --
> --Per Bothner
> per@bothner.com http://per.bothner.com/
--
Duncan.
More information about the Kawa
mailing list