/src/wrappers/glib/examples/do_stuff.e

http://github.com/tybor/Liberty · Specman e · 37 lines · 32 code · 4 blank · 1 comment · 3 complexity · b51cf47a79c472c01b15535d2465d0af MD5 · raw file

  1. class DO_STUFF
  2. inherit G_POOLED_ROUTINE
  3. creation
  4. make,
  5. default_create
  6. feature
  7. make (an_i: INTEGER_32) is
  8. local msg: STRING
  9. do
  10. i:=an_i
  11. msg := "Looking for "
  12. i.append_in(msg)
  13. msg.append(once ".%N")
  14. -- Warning! to_string is NOT thread safe!
  15. print(msg)
  16. end
  17. invoke (a_pool: G_THREAD_POOL[G_POOLED_ROUTINE]) is
  18. local x: like i; msg: STRING
  19. do
  20. from is_prime:=False; x:=2
  21. until not is_prime or x>=i loop
  22. is_prime := (i\\x)=0 -- rest of the division
  23. x:=x+1
  24. end
  25. msg := ""; i.append_in(msg)
  26. if is_prime then msg.append(" is prime.%N")
  27. else msg.append(" is not prime.%N")
  28. end
  29. print (msg)
  30. end
  31. i: INTEGER_32
  32. is_prime: BOOLEAN
  33. end