cheddar-lang / Cheddar

🧀 Cheddar, the language that works for you
cheddar.vihan.org
Apache License 2.0
28 stars 9 forks source link

Range is inclusive on both ends #43

Closed Maltysen closed 8 years ago

Maltysen commented 8 years ago

Current Behavior

cheddar> 4:4
 [4]
cheddar> 2:10
 [2, 3, 4, 5, 6, 7, 8, 9, 10]

Desired Behavior

2:10 giving [2,3,4,5,6,7,8,9] and 4:4 giving []

because now, 0:n has a length of n+1, not n

ConorOBrien-Foxx commented 8 years ago

I don't see why this is a problem.

Maltysen commented 8 years ago

@ConorOBrien-Foxx array indexing, (I'm guessing, based on js) will be 0-indexed, so the ranges should also be 0-indexed, which means that the end should not be inclusive.

ConorOBrien-Foxx commented 8 years ago

Why does that follow ?

Maltysen commented 8 years ago

@ConorOBrien-Foxx what happens when you want to loop through an array of len n? the indices of that array are 0..n-1 other langs have inclusive range, but then they need to make everything 1-indexed. (example, APL)

ConorOBrien-Foxx commented 8 years ago

Okay? I still don't see your point. In a range m:n, n is often not the length of the range.

Maltysen commented 8 years ago

@ConorOBrien-Foxx but you will be indexing up to n for that array, but the last index is n-1, so the last number returned from : should be n-1

ConorOBrien-Foxx commented 8 years ago

Could you maybe rephrase? Perhaps I'll understand then.

Maltysen commented 8 years ago

@ConorOBrien-Foxx http://stackoverflow.com/questions/4504662/why-does-rangestart-end-not-include-end

ConorOBrien-Foxx commented 8 years ago

Oh, I see. It's customary.

ConorOBrien-Foxx commented 8 years ago

Fixed by making monadic range do this.