On Sun, Jan 04, 2004 at 05:28:02PM -0800, GGarramuno wrote:
>   while $stdin.getc
>     begin
>       catch(:arg) do
>         p "A"
>         while true
>           p "B"
>           throw :arg if true
>         end
>       end
>     ensure
>       p "ensure"
>     end
>   end
> 
> Well, that's what I thought at first, but I had quickly discarded the
> idea as not right.
> Yet, it does work.  I am obviously missing some other gotcha here.
> 
> In the above example, by placing the catch where it is, the way I read
> it was that $stdin.getc gets run only once, instead of in each
> iteration (ie. the while condition is not evaluated as it is OUTSIDE
> the catch do/end, just as is the ensure block)?   This is what's
> loosing me.  What's the logic -magic- that makes it all work?

There are TWO loops.  The throw breaks out of the INNER loop, but the
OUTER loop continues on its merry way.

-Mark
> 
> Or to put in another way, what if I wanted to have a catch() that is
> inside the first while loop but does not evaluate the condition nor
> runs the ensure block (say, just to backtrace the code like an ugly
> goto command)?  How would that look like?  Or that's just not possible
> (and thus it explains why the above thing always gets interpreted the
> way we intended)?