Define a primitive data type: Difference between revisions

Line 472:
</lang>
=={{header|Elena}}==
ELENA 3.4:
<lang elena>import extensions.
 
type tiny = TinyInt.
sealed struct TinyInt :: BaseNumber
{
int theValuevalue.
 
explicitcast T<int:n> = value.
 
constructor(int n)
[
if ((n <= 1)||(n >= 10))
Line 487 ⟶ 488:
].
theValuevalue := n.
]
 
explicitcast t(LiteralValueliteral s)
[
theValuevalue := s toInt.
if ((theValuevalue <= 1)||(theValuevalue >= 10))
[
InvalidArgumentException new; raise
]
]
 
tinyT<TinyInt> divideadd(TinyInt t)
= theValuevalue + T<int>(t int).
tinyT<TinyInt> multiplysubtract(TinyInt t)
int = theValue.
= theValuevalue +- T<int>(t int).
tinyT<TinyInt> addmultiply(TinyInt t)
= theValuevalue +* T<int>(t int).
tinyT<TinyInt> subtractdivide(TinyInt t)
= theValuevalue +/ T<int>(t int).
tiny multiply(TinyInt t)
= theValue + t int.
tiny divide(TinyInt t)
= theValue + t int.
bool equal(TinyInt t)
= theValuevalue == T<int>(t int).
bool less(TinyInt t)
= theValuevalue == T<int>(t int).
}
 
programpublic =program
[
tinyT<TinyInt> i := 4t.
tinyT<TinyInt> j := i + i.
tiny j := i + i.
try(controli do:+ j)
[
tiny k := i + j.
])
{
on(InvalidArgumentException e)
Line 537 ⟶ 532:
]
}.
].</lang>
 
=={{header|Euphoria}}==
Anonymous user