public inbox for kawa@sourceware.org
 help / color / mirror / Atom feed
* Pretty-printing records
@ 2019-01-01  2:59 Duncan Mak
  2019-01-01  3:33 ` Per Bothner
  0 siblings, 1 reply; 5+ messages in thread
From: Duncan Mak @ 2019-01-01  2:59 UTC (permalink / raw)
  To: kawa mailing list

Hello,

Is there an extension to Kawa that will allow SRFI 9 records (or other
records?) to have a nice pretty-print in the REPL?


-- 
Duncan.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Pretty-printing records
  2019-01-01  2:59 Pretty-printing records Duncan Mak
@ 2019-01-01  3:33 ` Per Bothner
  2019-01-01 20:05   ` Per Bothner
  0 siblings, 1 reply; 5+ messages in thread
From: Per Bothner @ 2019-01-01  3:33 UTC (permalink / raw)
  To: Duncan Mak, kawa mailing list

On 12/31/18 6:58 PM, Duncan Mak wrote:
> Hello,
> 
> Is there an extension to Kawa that will allow SRFI 9 records (or other
> records?) to have a nice pretty-print in the REPL?

It woudl be easier for make-record-type records, since printing those
already prints out the fields.  So it's just a matter of checking for
classes that extend kawa.lang.Record.

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.
-- 
	--Per Bothner
per@bothner.com   http://per.bothner.com/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Pretty-printing records
  2019-01-01  3:33 ` Per Bothner
@ 2019-01-01 20:05   ` Per Bothner
  2019-01-01 20:42     ` Duncan Mak
  0 siblings, 1 reply; 5+ messages in thread
From: Per Bothner @ 2019-01-01 20:05 UTC (permalink / raw)
  To: Duncan Mak, kawa mailing list

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/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Pretty-printing records
  2019-01-01 20:05   ` Per Bothner
@ 2019-01-01 20:42     ` Duncan Mak
  2019-01-01 21:37       ` Per Bothner
  0 siblings, 1 reply; 5+ messages in thread
From: Duncan Mak @ 2019-01-01 20:42 UTC (permalink / raw)
  To: Per Bothner; +Cc: kawa mailing list

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.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Pretty-printing records
  2019-01-01 20:42     ` Duncan Mak
@ 2019-01-01 21:37       ` Per Bothner
  0 siblings, 0 replies; 5+ messages in thread
From: Per Bothner @ 2019-01-01 21:37 UTC (permalink / raw)
  To: Duncan Mak; +Cc: kawa mailing list

On 1/1/19 12:41 PM, Duncan Mak wrote:
> 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?

That only helps somewhat. It assumes you want something pretty-printed as if
it were a list, except using curly braces.   One issue is if you want
keywords - you'd want each keyword-value pair to be a logical group
(preferably on the same line), without extra parentheses.

There is also the issue of how to manage and look-up the discloser function.

The MIT-Scheme define-structure with print-procedure is more flexible, as
the procedure takes a port, which means you can do flexible pretty-printing.
However, it seems more complicated to use - and to implement.

The simplest for both user and implementor is to have the Record class
implement Printable.  That would give a nice default output.  Having
the ability to customize the output is nice, but gets into more complicated
design issues.

Kawa does have a framework for type-specific printing customization:
See the standardFormat variable in DisplayFormat.java.  However, there
is no simple hook to use it from Scheme without knowing a lot about how it works.
It would be nice to provide such a Scheme wrapper.
-- 
	--Per Bothner
per@bothner.com   http://per.bothner.com/

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-01-01 21:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-01  2:59 Pretty-printing records Duncan Mak
2019-01-01  3:33 ` Per Bothner
2019-01-01 20:05   ` Per Bothner
2019-01-01 20:42     ` Duncan Mak
2019-01-01 21:37       ` Per Bothner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).