Anonymous user
Define a primitive data type: Difference between revisions
→{{header|Dyalect}}
Line 534:
The code below defines a new type <code>TinyInt</code>, provides bounds checking and implementation of all standard arithmetic operators:
<lang dyalect>type TinyInt
var value
}
func Integer.toInteger() => this
static func TinyInt.TinyInt(Integer x) {
throw "Overflow" when x is <1 or >10
}
func TinyInt.toString() => "TinyInt (\(
func TinyInt.toInteger() =>
func TinyInt + (other) => TinyInt(
func TinyInt * (other) => TinyInt(
func TinyInt - (other) => TinyInt(
func TinyInt / (other) => TinyInt(
Sample usage (interactive session):
|