Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > request for times, step, upto...

Reply
Thread Tools

request for times, step, upto...

 
 
Peña, Botp
Guest
Posts: n/a
 
      01-14-2005
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




 
Reply With Quote
 
 
 
 
trans. (T. Onoma)
Guest
Posts: n/a
 
      01-14-2005
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.



 
Reply With Quote
 
 
 
 
Robert Klemme
Guest
Posts: n/a
 
      01-14-2005

"Peña, Botp" <> schrieb im Newsbeitrag
news:...
> 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

 
Reply With Quote
 
Pit Capitain
Guest
Posts: n/a
 
      01-14-2005
Robert Klemme schrieb:

> "Peña, Botp" <> schrieb im Newsbeitrag
> news:...
>>
>>(...)
>>
>> 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


 
Reply With Quote
 
Kristof Bastiaensen
Guest
Posts: n/a
 
      01-14-2005
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
 
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
Just got two emails: 1. your request for a new Access Code and 2. Request for my MCP ID# What's going on??!! belfast-biker Microsoft Certification 0 01-14-2006 12:49 PM
Re: Accessing Request.InputStream / Request.BinaryRead *as the request is occuring*: How??? Brian Birtle ASP .Net 2 10-16-2003 02:11 PM
best way to get data: request.form, request.params, controlname.value Christian H ASP .Net 1 07-29-2003 05:27 AM
Re: difference bet. request.querystring and Request.Params Daniel Bass ASP .Net 2 07-04-2003 12:12 PM
System.Web.HttpException: Request timed out - [HttpException (0x80004005): Request timed out.] Steve ASP .Net 0 07-01-2003 12:11 AM



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