Length of string stream? 
Author Message
 Length of string stream?

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



Sat, 16 Sep 2000 03:00:00 GMT  
 Length of string stream?


Quote:

>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.

--

GTE Internetworking, Powered by BBN, Cambridge, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.



Sat, 16 Sep 2000 03:00:00 GMT  
 Length of string stream?

Quote:



> >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.



Sun, 17 Sep 2000 03:00:00 GMT  
 Length of string stream?



Quote:



>> >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.

--

GTE Internetworking, Powered by BBN, Cambridge, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.



Sun, 17 Sep 2000 03:00:00 GMT  
 Length of string stream?


   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



Sun, 17 Sep 2000 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. STRING-STREAM length

2. Determning length of varable length string

3. String length of a binary string?

4. CORRECTION: binary stream address length?

5. Ada.Streams.Read Length Paramenter is not IN?

6. Stream on: String new - best way?

7. Stream editing of strings with Eiffel?

8. string streams in Ruby?

9. Tags.Internal_Tag(String'Input(Stream)) ??

10. Build a string from stream

11. Streaming in to/out of a string variable?

12. make-string-input-stream

 

 
Powered by phpBB® Forum Software