On Feb 1, 2:04 pm, toto <stop-aux-sp...@[EMAIL PROTECTED]
> wrote:
> ECMA allows to declare
>
> x: TUPLE[count, balance: INTEGER; name, forname: STRING]
>
> My question is: "how useful is it?".
>
> regards
Very useful for setting up lookup tables. Consider this sketch of an
enumeration (stream of consciousness code that's badly formatted and
untested, to get to the point):
class MONTH create make
feature make (a_id: INTEGER) is do id := a_id end
id: INTEGER
name: STRING is do Result := table[id].name end
long_name: STRING is do
Result := table[id].long_name
if Result = Void then
Result := name
end
end
feature {NONE} -- Implementation (the point)
table: TUPLE[id: INTEGER; name, long_name: STRING] is once
Result := <<
[ 1, "Jan", "January" ],
[ 2, "Feb", "February" ],
-- and so one
>>
end
invariant
valid_id: id >= 1 and then id <= table.count
end


|