From: Mark Hahn Date: 2002-01-01T08:49:40+09:00 Subject: [ruby-talk:29912] catch/throw (was Proc.class vs yield) > I haven't used Ruby's throw/catch yet and I don't plan to. I'm curious. What do you use to "break/retry/continue" inside a block? It always bothers me to have to use catch/throw in blocks. I would love to have an alternative. -----Original Message----- From: Mathieu Bouchard [mailto:matju@sympatico.ca] Sent: Monday, December 31, 2001 2:26 PM To: ruby-talk ML; Michael Lucas-Smith Cc: ruby-talk ML Subject: [ruby-talk:29907] Re: Proc.class vs yield On Mon, 31 Dec 2001, Michael Lucas-Smith wrote: > I'm a Smalltalk programmer and I have to say, of what I've seen of Ruby > I'm impressed. I like it. Except for one inconsistency which really > drives me up the wall. Two objects that nearly do the same thing, Proc > and Block Blocks are not the same thing. "block" is mostly a special (out-of-band) parameter slot. This means that the block slot (&) is completely separate from the optional (=) and rest (*) slots. Proc is the object type and from the outside you can think of the block slot as holding a Proc object: it doesn't matter that it's different under the hood, because you don't see it. I think I'd prefer Smalltalk-style [x|...] or Self-style (|x|...) to Ruby's proc{|x|...}, even though there are nice advantages to the block slot. > I suspect you're right. In Smalltalk, every bit of code inside the [] is > another object. They're always all full block closures. I have no idea > what this does to the performance. Lisp connoisseurs call it "slow" (but they also have lots of other ways of expressing their contempt) Anyway... it isn't clear to me that this can't be fixed. (disclaimer: i don't know enough about compilers) > I may be mistaken, but it appears as though the exception throwing and > catching is global within your namespace? when I read 'catch' and > 'throw' in the reference manuals for 1.4, they don't seem to talk about > a scope at all. Ruby's :foo is like Smalltalk's #foo or Lisp's :foo; so it's effectively global. If you want something more flexible use raise/rescue, which work with Exception objects. I haven't used Ruby's throw/catch yet and I don't plan to. ________________________________________________________________ Mathieu Bouchard http://hostname.2y.net/~matju