[Grace-core] Range weirdness

Andrew P. Black black at cs.pdx.edu
Tue Jul 1 15:02:18 PDT 2014


On 1 Jul 2014, at 11:44, Kim Bruce <kim at cs.pomona.edu> wrote:

> The construct (a..b) provides a list of numbers from a to b.  Thus 1..4 gives [1,2,3,4].
> 
> The question is what should happen if a and b are non-integers.  Here are some options, illustrated by 1.2 .. 5.5
> 1.  Return an error -- this is only supposed to give ranges of integers
> 2.  Return [1.2,2.2,3.2,4.2,5.2].  I.e, start with the initial value and go up to the last value <= upper bound.
> 3.  Return [1.2,2.2,3.2,4.2] ????
> 
> The third is what currently happens in Grace. It only picks up the 5.2 when the upper bound reaches 6.
> 
> Either 1 or 2 is acceptable, though I'd have a very slight preference for 1 just because it is simpler.
> 
> What do we want the answer to be and then can we make the correction?


Ranges in the collections module insist that their bounds are integers, and emit a runtime error if they are not.

I’m willing to update the compiler so that .. uses these ranges as soon as we like.  Of course, this requires that every program (that uses ..) imports collections; th obvious way to do this is to put collections in the standard prelude.

I was thinking this morning that this (implicitly importing collections) is entirely reasonable.    Every language that I have used, except Grace, provides basic collections (like arrays, or lists) built in, without having to say anything special.   When a colleague was interested in using Grace for our algorithms class, it was a real turn-off to have to say “import "collections" as coll”.

If we just make list, set, dictionary, range, etc part of the StandardPrelude, then we would not need a prefix to access them.  Bindings and Points are already in the StandardPrelude.

	Andrew

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailhost.cecs.pdx.edu/pipermail/grace-core/attachments/20140701/3ec67e6b/attachment.html>


More information about the Grace-core mailing list