Is the UNTIL syntax of for ranges grammatically correct


As a native English speaker, I’ve always found the distinction between “to” and “until” a bit strange.
There has probably been a lot of discussion in the past years. But a term such as “under” rather than “until” would have seemed much more intuitive and grammatically correct to me. “Until” (in my mind, as a word in the English language) includes its limit, whereas “Under” excludes its limit.


I read “2 under 10” as a fraction 10/2. Until might not be perfect, but I don’t think that English has an ideal word for this. I can say that I’ve taught a lot of beginner programmers using Scala (almost all native English speakers) and I’ve never had a student express confusion about the use of the words “until” or “to”. They get bounds errors when they use “to” instead of “until”, but that type of behavior is to be expected, especially among novices. It is also why I often use “seq.indices” if i want to run through a sequence by index instead of saying “0 until seq.length” or “0 to seq.length-1”.


I can never remember the distinction between to and until. I rely on auto-completion in the IDE to check if the return type is Range.Inclusive or Range.Exclusive. But since “under” and “until” both start with “un” perhaps I will be able to remember it in the future.


I agree “until” is confusing. I guess it is inspired by the repeat-until
loop, which excludes the case of true condition, and which exists in some
languages (like Pascal, I believe, though not Java or Scala)


Perhaps a better word might be below. (taking inspiration from Common Lisp)

(loop for i from 0 below 256 do ....)  ;; to count upward omitting upper limit
(loop for j from 255 above -1 do ...)   ;; to count downward omitting lower limit

BTW I’ve never heard a fraction read as 2 under 10, whereas It is common to say 10 over 2.

“to” and “until” have the same meaning to me in the English language sense. Except perhaps that until puts more emphasis on the target. I’ll stay until noon, means I’ll REALLY stay until noon.


repeat-until. That’s a good way to think about it. Perhaps you’re right.


No doubt that “over” would be more common than “under”, but the mental image I get from “under” is a spatial one, and therefore I see a fraction in my head and not a sequence of values. I do think that the “until” does a good job of creating the mental image of a sequence. I can see “below” being slightly better, but I’m not certain that invokes the mental image of a sequence either without the use of “from” as well. Both “to” and “until” invoke images of time or perhaps extended distance (more so for “to”) in my head, which translates into a sequence.

Of course, when you get into the connotative meaning of words, as this conversation is doing, you run into problems because those meanings can vary regionally by usage or even among individuals in the same social group.


In middle school, the students would ask if the reading assignment to page fifteen includes page fifteen or only up to page fifteen. Clearly the problematic word is “to”.

Nowadays for solace I go to the dictionary, which says until means before.

“I’ll stay until ten” means that at ten I’m not staying, I’m going. Also, “Till death us do part” is pretty definitive.

Older and therefore more fundamental is till. And one can’t discount Till Eulenspiegel.

Thanks for bringing this up, I also have to think twice. Maybe the IDE could have a rollover or annotation, “You know this is the one that means not including 10?”

In the REPL, print-tab says,

scala> 1 to 10 //print
   scala.Predef.intWrapper(1).to(10) // : scala.collection.immutable.Range.Inclusive

scala> 1 until 10 //print
   scala.Predef.intWrapper(1).until(10) // : scala.collection.immutable.Range

So the unnamed default is Exclusive. By coincidence, the unnamed default in society is also exclusive, which is how it maintains its privilege.