Add the Delphi range data type
opened this issue · comments
Deleted user commented
Range-based a type is a subset of values of an integer, character , or enumerated type and is described as a..b, where a - lower, b - upper limit of the interval type, a< b:
var
intI: 0..10;
intC: 'a'..'z';
intE: Mon..Thr;
The type that a range type is based on is called the base basic type for that range type. Values of the range type occupy the same amount of memory as values of the corresponding base type.
Isaac Shelton commented
Something like this could work:
record <$T> Range (lower, upper $T) {
func includes(value $T) bool {
return this.lower <= value && value <= this.upper
}
}
import basics
func main {
uppercase_letters <ubyte> Range = Range('A'ub, 'Z'ub)
printf("uppercase_letters.includes('Q'ub) = %b\n", uppercase_letters.includes('Q'ub))
printf("uppercase_letters.includes('q'ub) = %b\n", uppercase_letters.includes('q'ub))
}
Deleted user commented
Implement everything in code (that could be packed into a library) so you don't have to extend the syntax of the language. You are so clever! Btw, I would name the method as contains
instead of includes
to keep it universal.