goby-lang / goby

Goby - Yet another programming language written in Go
MIT License
3.49k stars 171 forks source link

Descending ranges should not return values, or return them in descending order #582

Closed 64kramsystem closed 6 years ago

64kramsystem commented 6 years ago

In Goby, descending ranges return the values in ascending orders (in Ruby, the don't return values):

Goby:

» (5..1).to_a
#» [1, 2, 3, 4, 5]
» (5..1).each do |i| puts i end
1
2
3
4
5
#» (5..1)

Ruby:

2.3.6 :001 > (5..1).to_a
 => []
2.3.6 :001 > (5..1).each do |i| puts i end
 => 5..1

I think that either they should work likey Ruby, or, they should returns descending values:

» (5..1).to_a
#» [5, 4, 3, 2, 1]
64kramsystem commented 6 years ago

@st0012 updated the title/description.

hachi8833 commented 6 years ago

Returning the descending values looks good to me:

» (5..1).to_a
#» [5, 4, 3, 2, 1]
st0012 commented 6 years ago

According to Ruby's behavior I think we should raise an error, since they are actually un-functional and returns unexpected result (at least for me (1..5).to_a shouldn't return an empty array). But descending value also works for me.

st0012 commented 6 years ago

@ear7h Can you work on this? We want descending ranges work in Ruby, let's start from making the to_a method returns right array:

» (5..1).to_a
#» [5, 4, 3, 2, 1]