Re: Generators and propagation of exceptions

2011-04-09 Thread Kent Johnson
On Apr 8, 3:47 pm, r wrote: > I'm already making something like this (that is, if I understand you > correctly). In the example below (an "almost" real code this time, I > made too many mistakes before) all the Expressions (including the > Error one) implement an 'eval' method that gets called by

Re: Generators and propagation of exceptions

2011-04-08 Thread Raymond Hettinger
On Apr 8, 12:47 pm, r wrote: > Anyway, thank you all for helping me out and bringing some ideas to > the table. I was hoping there might be some pattern specifically > designed for thiskind of job (exception generators anyone?), which > I've overlooked. If not anything else, knowing that this isn'

Re: Generators and propagation of exceptions

2011-04-08 Thread r
On Sat, Apr 9, 2011 at 3:22 AM, Raymond Hettinger wrote: > > You could just let the exception go up to an outermost control-loop > without handling it at all on a lower level.  That is what exceptions > for you: terminate all the loops, unwind the stacks, and propagate up > to some level where the

Re: Generators and propagation of exceptions

2011-04-08 Thread Ethan Furman
r wrote: The code above implements an interactive session (a REPL). Therefore, what I'd like to get is an error information printed out at the output as soon as it becomes available. Couple ideas: 1) Instead of yielding the error, call some global print function, then continue on; or 2) Col

Re: Generators and propagation of exceptions

2011-04-08 Thread Raymond Hettinger
On Apr 8, 8:55 am, r wrote: > I had a problem for which I've already found a "satisfactory" > work-around, but I'd like to ask you if there is a better/nicer > looking solution. Perhaps I'm missing something obvious. > > The code looks like this: > > stream-of-tokens = token-generator(stream-of-ch

Re: Generators and propagation of exceptions

2011-04-08 Thread r
Terry, Ian, thank you for your answers. On Sat, Apr 9, 2011 at 1:30 AM, Terry Reedy wrote: [...] > According to the above, that should be stream-of-parsed-expressions. Good catch. > The question which you do not answer below is what, if anything, you want to > do with error? If nothing, just pa

Re: Generators and propagation of exceptions

2011-04-08 Thread Raymond Hettinger
On Apr 8, 8:55 am, r wrote: > I had a problem for which I've already found a "satisfactory" > work-around, but I'd like to ask you if there is a better/nicer > looking solution. Perhaps I'm missing something obvious. > > The code looks like this: > > stream-of-tokens = token-generator(stream-of-ch

Re: Generators and propagation of exceptions

2011-04-08 Thread Terry Reedy
On 4/8/2011 11:55 AM, r wrote: I had a problem for which I've already found a "satisfactory" work-around, but I'd like to ask you if there is a better/nicer looking solution. Perhaps I'm missing something obvious. The code looks like this: stream-of-tokens = token-generator(stream-of-characters

Re: Generators and propagation of exceptions

2011-04-08 Thread Ian Kelly
On Fri, Apr 8, 2011 at 9:55 AM, r wrote: > I had a problem for which I've already found a "satisfactory" > work-around, but I'd like to ask you if there is a better/nicer > looking solution. Perhaps I'm missing something obvious. > > The code looks like this: > > stream-of-tokens = token-generator

Generators and propagation of exceptions

2011-04-08 Thread r
I had a problem for which I've already found a "satisfactory" work-around, but I'd like to ask you if there is a better/nicer looking solution. Perhaps I'm missing something obvious. The code looks like this: stream-of-tokens = token-generator(stream-of-characters) stream-of-parsed-expressions =