[Pharo-users] Interval form: x to: y when x > y - or how to count down...
tim at testit.works
Fri Feb 22 16:35:37 EST 2019
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.
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.
More information about the Pharo-users