#peekFor:, Squeak, and ANSI

Norton, Chris chrisn at Kronos.com
Thu Dec 19 21:02:48 UTC 2002


Hi Richard.

Here's how Visual Smalltalk Enterprise implements #peekFor:

Stream>>peekFor: anObject
    "Answer true if the next object to be accessed in
     the receiver stream equals anObject, else answer
     false.  Only advance the stream position if the
     answer is true."

    | nextObject |
    self atEnd
        ifTrue: [^false]
        ifFalse: [
            anObject = (nextObject := self next)
                ifTrue: [^true]
                ifFalse: [
                    self backupOver: nextObject.
                    ^false]].
Cheers,

---==> Chris



More information about the Squeak-dev mailing list