/tutorial/tuple/example1.e

http://github.com/tybor/Liberty · Specman e · 43 lines · 31 code · 4 blank · 8 comment · 0 complexity · c3b4101507fd045ffe8eafa7ea6f40b6 MD5 · raw file

  1. class EXAMPLE1
  2. --
  3. -- To start with TUPLE, just compile an run it :
  4. --
  5. -- compile -o example1 -boost example1
  6. --
  7. create {ANY}
  8. make
  9. feature {ANY}
  10. make
  11. local
  12. my_tuple: TUPLE[INTEGER_8, STRING, REAL]
  13. do
  14. -- Creation of a new TUPLE:
  15. my_tuple := [2, "Lucien", 6.5] -- Accessing:
  16. io.put_string("my_tuple.count = ")
  17. io.put_integer(my_tuple.count)
  18. io.put_string("%Nmy_tuple.item_1 = ")
  19. io.put_integer(my_tuple.item_1)
  20. io.put_string("%Nmy_tuple.item_2 = ")
  21. io.put_string(my_tuple.item_2)
  22. io.put_string("%Nmy_tuple.item_3 = ")
  23. io.put_real(my_tuple.item_3)
  24. -- Writing:
  25. my_tuple.set_item_1(3)
  26. my_tuple.set_item_2("Marie")
  27. my_tuple.set_item_3(4.5)
  28. -- Accessing:
  29. io.put_string("%Nmy_tuple.item_1 = ")
  30. io.put_integer(my_tuple.item_1)
  31. io.put_string("%Nmy_tuple.item_2 = ")
  32. io.put_string(my_tuple.item_2)
  33. io.put_string("%Nmy_tuple.item_3 = ")
  34. io.put_real(my_tuple.item_3)
  35. io.put_string("[
  36. To know more about TUPLEs, have a look at example #2.
  37. ]")
  38. end
  39. end -- class EXAMPLE1