Could someone explain why:
(5 to: 100010) copyFrom: 3 to: 1000000
returns an Array rather than an Interval?
Returning an Interval is more intuitive to me since the copyFrom:to: message is being sent to an Interval. Of course, for the the example above at least, it is more efficient as well.
Regards,
Ralph Boland
On 11.12.2010, at 13:58, Ralph Boland wrote:
Could someone explain why:
(5 to: 100010) copyFrom: 3 to: 1000000
returns an Array rather than an Interval?
Because Interval>>species is Array.
This lets us re-use the generic collection methods instead of having to re-implement them for little benefit.
Returning an Interval is more intuitive to me since the copyFrom:to: message is being sent to an Interval. Of course, for the the example above at least, it is more efficient as well.
It would only be more efficient if it ever got used. Can't imagine a case where this would be useful. It would add complexity to the implementation though.
- Bert -
Bert Freudenberg <bert <at> freudenbergs.de> writes:
It would only be more efficient if it ever got used. Can't imagine a case
where this would be useful. It would
add complexity to the implementation though.
- Bert -
"Speaking of complexity, beware if you ever mess with intervals of Floats... Oh, one should better learn to not expect too much from these. Here is an example of stupid problem quite hard to make right... ...just try it in a workspace."
start := 1. increment := Float epsilon + 0.5. stop := 10.
c1 := start to: stop by: increment.
(c1 copyFrom: 4 to: c1 size) = ((c1 at: 4) to: stop by: increment).
"clue:" ((c1 copyFrom: 4 to: c1 size) collect: [:e | e hex]) = (((c1 at: 4) to: stop by: increment) collect: [:e | e hex]).
"If you feel comfortable with Floats, I have some extra works: Could you find an increment producing the requested interval in this case ? Does such increment exist in the general case ? Good luck ;)
Nicolas"
beginners@lists.squeakfoundation.org