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

with-output-to-string query



    Date: Fri, 16 Aug 1985  15:41 EDT
    From: "Scott E. Fahlman" <Fahlman@CMU-CS-C.ARPA>


	The definition of WITH-OUTPUT-TO-STRING given in the Common Lisp 
	reference manual states that:

	"If string is specified ... the output is incrementally appended to the 
	 string, as if using VECTOR-PUSH-EXTEND if the string is adjustable, and
	 otherwise as if using VECTOR-PUSH."

	This implies that after a non-adjustable output string is "filled" any
	extra characters output to it will simply be dropped and no error will
	be signalled.  Is this correct?

    Yeah, given that VECTOR-PUSH is documented not to complain when a
    non-adjustable string overflows, it seems to follow that
    WITH-OUTPUT-TO-STRING should just ignore excess output in this case and
    not signal an error.  This seems like a treacherous mechanism that could
    screw the unwary, but in the vast majoirty of cases users will let the
    system create the string or will use an adjustable one if this meant to
    implement some sort of non-consing buffer.

    I'm not sure why we decided that VECTOR-PUSH should fail silently, but
    we must have had some good reason at the time.  Probably we just copied
    Zetalisp and THEY had a good reason.

VECTOR-PUSH doesn't fail silently, it returns a value to say whether or not
it was able to store into the vector.  I don't remember why this Zetalisp design
decision, made in 1974 or 1975, was done this way.  Actually I wasn't around then.

It seems clear to me that no one intended WITH-OUTPUT-TO-STRING to throw away
characters if given a non-adjustable string to fill.  Since it can't return
a value to say whether it filled the string, it should signal an error.  I
think this is just looseness in the manual, not a real language issue.  If
someone else disagrees they should speak up!