lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On Wed, 22 Jun 2005 - Rici Lake wrote:

"So, if you could provide me with a sample of your Lua code, I might have a
bit more confidence in your certification program."

I'm sorry that I can't fulfill this request directly.  The Lua code that is
sufficiently complex so that it would be of interest to you is also a trade
secret for us.  (Since it is used in our business operations.)  As a
somewhat lesser substitute, here is a question from one of our practice

Given the following code:

1	x = 0
3	prod = coroutine.create(
4	function()
5	    while true do
6	        put(x)
7	        x = x + 2
8	    end
9	end)
11	cons = coroutine.create(
12	function(p)
13	    while true do
14	        get(p)
15	    end
16	end)
18	function put(x)
19	    coroutine.yield(x)
20	end
22	function get(p)
23	    local status, value = coroutine.resume(p)
24	    return value
25	end
27	coroutine.resume(prod)
28	coroutine.resume(cons, prod)
29	print(coroutine.status())

What is the output?

a) dead
b) running
c) suspended
d) There is no output.  (on the test, this is a different font so that you
can see it is an answer, not a quote of output)
e) An error occurs.	(ditto)

I'd give the answer, but programmers tend to love puzzling these things out
for themselves.  :)  Can you figure it out without running it?   

R. Grant Reed
High-Level Certifications