Tuesday, December 20, 2011

Creation procedures

Eiffel required - a quarter of century ago - explicitly provide a creation procedure for each object; so each creation was in the form of
create my_list.make_empty
Nowadays SmartEiffel allow us to write
create my_list
when a class has put default_create command in the creation clauses list such as:
class LITTLE_LIST [ITEM]
  -- A list to contain few elements
inherit COLLECTION[ITEM]
creation default_create, make, make_empty, with_capacity
...
To create collections, lists, arrays, associative dictionaries you may use the manifest notation, like this:
some_primes := {LINKED_LIST[INTEGER] <<1, 3, 5, 7, 11, 13, 17, 23>> }
dictionary := {HASHED_DICTIONARY[CHARACTER, STRING] << 'a', "key #1";
'z', "key #2";
'z', "key #3";
'a', "key #4" >> }
bijective_dictionary :=
{HASHED_BIJECTIVE_DICTIONARY[STRING, STRING]
<< "value #1", "key #1";
"value #2", "key #2";
"value #3", "key #3" >> }
Please excuse the horrible formatting of the code, I'm working on it. 

No comments:

Post a Comment