Anonymous user
Define a primitive data type: Difference between revisions
m
→{{header|Elena}}
Line 472:
</lang>
=={{header|Elena}}==
ELENA
<lang elena>import extensions
sealed struct TinyInt
{
int value
constructor(int n)
if
InvalidArgumentException
value := n
cast t(literal s)▼
[▼
value := s toInt.▼
if ((value <= 1)||(value >= 10))▼
value :=
]▼
]▼
T<TinyInt> add(TinyInt t)▼
= value + T<int>(t).▼
T<TinyInt> subtract(TinyInt t)▼
InvalidArgumentException.raise()
= value
= value
bool equal(TinyInt t)
= value ==
bool less(TinyInt t)
= value ==
}
public program▼
T<TinyInt> i := 4t.▼
T<TinyInt> j := i + i.▼
▲public program()
try(i + j)▼
{
}
{
▲ on(InvalidArgumentException e)
▲ console printLine("A value is out of range").
▲ ]
▲ }.
▲]</lang>
=={{header|Euphoria}}==
|