/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

  1. class 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. create {ANY}
  8. make
  9. feature {ANY}
  10. make
  11. local
  12. my_collection: COLLECTION[STRING]; my_list: LINKED_LIST[STRING]; my_set: SET[STRING]
  13. do
  14. my_collection := {ARRAY[STRING] 1, << "Benedicte", "Lucien", "Marie" >> }
  15. create my_list.make
  16. -- Using an agent to fill `my_list' using `my_collection':
  17. my_collection.for_each(agent my_list.add_last(?))
  18. create {HASHED_SET[STRING]} my_set.make
  19. -- Using an agent to fill `my_set' with `my_list':
  20. my_list.for_each(agent my_set.add(?))
  21. -- Using an agent to print `my_set':
  22. my_set.for_each(agent print_item(?))
  23. end
  24. feature {}
  25. print_item (item: STRING)
  26. do
  27. std_output.put_string(item)
  28. std_output.put_character('%N')
  29. end
  30. end -- class EXAMPLE2