Closed ghost closed 7 months ago
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))
}
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.
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:
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.