From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 129505 invoked by alias); 1 Jan 2019 21:37:49 -0000 Mailing-List: contact kawa-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: kawa-owner@sourceware.org Received: (qmail 129371 invoked by uid 89); 1 Jan 2019 21:37:49 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=BAYES_00,KAM_SHORT,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:1823, framework, customize, knowing X-HELO: aibo.runbox.com Received: from aibo.runbox.com (HELO aibo.runbox.com) (91.220.196.211) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 01 Jan 2019 21:37:47 +0000 Received: from [10.9.9.210] (helo=mailfront10.runbox.com) by mailtransmit03.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1geRjN-0005ZV-3H; Tue, 01 Jan 2019 22:37:45 +0100 Received: by mailfront10.runbox.com with esmtpsa (uid:757155 ) (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.82) id 1geRj9-0001pN-5v; Tue, 01 Jan 2019 22:37:31 +0100 Subject: Re: Pretty-printing records To: Duncan Mak Cc: kawa mailing list References: <6d13d508-1739-191f-5c40-2a8b24be264f@bothner.com> From: Per Bothner Message-ID: Date: Tue, 01 Jan 2019 21:37:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2019-q1/txt/msg00012.txt.bz2 On 1/1/19 12:41 PM, Duncan Mak wrote: > The new output > > #|kawa:4|# path2 > #< 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/