From: Joseph Erickson Date: 2002-08-06T21:33:40+09:00 Subject: Re: Super-iterator? --Apple-Mail-1-937892310 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; format=flowed I like it. What about a 'multilpe_of?' function. I hope this makes sense: You could have a multiple_of? function so you could say multiple_of?(3) and it would give you every third iteration. You could also add another parameter that would subtract back that number like multiple_of?(3,2) would give you 1,4,7,10 etc. That would make even? be multiple_of?(2) and odd? be multiple_of?(2,1) def multiple_of?(multiple,back) @count_ % multiple == back end > From: "Hal E. Fulton" > Date: Tue Aug 06, 2002 02:25:23 AM US/Eastern > To: ruby-talk@ruby-lang.org (ruby-talk ML) > Subject: Re: Super-iterator? (long) > Reply-To: ruby-talk@ruby-lang.org > > > ----- Original Message ----- > From: "David Alan Black" > To: "ruby-talk ML" > Sent: Monday, August 05, 2002 4:37 PM > Subject: Re: Super-iterator? (long) > > > Just for fun, I've converted your tests to Test::Unit format. This is > a drop-in replacement for everything after the module Enumerable > extensions. > > Neat. I need to get into that habit. > > A few comments: > > 1. I'm still not sold on the whole thing :-) But it's extremely > interesting. > > Oh, neither am I (completely sold). It's an experiment. > I'm sold on my own "motivations" but not on this solution. > > 2. I had to change #next to #i_next, because it was next'ing integers > and > characters. > > Huh?? next is a method of IteratorVar... it shouldn't cause any > kind of conflict. Can you explain? > > 3. #odd? and #even? are, in my view, too "meta". When I see "x.odd?", > it's virtually impossible not to expect that it's testing an integer > for oddness. > > I agree. But I couldn't think of what else to call them. When I want > to do things alternately in a loop, sometimes I want the even-numbered > iterations, and sometimes the odd. > > 4. Are you sure you want #next (or #i_next, or whatever) to consume > items? What if you want to grab the next item, but also want to > iterate to that item in the normal way? You seem to have less > functionality here (if I'm right about that) than you would with one > of the "index" methods. > > According to my own usage patterns, I usually do want it to consume. > If I were writing some kind of parser, it might be different. > > 5. I've done some fancy #to_s'ing... not sure if I should have to do > that. Anyway, I've done it, just to get the tests to pass initially. > > Actually, according to the way I was doing things, I should have > said x.next.value instead of just x.next (assuming no one actually > wants to store an IteratorVar). Maybe that would help. > > Hal > --Apple-Mail-1-937892310 Content-Transfer-Encoding: 7bit Content-Type: text/enriched; charset=US-ASCII I like it. What about a 'multilpe_of?' function. I hope this makes sense: You could have a multiple_of? function so you could say multiple_of?(3) and it would give you every third iteration. You could also add another parameter that would subtract back that number like multiple_of?(3,2) would give you 1,4,7,10 etc. That would make even? be multiple_of?(2) and odd? be multiple_of?(2,1) def multiple_of?(multiple,back) @count_ % multiple == back end From: "Hal E. Fulton" < Date: Tue Aug 06, 2002 02:25:23 AM US/Eastern To: ruby-talk@ruby-lang.org (ruby-talk ML) Subject: Re: Super-iterator? (long) Reply-To: ruby-talk@ruby-lang.org ----- Original Message ----- From: "David Alan Black" < To: "ruby-talk ML" < Sent: Monday, August 05, 2002 4:37 PM Subject: Re: Super-iterator? (long) 0000,0000,DEDEJust for fun, I've converted your tests to Test::Unit format. This is a drop-in replacement for everything after the module Enumerable extensions. Neat. I need to get into that habit. 0000,0000,DEDEA few comments: 1. I'm still not sold on the whole thing :-) But it's extremely interesting. Oh, neither am I (completely sold). It's an experiment. I'm sold on my own "motivations" but not on this solution. 0000,0000,DEDE2. I had to change #next to #i_next, because it was next'ing integers and characters. Huh?? next is a method of IteratorVar... it shouldn't cause any kind of conflict. Can you explain? 0000,0000,DEDE3. #odd? and #even? are, in my view, too "meta". When I see "x.odd?", it's virtually impossible not to expect that it's testing an integer for oddness. I agree. But I couldn't think of what else to call them. When I want to do things alternately in a loop, sometimes I want the even-numbered iterations, and sometimes the odd. 0000,0000,DEDE4. Are you sure you want #next (or #i_next, or whatever) to consume items? What if you want to grab the next item, but also want to iterate to that item in the normal way? You seem to have less functionality here (if I'm right about that) than you would with one of the "index" methods. According to my own usage patterns, I usually do want it to consume. If I were writing some kind of parser, it might be different. 0000,0000,DEDE5. I've done some fancy #to_s'ing... not sure if I should have to do that. Anyway, I've done it, just to get the tests to pass initially. Actually, according to the way I was doing things, I should have said x.next.value instead of just x.next (assuming no one actually wants to store an IteratorVar). Maybe that would help. Hal --Apple-Mail-1-937892310--