Newsgroups: comp.lang.smalltalk
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!news2.near.net!news.mathworks.com!yeshua.marcam.com!usc!howland.reston.ans.net!cs.utexas.edu!utnut!nott!cunews!omega.scs.carleton.ca!ug940002
From: ug940002@omega.scs.carleton.ca (Alex Fitzpatrick)
Subject: Re: whileTrue:
Message-ID: <Cyp4zx.JFz@cunews.carleton.ca>
Sender: news@cunews.carleton.ca (News Administrator)
Organization: School of Computer Science, Carleton U., Ottawa, Canada
X-Newsreader: TIN [version 1.2 PL2]
References: <9411022316.AA04248@sci.brooklyn.cuny.edu>
Date: Thu, 3 Nov 1994 14:45:33 GMT
Lines: 47


Gerald Weiss 718-951-5945 (weiss@SCI.BROOKLYN.CUNY.EDU) wrote:
: I'm sure I'm being dense, but could someone explain the following
: implementation of whileTrue: from GNU Smalltalk? Isn't the embedded
: whileTrue: message simply a recursive one, and if so, where is the
: escape clause?

: The way I read it, the second function (using the unary selector whileTrue)
: is a syntactic convenience, not an escape clause for the whileTrue:

: !BlockContext methodsFor: 'basic'!

: whileTrue: aBlock
:     [ self value ] whileTrue: [ aBlock value ].
:     ^nil
: !

: whileTrue
:     ^[ self value ] whileTrue: []
: !

: !!


I don't know about you but I smell a stack overflow...
The following is the V/Win implementation


whileTrue: aBlock
        "Repetitively evaluate the receiver block and aBlock,
         until the result of receiver block evaluation is
         false.  Answer nil."
    self value
        ifTrue: [
            aBlock value.
            self whileTrue: aBlock].
    ^nil

I'm going to replace this with the code you posted and try it.
I'll let you know about results...



Alex Fitzpatrick
CS Student at Carleton, Ottawa
ug940002@omega.scs.carleton.ca

