[gambit-list] explicit pp

Stéphane Le Cornec coleste at videotron.ca
Fri Jul 24 13:22:46 EDT 2009


On 2009-7-24, at 11:28 , Marc Feeley wrote:

>
> On 24-Jul-09, at 10:55 AM, Stéphane Le Cornec wrote:
>
>> It would be oh so much clearer to handle it this way:
>>
>>        (write `(manifest ,name
>>                      (version ,version)
>>                      ...) output)
>>
>> This would read back properly, but it is not pretty enough to be  
>> human-
>> readable. So I'm trying to have that cake and eat it too, pretty code
>> and pretty output.
>
> So what you really want is a parameterized pretty-printer where such  
> formatting rules can be indicated.  That should be possible to add  
> to the current implementation.  The biggest problem is the API.   
> What is the form of these rules?


Thanks Marc!

I believe it should be explicit, with markers where the line break  
will be.

;;  I've replaced spaces by column numbers.
(aaa
12(bbb)
12(ccc ddd
1234567eee
1234567fff)
12(ggg))

These are the 2 behaviors that appear in these files.
- 1st element indents 1 from opening parenthesis,
- 2nd element indents 2 from opening parenthesis,
- later elements align with 2nd element.

Brainstorming here, but
(let ((proc (lambda (port rank open-parenthesis-column rankN-columns- 
proc)
               (let ((indent (case rank
                               ((0) (+ open-parenthesis-column 1))
                               ((1) (+ (rankN-columns-proc 0)  1))
                               (else (rankN-columns-proc 1)))))
                 (newline port)
                 (display (make-string indent #\space))))))
   (pp `(aaa ,(pp-box proc)
              (bbb) ,(pp-box proc)
              (ccc ddd  ,(pp-box proc)
                      eee  ,(pp-box proc)
                      ...))))

There's a more complex issue that requires 2 passes and may be beyond  
what pp could offer...
(aaa987654321aaa
12(bbb7654321bbb
1234(ccccccc1ccc
123456(ddd321ddd))))
where the alignment column is not known before the 1st pass is done.  
{And why should pp do the 1st pass anyway?}
Because of this 2nd use, the proc should be (lambda (port rank current- 
column open-parenthesis-column rankN-columns-proc) ...).


I hope this can be transmogrified into something useful for all. If  
there's no easy solution then I'll just eat the cake and be done with  
it.





More information about the Gambit-list mailing list