[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Yield should be renamed call_block

Yukihiro Matsumoto

7/10/2007 8:36:00 PM

Hi,

In message "Re: Yield should be renamed call_block"
on Tue, 10 Jul 2007 00:55:04 +0900, dblack@wobblini.net writes:

|If this ends up happening, I would (reluctantly) suggest getting rid
|of "yield", and just use call. b.yield, as others have pointed out,
|doesn't really work semantically: the function isn't yielding, it's
|being yielded *to*.

Since I am not a English speeker and I usually dont use that particlar
word, I feel like "yield" as rather like a symbol vaguly related to
passing valu to the blok.

Besides that, receivers often plays subjective roles for verbs (method
names), for example thread.kill or file.close, etc.

matz.

18 Answers

Gregory Brown

7/10/2007 8:51:00 PM

0

On 7/10/07, Yukihiro Matsumoto <matz@ruby-lang.org> wrote:
> Hi,
>
> In message "Re: Yield should be renamed call_block"
> on Tue, 10 Jul 2007 00:55:04 +0900, dblack@wobblini.net writes:
>
> |If this ends up happening, I would (reluctantly) suggest getting rid
> |of "yield", and just use call. b.yield, as others have pointed out,
> |doesn't really work semantically: the function isn't yielding, it's
> |being yielded *to*.
>
> Since I am not a English speeker and I usually dont use that particlar
> word, I feel like "yield" as rather like a symbol vaguly related to
> passing valu to the blok.
>
> Besides that, receivers often plays subjective roles for verbs (method
> names), for example thread.kill or file.close, etc.

That's true, but I shared the same confusion as David does when I was
playing with 1.9.
block.yield to me sounds like the opposite of block.call

In fact, my first instinct was to think this allowed currying for some reason.

like

block = lambda { |x,y| x + y + 3 }
block2 = block.yield(2)
block2.call(4) #=> 9

Of course, that imaginary syntax isn't a good idea either, but that's
what came to mind.

dblack

7/10/2007 9:34:00 PM

0

ara.t.howard

7/10/2007 10:37:00 PM

0


On Jul 10, 2007, at 3:33 PM, dblack@wobblini.net wrote:

>> Since I am not a English speeker and I usually dont use that
>> particlar
>> word, I feel like "yield" as rather like a symbol vaguly related to
>> passing valu to the blok.
>
> Vagueness would be OK, maybe, but the problem is bigger than that:
> it's that "block.yield" just doesn't express what's happening.

i'm with matz on this one

block.yield

reads, to me, simple as

'doing my own thing...'

block.yield 'control to you'

or

accum << block.yield

it's especially easy if you happen to think of blocks as a
specialized form of co-routinues, which i happen to.


i have always disliked

block.call

precisely because you are NOT doing that. calling a function/method
whatever implies a call stack and clean environment. with blocks we
actually invoke/yield to them in the particular way that makes them
useful - which is to say that they execute within the closure in
which they were defined. in general i think it's highly damaging to
align the terminology of methods and blocks, since the two operation
in entirely different ways wrst closures and people generally have a
very hard time with the concept of a real closure and all it's
implications.

2cts.

regards.

-a
--
we can deny everything, except that we have the possibility of being
better. simply reflect on that.
h.h. the 14th dalai lama




Phrogz

7/10/2007 11:15:00 PM

0

On Jul 10, 4:36 pm, "ara.t.howard" <ara.t.how...@gmail.com> wrote:
> On Jul 10, 2007, at 3:33 PM, dbl...@wobblini.net wrote:
> > Vagueness would be OK, maybe, but the problem is bigger than that:
> > it's that "block.yield" just doesn't express what's happening.
>
> i'm with matz on this one
>
> block.yield
>
> reads, to me, simple as
>
> 'doing my own thing...'
>
> block.yield 'control to you'

Hrm; nope, I'm with David. LET THE POLARIZATION BEGIN!

When you write:
foo.explode
you are saying:
"Tell the 'foo' object to 'explode'."

Thus, if you write:
blk.yield
you are saying:
"Tell the 'blk' object to 'yield'."
....which, as David pointed out, is backwards.

When you want to say "Now yield to the block" the imperative verb has
the implicit subject of "self". The extension of this would be:
self.yield( blk )
which of course is just:
yield( blk )

Of course, in the current situation where there cannot be more than
one Blessed block, this can be optimized to infer the blessed block,
and we get back to the current:
yield

blk.call is (IMHO and by the rationale above) sort of in the same
boat. You are telling the interpreter to call the block; you are not
telling the block to call itself. More sensible, IMHO, would be:
blk.run
blk.execute
because those are verbs that the block should know how to do.

Chad Perrin

7/11/2007 12:07:00 AM

0

On Wed, Jul 11, 2007 at 07:36:34AM +0900, ara.t.howard wrote:
>
> i'm with matz on this one
>
> block.yield
>
> reads, to me, simple as
>
> 'doing my own thing...'
>
> block.yield 'control to you'

Speaking more generally . . .

The way I've always read the object.message syntax is that you're saying
something like "Hey, Object! I want you to [yield]." Substitute the
particular message you're sending for [yield] as necessary.

--
CCD CopyWrite Chad Perrin [ http://ccd.ap... ]
print substr("Just another Perl hacker", 0, -2);

dblack

7/11/2007 12:27:00 AM

0

dblack

7/11/2007 12:28:00 AM

0

Chad Perrin

7/11/2007 12:33:00 AM

0

On Wed, Jul 11, 2007 at 09:28:14AM +0900, dblack@wobblini.net wrote:
>
> On Wed, 11 Jul 2007, Chad Perrin wrote:
> >On Wed, Jul 11, 2007 at 07:36:34AM +0900, ara.t.howard wrote:
> >>
> >>i'm with matz on this one
> >>
> >> block.yield
> >>
> >>reads, to me, simple as
> >>
> >> 'doing my own thing...'
> >>
> >> block.yield 'control to you'
> >
> >Speaking more generally . . .
> >
> >The way I've always read the object.message syntax is that you're saying
> >something like "Hey, Object! I want you to [yield]." Substitute the
> >particular message you're sending for [yield] as necessary.
>
> Exactly -- blocks don't yield, so let's not ask them to :-)

Is the word "accept" being used for anything?

--
CCD CopyWrite Chad Perrin [ http://ccd.ap... ]
Isaac Asimov: "Part of the inhumanity of the computer is that, once it is
completely programmed and working smoothly, it is completely honest."

dblack

7/11/2007 12:38:00 AM

0

Chad Perrin

7/11/2007 12:49:00 AM

0

On Wed, Jul 11, 2007 at 09:37:56AM +0900, dblack@wobblini.net wrote:
>
> On Wed, 11 Jul 2007, Chad Perrin wrote:
> >
> >Is the word "accept" being used for anything?
>
> $ ri Proc#accept
> Nothing known about Proc#accept
>
> Doesn't look like it :-)

It seems like words such as the following would be appropriate:

accept
receive
request

I don't know about "call", though. Maybe?

Maybe I'm not the guy to ask, though.

--
CCD CopyWrite Chad Perrin [ http://ccd.ap... ]
Paul Graham: "Real ugliness is not harsh-looking syntax, but having to
build programs out of the wrong concepts."