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
On Sep 26, 2018, at 8:46 AM, Brice Parent
wrote: Le 26/09/2018 à 14:33, James Lu a écrit : what about “repeat:”?
Sent from my iPhone I'm not sure it was on purpose, but you replied to me only, and not the entire list. I believe the adding of a new keyword to do something that is already straightforward (`while True:`), and that doesn't add any new functionality, won't probably ever be accepted.
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
repeat could be only considered a keyword when it’s used as a loop
Sent from my iPhone
On Sep 26, 2018, at 8:46 AM, Brice Parent
wrote: Le 26/09/2018 à 14:33, James Lu a écrit : what about “repeat:”?
Sent from my iPhone
I'm not sure it was on purpose, but you replied to me only, and not the entire list. I believe the adding of a new keyword to do something that is already straightforward (`while True:`), and that doesn't add any new functionality, won't probably ever be accepted.
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideasCode of Conduct: http://python.org/psf/codeofconduct/
On Wed, Sep 26, 2018, 9:42 AM Tobias Kohn
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.
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.
We also have:
from itertools import count
for i in count():
...
If you want to keep track of how close to infinity you are. :-)
On Wed, Sep 26, 2018, 12:24 PM Michael Selik
On Wed, Sep 26, 2018, 9:42 AM Tobias Kohn
wrote: 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.
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.
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
On Wed, Sep 26, 2018, 19:30 David Mertz
We also have:
from itertools import count for i in count(): ...
If you want to keep track of how close to infinity you are. :-)
We also have: from itertools import repeat for i in repeat(...): ... with kind regards, -gdg
On 26/09/18 18:23, Michael Selik 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.
Years ago, I proposed a do...loop. Guido rejected that. As an aside, here's a pattern you can use for do...loops. def do_loop(): if True: return True return False while do_loop(): pass Cheers, Hans
participants (6)
-
David Mertz
-
Hans Polak
-
James Lu
-
Kirill Balunov
-
Michael Selik
-
Tobias Kohn