question about ByteStream(Stream)>>#next:

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

question about ByteStream(Stream)>>#next:

Robin Redeker-2
Hi,

i'm currently running this expression and wonder why i got a backtrace:

   st> ((ByteStream on: 'foobar') next: 3)!
      Object: Character error: Invalid argument f: must be a SmallInteger
      SystemExceptions.WrongClass(Exception)>>#signal
      SystemExceptions.WrongClass class>>#signalOn:mustBe:
      SystemExceptions.WrongClass class>>#signalOn:mustBe:
      Character class>>#value:
      ByteStream>>#next
      [] in ByteStream(Stream)>>#next:
      BlockClosure>>#on:do:
      ByteStream(Stream)>>#next:
      UndefinedObject>>#executeStatements
      nil

   st> (ByteStream on: 'foobar')!
      ByteStream new "<0x2b782b783740>"

   st> (ByteStream on: 'foobar') next!
      Object: Character error: Invalid argument f: must be a SmallInteger
      SystemExceptions.WrongClass(Exception)>>#signal
      SystemExceptions.WrongClass class>>#signalOn:mustBe:
      SystemExceptions.WrongClass class>>#signalOn:mustBe:
      Character class>>#value:
      ByteStream>>#next
      UndefinedObject>>#executeStatements
      nil

I chased it down and looked in ByteStream>>#next:

   next
       "Return the next *character* in the ByteArray"
       ^Character value: super next

My guess:
As the collection used internally in ByteStream is a String (ByteStream>>#species returns that at least)
(super next) returns a Character and not a SmallInteger.

Fix/Workaround might be:

   next
       ^super next

(or just drop it :-)

This is gst 2.2b on a:
Linux elmex2 2.6.17.8 #2 Sun Sep 24 21:31:08 CEST 2006 x86_64 GNU/Linux

cu,
Robin


_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: question about ByteStream(Stream)>>#next:

S11001001
Robin Redeker wrote:
> Hi,
>
> i'm currently running this expression and wonder why i got a backtrace:
>
>    st> ((ByteStream on: 'foobar') next: 3)!

st> ByteStream comment displayNl!
My instances are read/write streams specially crafted for ByteArrays.
They are able to write binary data to them.
st> ByteArray comment displayNl!
My instances are similar to strings in that they are both represented as
a sequence of bytes, but my individual elements are integers, where as
a String's elements are characters.

In other words, if you really must use a ByteStream, do ByteStream on:
'foobar' asByteArray.  Otherwise, see ReadWriteStream, ByteStream's
superclass, for an alternative.

> As the collection used internally in ByteStream is a String (ByteStream>>#species returns that at least)
> (super next) returns a Character and not a SmallInteger.

Stream>>#species and overriders refer to the kind of collection
answered by #upTo: and other methods that "read from" or "write to"
the stream, which works as expected.  The question of the underlying
collection's class is a PositionableStream-specific concept.

--
Stephen Compall
http://scompall.nocandysw.com/blog


_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: question about ByteStream(Stream)>>#next:

S11001001
Stephen Compall wrote:
> st> ByteArray comment displayNl!
> My instances are similar to strings in that they are both represented as
> a sequence of bytes, but my individual elements are integers, where as
> a String's elements are characters.

Quick typo sidenote to Paolo: that should be "whereas".  :)

--
Stephen Compall
http://scompall.nocandysw.com/blog
##smalltalk,#gnu-smalltalk on irc.freenode.net


_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: question about ByteStream(Stream)>>#next:

Robin Redeker-2
In reply to this post by S11001001
On Wed, Oct 25, 2006 at 04:44:26PM -0500, Stephen Compall wrote:
> Robin Redeker wrote:
> > Hi,
> >
> > i'm currently running this expression and wonder why i got a backtrace:
> >
> >    st> ((ByteStream on: 'foobar') next: 3)!
[.snip.]
> In other words, if you really must use a ByteStream, do ByteStream on:
> 'foobar' asByteArray.  Otherwise, see ReadWriteStream, ByteStream's
> superclass, for an alternative.

Oh, ok, i guess i only need the functionality of ReadWriteStream, thanks
for the explanation!

cu,
Robin


_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk