From: Robert Klemme Date: 2004-03-19T17:39:43+09:00 Subject: Re: `#catch'ing many symbols "George Ogata" schrieb im Newsbeitrag news:878yhy0xwl.fsf@optushome.com.au... > "Robert Klemme" writes: > > > I don't think so. Problem is that catch returns the instance associated > > with the throw and when catching multiple symbols you can't distinguish > > what happened. In that case a single symbol is enough because you can use > > the returned element to carry information about the event: > > Thanks, I'd forgotten about the second throw arg. I guess that > satisfies the uncondtional case. Conditional was really the one I was > interested in, though. > > > Conditional catch does not make sense IMHO. What do you want to > > achieve with that? > > I think it can be useful in recursive scenarios. To unwind the stack > to the first call, you catch the symbol only if it's the first > invocation. Well, that's not too difficult, since one often has an entry method to recursion: def enter(*args) catch :quit do catch :done do recur_impl(*args) end end end def recur(*args) catch :done do recur_impl(*args) end end def recur_impl(*args) if ... recur x else ... end end > In my case, I have a stackable command interpreter interface > ("stackable" in the sense that you can recursively invoke one while > one is running, like the way you sometimes nest shells). One command > exits just the topmost layer to return to the one below. Another > exits the whole stack. Is that really a case for recursion? > To implement this, the former command throws :done, the latter :quit. > Only the bottom-most interpreter catches :quit, the others just catch > :done. > > I suppose there're few uses for multi-catching though, so fair enough. > If it's a harmless extension, though... As I said, I don't think it's a reasonable extension... Regards robert