Define a primitive data type: Difference between revisions

(Added Wren)
Line 535:
 
<lang dyalect>type TinyInt
 
private func getInteger(x) {
matchfunc getInteger(x) {
Integer =>match x, {
TinyInt Integer => x.toInteger(),
TinyInt => x.toInteger(),
_ => throw "Type \"\(x.getType().:name)\" is not supported by this operation."
x }
}
}
private func boundsCheck(x) {
 
if x < 1 || x > 10 {
private func boundsCheck(x) {
if x < 1 || x > 10 {throw "Overflow"
throw "Overflow."}
x
}
x
}
 
static func TinyInt.TinyInt(i) {
new(boundsCheck(Integer(i)))
}
 
func TinyInt.toString() {
valueof(this).toString()
}
 
func TinyInt.toInteger() {
valueof(this)
}
 
func TinyInt + (other) {
const z = valueof(this) + getInteger(other)
TinyInt(z)
}
 
func TinyInt * (other) {
const z = valueof(this) * getInteger(other)
TinyInt(z)
}
 
func TinyInt - (other) {
const z = valueof(this) - getInteger(other)
TinyInt(z)
}
 
func TinyInt / (other) {
const z = valueof(this) / getInteger(other)
Anonymous user