PageRenderTime 3ms CodeModel.GetById 1ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/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
 1class DO_STUFF
 2inherit G_POOLED_ROUTINE
 3creation
 4	make,
 5	default_create
 6feature 
 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
17	end
18	
19	invoke (a_pool: G_THREAD_POOL[G_POOLED_ROUTINE]) is
20		local x: like i; msg: STRING
21		do
22			from is_prime:=False; x:=2
23			until not is_prime or x>=i loop
24				is_prime := (i\\x)=0 -- rest of the division
25				x:=x+1
26			end
27			msg := ""; i.append_in(msg)
28			if is_prime then msg.append(" is prime.%N") 
29			else msg.append(" is not prime.%N") 
30			end
31			print (msg)
32
33		end
34
35	i: INTEGER_32
36	is_prime: BOOLEAN
37end