Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > JavaScript 1.7 yield

Reply
Thread Tools

JavaScript 1.7 yield

 
 
Kaleb Hornsby
Guest
Posts: n/a
 
      04-21-2009
I am having difficulty finding a working example of the yield
statement's .send() method in action.
This is what I have:

var f = function(x) {
var i = isNaN(x)? 0: x;
while(true) {
yield i++;
}
}
g = f();
g.next(); // 0
g.next(); // 1
g.next(); // 2
g.next(); // 3
g.send(2); // 4 should these return 2???
g.send(2); // 5
g.send(2); // 6
 
Reply With Quote
 
 
 
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      04-21-2009
Kaleb Hornsby wrote:
> I am having difficulty finding a working example of the yield
> statement's .send() method in action.
> This is what I have:
>
> var f = function(x) {
> var i = isNaN(x)? 0: x;
> while(true) {
> yield i++;
> }
> }
> g = f();
> g.next(); // 0
> g.next(); // 1
> g.next(); // 2
> g.next(); // 3
> g.send(2); // 4 should these return 2???


I'm not sure about that, the specification of the method is rather vague on
that:

,-<https://developer.mozilla.org/en/New_in_JavaScript_1.7#Resuming_a_generator_at_a_sp ecific_point>
|
| Once a generator has been started by calling its next() method,
| you can use send(), passing a specific value that will be treated
| as the result of the last yield. The generator will then return
| the operand of the subsequent yield.

However, the next generator.next() call should definitely return 3 if the
generator.send() method worked as described, and it doesn't. So it appears
that generator.send() is borken in Firefox 3(.0.6 for Linux), that is, it
works as if its argument is ignored. Barring further corrections, you
should file a bug or vote for an existing one (I don't know one, but I'm not
as up-to-date on Bugzilla as before.)

BTW, this is how I tested it in Firebug 1.3X3 which does not appear to
provide means to define the JavaScript version for the console (Joe
[Hewitt], please add that feature, like version(170)! TIA):

var s = document.createElement("script");
s.type = "text/javascript; version=1.7";
s.appendChild(document.createTextNode(<xml>
<![CDATA[
var f = function(x) {
var i = isNaN(x) ? 0 : x;active
while (true)
{
yield i++;
}
};

function bar()
{
try
{
var g = f();

/* 0 */
console.log(g.next());

/* 1 */
console.log(g.next());

/* 2 */
console.log(g.next());

/* 3 */
console.log(g.send(1));

/* yields 4, not 2 */
console.log(g.next());
}
catch (e)
{
/* not thrown */
e
}
}
]]>
</xml>));

document.body.appendChild(s);

bar();


PointedEars
 
Reply With Quote
 
 
 
 
Kaleb Hornsby
Guest
Posts: n/a
 
      04-21-2009
Yes, I have read this specification and have been using the
spidermonkey javascript engine to try and implement my code. I can get
the .next() and .close() methods to work, but I have no idea how to
get the .send() method to do what I think it is supposed to do.
 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      04-21-2009
Kaleb Hornsby wrote:
> I am having difficulty finding a working example of the yield
> statement's .send() method in action.


See answer in the Mozilla mozilla.dev.tech.js-engine group where you
posted too.

--

Martin Honnen
http://msmvps.com/blogs/martin_honnen/
 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      04-21-2009
Kaleb Hornsby wrote:
> Yes,


Yes -- to what of what I posted?

> I have read this specification and have been using the
> spidermonkey javascript engine to try and implement my code. I can get
> the .next() and .close() methods to work, but I have no idea how to
> get the .send() method to do what I think it is supposed to do.


If it's actually borken, you can't until the fix is checked in.


PointedEars
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[ANN] To Yield or Not to Yield: An Inferable Question Michael Edgar Ruby 13 04-21-2011 05:55 PM
yield expression programmized-formal interpretation. (interpretationof yield expression.) castironpi@gmail.com Python 1 04-22-2008 01:32 AM
yield keyword/command in JavaScript 1.7 VK Javascript 1 11-29-2007 10:06 PM
Yield & associations (was Proc / def /yield semantics) Markus Ruby 1 09-27-2004 07:04 PM
Make thread Yield and sleep at the same time Rick Java 2 10-04-2003 08:22 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57