Re: block/lambda

2008-07-29 Thread Terry Reedy
iu2 wrote: On Jul 29, 9:36 am, Duncan Booth <[EMAIL PROTECTED]> wrote: Your example becomes: def dotimes(n, callable): for i in range(n): callable(i) def block(i): for j in range(i): print j, print dotimes(5, block) 0 0 1 0 1 2 0 1 2 3 The on

Re: block/lambda

2008-07-29 Thread Jean-Paul Calderone
On Tue, 29 Jul 2008 07:26:38 -0700 (PDT), "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: 2. Will it be possible in Python 3.0 to do the following: >>> def dotimes(n, callable): for i in range(n): callable() >>> def block(): nonlocal i for j in range(i):

Re: block/lambda

2008-07-29 Thread [EMAIL PROTECTED]
> 2. Will it be possible in Python 3.0 to do the following: > > >>> def dotimes(n, callable): > >         for i in range(n): callable() > > >>> def block(): > >         nonlocal i >         for j in range(i): >                 print j, >         print dotimes seems ok and what is wrong with that

Re: block/lambda

2008-07-29 Thread iu2
On Jul 29, 9:36 am, Duncan Booth <[EMAIL PROTECTED]> wrote: > iu2 <[EMAIL PROTECTED]> wrote: > > Is it possible to grant Python another syntactic mark, similar to > > triple quotes, that will actually make the enclosed code a compiled > > code, or an anonymous function? > > Yes, the syntactic mark

Re: block/lambda

2008-07-29 Thread Duncan Booth
iu2 <[EMAIL PROTECTED]> wrote: > Is it possible to grant Python another syntactic mark, similar to > triple quotes, that will actually make the enclosed code a compiled > code, or an anonymous function? > Yes, the syntactic mark you are looking for is 'def'. Your example becomes: >>> def dotim

Re: block/lambda

2008-07-28 Thread John Nagle
iu2 wrote: Hi, Playing with imitating lambdas and ruby blocks in Python, I came up with a very simple construct, for example: import compiler Python supports nested functions. You don't have to use a lambda form just to get a local function. Just write an ordinary nested def within anoth

Re: block/lambda

2008-07-28 Thread castironpi
On Jul 28, 3:12 pm, iu2 <[EMAIL PROTECTED]> wrote: > On Jul 28, 10:06 pm, iu2 <[EMAIL PROTECTED]> wrote: > > > > > Hi, > > > Playing with imitating lambdas and ruby blocks in Python, I came up > > with a very simple construct, for example: > > > import compiler > > > def dotimes(i, code): > >     f

Re: block/lambda

2008-07-28 Thread iu2
On Jul 28, 10:06 pm, iu2 <[EMAIL PROTECTED]> wrote: > Hi, > > Playing with imitating lambdas and ruby blocks in Python, I came up > with a very simple construct, for example: > > import compiler > > def dotimes(i, code): >     for i in range(i): >         exec code > > dotimes(5, ''' > for j in ran