Define a primitive data type: Difference between revisions
Content deleted Content added
Added Wren |
|||
Line 535:
<lang dyalect>type TinyInt
private
TinyInt => x.toInteger(),
_ => throw "Type \"\(x.getType()
}
if x < 1 || x > 10 {
▲private func boundsCheck(x) {
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)
|