Block.call vs. yield

Hi,

I imagine ‘yield semantics’ were put in the language to solve some problem,
or make it work better in some circumstances; do you have an example of
that?

‘yield semantics’ is assignment between block parameters and yield
arguments, so that

a> given 1 argument x works as a = x
a> given 2 arguments x, y works as a = x, y

That’s because block parameters are originally loop variables.

Suppose block parameters worked like function arguments - how would life be
worse? (ignoring backwards compatibility)

I don’t know (yet). The whole behavior of yield and block parameters
is designed for assignment model. At least I need to reconstruct my
mental model using function argument model.

						matz.
···

In message “Re: block.call vs. yield” on 03/04/29, Brian Candler B.Candler@pobox.com writes:

Ah, right. So if you were to change that, you’d probably also have to get
rid of
a = x, y

Personally I would always write

    a = [x, y]

if I wanted to do that, as it makes the intention clearer; or there’s always

   *a = x, y

I hardly ever use parallel assignments though, so it’s hard for me to say
how it would affect things.

Cheers,

Brian.

···

On Tue, Apr 29, 2003 at 11:20:56AM +0900, Yukihiro Matsumoto wrote:

‘yield semantics’ is assignment between block parameters and yield
arguments, so that

a> given 1 argument x works as a = x
a> given 2 arguments x, y works as a = x, y

That’s because block parameters are originally loop variables.

If we are keeping the yield and call argument handling different, then
I prefer David Black’s solution
( http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/70220 ):

If Proc#call has method-like semantics, perhaps what’s needed is a
method with block-like semantics – namely, Block#call. That, of
course, would also mean “Block” would be needed :slight_smile:

This seems very clear to me. Is there any reason to not do this?

Stephen
± S.D.Sykes - www.stephensykes.com -

Hi,

···

In message “Re: block.call vs. yield” on 03/04/30, haldane jbshaldane@hotmail.com writes:

If Proc#call has method-like semantics, perhaps what’s needed is a
method with block-like semantics – namely, Block#call. That, of
course, would also mean “Block” would be needed :slight_smile:

This seems very clear to me. Is there any reason to not do this?

I’m not sure call/yield difference belong to caller or callee. If it
is callee matter, it is nice idea; if not, the current is the best.
I have to take time to ponder.

						matz.