[Openmcl-devel] Format bug?

Gary Byers gb at clozure.com
Thu Jan 5 16:30:51 PST 2012



On Thu, 5 Jan 2012, Waldek Hebisch wrote:

> $ scripts/ccl64
> Welcome to Clozure Common Lisp Version 1.8-dev-r15159M-trunk  (LinuxX8664)!
> ? (setf *print-circle* t)
> T
> ? (setf ll '(#1="PrimeField" #2="(" #1# #2# "x" ")" ")"))
> (#1="PrimeField" #2="(" #1# #2# "x" ")" ")")
> ? (FORMAT nil "~{~A~}" ll)
> "#1=PrimeField#2=(#1##2#x))"
> ?
>
> HypeSpec says that ~A should just use string "as is"

It does ?

The spec says a few things about ~A (and about PRINC), but none of
them seem to use the term "as is."  It does say that ~A will print its
argument without escape characters (and that it binds *PRINT-ESCAPE*
and *PRINT-READABLY* to NIL), and that certain modifiers control how
NIL is printed and control justifcation and padding.  None of this 
is defined to have any effect on whether or how *PRINT-CIRCLE* introduces
#n=/#n# syntax.

The spec also says quite a bit about how *PRINT-CIRCLE* affects
printing; none of what it says indicates that *PRINT-ESCAPE* or
*PRINT-READABLY affect what *PRINT-CIRCLE* does.  Unfortunately, some
aspects of what *PRINT-CIRCLE* does - notably, the "extent" over which
circularity/sharing detection is performed - are left unstated, and
implementations differ in this regard.

Should implementations try to detect circularity and sharing involving
everything that's ever been printed when *PRINT-CIRCLE* is true ?  Over
everything that's printed during the extent of a particular binding of
*PRINT-CIRCLE* to a true value ?  (I'm asking rhetorically, not suggesting
that either of these behaviors would be useful or practical or desirable.)

Should circularity/sharing detection be performed on everything
printed by a "toplevel" (non-nested) call to a printing primitive when
*PRINT-CIRCLE* is true ?  That seems much more useful and reasonable,
but implementations seem to vary a good deal in their interpretation
of what constitutes a toplevel call to a printing primitive.  In the case
of "~{~a~}", some implementations (including CCL) try to detect circularity
and sharing across the entire iteration, and other implementations presumably
do so on each iteration step.  Both behaviors could be useful (or not); I know
of no basis for thinking that one is closer to what the spec says than the other,
since the spec doesn't seem to discuss this.

, so this> looks like a bug.

It's tempting to think that "~A" will always produce "aesthetic-looking" output
that's fit for human consumption, but this isn't correct.  "~A"'s output may
be easier on the eyes than "~S"'s in most cases, but if *PRINT-CIRCLE* is involved
things can get unaesthetic pretty quickly and this has nothing to do with ~A.

A possibly simpler case that illustrates different *PRINT-CIRCLE* behavior is:

(let* ((*print-circle* t) (a "abc")) (format t "~s ~s~%" a a))

Some implementations (including CCL) will use #n=/#n# syntax here and others
won't.  Either behavior may be useful (or not), and I don't know of an argument
that suggests that either behavior is more or less correct than the other.



>
> --
>                              Waldek Hebisch
> hebisch at math.uni.wroc.pl
> _______________________________________________
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
> http://clozure.com/mailman/listinfo/openmcl-devel
>
>



More information about the Openmcl-devel mailing list