From: Sunil Mishra
Subject: Length of string stream?
Date: 
Message-ID: <efyemzi69g6.fsf@piedmont.cc.gatech.edu>
I have not been able to find this in the hyperspec, so I'm posting...

Is there a standard function for finding the length of a string stream (one
constructed using with-input-from-string)? I would think there would be,
but...

Thanks,

Sunil

From: Barry Margolin
Subject: Re: Length of string stream?
Date: 
Message-ID: <mYbU.16$XC.416941@cam-news-reader1.bbnplanet.com>
In article <···············@piedmont.cc.gatech.edu>,
Sunil Mishra <·······@piedmont.cc.gatech.edu> wrote:
>Is there a standard function for finding the length of a string stream (one
>constructed using with-input-from-string)? I would think there would be,
>but...

No.  I suppose it would be a reasonable extension to make FILE-LENGTH on a
string input stream return this.  But the standard only requires
FILE-LENGTH to work on a file stream.

-- 
Barry Margolin, ······@bbnplanet.com
GTE Internetworking, Powered by BBN, Cambridge, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
From: Kent M Pitman
Subject: Re: Length of string stream?
Date: 
Message-ID: <sfwk999ex8n.fsf@world.std.com>
Barry Margolin <······@bbnplanet.com> writes:

> In article <···············@piedmont.cc.gatech.edu>,
> Sunil Mishra <·······@piedmont.cc.gatech.edu> wrote:
> >Is there a standard function for finding the length of a string stream (one
> >constructed using with-input-from-string)? I would think there would be,
> >but...
> 
> No.  I suppose it would be a reasonable extension to make FILE-LENGTH on a
> string input stream return this.  But the standard only requires
> FILE-LENGTH to work on a file stream.

I agree this would be useful.  It's possible the reason there is not is because
of an ambiguity about whether string streams are all like those that 
MAKE-STRING-INPUT-STREAM creates -- I'm not sure that WITH-OUTPUT-TO-STRING
and WITH-INPUT-FROM-STRING are required to make streams of that type (and it's
late and I'm too lazy to check).  There's also GET-OUTPUT-STREAM-STRING which
flushes the buffer of a STRING-STREAM but maybe or maybe not of a stream 
created by WITH-OUTPUT-TO-STRING.  You'd think these were the same, but consider
the difference between a FILE-STREAM and a "stream associated with a file", which
allows enough implementation flexibility to have streams associated with files
that are not file streams.  MAKE-STRING-OUTPUT-STREAM is about creating something
of a certain representation type, not necessarily something of a certain 
intensional type, and there may be very important efficiency reasons for 
WITH-OUTPUT-TO-STRING to make a stream of another kind, so having done that it
finds itself underspecified.

So the question would be whether the FILE-LENGTH should remember the
length of the flushed parts.  My guess is that some applications would
want that and some wouldn't... Anyway, it's one of those things that
can't be fixed in isolation -- it's part of a whole ecology that needs
to be balanced in harmony.

That's not an excuse for not doing it--it's just a reminder that any proposal
to fix this one thing probably has to make sure that everyone is clear on
that either FILE-LENGTH tells you "buffer length" (what's available to  grab
now) and is probably an inappropriate name OR that FILE-LENGTH really tells you
the file length (even though some of it may have been destructively read already)
in which case it's a bad thing to use to find out how big the string resulting
from the next read might be. etc. e.g., in concrete terms, with:
 (with-output-to-string (str) 
    (princ "foo" str) 
    (print (get-output-stream-string str))
    (print (file-length str)))
is the file-length shown as 0?  i think it's not so clear...
but i might be misremembering... someone who's a little more awake and has
more time on their hands is welcome to check further.

g'nite all.
From: Barry Margolin
Subject: Re: Length of string stream?
Date: 
Message-ID: <C6tU.5$aU.156897@cam-news-reader1.bbnplanet.com>
In article <···············@world.std.com>,
Kent M Pitman  <······@world.std.com> wrote:
>Barry Margolin <······@bbnplanet.com> writes:
>
>> In article <···············@piedmont.cc.gatech.edu>,
>> Sunil Mishra <·······@piedmont.cc.gatech.edu> wrote:
>> >Is there a standard function for finding the length of a string stream (one
>> >constructed using with-input-from-string)? I would think there would be,
>> >but...
>> 
>> No.  I suppose it would be a reasonable extension to make FILE-LENGTH on a
>> string input stream return this.  But the standard only requires
>> FILE-LENGTH to work on a file stream.
>
>I agree this would be useful.  It's possible the reason there is not is because
>of an ambiguity about whether string streams are all like those that 
>MAKE-STRING-INPUT-STREAM creates -- I'm not sure that WITH-OUTPUT-TO-STRING
>and WITH-INPUT-FROM-STRING are required to make streams of that type (and it's
>late and I'm too lazy to check).  There's also GET-OUTPUT-STREAM-STRING which

It's early, so I checked.  X3J13 clarified that these macros are required
to create streams of type STRING-STREAM.

All of the rest of Kent's response seemed to be about
WITH-OUTPUT-TO-STRING, but the original question was about
WITH-INPUT-FROM-STRING.

-- 
Barry Margolin, ······@bbnplanet.com
GTE Internetworking, Powered by BBN, Cambridge, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
From: Sunil Mishra
Subject: Re: Length of string stream?
Date: 
Message-ID: <efy7m59o0m1.fsf@peachtree.cc.gatech.edu>
In article <···············@world.std.com> Kent M Pitman <······@world.std.com> writes:

   That's not an excuse for not doing it--it's just a reminder that any proposal
   to fix this one thing probably has to make sure that everyone is clear on
   that either FILE-LENGTH tells you "buffer length" (what's available to  grab
   now) and is probably an inappropriate name OR that FILE-LENGTH really tells you
   the file length (even though some of it may have been destructively read already)
   in which case it's a bad thing to use to find out how big the string resulting
   from the next read might be. etc. e.g., in concrete terms, with:
    (with-output-to-string (str) 
       (princ "foo" str) 
       (print (get-output-stream-string str))
       (print (file-length str)))
   is the file-length shown as 0?  i think it's not so clear...
   but i might be misremembering... someone who's a little more awake and has
   more time on their hands is welcome to check further.

   g'nite all.

Well, I am working with Lispworks 3.2.2, and I have been able to find some
internal functions to hack through this issue. file-length just generates
an error when I try to use it, so that's out of the question.

Sunil