[gambit-list] Foreign object printers?

Marc Feeley feeley at iro.umontreal.ca
Sun Mar 24 13:43:38 EDT 2013


On 2013-03-24, at 1:16 PM, Jason Felice <jason.m.felice at gmail.com> wrote:

> Whats macro-writeenv-style and ##wr-mark about?

The style field of a writeenv indicates the style in which the object is to be written.  Currently the style can be

- write           (11 "abc" 22) is written as: (11 "abc" 22)
- display         (11 "abc" 22) is written as: (11 abc 22)
- print           (11 "abc" 22) is written as: 11abc22
- pretty-print    uses indentation/line breaks for pretty printing
- mark            used by #n=... notation

So the mark style is special in that it does not produce output.  It is used when the readtable-sharing-allowed? flag is set:

  > (define (wr obj allow?)
      (call-with-output-string
        '()
        (lambda (p)
          (output-port-readtable-set!
            p
            (readtable-sharing-allowed?-set
              (output-port-readtable p)
              allow?))
          (write obj p))))
  > (wr (let ((x (cons 11 22))) (list x x)) #f)
  "((11 . 22) (11 . 22))"
  > (wr (let ((x (cons 11 22))) (list x x)) #t)
  "(#0=(11 . 22) #0#)"

The write/display/print/pretty-print procedures will make a first pass over the object/subobjects with style=mark.  This is to gather in a table all the subobjects to write.  Then, during the second pass, the #n=... notation will be used when an object has been marked more than once during the mark pass.

Marc



More information about the Gambit-list mailing list