Interval new feature

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Interval new feature

Nicolas Cellier-3

After reviewing some of Interval bugs, I discovered this one:

(10 to: 12) at: 1.5.
Will answer 10.5.

So maybe this is not a bug but a funny undocumented feature.
Anyone ever thought of using such feature?


Reply | Threaded
Open this post in threaded view
|

Re: Interval new feature

Bert Freudenberg

On Apr 29, 2007, at 16:52 , nicolas cellier wrote:

>
> After reviewing some of Interval bugs, I discovered this one:
>
> (10 to: 12) at: 1.5.
> Will answer 10.5.
>
> So maybe this is not a bug but a funny undocumented feature.

It's a bug. Intervals are Collections, and collection indices must be  
integral (see Interval>>at:). You should safely be able to, e.g.,  
convert the Interval into an Array and have the semantics stay the same.

> Anyone ever thought of using such feature?

Having an interpolating collection would be nice at times, but I  
wouldn't misuse Interval for that.

Maybe adding an #interpolatedAt: method would make this available in  
a better way. Probably someone even implemented this, including  
support for different interpolation styles.

- Bert -



Reply | Threaded
Open this post in threaded view
|

Re: Interval new feature

Boris.Gaertner
In reply to this post by Nicolas Cellier-3
 "nicolas cellier" <[hidden email]> wrote:


>
> After reviewing some of Interval bugs, I discovered this one:
>
> (10 to: 12) at: 1.5.
> Will answer 10.5.
>
> So maybe this is not a bug but a funny undocumented feature.
> Anyone ever thought of using such feature?
>
Interesting.
I agree with Bert that this should be considered a bug.
Interestingly enough, I just found that
    VisualWorks 7.3
    Dolphin 2.1
    VisualAge for Smalltalk 6.0.2
all exhibit the same behaviour. (Note that these are not the
newest available versions. I did not check the newest
versions of these products).

The star among these Smalltalks is the IBM product, where
we find this method definition:

at: anInteger

 "Answer the type of Number occurring at the index in the receiver
  specified by anInteger.  Report an error if anInteger exceeds
  the size of the receiver.

  Fail if anInteger is not an Integer."

 | result |
 result := from + (anInteger - 1 * by).
 by > 0
  ifTrue: [(result between: from and: to) ifTrue: [^result]]
  ifFalse: [(result between: to and: from) ifTrue: [^result]].
 ExCLDTIndexOutOfRange signalWith: 1



The  "Fail if anInteger is not an Integer" is simply not true.


Enjoy,
Boris