Define a primitive data type: Difference between revisions

(→‎{{header|Kotlin}}: Updated example see https://github.com/dkandalov/rosettacode-kotlin for details)
Line 471:
❗ error: One-ten : type-check failure : 42 → 'f10:x'
</lang>
=={{header|Elena}}==
<lang elena>type tiny = TinyInt.
 
sealed struct TinyInt :: BaseNumber
{
int theValue.
 
explicit int:n
[
if ((n <= 1)||(n >= 10))
[
InvalidArgumentException new; raise
].
theValue := n.
]
explicit t(LiteralValue s)
[
theValue := s toInt.
if ((theValue <= 1)||(theValue >= 10))
[
InvalidArgumentException new; raise
]
]
int = theValue.
tiny add(TinyInt t)
= theValue + t.
tiny subtract(TinyInt t)
= theValue + t.
tiny multiply(TinyInt t)
= theValue + t.
tiny divide(TinyInt t)
= theValue + t.
bool equal(TinyInt t)
= theValue == t int.
bool less(TinyInt t)
= theValue == t int.
}
 
program =
[
tiny i := 4t.
tiny j := i + i.
 
try(control do:
[
tiny k := i + j.
])
{
on(InvalidArgumentException e)
[
console printLine("A value is out of range").
]
}.
].</lang>
 
=={{header|Euphoria}}==
Anonymous user