define loop statement?

2006-02-17 Thread 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? Thanks, Alan Isaac -- http://mail.python.org/mailman/listinfo/python-list

Re: define loop statement?

2006-02-17 Thread Xavier Morel
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

Re: define loop statement?

2006-02-17 Thread Georg Brandl
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

Re: define loop statement?

2006-02-17 Thread Rene Pijlman
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

Re: define loop statement?

2006-02-17 Thread bearophileHUGS
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

Re: define loop statement?

2006-02-17 Thread Xavier Morel
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

Re: define loop statement?

2006-02-17 Thread Jonathan Gardner
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

Re: define loop statement?

2006-02-18 Thread Jeffrey Schwab
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

Re: define loop statement?

2006-02-18 Thread Georg Brandl
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"

Re: define loop statement?

2006-02-18 Thread Jeffrey Schwab
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

Re: define loop statement?

2006-02-18 Thread David Isaac
> 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

Re: define loop statement?

2006-02-18 Thread Felipe Almeida Lessa
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

Re: define loop statement?

2006-02-18 Thread Nigel Rowe
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

Re: define loop statement?

2006-02-18 Thread Felipe Almeida Lessa
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)(): >

Re: define loop statement?

2006-02-18 Thread Benji York
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.

Re: define loop statement?

2006-02-19 Thread David Isaac
"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

Re: define loop statement?

2006-02-19 Thread Cameron Laird
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

Re: define loop statement?

2006-02-22 Thread Magnus Lycka
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