Why not allow empty code blocks?

BartC bc at freeuk.com
Sat Jul 30 09:58:34 EDT 2016


On 30/07/2016 14:36, Chris Angelico wrote:
> On Sat, Jul 30, 2016 at 11:06 PM, Steven D'Aprano <steve at pearwood.info> wrote:
>>> "for i in range(N):" just to repeat a block N times...
>>
>> Why should there be special syntax just for repeating a block N times?
>> There's a general purpose for-loop which performs iteration. Why do you
>> need special syntax to do what it already does?

 >
 > Python could have chosen to make integers iterable, such that you say:
 >
 > for i in 10:
 >
 > but I don't think it really improves readability.

On 30/07/2016 13:47, Chris Angelico wrote:
 >(Also, it requires the use
 > and damage of some iterator variable, which may be significant in some
 > contexts.)

The 'i' is superfluous. Why not:

  for 10:

(In my own syntaxes I use (actual example):

   to 64 do
       table append:= nextbyte(fs)
   od

Python equivalent:

   for i in range(64):
       table.append(nextbyte(fs))

The range object isn't really necessary, and the 'i' variable doesn't 
need to be exposed (as a programmer-accessible, reference-counted variable).

The 'to' construct I also implemented with a single very fast byte-code, 
executed once per iteration.)


-- 
Bartc



More information about the Python-list mailing list