Anonymous user
Define a primitive data type: Difference between revisions
→{{header|Dyalect}}
Line 591:
The code below defines a new type <code>TinyInt</code>, provides bounds checking and implementation of all standard arithmetic operators:
<lang dyalect>type TinyInt
} with Lookup, Show
▲ throw Error.Overflow(x) when x is <1 or >10
func TinyInt + (other) => TinyInt(this.value + other
func TinyInt * (other) => TinyInt(this.value * other
func TinyInt - (other) => TinyInt(this.value - other
func TinyInt / (other) => TinyInt(this.value / other
Sample usage (interactive session):
Line 620 ⟶ 613:
dy>x * 2
Operation overflows</pre>
=={{header|E}}==
|