s-expressionists / wscl

Sources of the "Well Specified Common Lisp" specification which is based on the final draft of the Common Lisp standard but is not a new Common Lisp standard.
https://s-expressionists.github.io/wscl/
Other
38 stars 4 forks source link

Treatment of suffix in `*print-lines*` is ambiguous #43

Open yitzchak opened 8 months ago

yitzchak commented 8 months ago

In the descriptions of *print-lines* it states:

If an attempt is made to go beyond that many lines, “..” is printed at the end of the last line followed by all of the suffixes (closing delimiters) that are pending to be printed.

This is a bit ambiguous in the case that the suffix contains newlines. In that case should the suffix be printed with the containing newlines or should only the suffix text that trails the newlines be printed? Most implementations seem to assume the former, but this causes the number of lines to exceed *print-lines*. For example, on SBCL:

* (with-output-to-string (stream)      
    (let ((*print-pretty* t)
          (*print-lines* 1))
      (pprint-logical-block (stream nil :prefix "[" :suffix "a
]")
        (pprint-logical-block (stream nil :prefix "(" :suffix ")")
          (write-string "wibble" stream)
          (pprint-newline :mandatory stream)
          (write-string "bar" stream)))))
"[(wibble ..)a
]"

An alternative would be to do as Inravina does currently:

* (with-output-to-string (stream)      
    (let ((*print-pretty* t)
          (*print-lines* 1))
      (inravina-extrinsic:pprint-logical-block (stream nil :prefix "[" :suffix "a
]")
        (inravina-extrinsic:pprint-logical-block (stream nil :prefix "(" :suffix ")")
          (write-string "wibble" stream)
          (inravina-extrinsic:pprint-newline :mandatory stream)
          (write-string "bar" stream)))))
"[(wibble ..)]"