REBOL 3.0

Range Datatype?

Carl Sassenrath, CTO
REBOL Technologies
7-Feb-2007 20:50 GMT

Article #0058
Main page || Index || Prior Article [0057] || Next Article [0059] || 12 Comments || Send feedback

Ok, let's open the discussion about a range datatype. There have been prior talks about it. Various users are in favor of it.

The purpose of this article is to draw a conclusion with regard to 3.0 implementation.

Definition

By range I mean a series interval not a time interval.

The possible advantage of a range specification can be seen if we look at the common expression for series extraction:

copy/part at series start length

an example being:

str: "string"
str2: copy/part at str 2 3

A range datatype would shorten this to:

str2: copy/part str 2..5  ; result is "trin"

This is also valid:

range: 2..5
str2: copy/part str range

The make form of the above literal range type is:

range: make range! [2 5]

Of course, other series functions (remove, insert, etc.) could make use of the range type as well.

Powerful, dangerous?

So... it is possible for range to embed the series reference itself. This is where things get more powerful and interesting. If we allow:

str: "string"
substr: as-range str 2..5

Then, we could do this:

str: copy substr      ; "trin"
append "name" substr  ; "nametrin"

As you expect, as-range above is short for:

make range! reduce [str 2 5]

Such an implementation draws us into discussion about the meaning of forms such as:

substr: as-range str 2..5
print substr/2  ; result is r

But that's the easy one. Even more thought provoking is the issue of the datatype identity of the range above, since any series datatype could be referenced by the range. Example:

if range? substr [print "yes of course"]
if string? substr [print "probably not true, it is range!"]
if string? type-of? substr [print "a possible approach"]

So, you can see the issue. We need to think this out carefully... or even if it should be allowed.

Maybe 3.N

I will also note that this datatype is deep and odd enough that, if implemented at all, it may be pushed to a 3.n rather than 3.0.

12 Comments

REBOL 3.0
Updated 25-Dec-2024 - Edit - Copyright REBOL Technologies - REBOL.net