PageRenderTime 18ms CodeModel.GetById 15ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/tutorial/agent/example2.e

http://github.com/tybor/Liberty
Specman e | 34 lines | 22 code | 4 blank | 8 comment | 0 complexity | a5cc74fa00ec1c8875247b2574622466 MD5 | raw file
 1class EXAMPLE2
 2   --
 3   -- Actually, agents are available for all kinds of COLLECTION (i.e. ARRAY,
 4   -- FAST_ARRAY, LINKED_LIST, TWO_WAY_LINKED_LIST), but also for class SET
 5   -- as well as for class DICTIONARY.
 6   --
 7
 8create {ANY}
 9   make
10
11feature {ANY}
12   make
13      local
14         my_collection: COLLECTION[STRING]; my_list: LINKED_LIST[STRING]; my_set: SET[STRING]
15      do
16         my_collection := {ARRAY[STRING] 1, << "Benedicte", "Lucien", "Marie" >> }
17         create my_list.make
18         -- Using an agent to fill `my_list' using `my_collection':
19         my_collection.for_each(agent my_list.add_last(?))
20         create {HASHED_SET[STRING]} my_set.make
21         -- Using an agent to fill `my_set' with `my_list':
22         my_list.for_each(agent my_set.add(?))
23         -- Using an agent to print `my_set':
24         my_set.for_each(agent print_item(?))
25      end
26
27feature {}
28   print_item (item: STRING)
29      do
30         std_output.put_string(item)
31         std_output.put_character('%N')
32      end
33
34end -- class EXAMPLE2