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

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 algorithms

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 LaTeX

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 thing, since

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 Seems you

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 OK --

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 PROTECTED] wrote in message

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 militar

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 ;-). Doesn't work. You get a

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)(): print OK Looks

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)

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 compiler or an interpreter

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 suite and

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 language.

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 language

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 compiler or an interpreter