I think I missed something - why is Range#size (and all its synonyms)
not in 1.7(.3)?
martin
I think I missed something - why is Range#size (and all its synonyms)
not in 1.7(.3)?
martin
Hi,
In message “Range#size” on 02/12/31, Martin DeMello martindemello@yahoo.com writes:
I think I missed something - why is Range#size (and all its synonyms)
not in 1.7(.3)?
Range size is not easily calculatable; imagine when both ends are
floats, or strings.
matz.
Hi,
I think I missed something - why is Range#size (and all its synonyms)
not in 1.7(.3)?Range size is not easily calculatable; imagine when both ends are
floats, or strings.
Does this mean that there’s no Range#each in 1.7 either (I am still
using 1.6.7)? It seems to me that same considerations regarding floats
or strings apply to each as well as size.
From: Gennady F. Bystritsky gfb@tonesoft.com
Date: Mon Dec 30, 2002 23:05:10 US/Pacific
To: ruby-talk@ruby-lang.org
Subject: Re: Range#size
On Monday, Dec 30, 2002, at 17:46 US/Pacific, Yukihiro Matsumoto wrote:
In message “Range#size” > on 02/12/31, Martin DeMello martindemello@yahoo.com writes:
matz.
Ah, true.
martin
Yukihiro Matsumoto matz@ruby-lang.org wrote:
Hi,
In message “Range#size” > on 02/12/31, Martin DeMello martindemello@yahoo.com writes:
I think I missed something - why is Range#size (and all its synonyms)
not in 1.7(.3)?Range size is not easily calculatable; imagine when both ends are
floats, or strings.
Range without #each would be a bit odd, I think. #each on a range of
Strings is no big deal (you can use it to calculate #size if you like.
For some reason, Range#each treats floats like integers:
irb(main):004:0> (1.1…5.9).each do |i|
irb(main):005:1* puts i
irb(main):006:1> end
1
2
3
4
5
1.1…5.9
Gavin
On Tuesday, December 31, 2002, 6:07:06 PM, Gennady wrote:
Range size is not easily calculatable; imagine when both ends are
floats, or strings.
Does this mean that there’s no Range#each in 1.7 either (I am still
using 1.6.7)? It seems to me that same considerations regarding floats
or strings apply to each as well as size.
Range size is not easily calculatable; imagine when both ends are
floats, or strings.Does this mean that there’s no Range#each in 1.7 either (I am still
using 1.6.7)? It seems to me that same considerations regarding floats
or strings apply to each as well as size.Range without #each would be a bit odd, I think. #each on a range of
Strings is no big deal (you can use it to calculate #size if you like.
For some reason, Range#each treats floats like integers:irb(main):004:0> (1.1…5.9).each do |i|
irb(main):005:1* puts i
irb(main):006:1> end
1
2
3
4
5
1.1…5.9
So why not to have Range#size simply returning a number of iterations
that Range#each would undergo, whatever algorithm is involved? However
as I understand from the initial question and Matz’s reply, Range#size
is gone completely in 1.7.
On Monday, Dec 30, 2002, at 23:26 US/Pacific, Gavin Sinclair wrote:
On Tuesday, December 31, 2002, 6:07:06 PM, Gennady wrote:
Gavin
Hi,
In message “Re: Range#size” on 02/12/31, Gennady Bystritsky bystr@mac.com writes:
So why not to have Range#size simply returning a number of iterations
that Range#each would undergo, whatever algorithm is involved? However
as I understand from the initial question and Matz’s reply, Range#size
is gone completely in 1.7.
It is removed that Enumerable#size, where enumerables may not be
iterated more than once (e.g. file streams).
Besides, since ranges are used both for interval and true range,
preferred definition of “size” varies person to person (or occasion to
occasion). How many floats in the range of 0.0 … 1.0?
matz.
Hi !
is’nt it possible to define it just for integers ? Then it is nearly downward
compatible.
Jonas Hoffmann
I wish you all a happy new Year l !
Hi,
is’nt it possible to define it just for integers ? Then it is nearly downward
compatible.
Almost everything is possible, but we have define the concrete
bahavior before making it possible.
I wish you all a happy new Year l !
Only two hours left here. Happy new year.
matz.
In message “Re: Range#size” on 02/12/31, Jonas Hoffmann ruby@joelh.de writes:
Hi,
In message “Re: Range#size”
Almost everything is possible, but we have define the concrete
bahavior before making it possible.
Yes, was it not already defined before ? I mean it is right that it makes no
sense for floatingpointranges but for Integers there is a clear size.
Only two hours left here. Happy new year.
matz.
ten to go here, counting the minutes to start the party
Jonas Hoffmann
Am Dienstag, 31. Dezember 2002 13:59 schrieb Yukihiro Matsumoto:
Hi,
In message “Re: Range#size” on 02/12/31, Jonas Hoffmann ruby@joelh.de writes:
Almost everything is possible, but we have define the concrete
bahavior before making it possible.was it not already defined before ? I mean it is right that it makes no
sense for floatingpointranges but for Integers there is a clear size.
I’m not sure whether previous definition makes sense.
matz.
hmm,
i don’t know how you defined it before (1.6.x) , it just worked with integers
and float numbers.
Now, in 1.8.0 the each Method works only if the numbers are Integers, that
makes sense for me. But if this works, why is’nt the size Method also
possible for integers ? Sure i can help me with
a = Range::new(1,5)
counter = 0
a.each { |i|
counter += 1
}
puts counter
but then the size Method should also make sense here.
Jonas Hoffmann
Am Dienstag, 31. Dezember 2002 14:22 schrieb Yukihiro Matsumoto:
I’m not sure whether previous definition makes sense.
Now, in 1.8.0 the each Method works only if the numbers are Integers,
No, for object which respond to #succ
makes sense for me. But if this works, why is'nt the size Method also
possible for integers ?
[ruby-talk:60231]
Guy Decoux
Now, in 1.8.0 the each Method works only if the numbers are Integers,
No, for object which respond to #succ
I don’t understand this. Strings respond to #succ (“A”.succ is “B”),
but they don’t work well in Ranges:
irb(main):001:0> RUBY_VERSION
=> “1.8.0”
irb(main):002:0> “A”…“Z”.each { |x| p x }
“Z”
=> “A”…“Z”
makes sense for me. But if this works, why is’nt the size Method also
possible for integers ?[ruby-talk:60231]
I think that’s an answer to a slightly different question. Matz
described why #size doesn’t make sense for file streams and Floats. I’m
still interested in hearing why it won’t work for Integers.
Paul
On Tue, Dec 31, 2002 at 11:01:27PM +0900, ts wrote:
Now, in 1.8.0 the each Method works only if the numbers are Integers,
No, for object which respond to #succ
Okay, thats okay to because Integer is a Class with #succ
makes sense for me. But if this works, why is’nt the size Method also
possible for integers ?[ruby-talk:60231]
Thats okay, but i dont understand it in this situation There is no other
way to count from one Integer to another, or ?
Perhaps i dont understand the whole discussion but for me there is no point
why range#size for integers or all the objekts with defined #succ are’nt
inwolved anymore
Jonas Hoffmann
Am Dienstag, 31. Dezember 2002 15:01 schrieb ts:
irb(main):002:0> "A".."Z".each { |x| p x }
pigeon% ruby -e '("A".."Z").each { |x| p x }'
"A"
"B"
"C"
"D"
"E"
"F"
"G"
"H"
"I"
"J"
"K"
"L"
"M"
"N"
"O"
"P"
"Q"
"R"
"S"
"T"
"U"
"V"
"W"
"X"
"Y"
"Z"
pigeon%
I think that's an answer to a slightly different question. Matz
described why #size doesn't make sense for file streams and Floats. I'm
still interested in hearing why it won't work for Integers.
An object can respond to #succ and be like a file stream, i.e. an object
that can't iterate more than once.
Guy Decoux
Perhaps i dont understand the whole discussion but for me there is no point
why range#size for integers or all the objekts with defined #succ are'nt
inwolved anymore
Because #succ can be destructive, a stupid example with 1.6.8
pigeon% cat b.rb
#!/usr/bin/ruby
class A
attr_reader :a
def initialize(x)
@a = x
end
def succ
@a.pop
A.new(@a)
end
def >(x)
a.size < x.a.size
end
def <=(x)
a.size >= x.a.size
end
def <=>(x)
a.size <=> x.a.size
end
end
r = A.new([1,2,3,4,5]) .. A.new([1])
sz = r.size
raise "error" if sz != r.size
pigeon%
pigeon% b.rb
./b.rb:29: error (RuntimeError)
pigeon%
Guy Decoux
#succ could be destructive, but destructive methods should have a !
appended. so #succ! should be destructive, while #succ, following normal
Ruby naming, should NOT be destructive.
-Justin White
just6979@yahoo.com
http://tin.2y.net/
AIM: just6979
On Friday, January 3, 2003, at 02:46 , ts wrote:
Perhaps i dont understand the whole discussion but for me there is
no point
why range#size for integers or all the objekts with defined #succ
are’nt
inwolved anymoreBecause #succ can be destructive, a stupid example with 1.6.8
It’s not as simple as that. ! methods are generally to differentiate
from non-! methods when both are provided. Many methods are plainly
destruvtive, and it would be stylistic overkill to append a !. For
example:
Array#shift,unshift,push,pop,delete,…
Gavin
On Sunday, January 5, 2003, 6:20:41 PM, Justin wrote:
Because #succ can be destructive, a stupid example with 1.6.8
#succ could be destructive, but destructive methods should have a !
appended. so #succ! should be destructive, while #succ, following normal
Ruby naming, should NOT be destructive.