Hi ! A little question about each() function: function test() { $H(hashtable).each(function(entry,idx){ /* code */ }); } In my /*code*/ I can do - throw $continue - throw $break But can I do a return xxx ? It seems the loop didn''t ends ? Is it normal ? Regards, -- Jean-Philippe Encausse - R&D Jalios SA Jp [at] encausse.net - http://www.encausse.com - http://www.jalias.com GTalk: jp.encausse [at] gmail.com - SMS: sms [at] jp.encausse.net Mob: +33 6 82 12 56 99 Jalios: +33 1 39 23 92 83 Tel: +33 1 39 18 90 15 Do it Once, Use it Twice ~ Do it Twice, Make It Once --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Jean-Philippe Encausse wrote:> A little question about each() function: > function test() { > $H(hashtable).each(function(entry,idx){ /* code */ }); > } > > In my /*code*/ I can do > - throw $continue > - throw $break > > But can I do a return xxx ?Yes, it will have the same effect as (the already obsolete) "throw $continue".> It seems the loop didn''t ends ? Is it normal ?OFC it''s normal. Remember that "your code is outside of the loop scope: the looping code happens behind the scene". Yes, I was quoting the docs: http://prototypejs.org/api/enumerable/each Jean-Philippe, should I suppose you were trying to use "each -> return" hoping for a "filter"? That''s plain wrong, you should use "grep", "find" or "findAll" for such things. For example, to filter out "false" values you could use: $H({ a:0, b:1, c:0, d:3 }).findAll(function(x){ return x.value }) // returns: [["b", 1], ["d", 3]] BTW, folks, we need a documentation update, telling people there is no "throw $continue" in Enumerables from starters, in order to avoid any confusion when they will update to a newer version which won''t support that for good (yes, Sam already dropped it in SVN). - -- Marius Feraru -----BEGIN PGP SIGNATURE----- iD8DBQFFwdPPtZHp/AYZiNkRAhziAKCiCXt7ThBdL6TM8kduCmVh6l2fdwCgyfuT mYMLYeq2KWfaXbMh6pNjQ0Y=0ILK -----END PGP SIGNATURE----- --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Jean-Philippe Encausse
2007-Feb-01 16:34 UTC
Re: $H.each() behavior in Prototype 1.5 final
1. So there is no longer $continue and I have to use return 2. I understand the behavior of return because it is a function given to each() but It''s not the same behavior like in other programming language: In Java: public Object method(){ for (Iterator it = collect.iterator; it.hasNext(); ){ Object obj = it.next(); if (...){ continue; } if (...){ continue; } if (...){ continue; } return obj; } } In prototype I have to do: function(){ var good; $H(collect).each(function(entry,idx){ if (...){ return; /* throw $continue; */} if (...){ return; } if (...){ return; } good = entry.value; throw $break; } return good; } That''s more complicated. I hoped to return directly entry.value; Regards On 2/1/07, Marius Feraru <altblue-9gptZ63fvgw@public.gmane.org> wrote:> > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Jean-Philippe Encausse wrote: > > A little question about each() function: > > function test() { > > $H(hashtable).each(function(entry,idx){ /* code */ }); > > } > > > > In my /*code*/ I can do > > - throw $continue > > - throw $break > > > > But can I do a return xxx ? > Yes, it will have the same effect as (the already obsolete) > "throw $continue". > > > It seems the loop didn''t ends ? Is it normal ? > OFC it''s normal. Remember that "your code is outside of the loop scope: the > looping code happens behind the scene". Yes, I was quoting the docs: > http://prototypejs.org/api/enumerable/each > > Jean-Philippe, should I suppose you were trying to use "each -> return" > hoping for a "filter"? That''s plain wrong, you should use "grep", "find" or > "findAll" for such things. For example, to filter out "false" values you > could use: > $H({ a:0, b:1, c:0, d:3 }).findAll(function(x){ return x.value }) > // returns: [["b", 1], ["d", 3]] > > > BTW, folks, we need a documentation update, telling people there is no > "throw $continue" in Enumerables from starters, in order to avoid any > confusion when they will update to a newer version which won''t support that > for good (yes, Sam already dropped it in SVN). > > - -- > Marius Feraru > -----BEGIN PGP SIGNATURE----- > > iD8DBQFFwdPPtZHp/AYZiNkRAhziAKCiCXt7ThBdL6TM8kduCmVh6l2fdwCgyfuT > mYMLYeq2KWfaXbMh6pNjQ0Y> =0ILK > -----END PGP SIGNATURE----- > > > >-- Jean-Philippe Encausse - R&D Jalios SA Jp [at] encausse.net - http://www.encausse.com - http://www.jalias.com GTalk: jp.encausse [at] gmail.com - SMS: sms [at] jp.encausse.net Mob: +33 6 82 12 56 99 Jalios: +33 1 39 23 92 83 Tel: +33 1 39 18 90 15 Do it Once, Use it Twice ~ Do it Twice, Make It Once --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Jean-Philippe Encausse wrote:> 1. So there is no longer $continue and I have to use returnYes, 1.5.0 is the last release to support this construct _in Enumerable_.> 2. I understand the behavior of return because it is a function given to > each() but It''s not the same behavior like in other programming languageOFC it isn''t. I have to say it again, you''re using Enumerable there, which is by not a "normal loop" (which - obviously - would work as you expect). Please read Enumerable docs, it really rocks once you''re getting comfortable with it: http://prototypejs.org/api/enumerable> That''s more complicated. I hoped to return directly entry.value;Sorry, that''s the way Enumerable works. :) cheers - -- Marius Feraru -----BEGIN PGP SIGNATURE----- iD8DBQFFwkWBtZHp/AYZiNkRApnTAJ48nKgnHG686ul9qOrs0Hn89fu4nACfXB3J ewp7QoPCNf8ADEPP7U/8s0M=+c22 -----END PGP SIGNATURE----- --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Jean-Philippe Encausse
2007-Feb-01 22:53 UTC
Re: $H.each() behavior in Prototype 1.5 final
> > 2. I understand the behavior of return because it is a function given to > > each() but It''s not the same behavior like in other programming language > OFC it isn''t. I have to say it again, you''re using Enumerable there, which > is by not a "normal loop" (which - obviously - would work as you expect). > Please read Enumerable docs, it really rocks once you''re getting comfortable > with it: http://prototypejs.org/api/enumerable- I don''t remember, Was it In the same behavior in prototype 1.4? - So now I should use find() and my function should return true or false ? Thanks, Regards -- Jean-Philippe Encausse - R&D Jalios SA Jp [at] encausse.net - http://www.encausse.com - http://www.jalias.com GTalk: jp.encausse [at] gmail.com - SMS: sms [at] jp.encausse.net Mob: +33 6 82 12 56 99 Jalios: +33 1 39 23 92 83 Tel: +33 1 39 18 90 15 Do it Once, Use it Twice ~ Do it Twice, Make It Once --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Jean-Philippe Encausse wrote:>>> 2. I understand the behavior of return because it is a function given to >>> each() but It''s not the same behavior like in other programming language >> OFC it isn''t. I have to say it again, you''re using Enumerable there, which >> is by not a "normal loop" (which - obviously - would work as you expect). > - I don''t remember, Was it In the same behavior in prototype 1.4?Yes.> - So now I should use find() and my function should return true or false ?You really sound like desperately needing an Enumerable tutorial :)) As your name sounds like French, maybe TDD''s work could be helpful: http://www.tddsworld.com/blogs/eapc/?2006/11/20/506-bien-developper-pour-le-web-20 No, I didn''t read it yet, but, as TDD is a fellow Prototype brethren, I hope he did write something about Enumerable too. Christophe? ;-) Besides the official documentation (prototypejs.org), there''s also a fine Enumerable and Hash tutorial written by Justin Palmer at: http://encytemedia.com/blog/articles/2005/12/07/prototype-meets-ruby-a-look-at-enumerable-array-and-hash HTH - -- Marius Feraru -----BEGIN PGP SIGNATURE----- iD8DBQFFwwgetZHp/AYZiNkRAvEdAJ9FWW9uB8w7w4xcF/eV+ii0Fg+NMgCg19co 5vqVozsgIplb8anPguBOlAc=3GMB -----END PGP SIGNATURE----- --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Hey guys, Marius Feraru a écrit :> As your name sounds like French, maybe TDD''s work could be helpful: > http://www.tddsworld.com/blogs/eapc/?2006/11/20/506-bien-developper-pour-le-web-20Thanks for the spotlight, Marius :-)> > No, I didn''t read it yet, but, as TDD is a fellow Prototype brethren, I hope > he did write something about Enumerable too. Christophe? ;-)Chapters 4 and 6 cover Prototype 1.5_pre0 extensively (final draft was due on Sep 11), including Enumerable of course (which didn''t have size() yet, but hey!). Aside from a typo in the syntax block for include/member (stating the arg is an iterator, when it is in fact a regular value), it''s good :-) -- Christophe Porteneuve aka TDD tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Jean-Philippe Encausse
2007-Feb-02 14:35 UTC
Re: $H.each() behavior in Prototype 1.5 final
Thanks for links, I already saw them. My question was only a need of confirmation that the best way / regular way to do what I want to do is to use find(). I think it is. My other question about prototype version was also a confirmation. I think that doing a "return in each()" in prototype 1.4 was not the same behavior than in 1.5. But may be I mistake I don''t remember... Why this last question ? Because I may have to review all my JavaScript code If this behavior between 1.4 and 1.5 have change. Regards> > - So now I should use find() and my function should return true or false ? > You really sound like desperately needing an Enumerable tutorial :)) > As your name sounds like French, maybe TDD''s work could be helpful: > http://www.tddsworld.com/blogs/eapc/?2006/11/20/506-bien-developper-pour-le-web-20 > > No, I didn''t read it yet, but, as TDD is a fellow Prototype brethren, I hope > he did write something about Enumerable too. Christophe? ;-) > > Besides the official documentation (prototypejs.org), there''s also a fine > Enumerable and Hash tutorial written by Justin Palmer at: > http://encytemedia.com/blog/articles/2005/12/07/prototype-meets-ruby-a-look-at-enumerable-array-and-hash > > HTH > - -- > Marius Feraru > -----BEGIN PGP SIGNATURE----- > > iD8DBQFFwwgetZHp/AYZiNkRAvEdAJ9FWW9uB8w7w4xcF/eV+ii0Fg+NMgCg19co > 5vqVozsgIplb8anPguBOlAc> =3GMB > -----END PGP SIGNATURE----- > > > >-- Jean-Philippe Encausse - R&D Jalios SA Jp [at] encausse.net - http://www.encausse.com - http://www.jalias.com GTalk: jp.encausse [at] gmail.com - SMS: sms [at] jp.encausse.net Mob: +33 6 82 12 56 99 Jalios: +33 1 39 23 92 83 Tel: +33 1 39 18 90 15 Do it Once, Use it Twice ~ Do it Twice, Make It Once --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Hey Jean-Philippe, Jean-Philippe Encausse a écrit :> My question was only a need of confirmation that the best way / > regular way to do what I want to do is to use find(). I think it is.Well, yes. There are many, many uses cases that are best served by specific methods in Enumerable instead of a run-of-the-mill each... Just look at invoke and pluck, for instance! (not for your current need, though).> My other question about prototype version was also a confirmation. I > think that doing a "return in each()" in prototype 1.4 was not the > same behavior than in 1.5. But may be I mistake I don''t remember...Actually, it worked exactly the same way. -- Christophe Porteneuve aka TDD tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---