[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Generator#yield - what does it do?

Wolfgang Nádasi-donner

12/2/2007 11:04:00 PM

Hi!

I am confused somehow with respect to "Generator#yield". The description
(ri) is...

>ri Generator#yield
-------------------------------------------------------- Generator#yield
yield(value)
------------------------------------------------------------------------
Yields an element to the generator.

It's unclear for me what this means. I would expect that the Generator
object delivers (yields) values by requirement through
"Generator#current" or "Generator#next", but what should be yielded to
an already existing Generator object?

Wolfgang Nádasi-Donner
--
Posted via http://www.ruby-....

10 Answers

MonkeeSage

12/3/2007 2:09:00 AM

0

On Dec 2, 5:03 pm, Wolfgang Nádasi-Donner <ed.oda...@wonado.de> wrote:
> Hi!
>
> I am confused somehow with respect to "Generator#yield". The description
> (ri) is...
>
> >ri Generator#yield
>
> -------------------------------------------------------- Generator#yield
> yield(value)
> ------------------------------------------------------------------------
> Yields an element to the generator.
>
> It's unclear for me what this means. I would expect that the Generator
> object delivers (yields) values by requirement through
> "Generator#current" or "Generator#next", but what should be yielded to
> an already existing Generator object?
>
> Wolfgang Nádasi-Donner
> --
> Posted viahttp://www.ruby-....

It's for passing items *into* the generator's queue when the generator
is created with the block form of Generator#new rather than from an
existing enumerable. Example...

require 'generator'
g = Generator.new { | g |
1.upto(9) { | i |
g.yield(i)
}
g.yield(10)
}
until g.end?
p g.next
end

It probably should be spelled "inject" or something.

Regards,
Jordan

MonkeeSage

12/3/2007 2:12:00 AM

0

On Dec 2, 8:09 pm, MonkeeSage <MonkeeS...@gmail.com> wrote:
> On Dec 2, 5:03 pm, Wolfgang Nádasi-Donner <ed.oda...@wonado.de> wrote:
>
>
>
> > Hi!
>
> > I am confused somehow with respect to "Generator#yield". The description
> > (ri) is...
>
> > >ri Generator#yield
>
> > -------------------------------------------------------- Generator#yield
> > yield(value)
> > ------------------------------------------------------------------------
> > Yields an element to the generator.
>
> > It's unclear for me what this means. I would expect that the Generator
> > object delivers (yields) values by requirement through
> > "Generator#current" or "Generator#next", but what should be yielded to
> > an already existing Generator object?
>
> > Wolfgang Nádasi-Donner
> > --
> > Posted viahttp://www.ruby-....
>
> It's for passing items *into* the generator's queue when the generator
> is created with the block form of Generator#new rather than from an
> existing enumerable. Example...
>
> require 'generator'
> g = Generator.new { | g |
> 1.upto(9) { | i |
> g.yield(i)
> }
> g.yield(10)}
>
> until g.end?
> p g.next
> end
>
> It probably should be spelled "inject" or something.

err... ^^^^^^^^ = "insert"

> Regards,
> Jordan

Wolfgang Nádasi-donner

12/3/2007 7:13:00 AM

0

Jordan Callicoat wrote:
> On Dec 2, 5:03 pm, Wolfgang N�dasi-Donner <ed.oda...@wonado.de> wrote:
>> It's unclear for me what this means. I would expect that the Generator
>> object delivers (yields) values by requirement through
>> "Generator#current" or "Generator#next", but what should be yielded to
>> an already existing Generator object?
> It's for passing items *into* the generator's queue when the generator
> is created with the block form of Generator#new rather than from an
> existing enumerable. Example...

I see - the confusion came from the usual meaning of yield: call a block
and deliver objects to it. Here it is used from a block into a method.

btw. - at least in "PickAxe" the word "yield" it marked as a reserved
word.

Wolfgang Nádasi-Donner
--
Posted via http://www.ruby-....

MonkeeSage

12/3/2007 7:49:00 AM

0

On Dec 3, 1:13 am, Wolfgang Nádasi-Donner <ed.oda...@wonado.de> wrote:
> Jordan Callicoat wrote:
> > On Dec 2, 5:03 pm, Wolfgang N?dasi-Donner <ed.oda...@wonado.de> wrote:
> >> It's unclear for me what this means. I would expect that the Generator
> >> object delivers (yields) values by requirement through
> >> "Generator#current" or "Generator#next", but what should be yielded to
> >> an already existing Generator object?
> > It's for passing items *into* the generator's queue when the generator
> > is created with the block form of Generator#new rather than from an
> > existing enumerable. Example...
>
> I see - the confusion came from the usual meaning of yield: call a block
> and deliver objects to it. Here it is used from a block into a method.

Yes... it really should be spelled differently. The idea is "send this
item into the generator queue, so that the generator yields it (normal
meaning) on the next iteration"...but it is confusing to have it named
yield.

> btw. - at least in "PickAxe" the word "yield" it marked as a reserved
> word.

Object attributes can share the same name as reserved words since they
live in the namespace of the caller. Example...

class Control
def if(cond, yes, no) # 'if' is a reserved keyword
if instance_eval(cond) then yes else no end
end
end
Control.new.if("5>4", "ok", "broken")
# => "ok"

> Wolfgang Nádasi-Donner
> --
> Posted viahttp://www.ruby-....

Regards,
Jordan

Wolfgang Nádasi-donner

12/3/2007 8:25:00 AM

0

David A. Black wrote:
> Reserved words can still be method names (e.g., class). It would be
> nice to have a different word for this method, since it does feel a
> bit backwards in relation to the other "yield", but as I recall there
> have been discussions already and nothing that Matz liked was
> proposed.

I think the documentation of the method should be a little bit extended.
The name of the method is not as bad as it looks like in the first
moment, because it is used in the way to "yield" a value later to the
user of the generator.

After yours and Jordan's explanations everything is clear now. It's
simply the documentation text "Yields an element to the generator",
which leads to the assumption, that the method can be called elsewhere
and delivers some objekt to the existing generator.

Wolfgang Nádasi-Donner
--
Posted via http://www.ruby-....

Obveeus

11/5/2013 11:37:00 PM

0


"WrongWayWade" <rl3166pls@excite.com> wrote in message
news:l5bnb5$48r$1@dont-email.me...
> Obveeus wrote:
>> "anim8rFSK" <anim8rfsk@cox.net> wrote:
>>> from The Twitter:
>>>
>>> Natalie Morales
>>> @nataliemorales
>>> Also, I'm back on #TrophyWife tonight, doing awesome things as usual.
>>> 9:30pm, on @ABCNetwork
>>>
>>> Middleman!
>>
>> I much prefer THE MINDY PROJECT...and her hair is back...but maybe
>> I'll catch TROPHY WIFE later.
>
> Yea, I wonder if Mindy's short hair was a wig the whole time.

I'm pretty sure that it was a wig. Every time she touched it, she was
patting the top of her head (to make sure the wig was straight) rather than
tugging at the strands trying to make them grow faster. I've been calling
it a hair hat for just that reason.


Michael Black

11/5/2013 11:44:00 PM

0

Barry Margolin

11/6/2013 1:33:00 AM

0

In article <alpine.LNX.2.02.1311051843150.31390@darkstar.example.org>,
Michael Black <et472@ncf.ca> wrote:

> On Tue, 5 Nov 2013, Obveeus wrote:
>
> >
> > "WrongWayWade" <rl3166pls@excite.com> wrote in message
> > news:l5bnb5$48r$1@dont-email.me...
> >> Obveeus wrote:
> >>> "anim8rFSK" <anim8rfsk@cox.net> wrote:
> >>>> from The Twitter:
> >>>>
> >>>> Natalie Morales
> >>>> @nataliemorales
> >>>> Also, I'm back on #TrophyWife tonight, doing awesome things as usual.
> >>>> 9:30pm, on @ABCNetwork
> >>>>
> >>>> Middleman!
> >>>
> >>> I much prefer THE MINDY PROJECT...and her hair is back...but maybe
> >>> I'll catch TROPHY WIFE later.
> >>
> >> Yea, I wonder if Mindy's short hair was a wig the whole time.
> >
> > I'm pretty sure that it was a wig. Every time she touched it, she was
> > patting the top of her head (to make sure the wig was straight) rather than
> > tugging at the strands trying to make them grow faster. I've been calling
> > it a hair hat for just that reason.
> >
> Maybe she has lice.
>
> But seriously, it's easy to go from long to short hair, but it takes some
> time for short hair to grow back. Unless some of the episodes were done
> months back, and then she got a haircut (and then the episodes out of
> sequence), I can't see her hair being long by now.

They had to pull that trick on Breaking Bad. In one of the last few
episodes, they had a flashback that recreated a scene from season 1.
This was actually the last scene they shot before the series wrapped,
because they had to shave off Cranston's goatee.

--
Barry Margolin
Arlington, MA

Obveeus

11/6/2013 2:00:00 PM

0


"Barry Margolin" <barmar@alum.mit.edu> wrote:

> Michael Black <et472@ncf.ca> wrote:
>> But seriously, it's easy to go from long to short hair, but it takes some
>> time for short hair to grow back. Unless some of the episodes were done
>> months back, and then she got a haircut (and then the episodes out of
>> sequence), I can't see her hair being long by now.
>
> They had to pull that trick on Breaking Bad. In one of the last few
> episodes, they had a flashback that recreated a scene from season 1.
> This was actually the last scene they shot before the series wrapped,
> because they had to shave off Cranston's goatee.

Speaking of which, the BREAKING BAD promo for next week's HOW I MET YOUR
MOTHER (returning guest star Bryan Cranston) looks great.


Dano

11/6/2013 5:28:00 PM

0

"Michael Black" wrote in message
news:alpine.LNX.2.02.1311051843150.31390@darkstar.example.org...

On Tue, 5 Nov 2013, Obveeus wrote:

>
> "WrongWayWade" <rl3166pls@excite.com> wrote in message
> news:l5bnb5$48r$1@dont-email.me...
>> Obveeus wrote:
>>> "anim8rFSK" <anim8rfsk@cox.net> wrote:
>>>> from The Twitter:
>>>>
>>>> Natalie Morales
>>>> @nataliemorales
>>>> Also, I'm back on #TrophyWife tonight, doing awesome things as usual.
>>>> 9:30pm, on @ABCNetwork
>>>>
>>>> Middleman!
>>>
>>> I much prefer THE MINDY PROJECT...and her hair is back...but maybe
>>> I'll catch TROPHY WIFE later.
>>
>> Yea, I wonder if Mindy's short hair was a wig the whole time.
>
> I'm pretty sure that it was a wig. Every time she touched it, she was
> patting the top of her head (to make sure the wig was straight) rather
> than
> tugging at the strands trying to make them grow faster. I've been calling
> it a hair hat for just that reason.
>
Maybe she has lice.

But seriously, it's easy to go from long to short hair, but it takes some
time for short hair to grow back. Unless some of the episodes were done
months back, and then she got a haircut (and then the episodes out of
sequence), I can't see her hair being long by now.
=======================================

You think it's impossible that they could have used a wig or extensions?