[Pharo-users] Interval form: x to: y when x > y - or how to count down...

Sven Van Caekenberghe sven at stfx.eu
Fri Feb 22 16:57:40 EST 2019

```
> On 22 Feb 2019, at 22:35, Tim Mackinnon <tim at testit.works> wrote:
>
> If it’s always been that way - and things rely on it, sure.
>
> But it doesn’t feel like the Smalltalk way to me.
>
> Having to know about adding -1 seems very C, whereas Smalltalk always seems more natural ... and 5 to: 1 seems like you would count down, not be an empty range and do nothing.
>
> But as you say, it’s personal. I’m still curious though.

I personally would find it cool if

10 to: 1

counted down, it feels natural. But I must say I haven't thought it through.

I do known that Interval is a class that leads to lots of discussions and disagreements.

> Tim
>
> Sent from my iPhone
>
>> On 22 Feb 2019, at 16:13, Konrad Hinsen <konrad.hinsen at fastmail.net> wrote:
>>
>>> On 22/02/2019 15:57, Tim Mackinnon wrote:
>>> I've just been caught out with Intervals - why can't you do:
>>> 5 to: 1 do: [ :i | Transcript show: i printString]  (eg a negative interval)?
>>>
>>> if you want to iterate down a series of numbers do you really have to do:
>>> 5 to: 1 by: -1 do: […
>>>
>>> I always assumed that if x > y the step was automatically -1 (but its not).
>>
>> Expectations are obviously personal, but as far as I am concerned, I'd expect to see the behavior that Pharo implements. If you don't specify by:, you get a default value of 1. That's much simpler than a default value depending on the bounds of the interval.
>>