Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does [1..5] in Rascal return [1,2,3,4]?

Tags:

rascal

I expect it to return [1,2,3,4,5] as in Haskell.

like image 980
Oscar Nierstrasz Avatar asked Jan 12 '23 11:01

Oscar Nierstrasz


1 Answers

Short answer: the left index is inclusive and the right is exclusive by design.

Long answer: the reason for the short answer is that lists are zero indexed, and we noticed everybody having to write (or forgetting to write) [0..size(myList) - 1]. Now we can write [0..size(myList)] instead. It is not like Haskell, but its like Python.

like image 84
Jurgen Vinju Avatar answered Feb 12 '23 12:02

Jurgen Vinju