From: Robert Klemme Date: 2005-06-29T19:05:42+09:00 Subject: Re: yield does not take a block Eric Mahurin wrote: > --- Yukihiro Matsumoto wrote: > >> Hi, >> >> In message "Re: yield does not take a block" >> on Wed, 29 Jun 2005 02:30:05 +0900, Daniel Brockman >> writes: >> >>> I feel strange when I see these are not equivalent: >>> >>> def foo1 &block >>> block.call &bar >>> end >>> >>> def foo2 >>> Proc.new.call &bar >>> end >>> >>> def foo3 &block >>> yield &bar >>> end >> >>> If foo1 and foo3 are not equivalent, then we have an inconsistency. >> >> Indeed we have inconsistency here if those two are not >> equivalent, but >> I don't think consistency matters most in this case. Using >> yield >> emphasizes passing a value and control to a block given to >> the method. >> On the other hand, "call"ing an block argument (&block) >> emphasizes >> treating a block as a procedural object. If they are >> focusing >> different aspect, they might not be exact same. >> >> It's not a technical issue. Just a matter of how we feel >> when we see >> >> yield &bar >> >> or >> >> yield {...} >> >> I feel something strange (bad strange) when I see this, just >> because >> it passes a block to another block, which is apparently >> strange, >> whereas >> >> block.call &bar >> >> does not make me feel bad strange, since it is valid syntax >> in the >> microscopic view, even when it is semantically strange. >> >> If you have shown me the reason "yield &bar" is not strange >> (and is >> useful) other than consistency, I'd be glad to apply the >> Nobu's patch >> in [ruby-talk:146636]. >> >> matz. > > > I tend to agree that the yield should be made consistent with > block.call such that yield would basically be just an alias for > block.call (where block is the block given to the current > method). I think any keyword that can reasonably be made to > look like a method call, should. Makes the syntax more > consistent. If you were starting over, I'd even suggest things > like if/while to be like (or actually) method calls. > > but... > > Personally, I don't think having yield as a keyword really adds > that much value to the language. The only advantages I see > over explicitly having a &block arg and using block.call are a) > it looks like smalltalk, and b) rdoc parses it better. I think > showing the &block on the def line makes the method interface > clearer up front. I don't use yield at all and haven't missed > it. Note though that yield and &c.call work quite differently. This has for example performance implications. Kind regards robert