while (a=b()) ...

Johann Hibschman johann at physics.berkeley.edu
Sat May 1 19:54:06 EDT 1999


Derek T Jones writes:

> In article <slrn7ii759.eoc.wtanksle at dolphin.openprojects.net>,
> wtanksle at dolphin.openprojects.net wrote:

>> On Thu, 29 Apr 1999 16:48:39 -0700 (PDT), Nathan Clegg wrote:
>> >I have some deep-rooted "hates" in programming and don't even know where
>> >some of them came from.  One of them is "while 1" loops.  They seem
>> >somehow at the same level as goto statements and should be used, in my
>> >mind, about as rarely.
>> 
>> I agree.  Especially since while(1) loops require the use of a goto inside
>> of them.

> I disagree.  A 'break' is not a 'goto'.  The language Icon, which was
> part of Python's inspiration, has a 'repeat' loop which can only be
> broken out of with a 'break' statement.  The idea of a loop whose exit
> condition must be, for design reasons, not either at the very beginning or
> the very end of the loop is not a kluge.

Yes, but there has to be a better way than "while 1", which abuses the
abstraction of the while loop.

If python were a little more efficient in dealing with function
calls, you could do all sorts of things like

  def process_chars ():
    c = curs.fetchone ()
    if c:
      print c
      process_chars ()
  process_chars ()

Function calls are nice, right?  Tail recursion is good.  (Python 2.0,
perhaps?  Scheme's been around for a long time, so it's not new
technology.)

-- 
Johann Hibschman                           johann at physics.berkeley.edu




More information about the Python-list mailing list