request for times, step, upto...

Discussion in 'Ruby' started by Peña, Botp, Jan 14, 2005.

  1. Hi,

    1. I am a Integer#times fan :) So you see my (and my kids) nuby codes
    littered w it. I have a small request though.
    Can we pass initial and step params?

    ie

    from int.times {|i| block }

    to int.times(starting=0, step=1) {|i| block }

    I hope this would not break old code, right?


    2. my request may be handled by step. But I do not like step (me only);
    maybe because the sound does not ring or maybe because I do not like the
    order of params when read.

    iow

    from num.step(limit, step ) {|i| block },

    I prefer fr_num.step(step, upto ) {|i| block }

    since I would read the ff 1.step(2,5) {|x| p x} as
    "from 1 step 2 up to 5" (I know this would break old code)

    I feel Integer#upto has a better read -"int.upto(limit) {|i| block }", but
    sadly #upto has no steps either :(

    thanks for reading =)

    kind regards -botp
     
    Peña, Botp, Jan 14, 2005
    #1
    1. Advertising

  2. On Friday 14 January 2005 02:06 am, "Peña, Botp" wrote:
    | Hi,
    |
    | 1. I am a Integer#times fan :) So you see my (and my kids) nuby codes
    | littered w it. I have a small request though.
    | Can we pass initial and step params?
    |
    | ie
    |
    | from int.times {|i| block }
    |
    | to int.times(starting=0, step=1) {|i| block }
    |
    | I hope this would not break old code, right?
    |
    |
    | 2. my request may be handled by step. But I do not like step (me only);
    | maybe because the sound does not ring or maybe because I do not like the
    | order of params when read.
    |
    | iow
    |
    | from num.step(limit, step ) {|i| block },
    |
    | I prefer fr_num.step(step, upto ) {|i| block }
    |
    | since I would read the ff 1.step(2,5) {|x| p x} as
    | "from 1 step 2 up to 5" (I know this would break old code)
    |
    | I feel Integer#upto has a better read -"int.upto(limit) {|i| block }", but
    | sadly #upto has no steps either :(
    |
    | thanks for reading =)
    |
    | kind regards -botp

    Whether these make it into Ruby core or not (I'm all for it) I will definitely
    add these mods too Ruby Facets (unless of course someone can show that its a
    really bad idea, but I doubt that). Do you have them coded up already by
    chance?

    Thanks,
    T.
     
    trans. (T. Onoma), Jan 14, 2005
    #2
    1. Advertising

  3. "Peña, Botp" <> schrieb im Newsbeitrag
    news:-phil.com...
    > Hi,
    >
    > 1. I am a Integer#times fan :) So you see my (and my kids) nuby codes
    > littered w it. I have a small request though.
    > Can we pass initial and step params?
    >
    > ie
    >
    > from int.times {|i| block }
    >
    > to int.times(starting=0, step=1) {|i| block }
    >
    > I hope this would not break old code, right?


    Sure, but semantics of this method will be broken. The block will no
    longer execute int times. We have #step for that as know.

    > 2. my request may be handled by step. But I do not like step (me only);
    > maybe because the sound does not ring or maybe because I do not like the
    > order of params when read.


    Ah, so you *do* care about the correlation between semantics and method
    names.

    > iow
    >
    > from num.step(limit, step ) {|i| block },
    >
    > I prefer fr_num.step(step, upto ) {|i| block }
    >
    > since I would read the ff 1.step(2,5) {|x| p x} as
    > "from 1 step 2 up to 5" (I know this would break old code)
    >
    > I feel Integer#upto has a better read -"int.upto(limit) {|i| block }",

    but
    > sadly #upto has no steps either :(


    That could be added. And it would be a resonable and good change IMHO.
    Same for #downto btw.

    > thanks for reading =)


    Thanks for calling. :)

    Kind regards

    robert
     
    Robert Klemme, Jan 14, 2005
    #3
  4. Peña, Botp

    Pit Capitain Guest

    Robert Klemme schrieb:

    > "Peña, Botp" <> schrieb im Newsbeitrag
    > news:-phil.com...
    >>
    >>(...)
    >>
    >> int.times(starting=0, step=1) {|i| block }
    >>
    >>I hope this would not break old code, right?

    >
    > Sure, but semantics of this method will be broken. The block will no
    > longer execute int times. We have #step for that as know.


    I thought he just wanted to change the values passed into the block. Instead of

    0, 1, ..., n-1

    it would be

    start, start + step, ..., start + (n-1)*step

    Looks useful to me.

    Regards,
    Pit
     
    Pit Capitain, Jan 14, 2005
    #4
  5. On Fri, 14 Jan 2005 16:06:19 +0900, Peña, Botp wrote:
    > <snip>
    > 2. my request may be handled by step. But I do not like step (me only);
    > maybe because the sound does not ring or maybe because I do not like the
    > order of params when read.
    >


    Hi,

    I agree that Integer#step looks a bit odd. The most
    natural way to do this is IMO with Range#step (added
    in 1.8? ):

    irb(main):001:0> (2..9).step(2) do |i| puts i end
    2
    4
    6
    8

    KB
     
    Kristof Bastiaensen, Jan 14, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jaap de verwant slachter
    Replies:
    0
    Views:
    1,266
    jaap de verwant slachter
    Jul 1, 2003
  2. Roy in

    need step by step example

    Roy in, Aug 3, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    360
    Roy in
    Aug 3, 2003
  3. Steve Richter

    a step by step page

    Steve Richter, May 3, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    379
    Steve Richter
    May 3, 2005
  4. craig dicker
    Replies:
    1
    Views:
    375
    Peter Rilling
    Jul 10, 2005
  5. Dan
    Replies:
    7
    Views:
    159
    Marc Heiler
    Feb 23, 2010
Loading...

Share This Page