Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pretty-print Not Honoring ~:@_ Directive #4

Closed
Symbolics opened this issue Feb 12, 2017 · 3 comments
Closed

Pretty-print Not Honoring ~:@_ Directive #4

Symbolics opened this issue Feb 12, 2017 · 3 comments
Labels

Comments

@Symbolics
Copy link

Symbolics commented Feb 12, 2017

To see this error:

? (setq *print-pretty* t)
? (format t "~:@_FAILURE DETAILS:~:@_~4:I================")
FAILURE DETAILS:================ NIL

As I read the CLHS, section 22.3, the ~:@_ directive is equivalent to a mandatory newline (i.e. ~%), but that’s not the case here.

http://www.lispworks.com/documentation/HyperSpec/Body/22_cea.htm

@xrme xrme added the bug label Feb 12, 2017
@PuercoPop
Copy link

PuercoPop commented Feb 12, 2017

The issue appears to be with with pprint-newline. CLHS 22.3.5.1 states that ~:@_ is the same as (pprint-newline :mandatory). The following snippet shows that pprint-newline does not insert a newline.

(setf *print-pretty* t)
(with-output-to-string (out)
  (princ "a" out)
  (pprint-newline :mandatory out)
  (princ "b" out))
;; => "ab"

This happens in SBCL, CLISP, ECL, ABCL as well so we should check that the standard indeed mandates a newline to be inserted. Althought it is certainly my impression that that is the case the following part on the CLHS entry on pprint-newline raises an eyebrow

:mandatory
This specifies a ``mandatory-style'' conditional newline.

@Symbolics
Copy link
Author

Symbolics commented Feb 12, 2017

From CLtL2:

"If kind is :mandatory, it specifies a `mandatory-style' conditional newline. A line break is always inserted. This implies that none of the containing sections can be printed on a single line and will therefore trigger the insertion of line breaks at linear-style conditional newlines in these sections."

emphasis is mine.

@3b
Copy link

3b commented Feb 12, 2017

From CLHS pprint-newline:
"If stream is a pretty printing stream and the value of print-pretty is true, a line break is inserted in the output when the appropriate condition below is satisfied; otherwise, pprint-newline has no effect. "

From CLHS glossary: pretty printing stream:
"pretty printing stream n. a stream that does pretty printing. Such streams are created by the function pprint-logical-block as a link between the output stream and the logical block. "

So since there is no pprint-logical-block, it is not a pretty printing stream, so pprint-newline has no effect.

(with-output-to-string (out)
  (pprint-logical-block (out nil)
    (format out "~:@_FAILURE DETAILS:~:@_~4:I================")
    (princ "a" out)
    (pprint-newline :mandatory out)
    (princ "b" out)))

;; =>

"
FAILURE DETAILS:
================a
    b"

;; or

;; I don't think an argument should be required with ~@< ~:>, but ccl complains
(format nil "~@<~:@_FAILURE DETAILS:~:@_~4:I================~:>" nil) 
;; =>
"
FAILURE DETAILS:
================"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants