mutable default parameter problem [Prothon]

Antoon Pardon apardon at forel.vub.ac.be
Tue Jun 29 03:22:55 EDT 2004


Op 2004-06-28, Mark Hahn schreef <mark at prothon.org>:
>
> "Antoon Pardon" <apardon at forel.vub.ac.be> wrote
>
>> Well personnally I would solve this with a more general loop construct.
>>
>> Something like: (Pseudo code)
>>
>> loop:
>>     list.append(x)
>>   while len(list) < 10:
>>     blah blah.
>>
>>
>> The more general construct would be something like:
>>
>> loop:
>>     code
>>   while condition1:
>>     code
>>   else:
>>     exit code if condition1 fails
>>   while condition2:
>>     code
>>   else:
>>     exit code if condion2 fail
>
> This seems non-intuitive to me.  Also how would you know the "while" was not
> a regular "while"?  Even if the parser could figure it out, the reader would
> be confused.

These are details. If you want to do it with an other keyword, that is
fine by me. I'm interrested in the functionality, not in a particular
implementation. One possibility would be to not allow what you call
a regular while, all loop constructs would need to start with a loop
statement.

An other possibility would be the "and while" construction that
was dicussed here.  Something like

while condition1:
  loopcode
else
  exitcode
and while condition2:
  loopcode
else
  exitcode.

> BTW: Your code example has the "while" indentation not aligning with
> anything above which is illegal indentation.

I know. This is one reason I hate indentation as grammatical
information. Some possible language constructs don't have a structure
that is easily fitted in such a mold. You then see that such constructs
are disregarded because of layout problems, not on lack of merrit
for such a language construct.

It also makes it sometimes difficult to have your program follow
the logical structure of your program. e.g. if you have code
like this:

loop:
  loopcode1
and while condition
  loopcode2

You could simulate it like this

while true:
  loopcode1
  if not condition: break
  loopcode2

But in order to reflect the logical structure of above I would prefer
to write the if alliged with the while. But that of course is not
possible.

-- 
Antoon Pardon



More information about the Python-list mailing list