[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: For loops don't count down

Yukihiro Matsumoto

2/19/2007 1:38:00 PM

Hi,

In message "Re: For loops don't count down"
on Mon, 19 Feb 2007 22:27:02 +0900, SonOfLilit <sonoflilit@gmail.com> writes:

|Numeric#step counts down:
|
|5.step(-1) do |i|
| #stuff
|end

5.downto(1) do |i|
end

matz.

29 Answers

SonOfLilit

2/19/2007 1:44:00 PM

0

That was already mentioned, but I wanted to show the moer general
solution since it was seeked.

On 2/19/07, Yukihiro Matsumoto <matz@ruby-lang.org> wrote:
> Hi,
>
> In message "Re: For loops don't count down"
> on Mon, 19 Feb 2007 22:27:02 +0900, SonOfLilit <sonoflilit@gmail.com> writes:
>
> |Numeric#step counts down:
> |
> |5.step(-1) do |i|
> | #stuff
> |end
>
> 5.downto(1) do |i|
> end
>
> matz.
>
>

Michael Brooks

2/19/2007 4:43:00 PM

0

Yukihiro Matsumoto wrote:
> Hi,
>
> In message "Re: For loops don't count down"
> on Mon, 19 Feb 2007 22:27:02 +0900, SonOfLilit <sonoflilit@gmail.com> writes:
>
> |Numeric#step counts down:
> |
> |5.step(-1) do |i|
> | #stuff
> |end
>
> 5.downto(1) do |i|
> end
>
> matz.

Hello Yukihiro:

Thank you for the reply. I tried the step, as shown above, and it
doesn't work, it returns a 5, like so:

irb(main):013:0> 5.step(-1) do |i|
irb(main):014:0> puts i
irb(main):015:0> end
=> 5

However, adding the 1 parameter does work, like so:

irb(main):016:0> 5.step(1,-1) do |i|
irb(main):017:0> puts i
irb(main):018:0> end
5
4
3
2
1
=> 5

I'm glad that I'm forced to put in the 1 because I wouldn't want it
counting down to zero without me realizing it.

However, coming from other languages (e.g. Delphi) I still prefer the
for...end syntax because of the more easily recognizable blocks it
creates, like so:

for
...
end

but in time I'm sure I'll get used to seeing number / objects / sets /
ranges at the beginning of lines and won't be so hung up on keywords
like "for".

Maybe if the Range#each were smart enough to look at the start and end
value and count up or down accordingly that would fix things for the
(5..1) style syntax. I assume this wouldn't just benefit the "for" but
would cause less gotcha's wherever ranges were used.

BTW, thank you for creating such a wonderfully OO language. I looked at
Python and it seemed a little inconsistent at times, not to mention all
that __<stuff>__, so I was impressed to find such an rich, clean and OO
oriented language like Ruby. I was equally impressed to see how much
forethought had gone into aspects like sets, iterators, etc. So, please
keep up the great work!

Michael

Daniel Schierbeck

2/19/2007 5:45:00 PM

0

On Mon, 2007-02-19 at 22:38 +0900, Yukihiro Matsumoto wrote:
> Hi,
>
> In message "Re: For loops don't count down"
> on Mon, 19 Feb 2007 22:27:02 +0900, SonOfLilit <sonoflilit@gmail.com> writes:
>
> |Numeric#step counts down:
> |
> |5.step(-1) do |i|
> | #stuff
> |end
>
> 5.downto(1) do |i|
> end

Is there a necessity for a range such as 5..0 to be empty? It would
otherwise be easy to make iteration work for such cases. This is a
simplified solution that doesn't take into account #exclude_end?

class Range
def each
obj = first
if first <= last
while obj <= last
yield obj
obj = obj.succ
end
else
while first >= last
yield obj
obj = obj.pre
end
end
end
end

This would of course require that the objects in such a "reverse" range
respond to #pre, or whatever other name would be more suitable.

I'm basically asking if there is a reason why we shouldn't expand the
functionality of Range#each, other than backwards compatibility (not
that that isn't a big consideration.)


Cheers,
Daniel Schierbeck


SonOfLilit

2/19/2007 5:56:00 PM

0

In math classes, I've seen cases where it's very comfortable that
Sigma (n = b to a) = 0 if b > a.
It was just nice to define something as an empty sum this way
(generalization of solutions).

It's also more according to for(i = a; i < 5; i++) behavior, which is
something very useful. Perhaps we should have syntax for both types.
Or just Range#arrange (awul name) where (a..b).arrange would return
a..a if a<b .

Aur

On 2/19/07, Daniel Schierbeck <daniel.schierbeck@gmail.com> wrote:
> On Mon, 2007-02-19 at 22:38 +0900, Yukihiro Matsumoto wrote:
> > Hi,
> >
> > In message "Re: For loops don't count down"
> > on Mon, 19 Feb 2007 22:27:02 +0900, SonOfLilit <sonoflilit@gmail.com> writes:
> >
> > |Numeric#step counts down:
> > |
> > |5.step(-1) do |i|
> > | #stuff
> > |end
> >
> > 5.downto(1) do |i|
> > end
>
> Is there a necessity for a range such as 5..0 to be empty? It would
> otherwise be easy to make iteration work for such cases. This is a
> simplified solution that doesn't take into account #exclude_end?
>
> class Range
> def each
> obj = first
> if first <= last
> while obj <= last
> yield obj
> obj = obj.succ
> end
> else
> while first >= last
> yield obj
> obj = obj.pre
> end
> end
> end
> end
>
> This would of course require that the objects in such a "reverse" range
> respond to #pre, or whatever other name would be more suitable.
>
> I'm basically asking if there is a reason why we shouldn't expand the
> functionality of Range#each, other than backwards compatibility (not
> that that isn't a big consideration.)
>
>
> Cheers,
> Daniel Schierbeck
>
>
>

Heinrich

2/23/2013 7:22:00 AM

0



"Walt Hampton" schreef in bericht news:6c6euk.72c.19.1@news.alt.net...

"Heinrich" wrote in message news:A_XVs.42301$t82.5254@newsfe12.iad...

>This is very important, attaching real
>names to everything on the internet
is the Jews strategy for clamping down
>on the only information source they
>do not control. Once your name is all
>over everything, their goons will show
>up at your home, your workplace and
>intimidate you into silence.

I have been using my real name on the 'Net for years. If Yids show any
wherewithal by showing up around here where I live, they will get a
first-hand experience of what is called down here "an asswhipping."

that soundfs interesting. plse give full details about that asswhipping


The Peeler

2/23/2013 11:50:00 AM

0

On Sat, 23 Feb 2013 08:21:51 +0100, Dumb Heini, the heavily medicated Dutch
resident Nazi troll and laughing stock of sci and scj, wrote:

>>up at your home, your workplace and
>>intimidate you into silence.
>
> I have been using my real name on the 'Net for years. If Yids show any
> wherewithal by showing up around here where I live, they will get a
> first-hand experience of what is called down here "an asswhipping."
>
> that soundfs interesting. plse give full details about that asswhipping

"soundfs"? "plse"? LMAO! Why are ALL you Nazis, ALWAYS, without ANY
exception, such a laugh ...as long as you can't kill anybody? LOL


--
Dumb Dutch Nazi Heini's motto: "to suck rectum or not to suck rectum that is
the question"
MID: <4db7abbb$0$24816$2e0edba0@news.tweakdsl.nl>

The Peeler

2/23/2013 11:56:00 AM

0

On Fri, 22 Feb 2013 23:09:51 -0800 (PST), DoDo, the stupid dead animal,
wrote:


>>>up at your home, your workplace and
>>>intimidate you into silence.
>>
>> I have been using my real name on the 'Net for years. ?If Yids show any
>> wherewithal by showing up around here where I live, they will get a
>> first-hand experience of what is called down here "an asswhipping."
>
> You are a fat dumbfuck. Any Jew would laugh at you.

You certainly aren't much different from him, stupid Dodo! <BG>

Stewart

2/23/2013 12:34:00 PM

0


"Walt Hampton" <walt.hampton@att.net> wrote in message
news:6c6euk.72c.19.1@news.alt.net...
> "Heinrich" wrote in message
> news:A_XVs.42301$t82.5254@newsfe12.iad...
>>This is very important, attaching real names to everything on the
>>internet
> is the Jews strategy for clamping down
>>on the only information source they do not control. Once your name
>>is all over everything, their goons will show up at your home, your
>>workplace and intimidate you into silence.
>
> I have been using my real name on the 'Net for years. If Yids show
> any
> wherewithal by showing up around here where I live, they will get a
> first-hand experience of what is called down here "an asswhipping."
>
>
There are Jews "around there", and you haven't done shit. Keyboard
fucking rambo pussy is all you are.....


Stewart

2/23/2013 12:35:00 PM

0


"Heinrich" <Heinrich@Ruhrgasnet.de> wrote in message
news:x6_Vs.42320$t82.13998@newsfe12.iad...
>
>
> "Walt Hampton" schreef in bericht
> news:6c6euk.72c.19.1@news.alt.net...
> "Heinrich" wrote in message
> news:A_XVs.42301$t82.5254@newsfe12.iad...
>>This is very important, attaching real names to everything on the
>>internet
> is the Jews strategy for clamping down
>>on the only information source they do not control. Once your name
>>is all over everything, their goons will show up at your home, your
>>workplace and intimidate you into silence.
>
> I have been using my real name on the 'Net for years. If Yids show
> any
> wherewithal by showing up around here where I live, they will get a
> first-hand experience of what is called down here "an asswhipping."
>
> that soundfs interesting. plse give full details about that
> asswhipping
>
>

He's better at ass licking.


Heinrich

2/23/2013 12:41:00 PM

0



"Stewart" schreef in bericht news:kgactu$2af$1@dont-email.me...


"Heinrich" <Heinrich@Ruhrgasnet.de> wrote in message
news:x6_Vs.42320$t82.13998@newsfe12.iad...
>
>
> "Walt Hampton" schreef in bericht
> news:6c6euk.72c.19.1@news.alt.net...
> "Heinrich" wrote in message
> news:A_XVs.42301$t82.5254@newsfe12.iad...
>>This is very important, attaching real names to everything on the
>>internet
> is the Jews strategy for clamping down
>>on the only information source they do not control. Once your name
>>is all over everything, their goons will show up at your home, your
>>workplace and intimidate you into silence.
>
> I have been using my real name on the 'Net for years. If Yids show
> any
> wherewithal by showing up around here where I live, they will get a
> first-hand experience of what is called down here "an asswhipping."
>
> that soundfs interesting. plse give full details about that
> asswhipping
>
>

He's better at ass licking.

did heinrich give you permission to talk to him jew boy?