Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Generator

44 views
Skip to first unread message

epg...@gmail.com

unread,
Sep 16, 2014, 5:21:10 PM9/16/14
to

As it was brought to my attention, that the yield should not operate without the function* syntax in a regular function.

With that said again:

The ES5+ welcome the yield operand, not the function*

Her is my argument for the proposal that will follow:


function r(){
var i = 0, a = [0,9,8,7,6,5,4,3,2,1];
return (function (){return a.pop();});
}

var rr = r();

function y(){
let i = 0, a = [0,9,8,7,6,5,4,3,2,1];
while(a){
yield (a.pop());
}
}

let yy = y();

function* g(){
let i = 0, a = [0,9,8,7,6,5,4,3,2,1];
while(a){
yield (a.pop());
}
}

let gg = g();

print("return: " + rr() + " " + rr() + " " + rr() + " " + rr() + " " + rr() + " " + rr() + " " + rr() + " " + rr() + " " + rr() + " " + rr() + " " + rr() + "\n" +
"yield: " + yy.next() + " " + yy.next() + " " + yy.next() + " " + yy.next() + " " + yy.next() + " " + yy.next() + " " + yy.next() + " " + yy.next() + " " + yy.next() + " " + yy.next() + " " + yy.next() + "\n" +
"function*: " + JSON.stringify([gg.next(), gg.next(), gg.next(), gg.next(), gg.next(), gg.next(), gg.next(), gg.next(), gg.next(), gg.next(), gg.next()]));

/*
return: 1 2 3 4 5 6 7 8 9 0 undefined
yield: 1 2 3 4 5 6 7 8 9 0 undefined
function*: [{"value":1,"done":false},{"value":2,"done":false},{"value":3,"done":false},{"value":4,"done":false},{"value":5,"done":false},{"value":6,"done":false},{"value":7,"done":false},{"value":8,"done":false},{"value":9,"done":false},{"value":0,"done":false},{"done":false}]
*/

The above works great... and got me speculating that the yield contain a scope of its own... if what I display above should not fully work... it cause of the change to the language that new possibility are possible that wasn't before.

If this is non - valet ES6 generator function... Consider adding this feature to the spec:

function y(){
let i = 0, a = [0,9,8,7,6,5,4,3,2,1];
while(a){
yield (a.pop());
}
}

let yy = y();

print("yield: " + yy.next() + " " + yy.next() + " " + yy.next() + " " + yy.next() + " " + yy.next() + " " + yy.next() + " " + yy.next() + " " + yy.next() + " " + yy.next() + " " + yy.next() + " " + yy.next());

//yield: 1 2 3 4 5 6 7 8 9 0 undefined

the above is much better and allow list to be done to get the value. Considering the way to the function* way, this way wins. I'm not suggestion to get rid of the function* but if this way is an... additional feature only exclusive to that browser who allow it, then it should be included into the spec.... Especially when that browser is the one that is supporting this mailing list.

Ones people realize that one can use the yield operand -in this particular browser... which you are working with-- without the none ES5 syntax like function*, they will wonder and question; why can't this be done in all browser? Why is the browser that is help writing the spec isn't including this feature into the spec as well? -and for those who was told this type of syntax could not be done will be outrage--I though this wasn't possible, why is this allow in the browser that is helping the most to write the spec but not in the spec? They will question, so rightful should. In this plantation it doesn't return an object but a value, so it's much concise.

There are still some question that desire to be answer?

Why:

In some case when yield let say... this:

function ask(){
yield 1;
}
var why = ask();
why.next();why.next();
/*
Exception: [object StopIteration]
*/

What is that empty -stringify it--exception object?

Why isn't null or undefined, or even the false value return instead?

An exception being throw denote that the problem is my serious, and in most case, out of programmer hands to handle and most be dealt with via implantation means. I request that is be change to a false value being thrown rather than an exception for the none asterisk syntax style generator. And of course that the none asterisk style syntax be adopted into the spec as well.
0 new messages