I would like to be able to define a loop statement
(nevermind why) so that I can write something like
loop 10:
do_something
instead of
for i in range(10):
do_something
Possible? If so, how?
Thanks,
Alan Isaac
--
http://mail.python.org/mailman/listinfo/python-list
Rene Pijlman wrote:
> David Isaac:
>> I would like to be able to define a loop statement
>> (nevermind why) so that I can write something like
>>
>> loop 10:
>>do_something
>>
>> instead of
>>
>> for i in range(10):
>>do_something
>>
>> Possible? If so, how?
>
> Yes. By implementing a com
David Isaac wrote:
> I would like to be able to define a loop statement
> (nevermind why) so that I can write something like
>
> loop 10:
> do_something
>
> instead of
>
> for i in range(10):
> do_something
>
> Possible? If so, how?
It's not possible to create a new statement, with su
David Isaac:
>I would like to be able to define a loop statement
>(nevermind why) so that I can write something like
>
>loop 10:
>do_something
>
>instead of
>
>for i in range(10):
>do_something
>
>Possible? If so, how?
Yes. By implementing a compiler or an interpreter for your programming
David Isaac:
> I would like to be able to define a loop statement
> (nevermind why) so that I can write something like
>
> loop 10:
> do_something
>
> instead of
>
> for i in range(10):
> do_something
>
> Possible? If so, how?
It seems that you are looking for macros; maybe Logix "languag
Rene Pijlman wrote:
> David Isaac:
>> I would like to be able to define a loop statement
>> (nevermind why) so that I can write something like
>>
>> loop 10:
>>do_something
>>
>> instead of
>>
>> for i in range(10):
>>do_something
>>
>> Possible? If so, how?
>
> Yes. By implementing a com
No, not in the way you think it is. What you can do instead is
something like this:
def do_something(i):
... do_something ...
def loop(n, func):
for i in range(n): func(i)
loop(10, do_something)
--
http://mail.python.org/mailman/listinfo/python-list
David Isaac wrote:
> I would like to be able to define a loop statement
> (nevermind why) so that I can write something like
>
> loop 10:
> do_something
>
> instead of
>
> for i in range(10):
> do_something
>
> Possible? If so, how?
Ruby and Smalltalk are both good at this kind of thi
Jeffrey Schwab wrote:
> class Loop:
> def __init__(self, n):
> self.n = n
> def __call__(self):
> self.n = self.n - 1
> return self.n != 0
>
>
> if __name__ == '__main__':
> loop = Loop(10)
> while loop:
> print "OK"
Jeffrey Schwab wrote:
> class Loop:
> def __init__(self, n):
> self.n = n
> def __call__(self):
> self.n = self.n - 1
> return self.n != 0
>
>
> if __name__ == '__main__':
> loop = Loop(10)
> while loop:
Whoops. Should be "while loop()".
> print
> Alan Isaac wrote:
> > I would like to be able to define a loop statement
> > (nevermind why) so that I can write something like
> >
> > loop 10:
> > do_something
> >
> > instead of
> >
> > for i in range(10):
> > do_something
> >
> > Possible? If so, how?
"Jeffrey Schwab" <[EMAIL PROT
Em Sáb, 2006-02-18 às 20:04 +, Jeffrey Schwab escreveu:
> if __name__ == '__main__':
> loop = Loop(10)
> while loop:
> print "OK"
Maybe:
while Loop(10)():
print "OK"
Looks rather ugly but requires one less line ;-).
--
"Quem excele em empregar a força mili
Felipe Almeida Lessa wrote:
> Em Sáb, 2006-02-18 às 20:04 +, Jeffrey Schwab escreveu:
>> if __name__ == '__main__':
>> loop = Loop(10)
>> while loop:
>> print "OK"
>
> Maybe:
>
> while Loop(10)():
> print "OK"
>
> Looks rather ugly but requires one less line ;-).
>
Does
Em Dom, 2006-02-19 às 11:08 +1100, Nigel Rowe escreveu:
> Felipe Almeida Lessa wrote:
>
> > Em Sáb, 2006-02-18 às 20:04 +, Jeffrey Schwab escreveu:
> >> if __name__ == '__main__':
> >> loop = Loop(10)
> >> while loop:
> >> print "OK"
> >
> > Maybe:
> >
> > while Loop(10)():
>
David Isaac wrote:
> I would like to be able to define a loop statement
> (nevermind why) so that I can write something like
>
> loop 10:
> do_something
Here's a flagrant hack:
import sys
VAR_NAME = '__repeat_counter'
def set_repeat_counter(value):
frame = sys._getframe(2)
frame.
"Benji York" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Here's a flagrant hack:
Admiration wins out over revulsion. ;-)
Thanks,
Alan Isaac
PS Here's the motivation. Python closely resembles pseudocode. With
a very little LaTeX hacking, it is often possible to write algorith
In article <[EMAIL PROTECTED]>,
David Isaac <[EMAIL PROTECTED]> wrote:
.
.
.
>Admiration wins out over revulsion. ;-)
>Thanks,
>Alan Isaac
>
>PS Here's the motivation. Python closely resembles pseudocode. With
>a very little
David Isaac wrote:
> PS Here's the motivation. Python closely resembles pseudocode. With
> a very little LaTeX hacking, it is often possible to write algorithms is
> Python that typeset as reasonable pseudocode. A simple repetitive
> loop is a bit of a sticking point.
With slightly more LaTeX
18 matches
Mail list logo