[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



References:    CLtL, pages 331, 386

Category:      CLARIFICATION

Edit history:  Version 1, 25-Mar-88 JonL

Problem description:

CLtL p386 says that FORMATting to a fill-pointer'd string should add
characters "as if by use of VECTOR-PUSH-EXTEND"; but CLtL p331 says that
WITH-OUTUPUT-TO-STRING will work "as if using VECTOR-PUSH-EXTEND if the
string is adjustable, and otherwise as if using VECTOR-PUSH".  It's very
unlikely that the original authors of these parts intended differing
semantics for these two cases.  Furthermore, the semantics for
WITH-OUTUPUT-TO-STRING permit the inconspicuous loss of characters
written to the string, since VECTOR-PUSH will just "drop on the floor"
any characters that would go beyond the end.


Change the documentation of WITH-OPEN-STRING-APPEND-STYLE to be like
that under FORMAT.  That is, replace the first sentence of the next-to-last
paragraph on CLtL p331 by:
  "If *string* is specified, it must be a string with a fill pointer; 
   the output is incrementally appended to the string (as if by use of

Test Case: 
    (let ((str (make-array 4 :element-type 'string-char :fill-pointer 0)))
      (with-output-to-string (s str) (princ "You Luz, Bunkie!" s))
CLtL behaviour will return "You "; proposed behaviour will signal an error.


It's unlikely that the mention of VECTOR-PUSH in CLtL p331 was intended
to suggest that characters could be quietly "dropped on the floor".  In
any case, there is no practical or theoretical reason to make FORMAT and
WITH-OUTPUT-TO-STRING act differently on non-adjustable strings.

Current Practice:

VaxLisp 2.2 and Lucid 3.0 implement the proposal; Lucid 2.1 and earlier
versions implement CLtL.  The question is entirely moot for Symbolics since 
it is impossible to create a non-adjustable string, even upon demand.

Adoption cost:



Less special-casing in the semantics of "printing" to strings.
More conformity with current practice.


To quote The Great Quux: "Hey, come'on guys, this is FORMAT; there
is no esthetics".


Implementations may want to actually call VECTOR-PUSH, rather than
VECTOR-PUSH-EXTEND, on non-adjustable string in order to test the
result -- nil means an overflow of the total length of the string; 
thus they may signal an error more directly related to the problem,
rather than permitting VECTOR-PUSH-EXTEND to complain about a non-
adjustable array.  But either way, the semantics is still that of
VECTOR-PUSH-EXTEND: when you get to the end of the string, adjustable 
strings are extended, and non-adjustable strings cause error signals.