Re: [Python-ideas] "while:" for the loop

repeat could be only considered a keyword when it’s used as a loop Sent from my iPhone

Hello, Although I doubt it will really make it into Python's grammar, I am all +1 for the idea of having "repeat" as a loop keyword in Python. Actually, I have been using "repeat" as a keyword in Python for quite some time now, and found it not only convenient, but also a great help in education. My version of "repeat" has two versions. The primary usage is with an expression that evaluates to a number and specifies how many times the loop is to be repeated: ``` repeat <INT>: <SUITE> ``` The second version is without the number, and, indeed, stands for an infinite loop. ``` repeat: <SUITE> ``` I must admit, though, that I had hardly ever reason to use the second form. The implementation is currently built on top of Jython, and uses something like a preprocessor to implement the "repeat"-keyword. In order to keep some backward compatibility, the preprocessor does check a few cases to determine how it is used, and does not always treat it as a keyword. Even though it is possible to write a parser that detects if "repeat" is used as the keyword for a loop or anything else, it will make the syntax very brittle. Take, for instance: ``` repeat (3*4) ``` Now, is this supposed to be a function call, or is it a `repeat`-statement with a missing colon at the end? I therefore would strongly advise against having a word act as a keyword sometimes, and sometimes not. Probably a better solution would be to have something like `from __features__ import repeat` at the beginning. My reason for introducing "repeat" into Python in the first place was because of didactical considerations. Even though it might not seem so, variables are indeed a very hard concept in programming, particularly for younger students. And variables get particularly hard when combined with loops, where the value of a variable changes all the time (this requires a lot of abstract thinking to be properly understood). Loops alone, on the other hand, are a relatively easy concept that could be used early one. So, there is this dilemma: how do you teach loops at an early stage without using variables? That's when I added the "repeat"-keyword for loops, and it has worked marvellously so far :). Cheers, Tobias Quoting James Lu <jamtlu@gmail.com>:

On Wed, Sep 26, 2018, 9:42 AM Tobias Kohn <kohnt@tobiaskohn.ch> wrote:
Guido has repeatedly (haha) rejected this proposal [0]. He has written that he considered it, but decided that in practical code one almost always loops over data, and does not want an arbitrary number of iterations. The range object solves this problem. You might notice that a repeat keyword appears in many graphics-focused child education languages, but not many "serious" languages. [0] I remember at least two times, but can't find them with search at the moment.

Hello, Although I doubt it will really make it into Python's grammar, I am all +1 for the idea of having "repeat" as a loop keyword in Python. Actually, I have been using "repeat" as a keyword in Python for quite some time now, and found it not only convenient, but also a great help in education. My version of "repeat" has two versions. The primary usage is with an expression that evaluates to a number and specifies how many times the loop is to be repeated: ``` repeat <INT>: <SUITE> ``` The second version is without the number, and, indeed, stands for an infinite loop. ``` repeat: <SUITE> ``` I must admit, though, that I had hardly ever reason to use the second form. The implementation is currently built on top of Jython, and uses something like a preprocessor to implement the "repeat"-keyword. In order to keep some backward compatibility, the preprocessor does check a few cases to determine how it is used, and does not always treat it as a keyword. Even though it is possible to write a parser that detects if "repeat" is used as the keyword for a loop or anything else, it will make the syntax very brittle. Take, for instance: ``` repeat (3*4) ``` Now, is this supposed to be a function call, or is it a `repeat`-statement with a missing colon at the end? I therefore would strongly advise against having a word act as a keyword sometimes, and sometimes not. Probably a better solution would be to have something like `from __features__ import repeat` at the beginning. My reason for introducing "repeat" into Python in the first place was because of didactical considerations. Even though it might not seem so, variables are indeed a very hard concept in programming, particularly for younger students. And variables get particularly hard when combined with loops, where the value of a variable changes all the time (this requires a lot of abstract thinking to be properly understood). Loops alone, on the other hand, are a relatively easy concept that could be used early one. So, there is this dilemma: how do you teach loops at an early stage without using variables? That's when I added the "repeat"-keyword for loops, and it has worked marvellously so far :). Cheers, Tobias Quoting James Lu <jamtlu@gmail.com>:

On Wed, Sep 26, 2018, 9:42 AM Tobias Kohn <kohnt@tobiaskohn.ch> wrote:
Guido has repeatedly (haha) rejected this proposal [0]. He has written that he considered it, but decided that in practical code one almost always loops over data, and does not want an arbitrary number of iterations. The range object solves this problem. You might notice that a repeat keyword appears in many graphics-focused child education languages, but not many "serious" languages. [0] I remember at least two times, but can't find them with search at the moment.
participants (6)
-
David Mertz
-
Hans Polak
-
James Lu
-
Kirill Balunov
-
Michael Selik
-
Tobias Kohn